Repository navigation
Description
SolaraViz Reset button crashes when model_params contains raw Solara components
Bug Summary
Clicking the "Reset" button in SolaraViz causes a crash with TypeError: 'ValueElement' object cannot be interpreted as an integer when model_params contains raw Solara components (like solara.SliderInt()) instead of Mesa's wrapper classes.
Root Cause
In mesa/visualization/solara_viz.py, the do_reset() function attempts to re-instantiate the model by extracting user parameters. When a raw Solara component (yielding a reacton.core.ValueElement) is passed in the model_params dictionary without Mesa's Slider wrapper, the functions split_model_params() and check_param_is_fixed() incorrectly treat it as a "fixed" dictionary parameter.
During reset, do_reset() then passes this raw UI Component object directly to the model's __init__ kwargs instead of extracting its .value, causing the crash when the model constructor expects a primitive type (int, float, etc.).
Steps to Reproduce
from mesa import Model
from mesa.visualization import SolaraViz
import solara
class MyModel(Model):
def __init__(self, num_agents):
super().__init__()
self.num_agents = num_agents # Expects an integer
# Problematic: passing raw Solara component
model_params = {
"num_agents": solara.SliderInt(value=10, min=1, max=100) # Should use mesa.visualization.Slider
}
model = MyModel(10)
page = SolaraViz(model, components=[], model_params=model_params)
# Initial load works fine, but clicking "Reset" button crashesExpected Behavior
One of the following:
- Defensive extraction:
do_reset()should detectValueElementobjects and extract their.valueproperty before passing to the model constructor - Early validation: Raise a clear error during
SolaraVizinitialization ifmodel_paramscontains unsupported types, with a helpful message directing users to use Mesa'sSlider,Checkbox, etc. wrapper classes
Actual Behavior
TypeError: 'ValueElement' object cannot be interpreted as an integer
The error occurs deep in the model instantiation, making it unclear that the issue is with the parameter extraction logic.
Environment
- Mesa version: 4.0.0.dev0
- Python version: 3.14.3
Proposed Fix
I'm willing to submit a PR to fix this. The fix would involve:
- Adding type checking in
split_model_params()/do_reset()to extract.valuefromValueElementobjects - OR adding validation in
SolaraViz.__init__()to reject raw Solara components with a clear error message
Which approach would the maintainers prefer?
Note: This is part 1 of a series of SolaraViz DX improvements.
Activity
Rishav23av commentedon Mar 6, 2026
@Tejasv-Singh can i look into this are u going to open a pr
Tejasv-Singh commentedon Mar 9, 2026
@Rishav23av Thanks for offering to help out! I had already finished working on a fix for this back then and have now opened a PR for the same here: #3494.
However, I would genuinely love if you could review the PR and tell me what all could be improved. 🙌
satharyasin-hub commentedon Mar 14, 2026
Hi! I’m interested in working on this issue.
If no one is currently assigned, I’d be happy to investigate and submit a PR.
Please let me know if that would be helpful.
Fix SolaraViz reset crash on raw Solara components