Migrate tutorials and examples to model.run_for()#3270
Merged
Conversation
|
Performance benchmarks:
|
Member
|
Thanks for working on this. I will look into it after #3266 is merged. |
Member
|
#3266 is merged. Go ahead and update/rebase this PR! |
EwoutH
reviewed
Feb 11, 2026
4972894 to
810f0c4
Compare
Removed test for model.run_for() method.
EwoutH
approved these changes
Feb 11, 2026
Member
EwoutH
left a comment
There was a problem hiding this comment.
For now this is great, thanks.
Of course at some point the tutorial on Agent activation, event scheduling and time progression has to be actually rewritten.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates Mesa's tutorials, examples, and benchmarks to use the new
Model.run_for()method. It replaces manualfor _ in range(N): model.step()loops with a single, unified call tomodel.run_for(N).Motive
With the introduction of event-based scheduling, running a model for a specific duration should be handled by the model's internal time-advancement mechanism rather than external loops. Manual loops calling
.step()can lead to inconsistencies when models use discrete-event simulators.model.run_for()provides a declarative, robust, and unified way to advance a simulation regardless of the underlying scheduling mechanism.Implementation
docs/tutorials/to userun_for()which was introduced in Add public event scheduling and time advancement methods #3266 . This involved updating both the code cells and the surrounding markdown explanation to reflect the recommended usage.benchmarks/global_benchmark.pyto usemodel.run_for(). This significantly simplified the code by removing the need to check if a model was using aSimulatoror a standard loop.tests/examples/test_examples.pyto replace repetitive test loops with conciserun_for()calls.run_for()correctly increments both model steps and simulation time.Usage Examples
Legacy Pattern:
New Pattern:
Additional Notes