Skip to content

Add a RunConfiguration class for parameter sweeps - #3753

Merged
quaquel merged 14 commits into
mesa:mainfrom
quaquel:runners
Jun 23, 2026
Merged

quaquel merged 14 commits into
mesa:mainfrom
quaquel:runners

Conversation

@quaquel

@quaquel quaquel commented Jun 19, 2026

Copy link
Copy Markdown
Member

This PR adds a new RunConfiguration class. This class encapsulates the logic of instantiating a model, running it for a single scenario, and extracting user specifiable output from the run. This PR is part of the larger project of replacing the batch runner with a more flexible and powerful alternative. For detailed background, see #3483, and specifically #3483 (comment)

The RunConfiguration class is designed to be subclassable, but it makes some default assumptions and provides keyword arguments to control its basic behavior to cover the most common use cases.

  • The class using model.run_until with a user specifiable end time
  • It extracts all or the user specified output from the data_recorder. The attribute to which the recorder is assigned defaults to data_recorder but this is currently controllable via a keyword argument
  • additional arguments and keyword arguments necessary to instantiate a model can also be passed to RunConfiguration.

User subclassing can be done by overriding any of the three methods:

  • instantiate_model - handles model instantiation
  • run_model - handles running the model
  • extract_output - handles the extraction and any post processing the user wants to do.

It is likely that parts of this class will be refined in future PRs. Most notably, extract_output is currently a basic implementation which is likely to be expanded when working out the storage solution for parameter sweeps.

@quaquel quaquel added experimental Release notes label enhancement Release notes label labels Jun 19, 2026
@EwoutH
EwoutH self-requested a review June 19, 2026 08:36
@EwoutH
EwoutH requested a review from codebreaker32 June 19, 2026 08:36
@EwoutH

EwoutH commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

Make sense I think. The default use-case (for a single sweep) would be creating a single RunConfiguration, and then varying multiple Scenarios within that right?

So if I'm doing two experiments (that each answer a different subquestion in my research), I probably have two RunConfigurations, with each a (larger) set of scenario's, that can be either created manually or using some sort of (external library for) sampling?

(some use cases with minimal API examples might be useful here)

@quaquel

quaquel commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Make sense I think. The default use-case (for a single sweep) would be creating a single RunConfiguration, and then varying multiple Scenarios within that right?

Yes

So if I'm doing two experiments (that each answer a different subquestion in my research), I probably have two RunConfigurations, with each a (larger) set of scenario's, that can be either created manually or using some sort of (external library for) sampling?

Whether you need separate RunConfigurations will depend on the specifics. It is only needed if how you run the model or how you extract data is different

(some use cases with minimal API examples might be useful here)

I did not want to repeat everything here so see #3483 (comment)

@quaquel

quaquel commented Jun 21, 2026 •

Copy link
Copy Markdown
Member Author

If it is helps, the overall API will look roughly like this

# generate samples with scipy.qmc or salib

scenarios = MyScenario.from_dataframe(samples, rng=42, replications=10)
run_config = RunConfig(MyModel, until=150)

with ProcessPoolExecutor() as executor:
    results = run_scenarios(scenarios, run_config, executor=executor, store=InMemoryStore())

@tpike3

tpike3 commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

@quaquel This is really cool! I am just catching up and reading #3483 this draws a really nice boundary on what Mesa does and doesn't do.

It will take me a day or 2, but I have some minor thoughts on the code (e.g., should we consider this edge case or not etc), but this is really great!

@codebreaker32

Copy link
Copy Markdown
Collaborator

Looks great to me so far! Eagerly waiting for Store protocol 😀

@quaquel

quaquel commented Jun 22, 2026 •

Copy link
Copy Markdown
Member Author

Eagerly waiting for Store protocol

I hope to open a draft PR somewhere this week with run_scenarios, the Store protocol, and a working implementation of InMemoryStore.

Comment thread mesa/experimental/scenarios/runner.py Resolved
Comment thread mesa/experimental/scenarios/runner.py Resolved
Comment thread mesa/experimental/scenarios/runner.py Resolved
@tpike3

tpike3 commented Jun 23, 2026

Copy link
Copy Markdown
Member

A few nitpicks and a suggestion, I hope they are useful

@quaquel

quaquel commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

A few nitpicks and a suggestion, I hope they are useful

Thanks, those are useful and have all been addressed.

@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.

LGTM!

@quaquel
quaquel merged commit 8eaf95f into mesa:main Jun 23, 2026
12 checks passed
@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

enhancement Release notes label experimental Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants