Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add step count display to JupyterViz #1775

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

rlskoeser
Copy link
Contributor

@rlskoeser rlskoeser commented Aug 24, 2023

addresses #1773

I don't see any unit tests for the experimental JupyterViz code; I'd be game to add a test if/when there is existing testing infrastructure for this code, but not sure how to go about testing my contribution without examples for the other parts.

I'm not sure if there's any relevant documentation I need to update for this change. I could see if I can generate a new version of the screenshot for the Schelling segregration model displayed on the docs overview page that includes the step count, if that would be helpful/desirable.

@@ -201,6 +206,12 @@ def on_value_play(change):
playing=playing.value,
on_playing=playing.set,
)
widgets.IntText(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested, it looks like this
2023-08-25-064815_824x420_scrot

I think it shouldn't be boxed. Because a boxed UI element indicates it is user-editable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of widgets.IntText, maybe try solara.Markdown instead.

Also, your code means that the widget is created from scratch every time on_value_play is called. A Solara widget should only be created once, and then is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rht thanks for the feedback. I didn't see an obvious Solara output field so I followed the other widget examples; I had it set to disabled/read-only, but I agree a real output would be better and I can see now that markdown is feasible.

I've pushed an update that replaces widgets.IntText with solara.Markdown and tested locally, it is updating the number when I play through the simulation.

@codecov
Copy link

codecov bot commented Aug 26, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.28% ⚠️

Comparison is base (24a1df3) 80.29% compared to head (b630985) 80.02%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1775      +/-   ##
==========================================
- Coverage   80.29%   80.02%   -0.28%     
==========================================
  Files          15       15              
  Lines         878      881       +3     
  Branches      187      188       +1     
==========================================
  Hits          705      705              
- Misses        152      155       +3     
  Partials       21       21              
Files Changed Coverage Δ
mesa/experimental/jupyter_viz.py 20.00% <ø> (-0.46%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rht
Copy link
Contributor

rht commented Aug 27, 2023

Sorry for the late reply. I tested. While the play button updates the step correctly, the step button doesn't. Try removing the step variable, and then add dependency to solara.Markdown to make it auto-update, see e.g.

solara.FigureMatplotlib(fig, dependencies=[viz.model, viz.df])
.

@rht
Copy link
Contributor

rht commented Aug 27, 2023

I haven't tried, but what I meant was

solara.Markdown(f"**step:** {viz.model.schedule.steps}, dependencies=[viz.model.schedule.steps])

@rht
Copy link
Contributor

rht commented Aug 27, 2023

I tried.

solara.Markdown(f"**step:** {viz.model.schedule.steps}")

worked like magic (no dependency needed). If you can confirm this.

@rlskoeser
Copy link
Contributor Author

solara.Markdown(f"**step:** {viz.model.schedule.steps}")

worked like magic (no dependency needed). If you can confirm this.

@rht yes, confirmed. It's great that it's so simple.

I just pushed an update to my PR so that this the only line I'm proposing to change now (although it's really your solution, not mine!).

@rht
Copy link
Contributor

rht commented Aug 28, 2023

Content looks good to me. The remaining "concern" is that the viz becomes slightly crowded. @tpike3 do you have concern about information density etc? If you are fine with it, then you can squash and merge this PR.

@rlskoeser rlskoeser requested a review from rht August 28, 2023 16:29
@tpike3
Copy link
Member

tpike3 commented Aug 29, 2023

Content looks good to me. The remaining "concern" is that the viz becomes slightly crowded. @tpike3 do you have concern about information density etc? If you are fine with it, then you can squash and merge this PR.

Looks Good to Me --- thanks @rlskoeser! This is really good.

@tpike3 tpike3 merged commit 79bde5a into projectmesa:main Aug 29, 2023
@rlskoeser rlskoeser deleted the jupyterviz-step-count branch August 29, 2023 20:57
@tpike3 tpike3 added this to the Release 2.1.2 milestone Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants