Add parameter access and copy support to Scenario#3158
Closed
navneetkumaryadav207001 wants to merge 19 commits intomesa:mainfrom
Closed
Add parameter access and copy support to Scenario#3158navneetkumaryadav207001 wants to merge 19 commits intomesa:mainfrom
navneetkumaryadav207001 wants to merge 19 commits intomesa:mainfrom
Conversation
|
Performance benchmarks:
|
quaquel
reviewed
Jan 17, 2026
Comment on lines
+83
to
+87
| def get_parameters(self): | ||
| """Get scenario parameters excluding metadata.""" | ||
| excluded = {"model", "_scenario_id"} | ||
| return {k: v for k, v in self.__dict__.items() if k not in excluded} | ||
|
|
Member
There was a problem hiding this comment.
redundant with the already existing to_dict method.
quaquel
reviewed
Jan 17, 2026
| params.pop("model", None) # Don't copy model reference | ||
| params.pop("_scenario_id", None) # Create new scenario with new ID | ||
|
|
||
| return self.__class__(**params) |
Member
There was a problem hiding this comment.
Not sure if this is needed either because you have to_dict.
Can you give me an example of when you would need this?
Add convenience property to access model.scenario directly from agents. This follows the same pattern as the existing random and rng properties, making scenario parameters easier to access within agent code.
mesa#3163) * Optimise create_agents by replacing 'ListLike' approach * Optimised tuple slicing overhead * Add test for fast path --------- Co-authored-by: Jan Kwakkel <[email protected]>
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
Adds two utility methods to the
Scenariobase class:get_parameters()for accessing scenario parameters without metadata, andcopy()for creating modified scenario variants.Motive
Working with experiment sweeps, logging, and reproducibility often requires separating scenario parameters from internal metadata and creating slightly modified copies of scenarios. This change provides a simple, consistent API for both use cases.
Implementation
get_parameters()to return scenario attributes excludingmodeland_scenario_id.copy(**updates)to create a newScenarioinstance with optional parameter updates._scenario_idmodelreferenceUsage Examples
solves #3159.