-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
bug: InputText Widget Returns String Seed, Causing Model Reset to Fail #3516
Copy link
Copy link
Closed
Description
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)
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 100Expected behavior
When the seed is changed in the UI and clicked on Reset, the model should be instantiated with that seed.
To Reproduce
- Launch SolaraViz web app with these parameters
solara run app.py - Enter an integer in the "Random Seed" input box (e.g., 100) or just click the input box
- Click the Reset button
- Observe the
TypeErrorcrash
My setup:
- MacOs
- Mesa 4.0
Additional context
My assumption for the root cause:
- The Solara InputText component returns string values (e.g., "100")
- This string value is passed directly to
model.__init__(rng="100") model.reset_rng()callsnp.random.default_rng("100")- 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
