Skip to content

Refuse an essential condition on a fault that carries a law (#940) - #1285

Merged
lmoresi merged 4 commits into
developmentfrom
bugfix/pinned-fault-side-940
Nov 20, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
bugfix/pinned-fault-side-940

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #940. Review: H1, the session that reviews pull requests and runs the parallel tests on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).

The problem

The interface law (add_fault_bc) reads the slip and the normal traction at the fault's pair nodes from pooled local vectors filled by globalToLocal (_nodal_slip, nodal_normal_traction). globalToLocal does not write a DOF that an essential condition constrains. With a fault side pinned, for example add_dirichlet_bc((0, 0), "FltMinus") beside add_fault_bc(1.0, "Flt"), those reads return whatever the pool last held.

H1's probe of development showed the effect:

  • sigma_nn at one pair node read 1e-10 or 2.1e4 for pool contents 0 or 1e3;
  • the solve then crashed, with heap corruption or a SEGV in 8 of 10 serial runs and PETSc error 63 at np 2.

The issue's original route, a fault meeting a Dirichlet wall, is already closed, because add_fault refuses boundary faults. A condition on the fault's own sides still reaches the bad read.

The change

A law and conditions on the sides are the two documented ways to drive a split fault (fault_split.split_fault's docstring, test_1174). They are exclusive on one fault, so the mixture is refused rather than patched:

  • What is refused: fault_contact.refuse_essential_conditions_on_law_faults(solver) raises a ValueError when a fault with a law has an essential condition on its own label, on <name>Plus or on <name>Minus.
  • The message: it names the fault and the condition's boundary, and gives both ways to drive the fault: keep the law and put the condition on the walls, or remove add_fault_bc and put a condition on each side.
  • Every rank together: the check reads only the solver's registrations (_constraint_mechanisms), which are the same on every rank, so every rank refuses together with no communication.
  • Where it runs: at the start of the Stokes, thin-sheet and fault-contact solves, beside the existing free-side warning (warn_unpaired_split_faults).
  • What is not refused: natural conditions (they constrain no DOF), and conditions on the sides of a fault without a law.

Making the pooled read correct instead would mean deciding what slip and traction mean at a constrained pair node. Those quantities are not defined there, so the straight answer is to refuse.

Tests

tests/test_0940_essential_condition_on_a_fault_with_a_law.py uses H1's setup: an interior fault in a sheared box with a viscous law.

case development this branch
Dirichlet on FltMinus not refused; the solve reads the pool (DID NOT RAISE) refused, the message names 'Flt' and 'FltMinus'
Dirichlet on FltPlus not refused (DID NOT RAISE) refused
Dirichlet on the fault label Flt the process dies (exit 15) with no Python traceback refused
natural condition on FltMinus beside the law solves solves
Dirichlet on both sides, no law solves solves

tests/parallel/test_0940_..._parallel.py: the same ValueError, identical on every rank, for a condition on FltMinus and on Flt. It passes at np 2 and 3, and at np 3 with the last rank empty (a test-only shell partition).

The 09xx test decade had no batch line in scripts/test.sh. It gets one on shard 6, not shard 3, which is the longest since #1245.

Regression

  • Every test file that calls add_fault_bc or add_frictionless_fault_bc:
    • serially: 23 files, 201 passed;
    • at np 2: 22 files, all pass. One batch's summary line was lost to interleaved output; its six files pass when run one by one.
  • test_1174, test_0845, test_1107 and test_1092 (levels 1 and 2): 47 passed.
  • scripts/check_test_coverage.py: OK. --print-shards: unchanged.

Review fixes (a54bab4; development merged at 5b957ab)

From the review of d9cf206:

  1. The generic rotated path (Medium). The check now also runs at the top of _solve_rotated_if_registered, after its early return. Every solver's rotated path passes there, including a vector projection with a law. solve_with_fault keeps its own call, since it does not go through it.
    • New cases: a Vector_Projection with add_fault_bc(1.0, "Flt") and (0, 0) on FltMinus is refused, serially and with the same error on every rank at np 2 and 3, and at np 3 with an empty rank.
    • With the check disabled, the serial case does not raise, and at np 2 it gives PETSc error 63 ("Out of range index value -329"), as the review found.
  2. A pressure condition (Low). Only an essential condition on the velocity field is counted. A pressure Dirichlet on a side is refused by the pressure-nullspace check, as on development.
  3. An all-free condition (Low). (None, None) constrains no component and is not counted.
  4. A frictionless law (Low). The message now says that a frictionless law is lost there, the solve equal to one with no law.

Runs at this head:

  • tests/test_0940_…: 9 passed. The parallel file: 3 passed at np 2 and 3, and at np 3 with an empty rank.
  • Serial regression, the 51 files that call a fault law, solve_with_fault or add_rotated_freeslip_bc: 535 passed, 2 skipped. One skip needs MPI; one is a host gmsh difference.

Underworld development team with AI support from Claude Code

The interface law (add_fault_bc) reads the slip and the normal traction at
the fault's pair nodes from pooled local vectors filled by globalToLocal,
which does not write a DOF an essential condition constrains. With a side of
the fault pinned, those reads returned whatever the pool last held, and the
solve then crashed. A law and conditions on the sides are the two ways to
drive a split fault, and they are exclusive on one fault.

refuse_essential_conditions_on_law_faults (fault_contact) raises a
ValueError naming the fault, the condition's boundary and both ways to drive
the fault, when a fault with a law has an essential condition on its label
or either side. It reads only the solver's registrations, the same on every
rank, so every rank refuses together. It runs at the start of the Stokes,
thin-sheet and fault-contact solves, beside the free-side warning. Natural
conditions, and conditions on the sides of a fault without a law, are
unchanged.

The 09xx test decade gets a batch line (shard 6).

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 20, 2026 10:55

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 d9cf206: ready to merge on green from this review. The refusal works on every route the PR names. Each rank raises the same ValueError at np 1, 2, 3 and at np 3 with an empty rank, with no hang and no crash. Models without the clash give the same answers as on development. Finding 1 is a one-line extension: the generic vector solve reaches the same pooled read without the check. I would take it in this PR, but it can also go to a follow-up issue.

The head has since moved to 5b957ab, a merge of development. The PR's own diff against development is the same six files, unchanged. The runs below are at d9cf206.

Method

  • Head: d9cf206, built fresh in its own worktree (the .pyx changed). The compiled solvers' .so files are newer than the checkout.
  • Base: the merge base 86c8c85. The base package came from an existing build whose compiled sources (*.pyx *.pxi *.pxd *.h *.c setup.py) match 86c8c85 exactly, with the merge base's .py files laid over it.
  • Checks: every run printed underworld3.__file__. Tests from the head tree ran against both packages. Every MPI run went through scripts/mpi_supervisor.py --silence 60 inside an outer timeout (300 s for probes, 900 s for the slow parallel files).
  • Partitions: besides the default partition, a test-only shell hook gave a band partition with the last rank holding no cells ("np 3, empty rank").
  • Probes:
  • Regression: for head against base, a pytest plugin recorded the outcome and the solution vector (the unknowns too, since the rotated fault path solves outside the SNES) of every outermost solve().

Results

The PR's tests

development (merge base) this branch
test_0940_… serial (5 tests) 3 failed: FltMinus and FltPlus not refused; the worker running Flt crashed 5 passed
test_0940_…_parallel np 2 exit 142 (abort) 2 passed
np 3 exit 142 2 passed
np 3, empty rank hang: the ranks stopped in different collectives (unpack_uw_data_from_petsc, residual_add, rotated_residual) and the supervisor killed them 2 passed

The sweep probe of #940 (viscous law, (0, 0) on FltMinus)

np development this branch
1 SEGV the ValueError
2 PETSc error 63, "Out of range index value -354", exit 142 the same ValueError on both ranks
3 error 63 on rank 2, exit 142 the same on all 3
3, empty rank error 63, then a hang (killed) the same on all 3

A partial pin, (None, 0.0) on FltMinus, on development:

  • 3 of 4 serial runs died with heap corruption;
  • the survivor read the pool at all 11 pair nodes: sigma_nn -1.5e-9 against +9.4e3, slip 0.082 against -242, for pool contents 0 and 1e3.

So a partial pin needs refusing as much as a full one, and the branch refuses it.

Registration paths and naming (case probe; np 1 on both sides, and np 2, 3 and 3 with an empty rank on the branch)

On the branch, every row was identical on every rank at every rank count run.

case development np 1 this branch
add_dirichlet_bc((0,0), "FltMinus") + viscous law solved, but the answer equals the lawless one-side-pinned solve (sum|u| 79.0833185) refused, names 'FltMinus' and 'Flt'
the same on FltPlus solved, law lost refused
on the fault label Flt heap corruption, exit 134 refused
add_essential_bc on FltMinus heap corruption refused
(None, 0.0) on FltMinus heap corruption refused
(None, None) on FltMinus IndexError from the read refused (Low 3)
the condition added before add_fault_bc solved, law lost refused
the condition added after a first solve the first solve passes, the second aborts the first solve passes, the second is refused
frictionless law (add_fault_bc(0, …)) + FltMinus pin solved, law lost (sum|u| equals the lawless solve) refused
Coulomb law + pin heap corruption refused
fault_contact.add_frictionless_fault_bc + solve_with_fault + pin solved, law lost refused
thin sheet, viscous law + FltMinus pin solved refused
add_rotated_freeslip_bc on FltMinus + law refused by the existing "shares a node with a rotated free-slip boundary" the same
add_nitsche_bc on FltMinus + law solved solved, bit-identical to development
add_natural_bc on FltMinus + law solved solved, identical
both sides pinned, no law solved solved, identical
faults Flt (law) and Flt2 (both sides pinned, no law) solved solved, identical
Flt (law), only Flt2Minus pinned solved, warns 'Flt2' (nothing on 'Flt2Plus') the same answer and the same warning
Flt (no law, both sides pinned), Flt2 (law) with Flt2Minus pinned abort refused, names 'Flt2Minus' and 'Flt2'
two law faults, three clashes SEGV refused; the message lists the first and "(2 more: 'FltMinus' on 'Flt', 'Flt2Plus' on 'Flt2')"
pressure Dirichlet on FltMinus refused by the pressure-nullspace check refused by the #940 check (Low 2)
law only, or thin sheet with law only, or solve_with_fault with no pin solved solved, identical

What the table shows:

  • Side labels are matched by exact name (name, f"{name}Plus", f"{name}Minus") against the faults in mesh._fault_point_pairs. The prefix-sharing names Flt and Flt2 are attributed correctly.
  • Side names are always <name>Plus / <name>Minus in the code (fault_split, fault_network, extrude). No API sets custom side names.
  • fault_split refuses a touching junction, so the two faults' sides share no nodes.
  • Development gives evidence that refusing every law, frictionless included, is right. Wherever a pinned law fault survived the solve, its answer equals the solve with no law and that side pinned (79.083318529 against 79.083318531). The law was silently dropped, and nothing was said.

Legitimate models, head against base

set head base solutions
serial: 24 files calling add_fault_bc / add_*_fault_bc / solve_with_fault, plus test_0845; 207 tests, 4 workers 206 passed, 1 failed 203 passed, 4 failed (the 3 new #940 tests, plus the same failure as head) 420 solves, the same iteration counts; largest relative difference 1.1e-10 (test_0847, rotated iterative solve), every other file at or below 3.2e-14
test_1174 again without the recording plugin 28 passed 28 passed
np 2: 22 files under tests/parallel/ that call the fault laws 19 completed and passed (2 of them, test_1089 and test_1095, passed after a 60 s silence flag) the same 101 solves, the same iteration counts, 198 of 202 rank records bit-identical, largest difference 2.2e-16

About the failures and the unfinished files:

  • The one test_1174 failure on both sides came from the recording plugin. The test asserts that the free-side warning is attributed to the caller's file, and the plugin's wrapper became the caller. Without the plugin, both sides pass. The warning fires where it did before.
  • Three parallel files did not finish on either side under the 60 s silence rule: test_1174_second_add_fault_3d, test_1152 and test_1097. All ranks were still moving in the same rotated solve when they were killed. I don't count that against the branch.

CI

  • batch 6 tests/test_09*py runs the new serial file. The 09xx decade had no line before this PR.
  • The parallel file is under the tests/parallel/test_*.py glob of the --p N phase.
  • scripts/check_test_coverage.py reports OK (502 files reachable).

Reading the diff

  • refuse_essential_conditions_on_law_faults reads only solver.mesh._fault_point_pairs and solver._constraint_mechanisms(). Neither is rank-dependent, and the function makes no collective call, so there is no rank-local branch ahead of a collective.
  • Stokes: it runs after _reject_mixed_constraint_mechanisms("solve") and before the homotopy check, _build and anything else collective.
  • Thin sheet: it runs before _refresh_facet_normal.
  • solve_with_fault: it runs before solve_rotated_freeslip.
  • It raises before warn_unpaired_split_faults, so the warning's "said once" state is not touched by a refused solve.

Findings

  1. Medium: the generic vector solve reaches the same read unguarded.
    • The gap: SNES_Vector.solve sends any vector solver with a registered fault into the rotated path through _solve_rotated_if_registered. That path builds the _InterfaceAssembler when a law is registered. add_fault_bc is defined on SolverBaseClass, so every solver has it. The check is called only from SNES_Stokes_SaddlePt.solve, SNES_ThinSheet.solve and solve_with_fault.
    • The repro: a Vector_Projection on the same faulted box with add_fault_bc(1.0, "Flt") and (0, 0) on FltMinus:
      • on the branch at np 2, PETSc error 63 ("Out of range index value -329") in VecSetValues under residual_add, then a hang: rank 0 left the solve and rank 1 waited in an allreduce. Killed by the supervisor;
      • development behaves the same;
      • serially it solves, but 1 of 6 runs differed from the other 5 in the 8th digit (sum|u| 77.191728 against 77.191759), so the answer follows the pool.
    • The control: the same projection without the pin solves identically on both sides and at np 2.
    • The fix: a law on a projection is not a documented use, but the fix is one line. Call refuse_essential_conditions_on_law_faults(self) at the top of _solve_rotated_if_registered, after its early return False. Every solver's rotated path passes through it, and the check is rank-independent, so it is safe at that point. Keep the call in solve_with_fault, which does not go through it. A one-case test (a projection with a law and a pinned side) would hold it.
  2. Low: a pressure condition on a fault side is refused with the fault_contact reads the interface traction and slip from an unzeroed pooled vector at a pair node an essential wall constrains #940 message.
    • add_condition(1, "dirichlet", (0.0,), "FltMinus") is refused as "constrains the pair nodes of fault 'Flt'". It constrains no velocity pair DOF, and the law reads only velocity slip and the velocity reaction.
    • On development the same setup is refused by the pressure-nullspace check, so nothing that worked now fails. The check could filter on bc.f_id == 0, or the message could say which field it means.
  3. Low: an all-free condition is refused.
    • (None, None) on FltMinus has an empty component list and constrains nothing, yet it is refused as "constrains the pair nodes".
    • On development it raised an IndexError from inside the read, so a clear refusal is an improvement. Skipping entries with an empty components would make the message true.
  4. Low: the message gives the reason for a law that reads the pair nodes.
    • For a frictionless law, the message's reason ("The law reads the slip and the normal traction at those nodes") is not what happens: no interface assembler runs.
    • What happens on development is that the law is dropped and the solve equals the lawless one-side-pinned solve, as measured above. Refusing it is right. A clause such as "and a frictionless law is lost there" would make the message accurate for every law.
  5. Low (read, not probed): the check matches label names, not points.
    • An essential condition on a hand-made label that happens to contain a fault's pair points would not be seen.
    • No built-in label can do that: faults are strictly interior, and a touching junction is refused. I mention it only as a limit of the approach.

Run and not run

Run:

  • the PR's serial file (head and base) and parallel file (np 2, 3, and 3 with an empty rank, head and base);
  • the sweep probe at np 1, 2, 3 and 3 with an empty rank, head and base, plus a partial-pin variant on base;
  • the 27-case probe at np 1 on head and base, and 16 of its cases at np 2, 3 and 3 with an empty rank on head;
  • the projection cases at np 1 (head ×5, base) and np 2 (head ×2, base);
  • the serial fault-law regression (24 files, 4 workers) and the np 2 parallel regression (22 files), head against base, with solution comparison;
  • check_test_coverage.py.

Not run:

  • the parallel regression at np 3 or more;
  • the ptest_* files that use faults (ptest_0845, ptest_0852, ptest_1094);
  • tier C;
  • three parallel files to completion under the 60 s silence rule (above);
  • 3-D faults through the refusal. The 3-D side naming is the same code path, read only.

All runs were confined to 4 cores while other jobs on the machine were running. Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

From the review of d9cf206:

- refuse_essential_conditions_on_law_faults now runs at the top of
  _solve_rotated_if_registered, after its early return, so every solver's
  rotated path checks it: a Vector_Projection with a law and a pinned side
  reached the pooled read (PETSc error 63, then a hang, at np 2).
  solve_with_fault keeps its own call.
- Only a condition on the velocity field that constrains a component is
  counted: a pressure Dirichlet on a side is left to the pressure-nullspace
  check (as on development), and (None, None) is not said to constrain.
- The message says what happens for a frictionless law: it is lost.

New cases: the vector solve (serial, and the same error on every rank at
np 2 and 3), the frictionless reason, the pressure condition and the
all-free condition.

Underworld development team with AI support from Claude Code
@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 a54bab4: ready to merge on green from this review. The generic vector solve is now refused on every rank with the same message, with no hang. The three message and scope changes do what they say. Every model that solved at d9cf206 still solves, with the same answer to all printed digits.

This is a narrow re-check of the one commit since 5b957ab (git diff 5b957aba a54bab4d: the .pyx +6, fault_contact.py +26/-6, the two test files).

Earlier findings, then and now

finding at d9cf206 at a54bab4
1. Medium: SNES_Vector.solve reached the rotated path unguarded (a Vector_Projection with a law and a pinned side gave PETSc error 63, then a hang at np 2) Fixed. Refused at np 1, 2, 3 and at np 3 with an empty rank. Every rank gives the same ValueError (same md5), and the supervisor reports no hang. At d9cf206 the same case still gives error 63 ("Out of range index value -329") at np 2, then a hang, killed by the supervisor (rank 0 in an allgather, rank 1 in residual_add).
2. Low: a pressure Dirichlet on a side was refused with the #940 text Fixed. It is now refused by the pressure-nullspace check ("…Found pressure Dirichlet BCs on: FltMinus"), as on development.
3. Low: (None, None) on a side was refused as "constrains" Changed as intended. The #940 check no longer fires. The user now gets the existing IndexError: Out of bounds on buffer access (axis 0) from _setup_discretisation, the same error (same md5) that (None, None) gives on the Left wall with no fault and that development gives for this case. That error is not new and not from this PR. (My earlier review placed it "inside the read". The traceback shows it comes from _setup_discretisation, before any read.)
4. Low: the frictionless message said the law "reads" Fixed. The message now reads "A law with a coefficient reads … ; a frictionless law is lost there, the solve equal to one with no law (#940)".
5. Low: sides matched by label name Unchanged, as expected (a limit of the approach, not a defect).

Reading the diff

  • _solve_rotated_if_registered calls the check after its early return False. A solver with no rotated free-slip and no fault law therefore never reaches it. The call comes before _update_constants, mesh.update_lvec and solve_rotated_freeslip, so nothing collective runs first.
  • The check reads only mesh._fault_point_pairs and _constraint_mechanisms(), which hold the same registrations on every rank. The new filter (f_id == 0, plus at least one constrained component) reads only the stored conditions, so it is also rank-independent. No branch depends on a rank before a collective call.
  • Only SNES_Vector.solve and SNES_Stokes_SaddlePt.solve call _solve_rotated_if_registered. SNES_NavierStokes goes through the Stokes solve. Stokes now runs the check twice (once at the top of its solve, once here). That is harmless: no state changes, and it raises before anything else runs.
  • SNES_Scalar and SNES_MultiComponent never reach the rotated path.

Runs

Each run printed underworld3.__file__. a54bab4 was built fresh in its own worktree, and the compiled solver .so is newer than the checkout. d9cf206 and the earlier base package were reused from the first review. Each MPI run went through scripts/mpi_supervisor.py --silence 60 inside an outer timeout.

  • Projection route (Vector_Projection with add_fault_bc(1.0, "Flt")):

    case np d9cf206 a54bab4
    (0,0) on FltMinus 1 solved (sum|u| 77.1917589) refused
    (0,0) on FltMinus 2 error 63, hang (killed) refused, same message on both ranks
    (0,0) on FltMinus 3 not run refused, same on all 3
    (0,0) on FltMinus 3, empty rank not run refused, same on all 3
    (None, 0.0) on FltMinus 1 solved (development: exit 134) refused
    (None, 0.0) on FltMinus 2 not run refused
    (None, 0.0) on FltMinus 3, empty rank not run refused
    (0,0) on FltPlus 1 solved, not converged refused
    (0,0) on FltPlus 3, empty rank not run refused
    (0,0) on Flt 1 solved refused
    (0,0) on Flt 2 not run refused
    (None, None) on FltMinus 1 the existing IndexError (development the same) the same
    (None, None) on FltMinus 2 not run the same on both ranks
    law, no pin (control) 1 solved solved, identical
    law, no pin (control) 3, empty rank not run solved, the same on every rank
  • Other solver classes:

  • The 27-case probe at np 1, a54bab4 against d9cf206:

    • Every row that solved gives the same max|u| and sum|u| to 10 digits (10 rows, including the thin sheet, Nitsche, natural, solve_with_fault and the two-fault cases).
    • rotated_minus gives the same RuntimeError on both.
    • Every fault_contact reads the interface traction and slip from an unzeroed pooled vector at a pair node an essential wall constrains #940 refusal changed only its message text, which is intended.
    • The only rows whose outcome changed are the three intended ones: pressure_pin (now the nullspace message), partial_none (now the existing IndexError) and proj_pin (now refused).
    • The frictionless case at np 3 with an empty rank: refused, the same on every rank.
  • The PR's test files at a54bab4:

    • serial: 9 passed;
    • parallel: 3 passed on every rank at np 2, at np 3 and at np 3 with an empty rank.
    • Run against d9cf206, the serial file's four new tests all fail and the five old ones pass, so the new tests hold the change.

New findings

None.

Not run

  • the wider serial and np 2 fault-law regression (the commit adds one rank-independent check and a filter; the 27-case probe and the PR's tests cover the changed lines);
  • the projection route on 3-D meshes;
  • ptest_* files and tier C.

All runs were confined to 4 cores while other jobs on the machine were running. Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit bf022b1 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