Skip to content

SolaraViz DX Improvements: Reset bug, Class Instantiation errors, and Warning spam #3453

Closed

Description

@Tejasv-Singh

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 crashes

Expected Behavior

One of the following:

  1. Defensive extraction: do_reset() should detect ValueElement objects and extract their .value property before passing to the model constructor
  2. Early validation: Raise a clear error during SolaraViz initialization if model_params contains unsupported types, with a helpful message directing users to use Mesa's Slider, 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 .value from ValueElement objects
  • 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

  1. Rishav23av commented on Mar 6, 2026

    @Rishav23av
    Contributor

    @Tejasv-Singh can i look into this are u going to open a pr

  2. Tejasv-Singh commented on Mar 9, 2026

    @Tejasv-Singh
    ContributorAuthor

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

  3. satharyasin-hub commented on Mar 14, 2026

    @satharyasin-hub
    Contributor

    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.

  4. added a commit that references this issue on Mar 19, 2026
    c5ff06c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions