You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_peel_except raises SympifyError on a dimensional expression, killing EVERY row of a sensitivity table #765
_peel_except substitutes each named expression by its definition so the chain rule has
something to hold on to, and leaves a named expression alone when its value is a bare
number (the JIT passes those as run-time constants, so substituting them would recompile
the kernel on every sensitivity evaluation — four compiles per evaluation on the fault
example).
The leaf test was is_Number. A dimensional expression's .sym is a Pint quantity, which
is not a sympy Number, so it fell through to subs and raised
SympifyError: 2700 [kilogram / meter ** 3]
for uw.expression(r"\rho", uw.quantity(2700, "kg/m**3")).
Why it is worse than it looks
The failure is in the shared residual peel, not in the parameter being differentiated
against. So a single dimensional expression anywhere in the residual — the density — took
out every row of a parameter table, including rows for parameters that are themselves
perfectly ordinary numbers.
Fix
Treat a dimensional value as a leaf for exactly the same reason a bare number is one: the
JIT passes it as a run-time constant. wrt itself is still excluded from the peel, which
is what the chain rule needs.
Keeping dimensional values as leaves means a dimensional factor can now survive into dR/dm when the parameter differentiated against is dimensionless. That is correct
symbolically, and it is what exposed #763 (the sensitivity was then read out of a
re-dimensionalised integral with float()).
A second route into the same failure, without any user-supplied dimensional value: ViscoPlasticFlowModel's defaultyield_stress_min is 0 with units="Pa", so stokes.gradient(J, parameters=[model.Parameters.shear_viscosity_min]) on a stock viscoplastic model dies in _peel_except with SympifyError: 0 [pascal] — reproduced on scratch/adjoint-merge (82e697b) and feature/discrete-adjoint (e6e4e61). Any model that leaves the tension cutoff at its default is affected, whatever parameter is asked for.
Workaround used to check the adjoint in the meantime: model.Parameters.yield_stress_min = 0.0 (a bare number is left as a constant by the peel). With that, the sensitivity to the viscosity floor matches central differences to 4e-8 and the dual on a P0 viscosity field to 1e-7 per cell (tolerance 1e-11, softmin yield).
Still live on development 8f0ed0a (H3 units re-verification), on both routes:
a dimensional parameter (eta = uw.expression(..., uw.quantity(1e22, "Pa*s"))): SympifyError: 1e+22 [pascal * second];
a stock ViscoPlasticFlowModel in a model with no reference quantities. Its default yield_stress_min is 0 Pa, so stokes.gradient(J, parameters=[alpha]) raises SympifyError: 0 [pascal].
There is a third site that the fix has to cover. The first failure comes from adjoint._peel, through gradient -> field_duals -> _reads_of, before any sensitivity is computed. The is_Number leaf test is in three places: adjoint._peel, adjoint._peel_except, and the solver's own _peel_except in petsc_generic_snes_solvers.pyx, which is a copy of the second. With the leaf rule from the issue in all three, the no-units sensitivity matches central differences to 1.5e-4, and the units case then shows #763.
Script: runs/2026-11-10-h3/probes/h3_adjoint.py 765 on hyperion.
Underworld development team with AI support from Claude Code
Activity
lmoresi commentedon Sep 25, 2026
A second route into the same failure, without any user-supplied dimensional value:
ViscoPlasticFlowModel's defaultyield_stress_minis0withunits="Pa", sostokes.gradient(J, parameters=[model.Parameters.shear_viscosity_min])on a stock viscoplastic model dies in_peel_exceptwithSympifyError: 0 [pascal]— reproduced onscratch/adjoint-merge(82e697b) andfeature/discrete-adjoint(e6e4e61). Any model that leaves the tension cutoff at its default is affected, whatever parameter is asked for.Workaround used to check the adjoint in the meantime:
model.Parameters.yield_stress_min = 0.0(a bare number is left as a constant by the peel). With that, the sensitivity to the viscosity floor matches central differences to 4e-8 and the dual on a P0 viscosity field to 1e-7 per cell (tolerance 1e-11, softmin yield).Review of 06c6db0: a refresh keeps the units and the description
lmoresi commentedon Nov 10, 2026
Still live on development 8f0ed0a (H3 units re-verification), on both routes:
eta = uw.expression(..., uw.quantity(1e22, "Pa*s"))):SympifyError: 1e+22 [pascal * second];ViscoPlasticFlowModelin a model with no reference quantities. Its defaultyield_stress_minis0 Pa, sostokes.gradient(J, parameters=[alpha])raisesSympifyError: 0 [pascal].There is a third site that the fix has to cover. The first failure comes from
adjoint._peel, throughgradient -> field_duals -> _reads_of, before any sensitivity is computed. Theis_Numberleaf test is in three places:adjoint._peel,adjoint._peel_except, and the solver's own_peel_exceptinpetsc_generic_snes_solvers.pyx, which is a copy of the second. With the leaf rule from the issue in all three, the no-units sensitivity matches central differences to 1.5e-4, and the units case then shows #763.Script:
runs/2026-11-10-h3/probes/h3_adjoint.py 765on hyperion.Underworld development team with AI support from Claude Code
Adjoint gradients read PETSc's own numbers in a units model (#763, #1048
Restore #1036's custom-P lifecycle calls that this branch dropped
Adjoint gradients read PETSc's own numbers in a units model (#763, #1048
Merge pull request #1047 from underworldcode/bugfix/adjoint-peel-leaf…
Adjoint gradients read PETSc's own numbers in a units model (#763, #1048
A dimensional value in the residual no longer stops an adjoint gradie…