Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1786 +/- ##
==========================================
- Coverage 80.02% 79.58% -0.44%
==========================================
Files 15 15
Lines 881 877 -4
Branches 188 188
==========================================
- Hits 705 698 -7
- Misses 155 158 +3
Partials 21 21
☔ View full report in Codecov by Sentry. |
|
Just to give some perspective on what "future improvements" from my side are already locally implemented (for testing, need more polishing)
|
| self.model_params_fixed[k] = v | ||
|
|
||
| @solara.component | ||
| def JupyterViz( |
There was a problem hiding this comment.
Yeah, this is simpler. The reason why I split into JupyterContainer, MesaComponent, and JupyterViz was the answer to these questions on Discord:
The question:
Is it possible to do just
model_params = {
"N": {
"type": "SliderInt",
"value": 50,
"label": "Number of agents:",
"min": 10,
"max": 100,
"step": 1,
},
"width": 10,
"height": 10,
}
JupyterViz(
BoltzmannWealthModel, model_params, measures=["Gini"], name="Money Model"
)The answer,
@rht you can also assign to page = MesaComponent(...) but they you would have to reverse your model, so JupyterViz shouldn't call MesaComponent, but the other way around
This was the reason for the MesaComponent and JupyterViz split. But in hindsight, the split wasn't necessary.
This was the reason for the JupyterContainer split: https://discord.com/channels/1106593685241614489/1106593686223069309/1123583246307954828.
There was a problem hiding this comment.
Yes, the power of hindsight... but still quite impressive to make it work with all the necessary basic features! Solara uses quite a different paradigm, so not everything is clear from the beginning
mesa/experimental/jupyter_viz.py
Outdated
| model.step() | ||
| set_current_step(model.schedule.steps) | ||
|
|
||
| def do_play(self): |
mesa/experimental/jupyter_viz.py
Outdated
| while model.running: | ||
| self.do_step() | ||
|
|
||
| def threaded_do_play(self): |
In this PR, only |
| import mesa | ||
|
|
||
| # Avoid interactive backend | ||
| plt.switch_backend("agg") |
There was a problem hiding this comment.
This was added so that user code that does the pyplot interface (plt.plot, etc) can still work, even though not recommended.
There was a problem hiding this comment.
ah, makes sense. I reverted the change
Ah, I think you got the dependency list of FigureMatplotlib backwards. In Solara, when the state changes (here: current_step), the component and every child component is re-rendered. So we don't need to notify FigureMatplotlib explicitly to update the plot. Only if we dont want it to redraw we can add a dependency list and only if the values of the dependency list change a new figure is drawn. But even without a dependency change it technically still re-renders, but uses the old (cached) image. |
|
I see, that makes sense. I will merge now. |
|
Forgot to mention that the visualization tutorial needs to be updated ASAP before the release (see https://mesa.readthedocs.io/en/stable/tutorials/visualization_tutorial.html). I can't do this within the next few days, and so, @ankitk50, if you have the time to do it, it would be great. |
|
Hi all, I started working on updating this tutorial. I get the following error while rendering the page: Are we aware of this issue or I'm missing some config ? |
|
Thanks @rht, everything looked in order to me. Although I cannot get rid of the Jupyter notebook error. The error does not show on colab, so I use it for now. |
|
I don't recommend using Colab to develop for long term. You have to fix your local env problem soon. |
Over the past weeks, I've had the opportunity to delve into the Solara frontend and experiment with different ideas. A big thank you to @rht for laying the foundation of the Solara frontend.
I'm experimenting with exciting concepts for the frontend and am eager to incorporate my React knowledge.
However, with this PR, my primary aim is to streamline the codebase before introducing any additional modifications.
At present, the frontend code is organized across three functions/classes:
JupyterContainer: This contains model control functions, grid plotting features, and logic to segregate model parameters into fixed and user-configurable ones.MesaComponent: This establishes user-configurable controls, sets up the model, contains some model control functions, performsJupyterContainermanipulations, and holds the plotting logic.JupyterViz: This Solara component essentially returns the MesaComponent and initiates the Container.I've reorganized and simplified the structure. Now,
JupyterVizstands as the primary component, managing user input (subject to further enhancement in an upcoming PR), initializing the model, and handling the plotting logic. The model control has been externalized to a separate component namedModelController.While this PR might seem extensive, it's mainly due to the code repositioning to achieve a more intuitive flow. The actual modifications are minimal. Key changes include:
FigureMatplotlibdependencies. Presently, we're free from unnecessary re-renders, so this optimization isn't required.dffrom the container. Previously, I believe this was used to trigger re-renders. Now, we track the current step to achieve this. This approach also supports models without a data collector and is essential for upcoming enhancements to the model controller.split_model_paramsfunction has been made top-level and devoid of side effects.I think that sums it up.