Skip to content

Fix plot_graph mesh degree count for nodes without m2m edges - #884

Open
tygvi wants to merge 4 commits into
mllam:mainfrom
tygvi:fix/plot-graph-mesh-degree
Open

tygvi wants to merge 4 commits into
mllam:mainfrom
tygvi:fix/plot-graph-mesh-degree

Conversation

@tygvi

@tygvi tygvi commented Nov 14, 2026

Copy link
Copy Markdown

Describe your changes

plot_graph inferred the mesh node count from pyg.utils.degree(m2m_edge_index[1]), which returns max(index) + 1 entries. A mesh node with no m2m edge was therefore missing from z_mesh and the np.concatenate adding the z column raised ValueError, aborting the figure.

Passing num_nodes=mesh_pos.shape[0] uses the mesh node count from mesh_features.pt instead. An unconnected node now gets degree 0 and is drawn at the base mesh height. Same direction as #740 for #729; the graph storage spec §3.1.1 permits indices with no edges.

Tests

  • pytest tests/test_plot_graph.py tests/test_plotting.py -q → 36 passed.
  • New test_mesh_node_without_m2m_edges (parametrised 2/3/5 nodes) fails on main with the ValueError above and passes with the fix.
  • ruff check / ruff format --check on the two changed files: clean.
  • Not run: pre-commit (lychee needs network), full suite, GPU tests, and the CLI against real data (example data unavailable here).

Issue Link

Closes #883

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation (Addition or improvements to documentation)

Checklist before requesting a review

  • My branch is up-to-date with the target branch - if not update your fork with the changes from the target branch (use pull with --rebase option if possible).
  • I have performed a self-review of my code
  • For any new/modified functions/classes I have added docstrings that clearly describe its purpose, expected inputs and returned values
  • I have placed in-line comments to clarify the intent of any hard-to-understand passages of my code
  • I have updated the README to cover introduced code changes
  • If this PR changes contributor workflow, I've updated CONTRIBUTING.md / AGENTS.md
  • I have added tests that prove my fix is effective or that my feature works
  • I have given the PR a name that clearly describes the change, written in imperative form
  • I have requested a reviewer and an assignee (assignee is responsible for merging). This applies only if you have write access to the repo, otherwise feel free to tag a maintainer to add a reviewer and assignee.

Checklist for reviewers

Each PR comes with its own improvements and flaws. The reviewer should check the following:

  • the code is readable
  • the code is well tested
  • the code is documented (including return types and parameters)
  • the code is easy to maintain

Author checklist after completed review

  • I have added a line to the CHANGELOG describing this change, in a section reflecting type of change (add section where missing).

Checklist for assignee

  • PR is up to date with the base branch
  • the tests pass
  • (if the PR is not just maintenance/bugfix) the PR is assigned to the next milestone. If it is not, propose it for a future milestone.
  • author has added an entry to the changelog
  • Once the PR is ready to be merged, squash commits and merge the PR.

@Shivampal157 Shivampal157 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tygvi, passing num_nodes=mesh_pos.shape[0] to pyg.utils.degree makes sense. Just noticed one small thing in CHANGELOG.md: the link URL still has /pull/XXX instead of /pull/884, which will fail the lychee check once CI runs.

@tygvi

tygvi commented Nov 22, 2026

Copy link
Copy Markdown
Author

Fixed the CHANGELOG link now points to /pull/884 and lychee passes locally. Ready for re-review.

@nikhil3495

Copy link
Copy Markdown
Contributor

Had a look, @tygvi. The fix is the right one and matches how create_graph.py:62 already calls degree with num_nodes. I ran the new test on unmodified main and all three parametrisations fail with the concatenate ValueError, then pass on this branch. A fully empty m2m_edge_index of shape (2, 0) and an unconnected node in the middle of the index range also work now.

One small thing: an unconnected node now gets the right z, but its marker size is mesh_degrees / 2 = 0 (plot_graph.py:154), so I don't think it actually shows up in the figure, which makes it hard to spot the node someone is probably debugging. A small floor like np.maximum(mesh_degrees / 2, 0.5), or asserting on fig.data[-1].marker.size in the test, would cover that. Fine as a follow-up if you'd rather keep this minimal.

@tygvi

tygvi commented Dec 3, 2026

Copy link
Copy Markdown
Author

Thanks @nikhil3495 — good catch, you're right that the node was in the data but not actually visible. I've floored the marker size in plot_graph.py:

mesh_node_size = np.maximum(mesh_degrees / 2, 0.5)

so an unconnected node now renders as a small dot instead of collapsing to size 0. I also extended test_mesh_node_without_m2m_edges to assert on fig.data[-1].marker.size (the floored 0.5) alongside the existing z check, so this can't regress silently.

Pushed in 79195e3. Ready for re-review when you get a chance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plot_graph crashes when a mesh node has no m2m edge

3 participants