Commit 52bd150
test/parameter_initialization: use Enzyme.autodiff with Duplicated
Apply the same pattern as test/desauty (SciML#1454) to the
`Adjoint through Prob (Enzyme)` testset: express the loss as a plain
function `enzyme_loss(t, prob_)`, pass `prob` as an explicit
`Duplicated` argument (with `make_zero(prob)` shadow), and reconstruct
`repack` *inside* the loss from `prob_` so its captured parameter
template shares Enzyme's shadow. This is the idiomatic Enzyme
formulation for a loss that captures mutable state; `Const(loss)` on
a closure capturing mutable `prob` doesn't allocate shadows for the
captures, while `autodiff(... Duplicated(prob, dprob))` does.
The `@test_broken` is retained because the rewrite now exposes a
deeper, well-localized blocker: `Enzyme.autodiff` enters the
`GaussAdjoint` `_concrete_solve_adjoint` rule, which calls
`_init_originator_gradient` to differentiate the parameter-init
`tunables -> new_u0` mapping. That helper invokes
`Enzyme.gradient(Enzyme.Reverse, Const(init_loss), tunables)` without
`set_runtime_activity`, so the inner Enzyme call still raises
`EnzymeRuntimeActivityError` at the MTK init `remake` — the outer
call's runtime-activity setting does not propagate into that nested
gradient. The test now clearly indicates what's left: teach
`_init_originator_gradient(::EnzymeOriginator, ...)` to use
`set_runtime_activity(Reverse)` (or `autodiff` + `Duplicated` itself).
Flipping `@test_broken` -> `@test` is the only change needed here
once that fix lands.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>1 parent 5aadc53 commit 52bd150
1 file changed
Lines changed: 41 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
82 | 95 | | |
83 | 96 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
93 | 107 | | |
94 | 108 | | |
95 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
96 | 112 | | |
97 | | - | |
98 | | - | |
99 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
100 | 119 | | |
101 | 120 | | |
102 | 121 | | |
0 commit comments