Skip to content

Parallel plotting helpers: every rank joins global_evaluate, and a MeshVariable is accepted - #1243

Merged
lmoresi merged 2 commits into
developmentfrom
bugfix/parallel-visualisation-helpers-empty-ranks
Nov 20, 2026
Merged

lmoresi merged 2 commits into
developmentfrom
bugfix/parallel-visualisation-helpers-empty-ranks

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member

What changed and why

The four plotting helpers in src/underworld3/visualisation/parallel.py (parallel_line_plot, parallel_scatter_plot, parallel_profile_comparison, parallel_custom_plot) evaluate on the plotting rank (viz_rank) and have every other rank join the same global_evaluate with no points. They could not work at more than one rank. The parallel review desk found this while checking #1236 (its review there, finding 1); the bug predates that PR.

  • A sympy expression hung the run. The other ranks built their empty point array as np.array([]).reshape(0, field.mesh.dim). A sympy expression (T.sym, T.sym[0], 2*T.sym[0]) has no .mesh, so those ranks raised AttributeError and never reached global_evaluate, while the plotting rank waited inside it.
  • A MeshVariable raised on every rank. Every rank reached the collective, but global_evaluate does not accept a MeshVariable.

Now, in all four helpers:

  • the empty point array takes its dimension from the sample points, np.zeros((0, np.asarray(sample_points).shape[1])), so every rank reaches the collective whatever the field is;
  • a MeshVariable is evaluated through its .sym, so a user can pass either.

Both are two small private helpers (_no_points, _evaluable) used by all four functions. No signature changes; the docstrings now say a field may be a MeshVariable or a sympy expression.

What a user's run does now: a notebook or script calling these helpers under mpirun plots on viz_rank and returns on the others, where before it hung (sympy expression) or raised (MeshVariable). Serial runs are unchanged, apart from now accepting a MeshVariable.

Test

tests/parallel/test_1243_parallel_plot_helpers_parallel.py (level 1, tier B; 12 cases): each helper, viz_rank 0 and the last rank, with a MeshVariable and with sympy expressions (T.sym, T.sym[0], multiples of it). The baseline is exact: T is a degree-1 variable holding x + 2y, so the plotting rank's values at the sample points must equal x + 2y (or its multiple) to 1e-12; the other ranks must evaluate an empty (0, 2) array. scripts/test.sh runs the file at np 3 as well as in the np 2 pass, since at three ranks two ranks join with no points.

On development (unfixed source, same build), at np 2 and np 3, run case by case under the MPI supervisor:

  • the cases that pass a sympy expression first (parallel_line_plot with T.sym, parallel_profile_comparison with T.sym[0] first) hang: the plotting rank waits in global_evaluate and the job is killed by the timeout;
  • the cases that pass a MeshVariable first fail with AttributeError on every rank.

What was run

On a 96-thread Linux workstation (single system image, Intel Xeon Gold 6240R, MPICH):

What Result
new file, np 2 12 passed on both ranks
new file, np 3 12 passed on all three ranks
test_0846 (both files), test_1057_native_vis_higher_order, test_0052_collective_guard_scan, serial 70 passed
scripts/check_test_coverage.py OK, 489 files reachable
scripts/check_deprecated_patterns.py OK, no new patterns

Not run

np 4 and above; a real display (the test uses matplotlib's Agg backend, so plt.show() draws nothing); macOS; the full suite.

Reviewer: the parallel review desk (H1).

Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)

  • I have read the Style Charter and followed it over the surrounding code (S2)
  • No drive-by refactors, renames, or "while I was here" cleanups (S9)
  • Bug fixes ship the regression test, written first, with level_* and tier_* markers (S8)
  • No hedging names (maybe_ / try_ / do_) and no commented-out code (S3, S4)
  • Every exception swallow states its sanctioned failure mode in a comment (S4) — not applicable, none added
  • New data access uses .array / mesh.X.coords — no with ....access(...), no mesh.data (S7) — not applicable in the library change; the test writes T.array
  • Parallel safety considered — np2/np4 checked where swarm/mesh/solver dispatch is touched (S11) — np 2 and 3
  • No mesh entity or rank identified by coordinates; any remaining tolerance is named, relative and says what it bounds (S12)
  • No pixi.toml / pixi.lock or other dependency changes riding in an unrelated PR
  • AI-assisted work carries the attribution line below

Underworld development team with AI support from Claude Code

Every helper with a MeshVariable and with sympy expressions, viz_rank 0 and
the last rank, against the exact linear field. On development the sympy
cases hang (the plotting rank waits in global_evaluate) and the MeshVariable
cases raise AttributeError on every rank. Runs at np 3 as well as np 2.

Underworld development team with AI support from Claude Code
…shVariable is accepted

The non-plotting ranks built their empty point array from field.mesh.dim,
which a sympy expression does not have, so they raised before the
collective the plotting rank was waiting in. The empty array now takes its
dimension from the sample points, and a MeshVariable is evaluated through
its .sym, in all four helpers.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:02

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict at 5e5d599: ready to merge on green from this review. The hang is fixed in all four helpers, and the values match serial exactly. I have one low finding.

What I ran

check result
The hang I reported earlier: parallel_line_plot with T.sym, T.sym[0] and 2*T.sym[0], viz_rank 0 and last, np 2 and 3 All complete. Every rank enters global_evaluate once: the plotting rank with 20 points, every other rank with 0. On development, the same calls hang.
parallel_scatter_plot, parallel_profile_comparison and parallel_custom_plot, each with a sympy field and with a MeshVariable, viz_rank 0 and last, np 2 and 3 All complete. Every rank makes the same number of global_evaluate calls (2, 2 and 2), the non-plotting ranks with empty point sets.
Values On the plotting rank, every array returned by global_evaluate equals a serial (np 1) global_evaluate of the same expression at the same points exactly (max abs difference 0.0). This holds for all four helpers, both field kinds and both viz_rank choices.
An empty rank (np 3, the empty-band layout, which leaves the last rank with no cells) All four helpers with the plotting rank on the empty rank, and line/scatter/profile/custom with the MeshVariable on rank 0: they complete, and the values equal serial.
The PR's test_1243 12 passed at np 2 and at np 3. On development (2a41d49) it hangs at np 2 and 3: the supervisor kills the job with rank 0 inside global_evaluate (_refuse_points_far_outside).
test_0052 8 passed.

Finding

  1. Low: every rank must pass sample_points. _no_points takes the dimension from the caller's own sample_points. A caller that builds the points on the plotting rank only, passing None elsewhere, raises IndexError on the other ranks before global_evaluate. The plotting rank then waits: a hang at np 2 (viz_rank 0) and at np 3 (viz_rank last), measured. Building the points on every rank is the natural use, and that is how the docstring examples and the tests call the helpers.

    Two possible fixes:

    • say in the docstrings that every rank passes the same points;
    • broadcast the dimension from viz_rank, e.g. comm.bcast(np.asarray(sample_points).shape[1] if rank == viz_rank else None, root=viz_rank). The broadcast is reached on every rank, because every rank calls the helper.

Build

The change is Python-only. The merge base 2a41d49 has the same compiled sources as an existing build at 8d8533d. I overlaid the head's Python, or the merge base's for the development runs, on that build. Every run used at most 3 ranks, on cores 80 to 83; cores 0 to 3 were in use by other work.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

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.

3 participants