-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Support Scenarios in Visualization #3176
Description
Problem
Mesa now has first-class support for Scenarios (#3103, #3168, and updated example #3167), but SolaraViz doesn’t support them. This creates two distinct issues:
Issue 1: Parameter routing during reset
When users create sliders for scenario parameters (density, vision), clicking “Reset” fails because SolaraViz tries to pass these directly to MyModel.__init__(), which doesn’t accept them—they belong to the Scenario.
Issue 2: Leveraging Scenario for auto-generated UI
Scenarios already define typed parameters with defaults. How can we use this to create a clean, minimal-duplication API for generating UI controls? The challenge: Scenarios define defaults but not min/max ranges for sliders.
Current situation:
class MyScenario(Scenario):
density: float = 0.7
vision: int = 7
class MyModel(Model):
def __init__(self, height=40, width=40, scenario: MyScenario | None = None):
super().__init__(scenario=scenario)Possible solutions
Option 1: Add scenario_params argument
page = SolaraViz(
model,
renderer,
model_params={"height": 40, "width": 40},
scenario_params={
"density": Slider(...),
"vision": Slider(...),
}
)Mesa changes needed:
- Add
scenario_paramsparameter toSolaraViz() - Update
ModelController.do_reset()to reconstruct Scenario from parameters - Render scenario params in separate UI section
Pros: Clear, explicit, easy to understand
Cons: More verbose, requires manual specification
Option 2: Auto-detect from type hints
# SolaraViz introspects model.scenario and auto-generates UI
page = SolaraViz(model, renderer)
# Optional customization
page = SolaraViz(model, renderer, scenario_params={"density": Slider(...)})Mesa changes needed:
- Introspect
model.scenarioto get Scenario class - Use
get_type_hints()and_scenario_defaultsto auto-generate controls - Allow overrides via
scenario_params
Pros: Minimal user code, leverages existing type hints
Cons: Less explicit, auto-generated ranges might not fit
Option 3: Something else?
Other nice ideas for a clean API?
Discussion Questions
- How would the user API look?
- Should scenario parameters appear in a separate UI section?
- How do we handle the
rngparameter that scenarios own?
Implementation areas
Regardless of option chosen:
solara_viz.py: UpdateSolaraViz,ModelCreator,ModelController- Documentation: Add examples and migration guide