Skip to content

Adjoint: a datum that is one named constant no longer raises - #1240

Open
lmoresi wants to merge 1 commit into
developmentfrom
fix/adjoint-named-constant-datum
Open

lmoresi wants to merge 1 commit into
developmentfrom
fix/adjoint-named-constant-datum

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member

What changes for users: gradient() no longer raises when an essential condition's value is exactly one named constant, such as add_dirichlet_bc((V_w, None), "Left") in a model with reference quantities.

Found by H3 (the units desk, a Claude session) while converting the fault_friction example to explicit quantities. Runs were on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH), on development 4ab522a. adjoint.py is unchanged from there to this branch's base.

The defect

unwrap_expression returns a Python float for a bare constant expression in model units: V_w holding 5 mm/yr gives 0.5. _boundary_reads_of in adjoint.py then called .atoms on it:

AttributeError: 'float' object has no attribute 'atoms'

-V_w comes back as a sympy Float and passes, so a shortening box failed on its left wall only. The scan now sympifies the unwrapped element: a one-line change.

Test

tests/test_0036_adjoint_named_constant_datum.py, 2 tests: the gradient with respect to a viscosity knob, against central differences of the solve, with reference quantities and without. The case with reference quantities fails on development with the error above. The case without passes on both, because there the value is already a sympy number.

Existing tests: tests/test_002*.py and tests/test_003*.py, the adjoint tests: 135 passed. scripts/check_test_coverage.py passes.

Checklist (UW3 Style Charter)

  • Followed the Style Charter over the surrounding code (S2)
  • No drive-by refactors (S9)
  • Regression test written first, with level_* and tier_* markers (S8)
  • No hedging names, no commented-out code (S3, S4)
  • No new exception swallow (S4)
  • No dependency changes
  • AI-assisted work carries the attribution line

Underworld development team with AI support from Claude Code

unwrap_expression returns a Python float for a bare constant expression in
model units (V_w at 5 mm/yr gives 0.5), and the adjoint's scan of the
boundary reads called .atoms on it: gradient() raised AttributeError when an
essential condition's value was exactly one named constant. -V_w came back
as a sympy Float, so a shortening box failed on the left wall only. The scan
now sympifies the unwrapped element.

test_0036 checks the gradient against central differences, with reference
quantities and without; the case with them fails on development.

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

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.

This branch has not been deployed

No deployments
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