Repository navigation
Solve each safetycopy branch of batch_func on its own problem - #1634
Conversation
batch_func joined the deepcopy, the per-task copy and the user's problem into one problem before solving. When the problem is passed by reference, that join is a pointer phi of a fresh GC object and the caller's memory, which Enzyme cannot keep rooted, so reverse-mode Enzyme through an EnsembleProblem of SDEProblems failed (SciMLSensitivity.jl#1696). Solve within each branch instead, through a shared helper, so only the results join. The rerun loop uses the same helper. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015RAaewsVwF5wyRBfErBEEr
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015RAaewsVwF5wyRBfErBEEr
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19722-009c-71c0-9045-b568beca2f51, reviewed head 9fe43bf
Review written by the reviewer named above in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands. Summary: Splits ensemble problem selection into separate solve branches to avoid an Enzyme pointer-phi failure and adds serial/threaded SDE gradient coverage. Changes are required because the new regression errors in both supported CI configurations and the local head run. Blast radius: All basic ensemble backends call batch_func; safetycopy, per-task JumpProblem copies, output hooks, and reruns share the extracted helpers. Evidence: Blind diff assessment was frozen and hashed before author context. CI has 65 successful and seven failed checks; the added serial SDE regression errors on Julia 1 and lts, while the Julia 1 threaded case passes. The local Julia 1.13.2 head run also errors with UndefRefError (exit 1); the same added test fails on merge-base with EnzymeRuntimeException and fails on head with UndefRefError, so no passing-after result exists. An analytic copy/rerun probe passes 39/39 assertions. Blocking findings
Non-blocking findings
What I ran
What I did not verifyThe added test fails on base and does not pass on head in the reviewer's own runs; a successful failing-before/passing-after pair is therefore absent. The local test stops at its first serial testset, so its threaded case was not reached locally. Full package/downstream suites, GPU, MPI/distributed workers, other AD backends, and safetycopy=true differentiation were not run locally. The fetched default-branch runs do not establish matching failures for Waltman, Mooncake, or the PR's SymbolicIndexingInterface error; those failures are not classified as pre-existing. The changed Enzyme path did execute in CI (G2), but its serial regression did not pass. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5 |
Fixes reverse-mode Enzyme through an
EnsembleProblemofSDEProblems (SciML/SciMLSensitivity.jl#1696).Problem.
batch_funcjoined the three problem choices into one value before solving:When the problem is passed by reference, this join is a pointer phi between a freshly allocated GC object (the
deepcopy) and the caller's memory (prob.prob). Enzyme cannot keep that phi rooted for the garbage collector, so compilation failed with anEnzymeInternalError(nodecayed_phis!). On the latest Enzyme main this becomes a runtimeEnzymeRuntimeExceptionMIinstead, but the gradient still fails. The join block is reached on every trajectory, so it fails even with the defaultsafetycopy = false, where thedeepcopybranch never runs.Change. A helper
_batch_solvepicks the problem and calls_batch_solve_one(prob_func→solve→output_func) inside each branch. Only the results join, never the problems. The rerun loop uses the same helper. Behavior is otherwise unchanged.Results (Julia 1.12.7, Enzyme 0.13.210):
EnsembleSerialandEnsembleThreads.CoreandDownstreamtest groups pass locally.test/downstream/ensemble_enzyme_sde.jl(DownstreamAD group) compares Enzyme against ForwardDiff for both algorithms. It passes with this change and fails withEnzymeInternalErrorwithout it.The test sets
safetycopy = false, because a customprob_funcotherwise turnssafetycopyon. On that path Enzyme hits a separate problem differentiating thedeepcopyof anSDEProblemitself (MethodError: no method matching accumulate_into(::Base.RefValue{SDEProblem…})). That is an Enzyme issue and is not addressed here.🤖 Generated with Claude Code
https://claude.ai/code/session_015RAaewsVwF5wyRBfErBEEr