-
Notifications
You must be signed in to change notification settings - Fork 153
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
update examples to use new solara_viz #193
Conversation
examples/aco_tsp/app.py
Outdated
@@ -4,9 +4,10 @@ | |||
|
|||
import networkx as nx | |||
import solara | |||
from mesa.visualization.utils import update_counter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this import used at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, fixed. Currently, normal functions that accept a model and return a solara component automatically update correctly. If annotated with @solara.component you need to call the update counter. This has eventually go into the "author own components" of the viz tutorial
Examples that are difficult to update we could move back to the old, now |
f69e643
to
bbfcd72
Compare
Finally found some time to update the remaining models. There are still a lot of examples that use the old (tornado based) visualizations though. But they are out of scope of this pr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
I especially like that the agent_portrayal
now is a part of a the SpaceDrawer class/component, and you thus can have a portrayal for each drawer. Way more scalable!
@@ -20,11 +20,15 @@ | |||
}, | |||
} | |||
|
|||
gol = GameOfLifeModel(10, 10) | |||
|
|||
AlivePlot = make_plot_measure("Cells alive", "Fraction alive") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this plot nicely on a single plot? Since "Cells alive"
might be on the 0-100 scale, while "Fraction alive"
is in the 0-1 scale.
(they are a bit duplicate though, so removing one is also fine)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really, I split this into 2 plots
@@ -108,7 +108,8 @@ def agent_portrayal(agent): | |||
return portrayal | |||
|
|||
|
|||
def space_drawer(model, agent_portrayal): | |||
@solara.component | |||
def SpaceDrawer(model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is capitalized like a Class. For my own knowlegde, does @solara.component
make it Class-like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't they all just objects? ;)
As far as I understood this is mostly a convention. It's best to imagine them as neither a class nor a function but as a solara component (because some custom rules apply)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, since I have looked it up by now. @solara.component does indeed return a regular ´class` object (with a a defined call function, so you can call it like a function). Usually they should still be written in snake_case for standard Python formatting, but thats where the solara convention takes over
WIP to update the models to use the new solaraviz API.
This helps me to write a migration guide for things I notice. So far it goes smoothly, but is a bit tedious