Skip to content

Reject a state-variable wrt_input in the algorithmic tangent pass (#118) - #119

Merged
petlenz merged 4 commits into
mainfrom
fix-118-tangent-input-category
Nov 29, 2026
Merged

petlenz merged 4 commits into
mainfrom
fix-118-tangent-input-category

Conversation

@petlenz

@petlenz petlenz commented Jul 25, 2026

Copy link
Copy Markdown
Member

Closes #118.

AlgorithmicTangentPass's find_tensor_input scanned tensor_symbol_map() with
no category filter — but that map also holds tensor state-variable
current/_old handles. So a tangent whose wrt_input named a tensor state
variable resolved silently and was differentiated against, instead of being
rejected. (This is broader than the #117 add_hyperelastic_potential helper,
which already guards at the API level; it affects every add_algorithmic_tangent
caller.)

Fix: filter find_tensor_input to Category::Input (via model.inputs()),
so a non-input tensor symbol yields the existing "not a declared tensor input"
rejection path. Sharpened the error message to name the state-variable case.

Test: StateVariableStrainInputRejectedAtEmit — a tangent w.r.t. a declared
tensor state variable now throws at emit. The existing
TangentCoexistsWithLocalNewtonStateVariable still passes, confirming the legit
case (a tangent w.r.t. the strain input while a state variable exists) is
unaffected. Suite 322/322.

@petlenz
petlenz force-pushed the fix-118-tangent-input-category branch from 024914e to 831142f Compare September 20, 2026 19:46
@petlenz

petlenz commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

C++ review

PR #119 review: no findings. Verdict: correct and well tested; only a merge with main was needed.

Merge: tests/AlgorithmicTangentTest.cpp conflicted with main's [[maybe_unused]] cleanup of UnknownStrainInputThrowsAtEmit. I kept this PR's version of that test (it now asserts the message through emit_error_message, which already uses [[maybe_unused]]), so both sides' intent is preserved. Merge commit 6f73e95.

Findings: none.

Checked and held up

  • resolve_wrt_input goes through find_tensor_symbol and rejects everything except Category::Input. add_tensor_state_variable is the only way a tensor symbol with another category exists (Category::Parameter is scalar-only), so the NotAnInput message ("STATE VARIABLE") is accurate.
  • The three failure modes (undeclared / scalar / state variable, including _old) report distinct messages, and the typo test asserts the sharper diagnoses do not fire.
  • No false positive: a normal tangent w.r.t. a strain input while a state variable exists still passes (TangentCoexistsWithLocalNewtonStateVariable, full suite).
  • NumSimMaterialTarget already checks wrt_input against model.inputs() (src/targets/numsim_material.cpp:126), so the graph-coupled path was never exposed; this PR fixes the self-contained passes.
  • Mutation check: building AlgorithmicTangentTest.cpp against main's pass_bodies.h makes StateVariableStrainInputRejectedAtEmit, StateVariableOldStrainInputRejectedAtEmit and ScalarWrtInputRejectedAtEmit fail; with the PR's header all pass.

Outside this PR: none.

Verification: commit 6f73e95, gcc-14 Debug -Werror, full ctest: 100% tests passed, 0 tests failed out of 353.

@petlenz
petlenz merged commit 274bf28 into main Nov 29, 2026
5 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.

AlgorithmicTangentPass::find_tensor_input accepts state-variable handles as wrt_input

1 participant