Skip to content

Parallel plotting helpers: only the plotting rank needs the sample points - #1246

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/parallel-plot-points-from-viz-rank
Nov 20, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/parallel-plot-points-from-viz-rank

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member

What changed and why

Follow-up to #1243 (stacked on it; retarget to development once #1243 merges), from the parallel review desk's low note on it: a caller that passes sample_points=None on the ranks that do not plot still hung, because those ranks read the points' dimension themselves and raised, while the plotting rank waited in global_evaluate.

Now only viz_rank's sample points are read. One private helper, _points_on_this_rank, broadcasts their dimension from viz_rank and gives every other rank an empty array of that dimension, so the other ranks may pass anything, None included. If the points on viz_rank are not an (n, dim) array, every rank raises the same ValueError before global_evaluate, instead of hanging. Each helper now runs one code path to global_evaluate on every rank; only the plotting is on viz_rank. The docstrings say that every rank calls the helper and only viz_rank's points are used.

What a user's run does now: a parallel notebook that builds its sample points only on the plotting rank works; one that passes no usable points on the plotting rank gets an error on every rank naming viz_rank, where before it hung.

Tests

Two new cases in tests/parallel/test_1243_parallel_plot_helpers_parallel.py (tier B), each for viz_rank 0 and the last rank:

  • test_only_the_plotting_rank_needs_the_points: the other ranks pass None; all four helpers complete, and the plotting rank's values equal the exact field x + 2 y.
  • test_unusable_points_on_the_plotting_rank_are_refused_on_every_rank: None on the plotting rank raises the same ValueError on every rank.

On #1243's head both hang at np 2 (pytest's timeout fires).

What was run

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

What Result
the test file at np 2 16 passed on both ranks
the test file at np 3 16 passed on every rank
collective guard scan and the serial visualisation tests 39 passed
scripts/check_deprecated_patterns.py OK, no new patterns

Not run

np 4 or more; a real display; macOS; the full suite.

Underworld development team with AI support from Claude Code

…g rank only

On #1243's head, None for the points on the other ranks hangs at np 2
(pytest's timeout fires); None on the plotting rank also hangs.

Underworld development team with AI support from Claude Code
…efuse unusable ones on every rank

The dimension of the empty point array is broadcast from viz_rank, so the
other ranks may pass anything. Points on viz_rank that are not an (n, dim)
array raise the same ValueError on every rank before global_evaluate.
Every rank now runs one code path to global_evaluate; only the plotting
differs.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi changed the base branch from bugfix/parallel-visualisation-helpers-empty-ranks to development November 20, 2026 01:40
@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 on 3292306: changes requested. One line is needed: refuse non-finite sample points in the new guard (finding 1). Everything else in the change is correct.

  • With None on the ranks that do not plot, all four helpers complete at np 2 and 3, for viz_rank 0 and for the last rank, including when the plotting rank holds no cells. The values equal serial global_evaluate exactly.
  • Unusable points on the plotting rank are refused with the same ValueError on every rank. The exception is NaN points, which still hang.

Which head the runs used: they were made on 3550263. The current head, 3292306, is that commit merged with development after #1243 merged. Between the two heads, src/underworld3/visualisation/parallel.py and tests/parallel/test_1243_parallel_plot_helpers_parallel.py are byte-identical. Everything else the merge brings is development's own: solver and multigrid code and other tests, nothing under visualisation/. So these runs stand for 3292306.

Method

The PR changes Python files only. Both the PR and #1243's head (5e5d599) were run as Python overlays on one clean build whose compiled sources match their merge base with development, 2a41d49 (an empty diff over *.pyx *.pxi *.pxd *.h *.c setup.py). Every run printed underworld3.__file__ to confirm which overlay was loaded.

The parallel layouts are a test-only shell partition of the gmsh mesh:

  • default: PETSc's own partition.
  • band: horizontal bands of cells.
  • rand7: random assignment with seed 7.
  • emptyband: bands over np-1 ranks, so the last rank holds no cells.

The value check uses a degree-2 field set to sin(3x)cos(2y) + xy, sampled at 41 points along a line, through T, T² and T + x. The reference is global_evaluate at np 1. Each helper's own global_evaluate calls were recorded on every rank.

Results

case np layout #1243 head (5e5d599) PR (3550263 = 3292306 for these files)
sample_points=None off viz_rank; line, scatter, profile, custom; viz_rank 0 and last 2 default, band hangs (the PR's new test: pytest timeout) completes; values on viz_rank equal serial exactly (max difference 0.0); other ranks make the same number of empty evaluations
same 3 default, band, rand7 – same: completes, exact
same, viz_rank = the rank with no cells 3 emptyband – completes, exact
viz_rank points None, 1-D, empty 1-D, ragged list, string 2; 3 (emptyband) default; emptyband – the same ValueError naming viz_rank on every rank, for both viz_rank values
viz_rank points of shape (0, 2) 2, 3 default, emptyband – completes on every rank, with nothing evaluated
viz_rank points with 1 or 3 columns, or transposed 2, 3 default, emptyband – the same ValueError from global_evaluate (shape (n, cdim)) on every rank
viz_rank points outside the mesh 2, 3 default, band – the same ValueError from evaluate on every rank
viz_rank points with one NaN row 2 default hangs as well, with the same points on every rank (finding 1) different errors per rank (IndexError on one rank, the #960 RuntimeError on the other) with viz_rank 0; hangs with viz_rank 1
viz_rank points all NaN 2, 3 default, band – different RuntimeErrors per rank (kd-tree stencil, and #960); no hang
test_1243_parallel_plot_helpers_parallel.py (16) 2 default the two new cases hang (pytest's 120 s timeout) 16 passed on each rank
same 3 default, emptyband – 16 passed on every rank
test_0052_collective_guard_scan.py 1 – – 8 passed

Findings

  1. Medium: the new guard does not refuse NaN points, and NaN on the plotting rank can still hang.
    • What happens: _points_on_this_rank accepts any 2-D array that converts to float. With one NaN row on the plotting rank at np 2, the ranks leave global_evaluate with different errors. In the worst case, the plotting rank stays in Swarm.migrate's barrier inside global_evaluate after the other rank has left, and the supervisor stopped the run after 300 s of silence.

    • Not new: the hang lies in global_evaluate itself. It occurs on Parallel plotting helpers: every rank joins global_evaluate, and a MeshVariable is accepted #1243's head as well, with the same points passed on every rank.

    • Why fix it here: this PR's purpose is that unusable points on viz_rank fail together before the collective, and the fix belongs in the guard the PR adds. Requiring finite points there catches every case seen:

      if points is not None and points.ndim == 2 and np.isfinite(points).all():
          dim = points.shape[1]

      A NaN case in test_unusable_points_on_the_plotting_rank_are_refused_on_every_rank would pin it. The NaN hang in global_evaluate itself will be raised separately.

  2. Low, no change needed: points with the wrong column count (1 or 3 columns, or transposed) pass the guard, since only ndim == 2 is checked. global_evaluate then refuses them with the same ValueError on every rank, because the other ranks receive empty arrays of the same broadcast dimension. Checking the dimension against the mesh is not needed.

Confirmed correct

  • The broadcast is reached on every rank in every helper. _points_on_this_rank is the first collective in each helper, called unconditionally before any global_evaluate. In parallel_custom_plot it is called once per spec. The only code before the broadcast that could raise, the plotting rank's np.asarray, catches TypeError and ValueError, so the plotting rank always reaches the broadcast. The refusal is raised after it, on every rank together.
  • No rank-dependent branch before the collective: each helper runs one path to global_evaluate on every rank and only plots on viz_rank. The other ranks receive np.zeros((0, dim)).
  • What every rank must still pass the same: fields (profile comparison) and field_data_specs (custom plot). The custom plot's docstring says so.
  • The new tests hang on Parallel plotting helpers: every rank joins global_evaluate, and a MeshVariable is accepted #1243's head and pass on the PR.

Run and not run

  • Run: everything in the table. Each parallel run went under an MPI supervisor with a 300 s silence limit, and nothing used more than 3 ranks.
  • Not run:
    • np 4 or more;
    • a real display (Agg backend only);
    • 3-D meshes;
    • a rebuild at the new merge base 9cf3509. That merge base adds one Cython file over the build used here, in the solver and multigrid code, which the visualisation helpers do not reach.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

At np 2 on the previous head one rank fails with a different error and the
other hangs.

Underworld development team with AI support from Claude Code
Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

The parallel review desk's point, at 06cb900: the guard on the plotting rank's points now also requires np.isfinite(points).all(), so one non-finite row raises the same ValueError on every rank before global_evaluate. New case test_a_non_finite_point_on_the_plotting_rank_is_refused_on_every_rank (viz_rank 0 and last): on the previous head at np 2 one rank failed with a different error and the other hung. Now the file gives 18 passed on every rank at np 2 and np 3.

global_evaluate itself hanging on non-finite points (with every rank passing the same points) is a separate fix PR, next.

Underworld development team with AI support from Claude Code

Copilot AI balanced review requested due to automatic review settings November 20, 2026 02:07

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.)

Re-check of 06cb900: ready to merge on green from this review. The finite-points guard resolves the first review's only finding, and nothing else changed.

The diff since 3292306 is two commits, with no merge of development. The merge base is still 9cf3509.

  • 06cb900: _points_on_this_rank now also requires np.isfinite(points).all(), and its message and docstring say "finite".
  • 8a43dec: a NaN-row case, for viz_rank 0 and the last rank.

Build: an overlay on a clean build whose compiled sources match the merge base exactly. Every run printed underworld3.__file__.

case np layout 06cb900
one NaN row on viz_rank, line and custom helpers, viz_rank 0 and last 2, 3 default the same ValueError ("…must be a finite array of shape (n, dim)") on every rank; no hang. The first review measured different errors per rank here, and a hang
all-NaN points on viz_rank 2, 3 default the same ValueError on every rank; no hang
one inf row on viz_rank 2, 3 default the same ValueError on every rank; no hang
None on every other rank; all four helpers, viz_rank 0 and last 2, 3 default completes; the values on viz_rank equal serial global_evaluate exactly (difference 0.0) for a nonlinear degree-2 field
same, with viz_rank the rank that has no cells 3 emptyband completes, exact
test_1243_parallel_plot_helpers_parallel.py 2 default 18 passed on each rank
same 3 default, emptyband 18 passed on every rank

The other unusable inputs from the first review (None, 1-D, ragged, string, wrong column count) take code that did not change, so they were not rerun. Each parallel run went under an MPI supervisor with a 300 s silence limit, with nothing above 3 ranks. Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit c2f8b4f into development Nov 20, 2026
10 checks passed
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