Skip to content

Fix for Model.reset_rng#2946

Merged
quaquel merged 6 commits intomesa:mainfrom
quaquel:fix_rng
Dec 11, 2025
Merged

Fix for Model.reset_rng#2946
quaquel merged 6 commits intomesa:mainfrom
quaquel:fix_rng

Conversation

@quaquel
Copy link
Copy Markdown
Member

@quaquel quaquel commented Dec 11, 2025

Summary

Model.reset_rng did not correctly reset to the original seed if called with seed=None.

Bug / Issue

This closes #2940.

Implementation

Use Model._rgn, which contains the state information about the numpy random number generator that is being used. The code ensures that not only the seed value is reused, but also the correct BitGenerator is used.

Testing

added 2 tests that cover the bug

@quaquel quaquel added the bug Release notes label label Dec 11, 2025
@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🟢 -5.4% [-6.0%, -4.7%] 🔵 +1.1% [+1.0%, +1.3%]
BoltzmannWealth large 🔵 +0.3% [-1.9%, +3.7%] 🔵 -2.4% [-4.3%, -0.8%]
Schelling small 🔵 +0.9% [-0.0%, +1.9%] 🔵 +1.5% [+1.0%, +2.1%]
Schelling large 🔵 +0.8% [-2.3%, +4.2%] 🔵 +1.5% [+1.0%, +2.0%]
WolfSheep small 🔵 -3.3% [-4.9%, -1.9%] 🔵 +0.3% [+0.1%, +0.4%]
WolfSheep large 🔵 -0.2% [-0.5%, +0.1%] 🔵 +0.8% [-0.4%, +1.8%]
BoidFlockers small 🔵 -1.4% [-1.9%, -0.8%] 🔵 -0.4% [-0.9%, +0.0%]
BoidFlockers large 🔵 -1.9% [-2.6%, -1.1%] 🔵 +0.1% [-0.1%, +0.3%]

Copy link
Copy Markdown
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! One comment

@quaquel
Copy link
Copy Markdown
Member Author

quaquel commented Dec 11, 2025

@EwoutH clever solution, now I just need an approval and this can be merged.

Copy link
Copy Markdown
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Saves a bit on maintenance.

Could you briefly write up this bugfix following our template?

@quaquel
Copy link
Copy Markdown
Member Author

quaquel commented Dec 11, 2025

test seems to be failing will check in an hour

@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Dec 11, 2025

It seems to be the codecovconfig, not the tests. Probably due the org name change.

@quaquel
Copy link
Copy Markdown
Member Author

quaquel commented Dec 11, 2025

The tests are failling because of problems with uploading the coverage information. @EwoutH this might be related to the mesa move. Do you have time to check?

@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Dec 11, 2025

Tried some stuff, didn't help.

Apparently it sometimes takes a few days after a organization name change. We can ignore it for now.

macOS is an upstream NetworkX meets Python 3.14.1 bug. Will be fixed upstream.

We don't have any required checks, so go ahead and merge.

@quaquel quaquel merged commit a320b79 into mesa:main Dec 11, 2025
10 of 25 checks passed
@quaquel quaquel deleted the fix_rng branch December 11, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model.reset_rng() creates new RNG instead of restoring initial state

2 participants