model: Move random seed and random to __init__
Given that super().__init__() is now necessary for user's model class __init__(), the main motivation: this simplifies the Model construct.
And model.random can be initialized with other RNG objects (np.random.default_rng(...), or any other RNG).
Prior discussion https://github.com/projectmesa/mesa/discussions/1938.
This is a breaking change and should wait until Mesa 3.0.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
0bd4429) 79.87% compared to head (ed9b5aa) 79.82%.
Additional details and impacted files
@@ Coverage Diff @@
## main #1940 +/- ##
==========================================
- Coverage 79.87% 79.82% -0.05%
==========================================
Files 15 15
Lines 1267 1264 -3
Branches 277 277
==========================================
- Hits 1012 1009 -3
Misses 216 216
Partials 39 39
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Why would this have to wait for 3.0? I am not sure I understand how this is a breaking change?
Because this PR requires mandatory model super().__init__, which is an API breaking change. Mesa 2.2.x recommends having model super().__init__(), but is not necessary.
I forgot that #2026 hasn't been released as a patch release. cc: @EwoutH we need #2026 in a patch release so that 2.2.x is backward compatible with 2.1.x.
2.3 is released, so we can start with 3.0 development work, including moving this PR forward!
@jackiekazil This PR looks good; the ruff failure appears to be outside the code change and I assume it will go away once main is merged into it.