Visualization Tutorial
When running the Visualization Tutorial for "Latest" with Mesa 3.1.0, the basic dashboard throws a ValueError for a missing model parameter - "Missing required model parameter: n".
Expected behavior The expected behavior was the creation of the embedded page in the Jupyter Lab environment to interact with the MoneyModel.
To Reproduce I am using the provided code for the MoneyModel, MoneyAgent, and compute_gini provided in the Introductory Tutorial in the "Additional agent reporter" section with the provided code from Part 1 of the Visualization Tutorial in a Jupyter Lab environment.
Additional context I am running Jupyter Lab 4.2.5 on MacOS Sequoia 15.1.1
I am unable to reproduce this problem on my machine using MESA 3.1, and the code provided in the docs folder of this repo.
My hunch (combined with the info on elements) is that the version of the MoneyModel you are using is not correct.
I have
class MoneyModel(mesa.Model):
"""A model with some number of agents."""
def __init__(self, n=10, width=10, height=10, seed=None):
"""Initialize a MoneyModel instance.
Args:
N: The number of agents.
width: width of the grid.
height: Height of the grid.
"""
super().__init__(seed=seed)
self.num_agents = n
self.grid = mesa.space.MultiGrid(width, height, True)
Where did you get the code for the money model from? Did you take it from the introductory tutorial?
Yes, I am getting the error from my reproduced MoneyModel code and the code copied from the end of the Introductory Tutorial. The code below is what I was using for the model.
class MoneyModel(mesa.Model): """A model with some number of agents."""
def __init__(self, n, width, height, seed=None):
super().__init__(seed=seed)
self.num_agents = n
self.grid = mesa.space.MultiGrid(width, height, True)
self.running = True
# Create agents
for _ in range(self.num_agents):
a = MoneyAgent(self)
# Add the agent to a random grid cell
x = self.random.randrange(self.grid.width)
y = self.random.randrange(self.grid.height)
self.grid.place_agent(a, (x, y))
self.datacollector = mesa.DataCollector(
model_reporters={"Gini": compute_gini},
agent_reporters={"Wealth": "wealth", "Steps_not_given": "steps_not_given"},
)
def step(self):
self.datacollector.collect(self)
self.agents.shuffle_do("move")
self.agents.shuffle_do("give_money")
Ok, just change the signature to the one from my snippet and you should be good to go.
so use def __init__(self, n=10, width=10, height=10, seed=None): instead of def __init__(self, n, width, height, seed=None).
The underlying issue that needs to be fixed is to to update the introductory tutorial to use keywords only on all model classes.
Thanks for reporting this issue and finding the root cause of it.
I think a more structural solution, would be to let SolaraViz give a proper warning that notifies the user that not all arguments are keyword arguments.
#2510 is adding this warning.
I am currently encountering the same issue as originally mentioned. I implemented the recommended change to def__init__ which fixed the error but is not giving me the expected output. My output is just the blank white bar at the bottom.
Versions I'm running: MESA 3.1.0 Windows 11 Visual Studio Code 1.88.1
Does it say anything in the bar? This is most likely an issue in solara/javascript. I have seen others with similar issues but I so far haven't been able to figure out what is going on.
The offered solution worked to resolve the ValueError, however I am also seeing an empty cell output now that the code is executing. If this is likely something distinct, we can open a new issue for it.
@nicolas-starck and @tleung24 That is a jupyter version issue; you need to update your version of jupyter
@tpike3 - I just updated to jupyterlab 4.3.2 and see the same behavior.
@tpike3 - I just updated to jupyterlab 4.3.2 and see the same behavior.
HMMM @nicolas-starck can you share your
iypthon ipyvue ipvuetify and solara version
I am 90% sure this is a dependency issue, I am just hoping it is not a Mac issue.
I am on a mac and for me, everything works fine. So, it can work on a. mac.
@tpike3 - here are the current versions of those packages in my environment.
iypthon - 8.27.0 ipyvue - 3.0.0a4 ipyvuetify - 3.0.0a2 solara - 1.42.0
Ahhh got it, now I remember I need to document this. You are in the pre-release version of ipyvue and ipvuetify You want to uninstall and then
use
ipyvue ~1.11.2 ipyvuetify ~1.2.2
Not sure this is what you did but if you install Mesa pre-release and dont have solara it will install the pre-release dependencies (ipyvue and ipyvuetify) as well causing this issue.
@tpike3 - here are the current versions of those packages in my environment.
iypthon - 8.27.0 ipyvue - 3.0.0a4 ipyvuetify - 3.0.0a2 solara - 1.42.0
Can we pin those dependencies <3 in our pyproject.toml?
Also @maartenbreddels is this incompatibility a known issue over at Solara?
Can we pin those dependencies
<3in ourpyproject.toml?Also @maartenbreddels is this incompatibility a known issue over at Solara?
Yes we should do that, just need to remember to undo it at some point; there has to be someway to add a dependency and even docker report to our CI/CD. Of course the trick will be to not just ignore it when we get an alert :) -- never enough time in the day
@tpike3 - thanks for the suggestion! I was able to get it running with the following combination of packages:
ipyvue - 1.11.2 ipyvuetify - 1.10.0 jupyter lab - 4.2.6 (downgraded due to dependency errors with the other packages)
Partially addressed in #2510 still need to update pyproject.toml
I am also having an issue running the visualization I have version: mesa: 3.0.0 ipyvue: 1.11.2 ipyvuetify: 1.1.10 Solara: 1.42.0 Numpy: 1.26.4 Pandas: 2.2.3
I get an import error: 1 from mesa.visualization import ( ImportError: cannot import name 'make_plot_measure' from 'mesa.visualization'
Do I have a wrong version of something?
Could you start with updating to the latest Mesa version? (3.1.1)
With Mesa 3.1.1 I still have the same problem
Can we pin those dependencies
<3in ourpyproject.toml?Also @maartenbreddels is this incompatibility a known issue over at Solara?
Those are pre-releases, which you should only get with pip install --pre, no need to pin (I consider this a user error). But it's good to know it's not working, because most thing should work!
Hi everyone, I'm new to Project Mesa and looking for a "good first issue" to get started, with the goal of applying for GSoC 2026.
I see this issue is labeled good first issue and docs. The original bug seems to be that the Introductory Tutorial's code snippet for MoneyModel is outdated (it's missing default values like n=10).
Has this documentation update been done yet? If not, I would love to take this task, update the tutorial, and submit a pull request.
@pragam-m25 thanks for the PR.
Can you first check if you can reproduce this issue with the latest Mesa version? I believe we might have already fixed or migrated is somewhere in the mean time.
We're not fully up to speed with tracking the state of all issues. Sorry.
Hi @EwoutH, thanks for checking!
I've just fetched upstream/main and re-checked the file. The bug is still present in docs/tutorials/0_first_model.ipynb.
All three instances of the MoneyModel class are still defined without a default value for n (e.g., def __init__(self, n, seed=None):), which is what causes the error reported in issue #2535.
My PR adds the default value n=10 in all three places, which fixes this. Let me know if you need anything else!
Does it actually still give the error? If so, I'm wondering why our Readthedocs CI isn't failing (https://app.readthedocs.org/projects/mesa/builds/30167437/)
Hi @EwoutH, that's a great question. You are right that the 0_first_model.ipynb notebook runs successfully on its own (which is why the RTD build is passing), because it calls the model with MoneyModel(10).
The error only occurs when the MoneyModel class (as defined in that tutorial) is used by Solara for the visualization, which expects default values.
I just confirmed this locally. If you run:
import solara
from mesa.visualization.solara import ModelPage
# MoneyModel is the one from the tutorial, without the default value
# This line fails
solara.display(ModelPage(MoneyModel))
Thanks for investigating and clarifying. So we missed this because this issue (still) isn't fixed:
- https://github.com/projectmesa/mesa/issues/2734
Could you:
- Add a clear problem statement to https://github.com/projectmesa/mesa/pull/2871 (following the PR template)
- Add a comment to https://github.com/projectmesa/mesa/issues/2734 about what exactly you found that currently isn't tested.
Hi @EwoutH, thanks! I have:
- Updated the PR description with a clearer problem statement, as requested.
- Left a comment on issue #2734 explaining what our current CI is missing.
Let me know if you need anything else!
