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 an option to disable drawing agent space #1778 #1783

Merged
merged 1 commit into from
Sep 7, 2023

Conversation

rlskoeser
Copy link
Contributor

as discussed on #1778

@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +1.83% 🎉

Comparison is base (494c917) 79.88% compared to head (f56ee0f) 81.72%.

❗ Current head f56ee0f differs from pull request most recent head ae76fdd. Consider uploading reports for the commit ae76fdd to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1783      +/-   ##
==========================================
+ Coverage   79.88%   81.72%   +1.83%     
==========================================
  Files          15       15              
  Lines         880      881       +1     
  Branches      188      189       +1     
==========================================
+ Hits          703      720      +17     
+ Misses        154      136      -18     
- Partials       23       25       +2     
Files Changed Coverage Δ
mesa/experimental/jupyter_viz.py 31.11% <100.00%> (+12.45%) ⬆️

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

@rlskoeser rlskoeser force-pushed the jupyterviz-space-optional branch from a86f51c to ac08724 Compare August 30, 2023 18:30
@rht
Copy link
Contributor

rht commented Aug 31, 2023

I have seen None and False being used as distinct possible values in a parameter in a library somewhere. Can't remember which one. But it's easy to confuse the 2, because None is considered falsy. I am not fully sure yet of the best way forward in this situation.

@rht
Copy link
Contributor

rht commented Aug 31, 2023

Maybe a string "disabled"? @Corvince thoughts?

the model; if not specified, will call :meth:`make_space`
to render; simulations with no space to visualize should
specify `space_drawer=False`
play_interval: play interval (default: 400)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @rlskoeser!

This change is making me wonder if we should switch to a different naming convention as the False, None, Else took me a while to think through, which I worry will confuse users.

Maybe kwargs for different space and not space options?

Thoughts @rlskoeser?
Thoughts @rht?
Thoughts @ankitk50

Copy link
Contributor

@ankitk50 ankitk50 Aug 31, 2023

Choose a reason for hiding this comment

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

'None' should represent absence of a value which seems to be the case here.

@Corvince
Copy link
Contributor

I think space_drawer=None reads pretty good and should be unambiguous.

That said I think we shouldn't assume what and how people want to plot there models.

I think it would be easier to let users just decide on which solara components they want to display (and provide some components)

@rht
Copy link
Contributor

rht commented Aug 31, 2023

I think it would be easier to let users just decide on which solara components they want to display (and provide some components)

The reason why I set the space drawing to be automatic was to cover the 80% of the use case to be easy. The previous Tornado version does require users to specify manually, but I find this too much boilerplate code.

@rlskoeser
Copy link
Contributor Author

I was thinking of None as the default / unspecified option, but it's plausible that someone would specify specify_drawer=None and expect to have no space and I agree that the code isn't as readable.

I was wondering if there was a different way to pass in the default make_space method instead of using None to flag the default, but when I tried that locally I couldn't pass through the False / None value; maybe because there's something I'm missing about how the JupyterViz method generates a MesaComponent.

I thought about a defined constant for either the default or the disabled state, but adding an optional kwarg parameter to disable drawing the space as @tpike3 suggested sounds easier to use and more readable to me. Although I'm not sure of a brief, readable name for that argument.

@rht
Copy link
Contributor

rht commented Sep 1, 2023

What about passing a do-nothing lambda: None function and document this in the docstring?

@rht
Copy link
Contributor

rht commented Sep 1, 2023

As in, if user doesn't want the space to be drawn, they should pass in the empty lambda function.

@rht
Copy link
Contributor

rht commented Sep 1, 2023

Another option is to set space_drawer=make_space as the default argument, and if user specifies it with a falsy value (None, False, 0, etc), then don't draw anything.

@rlskoeser
Copy link
Contributor Author

Another option is to set space_drawer=make_space as the default argument, and if user specifies it with a falsy value (None, False, 0, etc), then don't draw anything.

I tried this and it didn't work (the None turned into default behavior somewhere - I think related to the component creation). I will try again with the refactored jupyterviz code and see if I can get it to work. This seems like the cleanest option to me.

@rht
Copy link
Contributor

rht commented Sep 1, 2023

You could also do space_drawer="default" and then replace is with make_space, and do nothing for falsy values.

@tpike3
Copy link
Member

tpike3 commented Sep 4, 2023

I don't want to stand in the way of merging this as it is an unequivocally an improvement;

The doc build issue was fixed with #1785

But as I opened a can of worms, any issue merging @rht, @Corvince, @jackiekazil ?

@rht
Copy link
Contributor

rht commented Sep 4, 2023

But it's easy to confuse the 2, because None is considered falsy.

I stand by the statement of the problem of using None and False in a different way, so this PR can't be merged yet.

@tpike3
Copy link
Member

tpike3 commented Sep 4, 2023

You could also do space_drawer="default" and then replace is with make_space, and do nothing for falsy values.

I am good with this solution

@Corvince
Copy link
Contributor

Corvince commented Sep 4, 2023

You could also do space_drawer="default" and then replace is with make_space, and do nothing for falsy values.

I am good with this solution

me too

@tpike3
Copy link
Member

tpike3 commented Sep 5, 2023

@rlskoeser This is your PR, so you are lead, let us know your thoughts or if there is any support we can provide.

@jackiekazil
Copy link
Member

You could also do space_drawer="default" and then replace is with make_space, and do nothing for falsy values.

I am good with this solution

me too

+1

@rlskoeser rlskoeser force-pushed the jupyterviz-space-optional branch from ac08724 to 551bcb4 Compare September 5, 2023 18:12
@rlskoeser
Copy link
Contributor Author

Thanks for the input, everyone. I've re-implemented based on the latest refactor of the jupyter viz code with the proposed 'default' option, which does seem to be the simplest solution. I added a docstring for JupyterViz (although not sure my description of the measures parameter is accurate/helpful) and a minimal unit test that confirms the expected behavior for various options for drawing the space (default, custom, none).

@rlskoeser rlskoeser requested a review from tpike3 September 5, 2023 18:27
@rht
Copy link
Contributor

rht commented Sep 6, 2023

The ruff lint failed.

from mesa.experimental.jupyter_viz import make_user_input
import solara

from mesa.experimental.jupyter_viz import make_user_input, JupyterViz
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a super simple fix ... https://beta.ruff.rs/docs/rules/unsorted-imports/ and the only issue I see

@tpike3
Copy link
Member

tpike3 commented Sep 6, 2023

@rlskoeser This is great and thanks for the tests! I think 2 commits is good, one for the improvement and one for the tests, but please squash the lint correction

Again thank you very much!

@rht
Copy link
Contributor

rht commented Sep 6, 2023

It's fine to not squash the commits. We can do "squash and merge" later instead.

Correct linter rerors flagged by ruff check
@rlskoeser rlskoeser force-pushed the jupyterviz-space-optional branch from f56ee0f to ae76fdd Compare September 6, 2023 14:00
@rlskoeser
Copy link
Contributor Author

Sorry I missed the linting error! I guess I've gotten too used to the isort pre-commit hook that I've started using on other projects.

Corrected now, and I amended & squashed the commit history.

@rlskoeser rlskoeser requested a review from tpike3 September 6, 2023 14:08
@jackiekazil
Copy link
Member

I am excited about this addition. Thank you for your contribution. <3
I haven't had a chance to test, so I will defer to someone else to make the final review/merge.

@rht rht merged commit 9572e65 into projectmesa:main Sep 7, 2023
@rlskoeser rlskoeser deleted the jupyterviz-space-optional branch September 8, 2023 13:21
@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.

6 participants