From 2310bd6ce5cdb09a15beedbacc7b331623195922 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Tue, 8 Aug 2023 11:37:35 -0400 Subject: [PATCH 1/3] Add step count display to JupyterViz --- mesa/experimental/jupyter_viz.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mesa/experimental/jupyter_viz.py b/mesa/experimental/jupyter_viz.py index 7a49d7aa64f..385b673c525 100644 --- a/mesa/experimental/jupyter_viz.py +++ b/mesa/experimental/jupyter_viz.py @@ -175,9 +175,14 @@ def make_model(): # 3. Buttons playing = solara.use_reactive(False) + # 4. Status indicators + #: current round step count + step = solara.use_reactive(False) + def on_value_play(change): if viz.model.running: viz.do_step() + step.value = viz.model.schedule.steps else: playing.value = False @@ -201,6 +206,12 @@ def on_value_play(change): playing=playing.value, on_playing=playing.set, ) + widgets.IntText( + value=step.value, + description="Step:", + disabled=True, + interval=play_interval, + ) # threaded_do_play is not used for now because it # doesn't work in Google colab. We use # ipywidgets.Play until it is fixed. The threading From c59e15f045e12cd1c7920e6b9a44ca46fc85f986 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Fri, 25 Aug 2023 13:14:56 -0400 Subject: [PATCH 2/3] Use Solara markdown instead of int text to display step count --- mesa/experimental/jupyter_viz.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mesa/experimental/jupyter_viz.py b/mesa/experimental/jupyter_viz.py index 385b673c525..c0ef2c9a423 100644 --- a/mesa/experimental/jupyter_viz.py +++ b/mesa/experimental/jupyter_viz.py @@ -177,7 +177,7 @@ def make_model(): # 4. Status indicators #: current round step count - step = solara.use_reactive(False) + step = solara.use_reactive(True) def on_value_play(change): if viz.model.running: @@ -206,12 +206,7 @@ def on_value_play(change): playing=playing.value, on_playing=playing.set, ) - widgets.IntText( - value=step.value, - description="Step:", - disabled=True, - interval=play_interval, - ) + solara.Markdown(md_text="**Step:** %d" % step.value) # threaded_do_play is not used for now because it # doesn't work in Google colab. We use # ipywidgets.Play until it is fixed. The threading From b6309851a5da49512a7a885d96656030d279f099 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Mon, 28 Aug 2023 12:25:20 -0400 Subject: [PATCH 3/3] Reference model step count directly for markdown output per @rht feedback --- mesa/experimental/jupyter_viz.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mesa/experimental/jupyter_viz.py b/mesa/experimental/jupyter_viz.py index c0ef2c9a423..2c378631290 100644 --- a/mesa/experimental/jupyter_viz.py +++ b/mesa/experimental/jupyter_viz.py @@ -175,14 +175,9 @@ def make_model(): # 3. Buttons playing = solara.use_reactive(False) - # 4. Status indicators - #: current round step count - step = solara.use_reactive(True) - def on_value_play(change): if viz.model.running: viz.do_step() - step.value = viz.model.schedule.steps else: playing.value = False @@ -206,7 +201,7 @@ def on_value_play(change): playing=playing.value, on_playing=playing.set, ) - solara.Markdown(md_text="**Step:** %d" % step.value) + solara.Markdown(md_text=f"**Step:** {viz.model.schedule.steps}") # threaded_do_play is not used for now because it # doesn't work in Google colab. We use # ipywidgets.Play until it is fixed. The threading