Skip to content

bug: InputText Widget Returns String Seed, Causing Model Reset to Fail #3516

@IlamaranMagesh

Description

@IlamaranMagesh

Describe the bug

When a user enters an integer seed value (e.g., 100) or even just clicks the default value in the InputText widget in the Solara UI and clicks "Reset," the model initialization fails with:

TypeError: SeedSequence expects int or sequence of ints for entropy not 100

As far as I checked this happens in most of the examples (boid, wolf-sheep, pd_grid)

Example of Wolf-Sheep model:
Image

Stack traceback
Traceback (most recent call last):
  File "/Users/Maran/Library/Application Support/hatch/env/virtual/mesa/WZe1FseN/mesa/lib/python3.12/site-packages/reacton/ipyvue.py", line 23, in handler
    callback_ref.current(*args)
  File "/Users/Maran/Library/Application Support/hatch/env/virtual/mesa/WZe1FseN/mesa/lib/python3.12/site-packages/solara/components/button.py", line 84, in <lambda>
    ipyvue.use_event(btn, click_event, lambda *_ignore: on_click and on_click())
                                                                     ^^^^^^^^^^
  File "/Users/Maran/Coding/Repos/mesa-fork/mesa/mesa_logging.py", line 133, in wrapper
    res = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Maran/Coding/Repos/mesa-fork/mesa/visualization/solara_viz.py", line 593, in do_reset
    model.value = type(model.value)(**kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Maran/Coding/Repos/mesa-fork/mesa/examples/advanced/wolf_sheep/model.py", line 70, in __init__
    super().__init__(scenario=scenario)
  File "/Users/Maran/Coding/Repos/mesa-fork/mesa/mesa_logging.py", line 112, in wrapper
    res = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Maran/Coding/Repos/mesa-fork/mesa/model.py", line 143, in __init__
    self.reset_rng(rng)
  File "/Users/Maran/Coding/Repos/mesa-fork/mesa/model.py", line 347, in reset_rng
    self.rng: np.random.Generator = np.random.default_rng(rng)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "numpy/random/_generator.pyx", line 5076, in numpy.random._generator.default_rng
  File "numpy/random/_pcg64.pyx", line 123, in numpy.random._pcg64.PCG64.__init__
  File "numpy/random/bit_generator.pyx", line 536, in numpy.random.bit_generator.BitGenerator.__init__
  File "numpy/random/bit_generator.pyx", line 308, in numpy.random.bit_generator.SeedSequence.__init__
TypeError: SeedSequence expects int or sequence of ints for entropy not 100

Expected behavior

When the seed is changed in the UI and clicked on Reset, the model should be instantiated with that seed.

To Reproduce

  1. Launch SolaraViz web app with these parameters
    solara run app.py
  2. Enter an integer in the "Random Seed" input box (e.g., 100) or just click the input box
  3. Click the Reset button
  4. Observe the TypeError crash

My setup:

  • MacOs
  • Mesa 4.0

Additional context

My assumption for the root cause:

  1. The Solara InputText component returns string values (e.g., "100")
  2. This string value is passed directly to model.__init__(rng="100")
  3. model.reset_rng() calls np.random.default_rng("100")
  4. NumPy's SeedSequence rejects the string and raises a TypeError

Am I looking to open a PR?

Not now. Anyone interested can take up to resolve this issue.

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