Two remaining Enzyme issues after #869 / #870
1. MixedReturnException with default PolyAlgorithm
The MixedReturnException persists with Enzyme 0.13.134 and NonlinearSolveBase 2.16.0. It occurs even without SciMLSensitivity loaded — it's a compile-time type check failure.
Root cause: NonlinearSolution has Any as the 7th type parameter (the original/cache field) when using PolyAlgorithm, because different sub-algorithms have different cache types. Enzyme can't determine activity for Any-typed fields and rejects the custom rule's return type.
With explicit NewtonRaphson(), the solution has all concrete type parameters and works fine.
using NonlinearSolve, Enzyme
f(u, p) = u .^ 2 .- p
# Works (concrete types in solution)
loss1(p) = sum(solve(NonlinearProblem(f, [1.0], p), NewtonRaphson()).u)
Enzyme.gradient(Enzyme.Reverse, loss1, [2.0]) # ✓
# Fails (Any in solution type from PolyAlgorithm)
loss2(p) = sum(solve(NonlinearProblem(f, [1.0], p)).u)
Enzyme.gradient(Enzyme.Reverse, loss2, [2.0]) # MixedReturnException
Fix needed: Make the original/cache field type concrete for PolyAlgorithm solutions, or find a way to tell Enzyme to ignore inactive fields.
2. NamedTuple broadcasting error in reverse rule with MTKParameters
When p is MTKParameters, the reverse rule at line 62 (ptr.dval .+= darg) fails because darg (from SciMLSensitivity's steadystatebackpass) is a NamedTuple:
ArgumentError: broadcasting over dictionaries and `NamedTuple`s is reserved
The tangent from steadystatebackpass uses a Zygote pullback that produces a NamedTuple{(:tunable, :initials, ...)} when the parameter type is MTKParameters. The reverse rule needs to handle this case.
Proposed fix: Use SciMLStructures to accumulate the tangent, or convert the NamedTuple to the appropriate parameter type before accumulating.
Versions
- Julia 1.10.11
- Enzyme 0.13.134
- NonlinearSolveBase 2.16.0
Related
- SciMLSensitivity.jl#1358
- Enzyme.jl#3020 (EnzymeMutabilityException with remake closure)
🤖 Generated with Claude Code
Co-Authored-By: Chris Rackauckas accounts@chrisrackauckas.com
Two remaining Enzyme issues after #869 / #870
1. MixedReturnException with default PolyAlgorithm
The
MixedReturnExceptionpersists with Enzyme 0.13.134 and NonlinearSolveBase 2.16.0. It occurs even without SciMLSensitivity loaded — it's a compile-time type check failure.Root cause:
NonlinearSolutionhasAnyas the 7th type parameter (theoriginal/cache field) when usingPolyAlgorithm, because different sub-algorithms have different cache types. Enzyme can't determine activity forAny-typed fields and rejects the custom rule's return type.With explicit
NewtonRaphson(), the solution has all concrete type parameters and works fine.Fix needed: Make the
original/cache field type concrete for PolyAlgorithm solutions, or find a way to tell Enzyme to ignore inactive fields.2. NamedTuple broadcasting error in reverse rule with MTKParameters
When
pisMTKParameters, the reverse rule at line 62 (ptr.dval .+= darg) fails becausedarg(from SciMLSensitivity'ssteadystatebackpass) is aNamedTuple:The tangent from
steadystatebackpassuses a Zygote pullback that produces aNamedTuple{(:tunable, :initials, ...)}when the parameter type isMTKParameters. The reverse rule needs to handle this case.Proposed fix: Use
SciMLStructuresto accumulate the tangent, or convert the NamedTuple to the appropriate parameter type before accumulating.Versions
Related
🤖 Generated with Claude Code
Co-Authored-By: Chris Rackauckas accounts@chrisrackauckas.com