Skip to content

Commit

Permalink
Merge pull request #577 from JoeJimFlood/fix_gen_random_seed
Browse files Browse the repository at this point in the history
Fixed random seed generator to generate unsigned integers instead of …
  • Loading branch information
jpn-- authored Dec 10, 2022
2 parents f01e8ac + 067c717 commit d137b36
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 49 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/core_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,59 @@ jobs:
run: |
python -m pytest activitysim/examples/${{ matrix.region }}/test --durations=0
random_seed_generation:
needs: foundation
env:
mamba-env-prefix: /usr/share/miniconda3/envs/asim-test
python-version: 3.9
label: linux-64
defaults:
run:
shell: bash -l {0}
name: random_seed_generation_test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: asim-test
use-mamba: true
python-version: ${{ env.python-version }}

- name: Set cache date for year and month
run: echo "DATE=$(date +'%Y%m')" >> $GITHUB_ENV

- uses: actions/cache@v2
with:
path: ${{ env.mamba-env-prefix }}
key: ${{ env.label }}-conda-${{ hashFiles('conda-environments/github-actions-tests.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
id: cache

- name: Update environment
run: mamba env update -n asim-test -f conda-environments/github-actions-tests.yml
if: steps.cache.outputs.cache-hit != 'true'

- name: Install activitysim
# installing without dependencies is faster, we trust that all needed dependencies
# are in the conda environment defined above. Also, this avoids pip getting
# confused and reinstalling tables (pytables).
run: |
python -m pip install -e . --no-deps
- name: Conda checkup
run: |
mamba info -a
mamba list
- name: Test Random Seed Generation
run: |
python -m pytest test/random_seed/test_random_seed.py --durations=0
estimation_mode:
needs: foundation
env:
Expand Down
112 changes: 65 additions & 47 deletions HOW_TO_RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
01. Check that the branch you intend to release is passing tests on Travis.
If it's not passing there you should not release it.

00. Start from a completely clean conda environment
and git repository. Assuming you have `conda` installed, you can do so
by starting where ActivitySim is not yet cloned (e.g. in an empty
00. Start from a completely clean conda environment
and git repository. Assuming you have `conda` installed, you can do so
by starting where ActivitySim is not yet cloned (e.g. in an empty
directory) and running:
```sh
conda create -n TEMP-ASIM-DEV python=3.9 git gh -c conda-forge --override-channels
Expand All @@ -19,7 +19,7 @@

00. Per project policy, code on the main branch should have been released,
but if you are *preparing* a release then the code should be on the `develop`
branch. Switch to that branch now, and make sure it is synced to the
branch. Switch to that branch now, and make sure it is synced to the
version on GitHub:
```sh
git switch develop
Expand All @@ -28,46 +28,45 @@

00. Update your Conda environment for testing. We do not want to use an
existing environment on your machine, as it may be out-of-date
and we want to make sure everything passes muster using the
and we want to make sure everything passes muster using the
most up-to-date dependencies available. The following command
will update the active environment (we made this to be `TEMP-ASIM-DEV`
will update the active environment (we made this to be `TEMP-ASIM-DEV`
if you followed the directions above).
```sh
conda env update --file=conda-environments/activitysim-dev.yml
```
If you add to the ActivitySim dependencies, make sure to also update
the environments in `conda-environments`, which are used for testing
and development. If they are not updated, these environments will end
If you add to the ActivitySim dependencies, make sure to also update
the environments in `conda-environments`, which are used for testing
and development. If they are not updated, these environments will end
up with dependencies loaded from *pip* instead of *conda-forge*.

00. Run `black` to ensure that the codebase passes minimal style checks.
00. Run pycodestyle to ensure that the codebase passes all style checks.
This check should only take a few seconds. These checks are also done on
GitHub Actions and are platform independent, so they should not be necessary to
Travis and are platform independent, so they should not be necessary to
replicate locally, but are listed here for completeness.
```sh
black --check --diff .
pycodestyle .
```

00. Run the regular test suite on Windows. Most GitHub Actions tests are done on Linux,
Linux (it's faster to start up and run a new clean VM for testing) but most
users are on Windows, and the test suite should also be run on Windows to
ensure that it works on that platform as well. If you
00. Run the regular test suite on Windows. Travis tests are done on Linux,
but most users are on Windows, and the test suite should also be run
on Windows to ensure that it works on that platform as well. If you
are not preparing this release on Windows, you should be sure to run
at least through this step on a Windows machine before finalizing a
release.
A few of the tests require pre-created data that is not included in the
repository directly, but rather recreated on the fly before testing. The
regular test suite takes some time to run, between about half an hour and
at least through this step on a Windows machine before finalizing a
release.
A few of the tests require pre-created data that is not included in the
repository directly, but rather recreated on the fly before testing. The
regular test suite takes some time to run, between about half an hour and
two hours depending on the specs of your machine.
```sh
python activitysim/examples/placeholder_multiple_zone/scripts/two_zone_example_data.py
python activitysim/examples/placeholder_multiple_zone/scripts/three_zone_example_data.py
pytest .
```
00. Test the full-scale regional examples. These examples are big, too
large to run on GitHub Actions, and will take a lot of time (many hours) to
large to run on Travis, and will take a lot of time (many hours) to
download and run.
```sh
mkdir tmp-asim
Expand All @@ -77,41 +76,68 @@
call run_all_examples.bat
```
These tests will run through the gamut even if some of them crash, so
if you don't sit and watch them go (please don't do this) you'll need
if you don't sit and watch them go (please don't do this) you'll need
to scan through the results to make sure there are no errors after the
fact.
```sh
python ../activitysim/examples/scan_examples_for_errors.py .
```
00. Test the notebooks in `activitysim/examples/prototype_mtc/notebooks`.
There are also demo notebooks for estimation, but their functionality
There are also demo notebooks for estimation, but their functionality
is completely tested in the unit tests run previously.
00. For non-development releases, open a pull request to merge the proposed
release into main. The following command will open a web browser for
00. Use bump2version to tag the release commit and update the
version number. The following code will generate a "patch" release,
incrementing the third value in the version number (i.e. "1.2.3"
becomes "1.2.4"). Alternatively, make a "minor" or "major" release.
The `--list` command will generate output to your console to confirm
that the old and new version numbers are what you expect, before you
push the commit (with the changed version in the code) and tags to
GitHub.
```sh
bump2version patch --list
```
It is also possible to make a development pre-release. To do so,
explicitly set the version number to the next patch plus a ".devN"
suffix:
```sh
bump2version patch --new-version 1.2.3.dev0 --list
```
Then, when ready to make a "final" release, set the version by
explicitly removing the suffix:
```sh
bump2version patch --new-version 1.2.3 --list
```
00. Push the tagged commit to GitHub.
```sh
git push --tags
```
00. For non-development releases, open a pull request to merge the proposed
release into main. The following command will open a web browser for
you to create the pull request.
```sh
gh pr create --web
```
After creating the PR, confirm with the ActivitySim PMC that the release
is ready before actually merging it.

Once final approval is granted, merge the PR into main. The presence
of the git tags added earlier will trigger automated build steps to
prepare and deploy the release to pypi and conda-forge.

00. Create a "release" on GitHub.
```sh
gh release create v1.2.3
```
The process of creating and tagging a release will automatically
trigger various GitHub Actions scripts to build, test, and publish the
new release to PyPI and conda forge, assuming there are no errors.

For a development pre-release, include the `--prerelease` argument.
As the project's policy is that only formally released code is merged
to the main branch, any pre-release should also be built against a
to the main branch, any pre-release should also be built against a
non-default branch. For example, to pre-release from the `develop`
branch:
```sh
Expand All @@ -121,19 +147,11 @@
--notes "this pre-release is for a cool new feature" \
--title "Development Pre-Release"
```
00. Clean up your workspace, including removing the Conda environment used for
testing (which will prevent you from accidentally using an old
00. Clean up your workspace, including removing the Conda environment used for
testing (which will prevent you from accidentally using an old
environment when you should have a fresh up-to-date one next time).
```sh
conda deactivate
conda env remove -n TEMP-ASIM-DEV
```
00. Change the default redirect page for the ActivitySim documentation to point
to the newly released documentation. The redirect page can be edited
[here](https://github.com/ActivitySim/activitysim/blob/gh-pages/index.html).
00. Add the new release to the `switch.json` file. Don't delete the references
for existing old documentation. The switcher can be edited
[here](https://github.com/ActivitySim/activitysim/blob/gh-pages/switcher.json).
```
2 changes: 1 addition & 1 deletion activitysim/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def pipeline_file_name(settings):

@inject.injectable()
def rng_base_seed():
return 0
return setting("rng_base_seed", 0)


@inject.injectable(cache=True)
Expand Down
2 changes: 1 addition & 1 deletion activitysim/core/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def set_base_seed(self, seed=None):
assert len(list(self.channels.keys())) == 0

if seed is None:
self.base_seed = np.random.RandomState().randint(_MAX_SEED)
self.base_seed = np.random.RandomState().randint(_MAX_SEED, dtype=np.uint32)
logger.debug("Set random seed randomly to %s" % self.base_seed)
else:
logger.debug("Set random seed base to %s" % seed)
Expand Down
2 changes: 2 additions & 0 deletions test/random_seed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Configuration files created by test
configs_random_seed_*/
15 changes: 15 additions & 0 deletions test/random_seed/simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ActivitySim
# See full license in LICENSE.txt.

import argparse
import sys

from activitysim.cli.run import add_run_args, run

if __name__ == "__main__":

parser = argparse.ArgumentParser()
add_run_args(parser)
args = parser.parse_args()

sys.exit(run(args))
Loading

0 comments on commit d137b36

Please sign in to comment.