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

V0.3.0 #418

Merged
merged 22 commits into from Feb 2, 2024
Merged

V0.3.0 #418

merged 22 commits into from Feb 2, 2024

Conversation

peterrrock2
Copy link
Collaborator

This should be the main PR for v0.3.0. Below is a summary of the proposed release notes:

What's Changed

  • Major updates have been made to all of the documentation to try to make it

    (i) More complete
    (ii) More accessible for new Python users

  • Bipartition Tree now has max_attempts default set to 100000 to prevent infinite loop conditions, but this value should also give plenty of time to sample sufficiently from the set of spanning trees.

  • The recom method now has functionality for running region-aware chains which allow for the construction of ensembles of districting plans that try not to split a particular region or set of regions

    • An updater tally_region_splits has been added to make quick tallying of the number of splits of a region type easy
  • Many of the issue tickets have been resolved. See below for more info.

Deprecations

  • Installation through conda-forge is no longer supported
  • Python 3.8 is no longer supported due to deprecated support in dependencies

Resolved Issues

Regarding the deletion of the random.py file: this is
a fix for issue #364.

The problem that the inclusion of the
random.py file was supposed to address was the issue of
reproducibility of Markov chain, and the idea was to set
the global random seed to 2018 at any point where we
would like to import the random module internally within
the gerrychain package. However, this approach also causes
the trees that are generated by the tree.py file to be
fixed if the user does not set the random seed after
the import of the gerrychain package. So an import pattern of

import random
random.seed(0)
import gerrychain
print(random.random())
print(random.random())

will output

0.5331579307274593
0.02768951210200299

as opposed to the expected

0.8444218515250481
0.7579544029403025

will actually force the random seed to be 2018 rather than the
expected 0. This can often cause issues in jupyter notebooks
where the user is not aware that the random seed has been forcibly
set to 2018 after the import of gerrychain. Instead, it is best
to allow to user to set the random seed themselves, and to not
forcibly set the random seed within the gerrychain package
since that can affect the execution of other packages and
can cause the chain to hang when the 2018 seed does not produce
a valid tree.

This issue does not appear if we remove the random.py file
and instead use the random module from the standard library
within the tree.py and accept.py files. This is because of
how python handles successive imports of the same module.
Consider the following snipit:

import random
random.seed(0)
import random
print(random.random())
print(random.random())

This will output

0.8444218515250481
0.7579544029403025

as expected. This is because the random module is only imported once
and then places its name in the internal list of imported modules.
Subsequent imports of the random module within the same python
session will not will simply retrieve the module from the list
and will not re-execute the code contained within the module.
Thus, the random seed is only set once and not reset when the
random module is imported again.

In terms of reproducibility, this means that the user will
be required to set the random seed themselves if they want
to reproduce the same chain, but this is a relatively
standard expectation, and will be required when we move
the package over to a rust backend in the future.
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

Attention: 39 lines in your changes are missing coverage. Please review.

Comparison is base (627e6c6) 88.88% compared to head (ea56d4e) 91.88%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #418      +/-   ##
==========================================
+ Coverage   88.88%   91.88%   +3.00%     
==========================================
  Files          39       38       -1     
  Lines        1790     1911     +121     
==========================================
+ Hits         1591     1756     +165     
+ Misses        199      155      -44     
Files Coverage Δ
gerrychain/__init__.py 81.25% <100.00%> (+1.25%) ⬆️
gerrychain/accept.py 55.55% <100.00%> (ø)
gerrychain/constraints/__init__.py 100.00% <100.00%> (ø)
gerrychain/constraints/contiguity.py 96.59% <100.00%> (ø)
gerrychain/graph/__init__.py 100.00% <ø> (ø)
gerrychain/graph/adjacency.py 89.47% <100.00%> (+0.58%) ⬆️
gerrychain/graph/geo.py 100.00% <100.00%> (ø)
gerrychain/grid.py 80.51% <100.00%> (+6.40%) ⬆️
gerrychain/meta/__init__.py 100.00% <100.00%> (ø)
gerrychain/meta/diversity.py 100.00% <100.00%> (ø)
... and 28 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 627e6c6...ea56d4e. Read the comment docs.

@peterrrock2
Copy link
Collaborator Author

Codecov Report

Attention: 39 lines in your changes are missing coverage. Please review.

Comparison is base (627e6c6) 88.88% compared to head (06350dd) 91.88%.

❗ Current head 06350dd differs from pull request most recent head 000fbfb. Consider uploading reports for the commit 000fbfb to get more accurate results

Additional details and impacted files

Ignore this. The code coverage has gone up compared to base and several tests were added for this release

@peterrrock2 peterrrock2 merged commit 314f414 into main Feb 2, 2024
3 checks passed
@peterrrock2 peterrrock2 deleted the v0.3.0 branch February 2, 2024 17:20
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.

None yet

2 participants