Repository navigation
add_condition refuses a value with no entry for a named component; shipped examples corrected (#1129) - #1139
Conversation
…m becomes full-length (#1129) Nine files used the deprecated form with a value shorter than the components it names, e.g. add_dirichlet_bc((0.0), "Top", (1)). On development that prescribes uninitialised memory for the named component. On a convection-style box, u_y on Top and Bottom read 2.739 where 0 was asked, and the solve diverged (reason -3). The full-length form gives 0 on every wall and converges. Fixed: - the convection examples: Cartesian-Swarm, SLCN-TdepVisc, SLCN-NL, SLCN-Yield and ThermoChem; - fluid_mechanics/basic/falling_sphere.py; - Ex_Stokes_Disk_CylCoords_DEPRECATED_NATIVE.py; - utilities/advanced/Ex_Tensor_Variables_etc.py; - docs/developer/ai-notes/UW3-SCRIPT-WRITING-CHEAT-SHEET.md, which taught the form. The WIP developer example's three calls are in the previous commit. Four other WIP files pass a list of boundaries, which already fails the boundary-type check, and are left alone. The examples parse gate passes (316 scripts, 27 notebooks). Underworld development team with AI support from Claude Code
Adversarial review at 1601f77Reviewed by W1 (the integration session, which owns the solver code) with a fresh reviewing agent that was given the code and the PR, not our conclusions. Run on macOS (12-core Apple M4), serial only; nothing was run on more than one rank. Two builds in one environment were compared: "before" is c1eebf0 (the head of PR #1119, which contains development 01dec8d; it is not this PR's merge base a729719) and "after" is 1601f77. Between them the solver source differs by exactly this PR's 20 lines; five other Python files (mesh, swarm, multigrid) also differ, so the comparison does not isolate the 20 lines. Result. The refusal does what the PR says: of 93 calls probed, 26 are now refused at the add call, none of those 26 worked before, and the other 67 are unchanged to the bit. Before merge we would have the example in the error message fixed: in three measured cases, following it gives a different condition or none, with no error (finding A). Whichever of this PR and #1127 merges second must first change a test in #1127 that this PR makes fail (finding B). The remaining findings do not block. FindingsA. The example in the error message is wrong in three measured cases, and following it gives a wrong or absent condition with no exception. The message puts the value's first entry at the highest named component and
Other examples we read off the message: 3-D B. With this PR and #1127 both merged, a tier B test of #1127 fails; the body's "that fallback becomes unreachable. It is harmless" does not hold. #1127 (run at 0764729; the test is the same at its current head e4faf9b) has C.
None of this is in #1129's text and none of it changed. Does not block. D. "Natural BCs … now gets the same refusal at the call" holds only when a component is named beyond the value's length. E. The tests do not pin what the body promises stays accepted. F. Two statements in the body we could not reproduce. (1) "uninitialised memory": the wrong values were the same in every process and for every value given (−2.73861 and 0.866025 in 2-D, velocity hash identical across twelve spellings and across 0 and 0.05). We did not trace what the slot holds. (2) "the solve diverges (reason −3)" on a convection-style box: on our box (unit square, cell size 0.1, free slip on four walls, buoyancy) the short form gave u_y from −2.73861 to 0.866025 on Top and Bottom with SNES reason 2 after one iteration. The body's driver is not in the PR. Does not block. G. Four of the nine corrected scripts stop before their boundary-condition calls on the after build, on errors unrelated to this PR. Each script was truncated after its last corrected call and run. Five reach and pass the corrected calls (three convection examples, the thermochemical one, H. Housekeeping. The body says "H6's #1127" without saying what H6 is. The checklist ticks "no commented-out code" while the PR edits a commented-out call in the disk example and leaves a commented-out refused call in the shear-band timing example (line 328). The first commit's subject ends "[wip: examples next]". The new comment in the solver source partly narrates the old defect. The cheat sheet still teaches the deprecated short form for component 0 ( What holds
Tolerances and coordinate matchesThe library change introduces none. The test file selects wall nodes by coordinate ( Not checked
Issue verdicts
Underworld development team with AI support from Claude Code |
…he call (#1129) The example in the refusal was built as "None up to the highest named component, then the value's first entry". Following it changed the condition where names and entries do not pair one to one: (0.05,) with components (0, 1) advised (None, 0.05), which frees u_x; in 3-D (0.01, 0.05) with (1, 2) advised (None, None, 0.01), putting u_y's value on u_z; on a one-component unknown, components 1 advised (None, 0.0), which is accepted and applies nothing. The example is now printed only when the value has one entry per named component, the names are distinct, and each is a component of the field; each entry goes to its own component. Otherwise the refusal gives no example. A repeated name is listed once. Underworld development team with AI support from Claude Code
… prescribes its value (#1129) Underworld development team with AI support from Claude Code
…1129, with #1127) #1127's test called add_dirichlet_bc(0.05, "Left", 1), the one-entry value naming component 1 that this branch refuses. It now asserts the refusal: the same message on every rank, naming the missing entry and the full-length form (None, 0.05). Underworld development team with AI support from Claude Code
Fixes #1129. A boundary value shorter than the components it names is now refused at the call, and the shipped examples and docs that used that form are corrected.
The defect.
add_dirichlet_bc(0.05, "Left", 1)and((0.05,), "Left", (1,))use the deprecatedcomponents=form with only the named value. They prescribed garbage, and the solve gave no sign of it. Measured on development 01dec8d, serial, on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH):0.05, "Left", 1(2-D)(0.05,), "Left", (1,)(2-D)0.05, "Left", 1(3-D)(None, 0.05)and(0.0, 0.05), components=(1,)Where the numbers come from. PETSc's essential-field callback fills the value array from the generated point function. A one-entry value writes only slot 0, which belongs to the free component. PETSc then reads the constrained component's slot, which the generated function never writes. The wrong values are the same in every process, so they are whatever the callback leaves in that slot, not random memory. So a short value naming component 0 happens to work, and one naming a later component does not.
The fix.
add_condition(petsc_generic_snes_solvers.pyx) now raisesValueErrorwhen a component named bycomponentshas no entry in the value. It runs after the component list is resolved and before anything is recorded, so it covers essential and natural conditions on every solver class. The message gives the full-length form, e.g.(None, 0.05), only where it follows from the call: one entry per named component, the names distinct, each a component of the field, and each entry put at its own component. Otherwise it gives no example. Following a guessed example could free a constrained component, move a value to another component, or name a component the field lacks and be accepted while applying nothing.add_dirichlet_bc(0.0, "Left", 0). A test pins it.Why refuse rather than make the short form work. Making
(0.05,)withcomponents=(1,)mean "0.05 on component 1" would silently change what every such call has done until now. That would be a behaviour change through a deprecated form, which the deprecation exists to retire. The refusal changes no solve that works today, and it turns every one that didn't into an error naming the fix.What it uncovered. Nine shipped files used the short form, and on development they were silently wrong:
fluid_mechanics/basic/falling_sphere.py;On a convection-style box,
add_dirichlet_bc((0.0), "Top", (1))puts 2.739 on u_y at Top and Bottom, where 0 was asked. All nine are rewritten to the full-length form, which gives 0 on every wall. So is a WIP developer example. Four WIP files that also pass a list of boundaries already fail the boundary-type check and are left alone. The examples parse gate passes (316 scripts, 27 notebooks). Four of the nine corrected scripts stop on unrelated errors before they reach their boundary conditions; that is #944's runtime half. For those four, the edit is checked by parsing only.Tests.
tests/test_1166_short_bc_value_with_components_refused.py, tier B:(None, 0.05), and the deprecated form with a full-length value) still put 0.05 on the wall;The refusal and example tests fail on development (the example tests also at 1601f77, this PR's earlier head) and pass here. The full-length and component-0 tests pass on both. Every test file that sets a boundary condition, 195 files, passes: 1530 passed, 7 skipped, 1 xfailed, 1 xpassed.
Relation to #1127 (merged). #1127 reads an essential condition's value at a node of a rotated wall. For the older form it falls back to one entry per named component (
bc.fn[components.index(component)]). Its testtest_the_older_components_form_of_an_essential_condition_still_solvescalledadd_dirichlet_bc(0.05, "Left", 1), which this PR refuses. Development, with #1127, is merged in (a26acde), and that test is nowtest_the_older_short_components_form_is_refused_on_every_rank. It asserts the same refusal message on every rank, naming the missing entry and(None, 0.05). test_1066 and test_1166 pass serially (29), and the changed test passes at np 2. #1127's fallback for the short form now has no caller and can go in a later tidy.Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)
level_*andtier_*markers (S8)maybe_/try_/do_) and no commented-out code (S3, S4).array/mesh.X.coords— nowith ....access(...), nomesh.data(S7)pixi.toml/pixi.lockor other dependency changes riding in an unrelated PRUnderworld development team with AI support from Claude Code