Fixing the model visualization #2603
Answered
by
quaquel
Sahil-Chhoker
asked this question in
Q&A
-
I was building an example model to recreate an issue(unrelated to this discussion) but upon running it I just get a white screen with a sidebar, it would be really helpful if someone can help me debug this issue. Here is the entire code: from mesa.experimental.cell_space.grid import OrthogonalMooreGrid
from mesa import Model
import math
from mesa.experimental.cell_space import CellAgent
from mesa.visualization import SolaraViz, make_space_component, make_plot_component
from mesa.datacollection import DataCollector
class myAgent(CellAgent):
def __init__(self, model, cell=None):
super().__init__(model)
self.number = 0
self.cell = cell
def step(self):
self.number = self.random.randint(1, 5)
class myModel(Model):
def __init__(self, seed=None, width=20, height=20, n_agents=4):
super().__init__(seed=seed)
self.width = width
self.height = height
self.num_agents = n_agents
self.grid = OrthogonalMooreGrid(
(self.width, self.height), capacity=math.inf, torus=True, random=self.random
)
myAgent.create_agents(
self, self.num_agents, cell=self.random.choice(self.grid.all_cells.cells)
)
self.datacollector = DataCollector(
model_reporters={
"number": lambda m: sum(agent.number for agent in m.agents)
},
agent_reporters={"number": "number"},
)
self.running = True
self.datacollector.collect(self)
def step(self):
self.agents.shuffle_do("step")
self.datacollector.collect(self)
def portrayal(agent):
if agent is None:
return None
return {
"color": "tab:orange",
"size": 1,
}
model_params = {
"seed": {
"type": "InputText",
"value": 42,
"label": "Random Seed",
},
"n_agents": {
"type": "SliderInt",
"value": 4,
"min": 1,
"max": 10,
"step": 1,
"label": "Number of Agents",
},
"width": 20,
"height": 20,
}
model = myModel()
space_component = make_space_component(
agent_portrayal=portrayal, draw_grid=True
)
plot_component = make_plot_component(
{"number": "tab:blue"},
)
page = SolaraViz(
model,
components=[space_component, plot_component],
model_params=model_params,
name="Test Model",
)
page |
Beta Was this translation helpful? Give feedback.
Answered by
quaquel
Jan 9, 2025
Replies: 1 comment 4 replies
-
I can't reproduce your issue, om my side the model and visualisation works. What OS, browser, Mesa version, IDE, Python version, etc.? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it probably has to do with the versions of solara's dependencies. We have had an earlier issue about this: #2535
We might want to update the readme and main docs landing page to remove the use of
pre
in the installation instructions.