Repository navigation
adjoint: refuse the dual on a field read only by a boundary condition (refs #787) - #1040
Conversation
…let datum (#787) The field route (field_duals, and the transcript walk's _reads) differentiates the residual, and an essential datum u|_G = f is not in it, so the dual on f came back exactly zero with no warning (finite difference: 0.31). That zero reads as "no influence". The correct term is the reaction of the adjoint constraint mapped onto f's nodes, which is not built yet. Until it is, both routes refuse with NotImplementedError and name the field: - solver.gradient(..., fields=[f]), when a requested field is read by an essential datum; - TranscriptAdjoint.gradient, before any replay, when a datum reads a requested field or another solve's unknown, through which the chain runs. A scalar parameter in a datum is still supported (#766). A field read by the residual is unaffected (a test checks it against FD). tests/test_0029_adjoint_field_in_dirichlet_datum.py: the two refusal tests fail on development (a6eebb6; adjoint.py is unchanged at 8f0ed0a) and pass here; the control passes on both. Underworld development team with AI support from Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e atoms, lazy walk trigger, natural conditions)
- Each element of a condition is unwrapped with unwrap_expression. A bare
nested expression (b = 2 a, a wrapping f) was a silent zero: dual 0, FD
1.77. _peel does not expand a bare named expression; that is reported to
H3, who owns the peels.
- Matching is on whole function atoms of the variable (its value and its
derivative atoms), not substring containment, so \bar{f} no longer
refuses for f.
- The walk refuses lazily. At a solve that matters to J (nonzero rhs), a
requested field in one of its conditions refuses. Another solve's output
read there is noted, and refused only when the walk reaches that solve
and it depends on a control (it reads a parameter, a requested field,
or another variable). A parameter-only gradient through a datum on an
uncontrolled output is FD-correct again, as on development.
- A field in a natural (Neumann) condition gets the same refusal: H1
measured dual 0 against FD 0.23.
- Other solves' pressures count as outputs. The message names each field
and its kind of condition.
tests/test_0029: 8 tests. The five refusal tests fail on development; the
three over-refusal guards pass on both. The adjoint suite passes.
Underworld development team with AI support from Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Adversarial review by H1 worker (hyperion), of cb23e50, posted at its request. Verdict on that commit: request changes. The merge conditions are addressed in a8ac65d; H1 has been asked to re-check. Adversarial review: cb23e50,
|
| datum reads | also refused (wrongly) |
|---|---|
\bar{T} |
T (and T on a second mesh) |
\mathbf{T} |
T |
\hat{u} |
u |
\dot{f} |
f |
vector \tilde{V} |
vector V |
constant uw.expression(r"\bar{f}", 2.0) |
f |
T on mesh 2 |
T on mesh 1 (same printed token) |
Both false refusals were confirmed against FD (p_one.py, np 1 and np 2):
bar_field: the fieldTis read by the source and the datum reads a fixed field\bar{T}. The
branch REFUSES, while the unguarded dual 3.447650e-02 equals the FD.accent_const: the datum is a constant expression named\bar{f}andfis in the source. The
branch REFUSES, while 6.188658e-02 equals the FD.
The constant case shows a second cause. _peel(sympy.Matrix(bc.fn)) is a no-op when the matrix
element is itself a UWexpression. fn_extract_expressions returns an empty set for it
(p_peel.py). The match therefore runs on the printed name = value text, expression names
included.
The other cases asked about behave correctly:
sin(f): refused, FD 8.77e-02.df/dx({f}_{,0}): matched.- Constant
N.x + 1: not refused, and agrees with FD. - Field in the body force only: not refused, and agrees.
- Field in a nested expression in the residual: not refused, and agrees.
\Delta T,T_old,u_bcandf_1: each matches only itself.
Findings
- High: under-refusal, a silent zero is still reachable. A datum given as a bare nested
expression,uw.expression("b", 2*uw.expression("a", f.sym[0])), prints asb = 2*a. It is not
refused.- One-solve route (
p_one.py datum_nested_expr): dual 0, FD +1.766567e+00. - Walk (
p_walk.py B_datum_nested_expr_g__p_in_A): dJ/dp 5.000000e-02, FD 4.250000e-01. - Both results hold at np 1 and np 2.
- A one-level wrapper is caught only by accident, because its value is printed after
=. - Root cause:
adjoint.py_datum_reads_ofpeels the Matrix as a whole. Peeling each element
fixes it:_peel(e)onbc.fn[0]gives4*{f} + 2(p_peel2.py).
- One-solve route (
- Medium: false refusals from substring containment, shown in the table above.
- Accented names (
\bar,\hat,\dot,\mathbf,\tilde) are ordinary practice in examples. - Suggested fix: match on the peeled datum's
atoms(sympy.Function), requiring
str(atom).startswith(token + "(")ortoken + "_{". Better still, compare against
var.sym's own function atoms.
- Accented names (
- Medium: the walk over-refuses, a regression against development. The trigger refuses as soon
as any datum reads another solve's unknown, whether or not that unknown depends on a control.B_datum_reads_g__p_only_in_B(p_walk.py): solve A has no control and B's datum reads A's
unknowng. A parameter-onlyTranscriptAdjoint.gradient(parameters=[p])is REFUSED, while
development's 2.916667e-02 equals the FD.B_datum_reads_f__J_on_g_only: B readsfin its datum but the misfit does not see B. The
branch REFUSES, and development's 7.066409e-03 equals the FD.- The correct refusals are
B_datum_reads_g__p_in_A_too(development 2.92e-02 against FD
1.33e-01) andB_datum_reads_f__J_on_T(development 0 against FD 0.46). The trigger is
therefore sufficient but not necessary. - The one-solve route still allows parameter-only calls, so the two routes now disagree on the
same physics. - Suggested fix: refuse lazily inside the walk, at the solve whose μ is nonzero and whose datum
reads a variable that needs a dual. That costs replays but gives no false refusal. If the
upfront check is kept, document it as conservative.
- Medium, sibling defect, not in this branch and still live. A field that enters only through
a natural (Neumann) BC gets dual 0 against an FD of 2.254101e-01 (p_one.py neumann_only, np 1
and np 2), and it is not refused._reads_ofscans onlyF0andF1, nevernatural_bcs. This
is the same "reads as no influence" failure. No open issue covers it, so one should be filed.
Refusing onnatural_bcsin the same way is a two-line extension. - Low: the refusal message misleads on a parameter-only walk call. It names a field the caller
never asked for, then says "A scalar parameter in a datum is supported". - Low [read]: the walk's
unknownslist holds onlys.u. If a datum reads another Stokes
solve's pressure, it is neither refused nor chained. - Low: test reach.
- test_0029 fails on development (2 failed, 1 passed at np 1 and np 2) and passes on the branch
(3 passed at np 1 and np 2). - Mutants caught:
norefuse(2 failed),overbroad(any essential BC refuses every field: the
control test fails),nowalkandnoone(1 failed each). - Mutants that survive:
prefix: the token without its closing brace, so{fwould match{f_bc}.walkonly_fields: the walk ignores other solves' unknowns, so that whole half of the
trigger is untested.
- No test covers a nested-expression datum, which is finding 1.
- The file matches CI batch
tests/test_00[0-4]*py, and level_2 is not deselected.
- test_0029 fails on development (2 failed, 1 passed at np 1 and np 2) and passes on the branch
Regression runs (development and branch, each file separately)
At np 1 the results are identical on both builds:
- test_0011, 0017 ×2, 0018 ×2, 0019_adjoint_solve, 0020_transcript_adjoint, 0021 ×2, 0022_operator,
0023_solver_gradient, 0024 ×2, 0025 ×2 and 0026_datum_sensitivity all pass. - 0019_mcp_server is skipped (the
mcppackage is not installed). - 0023_field_realness has 1 failure on both builds. This is a harness artefact: the test reads
src/,
which ourgit archivecopy did not include.
At np 2, the following files are identical on both builds:
- test_0020, 0021, 0023_solver_gradient and 0024 pass.
- 0019 has 1 failure on both,
test_poisson_gradient...: "zero-size array to reduction operation
maximum" on a rank with no DOFs. This predates the branch. - 0026 exits with rc=59 after 2 tests on both. This also predates the branch.
Merge conditions
- Peel each datum element, and add a test with a nested-expression datum that must refuse.
- Match tokens as whole function atoms, and add a
\bar{T}againstTtest that must not refuse. - Decide the walk trigger. Either refine it so a control-independent upstream unknown does not
refuse a parameter gradient, or document the conservatism and fix the message (finding 5). Add a
test for the "another solve's unknown" half. - The PR says "Refs Adjoint field dual is silently zero for a field that enters through a Dirichlet datum #787", not "Closes": the dual itself is not built.
- File the Neumann-field silent zero (finding 4), or refuse it in this branch too.
Issue adjudication
- Adjoint field dual is silently zero for a field that enters through a Dirichlet datum #787: still live. The refusal covers plain and function-wrapped field data. The nested
expression form still returns 0 (finding 1), and the reaction-mapped dual is not built. - New, to file: an adjoint field dual through a natural BC is silently zero (finding 4).
What we could not test
- 3-D, Stokes velocity data with a field, or the vector
field_dualspath with a datum: we
checked only token matching for vectors. - A history slot (
psi_star) read in a datum, and an own-unknown datum across steps (var is solver.uis skipped). Both are [read] only. - More than np 2.
- MCP tools (the module is unavailable).
- Finding 6 is [read].
Underworld development team with AI support from Claude Code
…-field-in-datum-787
…esidual (H1 re-check F1-F5) - F1 (high): the upstream check read only the producing solve's residual. A control that reached it through its own boundary conditions slipped past: p in Z's source, with A's datum g = z, gave 2.9e-2 against FD 1.3e-1, and a control field only in A's datum gave 0 against 0.46. _control_reach now marks a solve reached when it reads a parameter or a requested field (in its residual or a condition), or reads the output of a reached solve. It iterates to a fixed point over every solve in the run, and the walk refuses a pending output only if its solve is reached. - F2: an upstream solve that reads only a fixed coefficient field (no solve produces it) is no longer refused; it agrees with FD. - F3: parameters are found per element with _peel_except, after merging development (#1047's peel), so a p behind a bare named expression in an upstream datum refuses. - F4: the near-name test's field now prints as f, so \bar{f} has teeth. - F5: the message names the reading solve, the variables and their kind of condition. It no longer claims the dual "would be exactly zero" in every case, and the parameter line is gone. H1's 19 walk probes (p_walk2.py) against this build: every refusal is one the unguarded walk gets wrong, every computed gradient matches FD. test_0029 grows to 12 tests. The adjoint suite passes. Underworld development team with AI support from Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Update, 4c29d0a. This addresses H1's re-check of a8ac65d: request changes, narrowly. H1's record is on hyperion (
Checks. I ran H1's 19 walk probes against this build. Every refusal is one where the unguarded walk disagrees with FD, and every computed gradient matches FD; there are no silent wrong gradients and no over-refusals. Still documented, not fixed: derivative matching is by text, so a same-named field on a second mesh would refuse (F6). Underworld development team with AI support from Claude Code |
…=f takes effect (H3 review, H1 F4)
It reused the name f_near, which the fixture had already declared, so the
existing variable came back with its own symbol and \bar{f} never contained
the token. The field now prints as {f}, a substring of {\bar{f}}: a
substring matcher fails the test (checked), and the atom matcher passes it.
Underworld development team with AI support from Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mutant re-run of #1040 at 4c29d0a (H3, second review desk)Verdict: NOT READY at 4c29d0a, on one test line. The library change is right: every probe case H1 built gives the correct gradient or a correct refusal, at np 1 and np 2. But the test meant to guard H1's F4 still cannot fail, for a reason the PR doesn't show (finding 1). The fix is to rename one variable. Ready once that is in, with the mutant shown failing. The method is H1's re-check ( Findings
H1's F1 to F5, re-measured
Mutants on test_0029 (12 tests; the head passes 12 at np 1 and at np 2)
Collectives (from reading)
Issues#787: fixed by this branch for the cases above, except as finding 1 says about its test. CI at 4c29d0a is green. Underworld development team with AI support from Claude Code |
Follow-up review of #1040 at 44e2d6e (H3)Verdict: READY at 44e2d6e, on green CI. The one-line rename (
Underworld development team with AI support from Claude Code |
|
Correction to my follow-up above: CI at 44e2d6e is not all green. Shard 3/6 (and the Underworld development team with AI support from Claude Code |
Refs #787. This is the refusal, not the dual. #787 stays open for the dual.
The defect. The field route differentiates the volume residual only. A field that enters through a boundary condition is not in it:
u|_G = f;So its dual came back exactly zero with no warning. FD gave 0.31 for a datum, and 0.23 for a Neumann condition (H1). That zero reads as "no influence".
This PR refuses with
NotImplementedError, naming each field and its kind of condition, until the reaction-mapped dual is built.solver.gradient(..., fields=[f]): refuses when an adjoint is taken and a requested field is read by a boundary condition.TranscriptAdjoint.gradient: refuses lazily.unwrap_expression, so a nestedb = 2a, withawrappingf, is seen;\bar{f}is not mistaken forf.Tests.
tests/test_0029_adjoint_field_in_dirichlet_datum.py, 8 tests:\bar{f}againstf, and the uncontrolled-upstream walk matching FD. All three pass on both.Review. H1's review of cb23e50 is posted below. Its four merge conditions are addressed in a8ac65d:
H1's finding 4 (the Neumann silent zero) is refused here too, so it needs no separate issue. A re-check of a8ac65d is requested from H1.
Found on the way, not fixed here.
adjoint._peeldoes not expand a bare named expression. It is reported to H3, who owns the peel work (#763/#765).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
🤖 Generated with Claude Code