Skip to content

Fix network crash error - #3856

Merged
quaquel merged 5 commits into
mesa:mainfrom
dietcoke-17:network_crash_error
Sep 16, 2026
Merged

quaquel merged 5 commits into
mesa:mainfrom
dietcoke-17:network_crash_error

Conversation

@dietcoke-17

@dietcoke-17 dietcoke-17 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2691 and #3712 follow up

Bug

collect_agent_data in both mpl_space_drawing.py and MatplotlibBackend only added edgecolors when an agent provided it.

If only some agents had edgecolors, the array length became smaller than other agent data arrays (loc, marker, zorder, etc.), causing an IndexError during boolean indexing.

Fix

  • Always add one edgecolors entry per agent.
  • Use None when an agent does not specify a value, keeping all arrays aligned.

Also added a shared _to_numpy_argument_array() helper in mpl_space_drawing.py and reused it in MatplotlibBackend to avoid duplicate array handling logic.

The helper correctly handles:

  • None values
  • Mixed color formats
  • Tuple markers like (numsides, style, angle)

@github-actions github-actions Bot added testing Release notes label visualization labels Sep 13, 2026
@Dilraj07

Copy link
Copy Markdown
Contributor

Nice work consolidating the array handling into _to_numpy_argument_array! One quick thought: should the object-array fallback also apply to c (face colors), in case a portrayal mixes string colors (e.g. "blue") and RGBA tuples?

@dietcoke-17

Copy link
Copy Markdown
Contributor Author

Good catch, and I checked — it's real (np.asarray(["blue", (1.0,0.0,0.0,1.0)]) raises the same ValueError). It's a separate pre-existing bug though, not something this PR introduces — happens on current main too.Happy to pick it up right after this merges since the fix is basically the same pattern.

@quaquel

quaquel commented Sep 14, 2026

Copy link
Copy Markdown
Member

How does this relate to #3712

@dietcoke-17

Copy link
Copy Markdown
Contributor Author

How does this relate to #3712

#3856 fixes the same root cause as #3712 (#2691) — collect_agent_data only appended edgecolors when an agent's portrayal set it, so that array could end up shorter than every other per-agent array (loc, marker, zorder), causing the boolean-index IndexError.
It's a fresh implementation rather than a continuation of that branch, but it builds on:
the diagnosis in #3712 — same bug, same root cause
@tpike3's review comment there asking to consolidate the duplicated array-conversion logic — this PR does that via a shared _to_numpy_argument_array() helper in mpl_space_drawing.py, imported by MatplotlibBackend instead of reimplementing
#3712 stalled after that review request with no follow-up.

@quaquel

quaquel commented Sep 15, 2026

Copy link
Copy Markdown
Member

there is a conflict that must be resolved before this can be merged. Code wise it looks fine to me.

@dietcoke-17

Copy link
Copy Markdown
Contributor Author

Is it regarding the object array fallback asked by dilraj or any other conflicts?

@quaquel

quaquel commented Sep 15, 2026

Copy link
Copy Markdown
Member

it seems import related so trivial to fix. I can probably handle it if needed but would be good if you can take a quick lok.

@dietcoke-17

Copy link
Copy Markdown
Contributor Author

Found it and fixed it too — test_components_matplotlib.py had two PRs adding different names to the same mpl_space_drawing import list (_get_hexmesh from another PR, _to_numpy_argument_array from mine).

@quaquel
quaquel merged commit 8503a32 into mesa:main Sep 16, 2026
15 of 16 checks passed
@dietcoke-17 dietcoke-17 mentioned this pull request Sep 18, 2026
1 task done
EwoutH pushed a commit that referenced this pull request Oct 28, 2026
* Fix network crash error in matplotlib backend network drawing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix remaining IndentationError and edgecolors length bug in matplotlib backend

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit 8503a32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Network Visualization error when Agent Portrayal has inconsistent fields

3 participants