Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 wrap-up #117

Merged
merged 22 commits into from
Feb 24, 2020
Merged

Python 3 wrap-up #117

merged 22 commits into from
Feb 24, 2020

Conversation

smmaurer
Copy link

@smmaurer smmaurer commented Oct 16, 2019

This PR wraps up the Python 3 compatibility work with some cleanup and additional testing. I've merged all the individual changes into a single staging branch that can run in Python 3.6, and also updated some ancillary files like setup.py and requirements.txt.

My recommendation would be to merge the underlying PRs first — #101, #102, #114, #116 — and then evaluate whether this PR should be merged as-is, or reimplemented to be cleaner.

Dependencies

Running the model in Python 3.6 requires newer versions of several of the dependencies that are pinned in requirements.txt (they were frozen in place for the prior PBA, I think):

  • pandana v0.3+
  • urbansim v3.1+
  • urbansim_defaults v0.2+

My suggestion here is to maintain multiple lists of requirements -- a general one in setup.py that avoids pinning version numbers as much as possible, and then task-specific requirements.txt files when you need to guarantee that the environment is identical across many runs.

The way this works is that setup.py is the official installation script -- if you install baus and the dependencies aren’t in place yet, the package manager will automatically get the latest versions of them. requirements.txt is a stand-alone environment description file (and can be named anything you want). If you feed it to Pip or Conda before installing baus, you’ll get the specific versions that are listed.

pip install -r requirements.txt  # optional, to get specific versions
pip install -e .  # installs baus

Here's the updated setup.py. I renamed the old requirements.txt to requirements-2017.txt, and added a new requirements-2019.txt that lists current versions of all the dependencies.

Travis tests

Automated tests run on travis-ci.org whenever code is pushed to Github. Currently it's checking whether code meets the PEP8 style guidelines, and running a couple of small unit tests.

In this PR i cleaned up the Travis script to make it much simpler, while still doing the same things. It also now checks whether baus can be installed solely by running the setup script (which didn't work before, because the dependencies were listed somewhere else).

Travis is now set up to run its tests in both Python 2.7 and 3.6, so if we add additional logic later on it will be tested on both platforms.

(The tests are failing in Python 2.7 right now for an unrelated reason: UDST/orca#41)

Testing the Python 3 updates

Now that we’re able to run the model in Python 3, we want to confirm that the forecast results are equivalent to running it in Python 2.7.

Using a random seed doesn’t work in this case, because there are so many changes to the underlying code paths -- so i ran the same model three times, twice in Python 2.7 and once in Python 3.6, and compared the results. (Mac, Scenario 4, running to 2015.)

Comparing the total households by jurisdiction in 2015 (runXX_juris_summaries_2015.csv: tothh):

  • mean difference between the Python 2.7 runs (with different random seeds) was 0, with a standard deviation of 261
  • mean difference between the first Python 2.7 run and the Python 3.6 run was 0, with a standard deviation of 111

So, the effect of shifting to Python 3 is in line with what we'd expect from normal stochasticity.

@mkreilly mkreilly changed the base branch from master to ft_python_3x December 23, 2019 21:22
@smmaurer smmaurer mentioned this pull request Feb 3, 2020
5 tasks
@smmaurer smmaurer changed the base branch from ft_python_3x to master February 24, 2020 05:12
@smmaurer smmaurer merged commit 0bb1906 into BayAreaMetro:master Feb 24, 2020
@theocharides
Copy link

theocharides commented Mar 31, 2020

I was able to get requirements-2019.txt installed with Windows, in a new conda environment using conda install --yes --file requirements-2019.txt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants