From 7927fcdc04b8aeb449aae83a05998f24081a9436 Mon Sep 17 00:00:00 2001 From: Jahan Ravi Date: Thu, 18 Dec 2025 15:13:44 +0530 Subject: [PATCH 1/2] Fix Solara render crash for CellAgent visualization --- examples/hotelling_law/app.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/examples/hotelling_law/app.py b/examples/hotelling_law/app.py index ec195ede..e69bab89 100644 --- a/examples/hotelling_law/app.py +++ b/examples/hotelling_law/app.py @@ -123,13 +123,20 @@ def SpaceDrawer(model): jitter_amount = 0.3 # Jitter for visual separation for agent in model.agents: + if ( + not hasattr(agent, "cell") + or agent.cell is None + or agent.cell.coordinate is None + ): + continue + + pos = agent.cell.coordinate portrayal = agent_portrayal(agent) - # Track store agents for cell coloring if isinstance(agent, StoreAgent): - if agent.pos not in cell_store_contents: - cell_store_contents[agent.pos] = [] - cell_store_contents[agent.pos].append(portrayal) + if pos not in cell_store_contents: + cell_store_contents[pos] = [] + cell_store_contents[pos].append(portrayal) # Color cells based on store occupancy for pos, stores in cell_store_contents.items(): @@ -138,7 +145,7 @@ def SpaceDrawer(model): for i, store in enumerate(stores): # Calculate rectangle position and size for # each store's portion of the cell - rect_x = pos[0] + (i * width) + rect_x = pos[0] + (i * width) rect_y = pos[1] rect = patches.Rectangle( (rect_x, rect_y), @@ -151,10 +158,20 @@ def SpaceDrawer(model): ax.add_patch(rect) # Jittered scatter plot for all agents + # Jittered scatter plot for all agents for agent in model.agents: + if ( + not hasattr(agent, "cell") + or agent.cell is None + or agent.cell.coordinate is None + ): + continue + portrayal = agent_portrayal(agent) - jitter_x = np.random.uniform(-jitter_amount, jitter_amount) + agent.pos[0] + 0.5 - jitter_y = np.random.uniform(-jitter_amount, jitter_amount) + agent.pos[1] + 0.5 + pos = agent.cell.coordinate + + jitter_x = np.random.uniform(-jitter_amount, jitter_amount) + pos[0] + 0.5 + jitter_y = np.random.uniform(-jitter_amount, jitter_amount) + pos[1] + 0.5 ax.scatter( jitter_x, From 893f4379d5cd5fc31fb4b30baa03cb41391a8a15 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Dec 2025 11:08:48 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/hotelling_law/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/hotelling_law/app.py b/examples/hotelling_law/app.py index e69bab89..2ebc63be 100644 --- a/examples/hotelling_law/app.py +++ b/examples/hotelling_law/app.py @@ -145,7 +145,7 @@ def SpaceDrawer(model): for i, store in enumerate(stores): # Calculate rectangle position and size for # each store's portion of the cell - rect_x = pos[0] + (i * width) + rect_x = pos[0] + (i * width) rect_y = pos[1] rect = patches.Rectangle( (rect_x, rect_y), @@ -158,7 +158,7 @@ def SpaceDrawer(model): ax.add_patch(rect) # Jittered scatter plot for all agents - # Jittered scatter plot for all agents + # Jittered scatter plot for all agents for agent in model.agents: if ( not hasattr(agent, "cell")