Fix SciMLStructures support for BacksolveAdjoint and InterpolatingAdjoint #1260
+110
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR extends SciMLStructures support to BacksolveAdjoint and InterpolatingAdjoint, following the pattern established in PR #1236 for GaussAdjoint.
Previously, while GaussAdjoint fully supported SciMLStructures, BacksolveAdjoint and InterpolatingAdjoint did not properly handle parameters that implement the SciMLStructures interface, leading to
MethodError
when using these methods with structured parameters.Root Cause
The issue was in two places:
adjoint_common.jl
, the parameter jacobian wrappers were created without therepack
functionality needed for SciMLStructuresderivative_wrappers.jl
, the jacobian calculation was passing full parameter structures instead of tunables to the jacobian computationChanges
Fixed in
src/adjoint_common.jl
:isscimlstructure(p)
in ParamJacobianWrapper creationrepack(p)
to convert tunables back to full structureFixed in
src/derivative_wrappers.jl
:canonicalize(Tunable(), p)
jacobian\!
callsTest improvements:
test/scimlstructures_interface.jl
(missingend
statement)Testing
✅ BacksolveAdjoint now works with SciMLStructures
✅ InterpolatingAdjoint now works with SciMLStructures
Both adjoints now properly support gradient computation with structured parameters:
Test plan
Related Issues
Builds upon and completes the work started in PR #1248 to add comprehensive SciMLStructures support across all adjoint methods.
🤖 Generated with Claude Code