vivarium-collective / vivarium-core

Core Interface and Engine for Vivarium
https://vivarium-core.readthedocs.io/
Apache License 2.0
23 stars 2 forks source link

Recalculate hashes for comparison of Units #220

Closed thalassemia closed 1 year ago

thalassemia commented 1 year ago

The __eq__ method for instances of Unit (from a pint.UnitRegistry) compares the cached hash values for the two objects (source). Since Python 3.3, hash randomization has been enabled by default, meaning different Python interpreters will almost certainly produce different hashes for the same object. This includes Python interpreters created by multiprocessing with the spawn start method (default on Mac and Windows). Thus, when division is triggered from a subprocess and passed back to the main process, a simple == comparison of two Unit instances will result in False even when they are actually identical.

I don't love the idea of accessing private attributes to recalculate this hash as I've done in this PR. Suggestions are welcome!


By creating this pull request, I agree to the Contributor License Agreement, which is available in CLA.md at the top level of this repository.