Skip to content

Scenario persistence - #3769

Merged
quaquel merged 58 commits into
mesa:mainfrom
quaquel:scenario_persistence
Jul 5, 2026
Merged

quaquel merged 58 commits into
mesa:mainfrom
quaquel:scenario_persistence

Conversation

@quaquel

@quaquel quaquel commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

As part of my ongoing work to replace the batch runner, this PR changes the way in which Scenario instances are pickled/unpickled and can be safely stored to disk. This PR is needed in preparation for storing parameter sweeps to disk.

Some background: the original implementation relied on the initial state dict of the numpy bit generator. This works, but this state dict might not cleanly be saved in e.g., a JSON or CSV file because it relies on numpy dtypes. Due to numerical precision, integers might be lost in a round trip. This in turn will invalidate any attempt to exactly replicate a given run.

After some more in depth digging, this PR implements a much cleaner approach to achieve the same end. It takes the state information from the underlying seed sequence and the class of the bit generator. The advantage of this is that the state information of the seed sequence are simple integers and thus will survive a round trip to e.g., a JSON or CSV file

This PR branches from the parallel running branch (#3767) so the diff might seem larger than is actually the case. It also means that #3767 should be merged prior to this one.

quaquel and others added 30 commits June 18, 2026 14:30
pre-commit-ci Bot and others added 18 commits June 26, 2026 18:33
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.1% [-1.8%, -0.4%] 🔵 +0.3% [+0.1%, +0.6%]
BoltzmannWealth large 🔵 -2.1% [-2.7%, -1.4%] 🔵 -1.3% [-4.7%, +2.4%]
Schelling small 🔵 +0.6% [-0.2%, +1.4%] 🔵 +0.3% [-0.6%, +1.1%]
Schelling large 🔵 +1.7% [+0.8%, +2.6%] 🔴 +6.5% [+4.2%, +8.3%]
WolfSheep small 🔵 +0.9% [+0.4%, +1.4%] 🔵 +1.5% [-2.2%, +5.2%]
WolfSheep large 🔵 +1.2% [-0.4%, +2.6%] 🔵 +5.4% [+2.4%, +8.4%]
SugarscapeG1mt small 🔵 -0.3% [-1.0%, +0.4%] 🔵 +0.6% [-0.8%, +2.1%]
SugarscapeG1mt large 🔵 +2.1% [+0.4%, +4.1%] 🔵 +3.0% [+0.9%, +5.5%]
BoidFlockers small 🔵 +2.2% [+1.5%, +2.9%] 🔵 +2.7% [+2.2%, +3.2%]
BoidFlockers large 🔵 -1.6% [-2.1%, -1.1%] 🔵 +0.9% [+0.6%, +1.3%]

@quaquel
quaquel marked this pull request as ready for review July 4, 2026 19:43
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +1.4% [+0.8%, +2.0%] 🔵 +2.9% [+2.4%, +3.3%]
BoltzmannWealth large 🔵 -2.2% [-3.1%, -1.3%] 🔵 +0.8% [+0.3%, +1.3%]
Schelling small 🔵 +0.3% [-0.2%, +0.8%] 🔵 -1.4% [-2.1%, -0.7%]
Schelling large 🔵 -0.9% [-1.5%, -0.2%] 🔵 -0.2% [-1.0%, +0.6%]
WolfSheep small 🔵 -0.8% [-1.1%, -0.4%] 🔵 -0.8% [-4.9%, +3.5%]
WolfSheep large 🔵 -1.1% [-1.5%, -0.5%] 🔵 -0.6% [-1.8%, +0.5%]
SugarscapeG1mt small 🔵 +0.9% [+0.5%, +1.4%] 🔵 +1.3% [-0.1%, +2.7%]
SugarscapeG1mt large 🔵 +0.3% [-1.3%, +1.7%] 🔵 +1.3% [-0.3%, +2.9%]
BoidFlockers small 🔵 +1.1% [+0.5%, +1.6%] 🔵 +0.5% [+0.0%, +0.9%]
BoidFlockers large 🔵 +1.9% [+1.3%, +2.4%] 🔵 +0.5% [+0.1%, +0.8%]

@tpike3 tpike3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see no issues, LGTM

@quaquel
quaquel merged commit d7dd691 into mesa:main Jul 5, 2026
11 checks passed
@quaquel
quaquel deleted the scenario_persistence branch July 6, 2026 05:38
@EwoutH EwoutH mentioned this pull request Nov 15, 2026
53 of 65 tasks
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.

2 participants