Skip to content

tests: Resolved "Missing Random Number Generator" warnings#2911

Merged
EwoutH merged 1 commit intomesa:mainfrom
ShreyasN707:issue-2.1
Dec 3, 2025
Merged

tests: Resolved "Missing Random Number Generator" warnings#2911
EwoutH merged 1 commit intomesa:mainfrom
ShreyasN707:issue-2.1

Conversation

@ShreyasN707
Copy link
Copy Markdown
Contributor

Summary

Resolved "Missing Random Number Generator" warnings in the test suite by explicitly passing a random number generator to grid instantiations.

Bug / Issue

DiscreteSpace subclasses (such as OrthogonalMooreGrid, HexGrid, Network, and VoronoiGrid) emit a UserWarning: Random number generator not specified when instantiated without a random parameter. This warning highlights potential non-reproducibility in models. The goal was to resolve these warnings within the project's tests.

Implementation

Updated the following test files to explicitly pass random=random.Random(42) during grid instantiation:

  • tests/test_space_renderer.py
  • tests/test_space_drawer.py
  • tests/test_solara_viz.py

This ensures that the tests are reproducible and eliminates the warnings.

Testing

Verified the fix by running the relevant tests using pytest:
pytest tests/test_discrete_space.py tests/test_space_renderer.py tests/test_space_drawer.py tests/test_solara_viz.py

All tests passed successfully.

Additional Notes

No changes were made to the core library logic; only test files were modified to adhere to the requirement of explicit RNG specification.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2025

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔴 +6.7% [+5.8%, +7.7%] 🔵 -1.1% [-1.2%, -1.0%]
BoltzmannWealth large 🔵 +1.1% [+0.5%, +1.8%] 🔴 +7.7% [+6.3%, +9.2%]
Schelling small 🔵 -0.2% [-0.4%, -0.0%] 🔵 +0.2% [+0.1%, +0.4%]
Schelling large 🔵 -1.8% [-2.4%, -1.3%] 🔵 -1.8% [-3.2%, -0.6%]
WolfSheep small 🔵 -1.6% [-1.9%, -1.2%] 🔵 -1.9% [-2.1%, -1.7%]
WolfSheep large 🔵 -3.5% [-4.2%, -2.7%] 🟢 -6.5% [-7.6%, -5.4%]
BoidFlockers small 🔵 +0.6% [-0.0%, +1.2%] 🔵 +0.6% [+0.4%, +0.7%]
BoidFlockers large 🔵 +0.4% [-0.0%, +0.9%] 🔵 -0.1% [-0.3%, +0.1%]

@ShreyasN707
Copy link
Copy Markdown
Contributor Author

@EwoutH Please review my PR.

@EwoutH EwoutH requested a review from quaquel December 2, 2025 19:37
@EwoutH EwoutH added the testing Release notes label label Dec 2, 2025
@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Dec 2, 2025

Thanks for the PR, nice and clean!

@quaquel can you confirm this is the best practice on passing random? Didn’t we have mesa.random or something?

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Dec 3, 2025

looks good to me

@EwoutH EwoutH changed the title solved the warning issues tests: Resolved "Missing Random Number Generator" warnings Dec 3, 2025
@EwoutH EwoutH merged commit be2e704 into mesa:main Dec 3, 2025
13 checks passed
@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Dec 3, 2025

@ShreyasN707 thanks!

@ShreyasN707
Copy link
Copy Markdown
Contributor Author

@ShreyasN707 thanks!

Sure I would be very happy to contribute more .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants