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

feat: Implement Slider class for JupyterViz #1972

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

rht
Copy link
Contributor

@rht rht commented Jan 18, 2024

This provides API parity with the previous Tornado viz. Supersedes #1945.
For the Schelling experimental example, from

model_params = {
    "density": {
        "type": "SliderFloat",
        "value": 0.8,
        "label": "Agent density",
        "min": 0.1,
        "max": 1.0,
        "step": 0.1,
    },
    "minority_pc": {
        "type": "SliderFloat",
        "value": 0.2,
        "label": "Fraction minority",
        "min": 0.0,
        "max": 1.0,
        "step": 0.05,
    },
    "homophily": {
        "type": "SliderInt",
        "value": 3,
        "label": "Homophily",
        "min": 0,
        "max": 8,
        "step": 1,
    },
    "width": 20,
    "height": 20,
}

to

model_params = {
    "density": Slider("Agent density", 0.8, 0.1, 1.0, 0.1),
    "minority_pc": Slider("Fraction minority", 0.2, 0.0, 1.0, 0.05),
    "homophily": Slider("Homophily", 3, 0, 8, 1),
    "width": 20,
    "height": 20,
}

I haven't added test because still waiting for agreement. But I have tested this manually on the Schelling experimental example.

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (b60caa4) 79.27% compared to head (5f53869) 79.00%.
Report is 2 commits behind head on main.

Files Patch % Lines
mesa/experimental/jupyter_viz.py 33.33% 5 Missing and 1 partial ⚠️
mesa/experimental/UserParam.py 84.21% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1972      +/-   ##
==========================================
- Coverage   79.27%   79.00%   -0.28%     
==========================================
  Files          16       17       +1     
  Lines        1298     1324      +26     
  Branches      291      295       +4     
==========================================
+ Hits         1029     1046      +17     
- Misses        230      237       +7     
- Partials       39       41       +2     

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

@quaquel
Copy link
Contributor

quaquel commented Jan 18, 2024

I really like this API.

@rht rht force-pushed the jupyterviz_slider branch 3 times, most recently from 485365c to 5f53869 Compare January 18, 2024 08:12
@rht
Copy link
Contributor Author

rht commented Jan 18, 2024

Added test. This PR is ready for review.

@rht rht added feature Release notes label visualisation labels Jan 18, 2024
Copy link
Contributor

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

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

Really like the API, this is good stuff.

Do we want to drop the explicit distinction between float and int? Is that implied with the values (mainly step) that you input now?

Will try to do a full review later today.

@quaquel
Copy link
Contributor

quaquel commented Jan 18, 2024

Do we want to drop the explicit distinction between float and int? Is that implied with the values (mainly step) that you input now?

I am fine with dropping the distinction, but I can see arguments to have explicit int and float sliders. If desired, one possibility would be to just add a dtype kwarg to optionally control this behavior. If dtype is none, you derive the dtype from the arguments.

@rht
Copy link
Contributor Author

rht commented Jan 19, 2024

Added an optional dtype argument.

This provides API parity with the previous Tornado viz.
@EwoutH
Copy link
Contributor

EwoutH commented Jan 19, 2024

@ankitk50 since you’re also working of visualization, what’s your take?

@ankitk50
Copy link

I would agree with being explicit with float/int data type. This would also later cater to the possibility of a custom slider with strings ['min', 'mid', 'max'].

@quaquel
Copy link
Contributor

quaquel commented Jan 19, 2024

With the optional dtype argument, it should be quite easy to expand to categorical sliders with string labels later down the line. I can't fully judge the code because I am unfamiliar with solara. But from an API and extensibility point of view, this looks all fine to me.

@rlskoeser
Copy link
Contributor

Really like how much more concise this is to configure.

@EwoutH
Copy link
Contributor

EwoutH commented Jan 24, 2024

Should it have an initial_value and a current_value (or just value)? So that you can reset it to it's original state, if wanted? (@Corvince would you think that is useful?)

@rht
Copy link
Contributor Author

rht commented Jan 26, 2024

Should it have an initial_value and a current_value (or just value)? So that you can reset it to it's original state, if wanted?

That would need an extra button "reset to initial value" in order to be usable, and would be out of the scope of this PR. This PR wraps the same number of params in Solara's slider.

@quaquel
Copy link
Contributor

quaquel commented Jan 26, 2024

I agree with @rth. Let's merge this.

@Corvince Corvince merged commit 6a4ea54 into projectmesa:main Jan 26, 2024
13 checks passed
@rht rht deleted the jupyterviz_slider branch January 27, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Release notes label visualisation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants