Repository navigation
Reverse-mode rules for PDE solution wrappers behind discretizer hooks - #1630
Conversation
|
Check Enzyme and Mooncake compatability? Since Zygote isn't used much anymore. |
494acc5 to
b858e98
Compare
|
@ChrisRackauckas Reworked so ChainRulesCore, Mooncake and Enzyme each get their own rules, all tested against ForwardDiff. Mooncake works end to end on MOL (SciML/MethodOfLines.jl#698, with chalk-lab/Mooncake.jl#1385 and SciML/ModelingToolkit.jl#5288); Enzyme is blocked on EnzymeAD/Enzyme.jl#3855 |
Independent review of
|
|
@ChrisRackauckas Fixed with tests. Views and ranges go through the AD’s own collect pullback now, and the observed parameter part is added with increment!!, so scalar and matrix p work too. Found and fixed two Enzyme issues on the same path while at it, and an argument Enzyme can’t push a cotangent through now errors instead of zeroing. |
Re-review of head c70735b (fresh-session Codex gpt-6.1-sol)This re-reviews the two blocking Mooncake findings from the previous review (#1630 (comment)) and the commits pushed since (e097476, c70735b). The reviewer rated risk on its own before seeing any other rating. Its verdict is advice only: the PR is rated medium risk, so it still needs a maintainer's review before merge. VERDICT: MERGE Riskmedium (M1: new methods on external reverse-mode AD interfaces for explicitly opted-in PDE wrappers; ordinary solution paths retain their dispatch). Blocking findingsNone. Both first-review findings are resolved, confirmed by running. Non-blocking findingsThe claimed MethodOfLines integration run remains unverified here; its exact invocation and output are absent from the PR body. What I ranReviewed c70735b, confirmed with Used a fresh copy of the first review's environment, re-developed this checkout into it, and ran Julia 1.10.12, Mooncake 0.5.65, Enzyme 0.13.216, SciMLSensitivity 7.119.13, Zygote 0.7.13. Julia threads: 4; precompile tasks: 4; OpenBLAS threads: 1. Interrupted automatic environment precompilation, then completed validation with Affected suites: exit 0, 348/348 assertions. Under module CorePDE
include(joinpath(ENV["PWD"], "test/pde_solutions.jl"))
include(joinpath(ENV["PWD"], "test/public_interface.jl"))
end
module AdjointPDE
include(joinpath(ENV["PWD"], "test/downstream/pde_solution_adjoints.jl"))
end
Original reproducers, included unchanged by
Zygote also matched both references. Enzyme intentionally rejects observed-parameter differentiation rather than returning zero. Adversarial runs: invoked each probe with
Failing-before controls, in an isolated scratch worktree with current test definitions:
What I did not verifyFull DownstreamAD/Core groups, QA, docs build, other Julia versions/dependency lower bounds, ComponentArrays, MethodOfLines' SolutionAD suite, pending upstream patches, or unrelated CI failures against master. Conclusions cover the exercised representations. Links
🤖 Posted by an AI agent — harness: codex-cli 0.163.0 (review), posted by Claude Code (claude-opus-5-5) · model: gpt-6.1-sol |
Moves the rrules for
sol[u(t, x)]andsol(t, x; dv)out of SciML/MethodOfLines.jl#698 into SciMLBase, where the wrapper types live, and dispatches down to the discretizer. Rules for ChainRulesCore, Mooncake and Enzyme.AbstractDifferentiableDiscretizationMetadataopts a discretizer in. Not on by default because NeuralPDE's PINO solution evaluates the trained operator insol(p, t)and Zygote already differentiates that by tracing; rules on every metadata would break it until NeuralPDE implements the hooks.pde_index_cotangentandpde_call_cotangent, plain code with no AD types: from the cotangent of a field or an evaluation they return the cotangent oforiginal_sol.uand the observed terms(f, k, δ)to pull back throughf(u[k], p, t[k]). Fallbacks error like the primal ones.sol[sym],sol[sym, inds...]andsol(args...; dv): it pulls the observed terms back with its own AD and hands the rest to the solver's rule fororiginal_sol. Mooncake gets nativerrule!!s like the existing ones forsol[sym], since@from_rrulecan't take a config or a struct tangent. A gradient that reaches the wrapper through a field instead (sol.u[sym]) is an error in all three, not a zero.prob.pfrom it, so their parameter part would be dropped.NoTangentfor Mooncake andinactive_typefor Enzyme, it's a constant of the solve.gradient(x -> sol(t, x; dv), x0)already works on MOL master and Differentiate the PDE solution interface in reverse mode MethodOfLines.jl#698 was zeroing it.Why here and not PDEBase: the rules have to call the hooks, and only SciMLBase can put rules on its own types without piracy. The discretizer side of the contract goes into PDEBase's interface page once this is in.
NeuralPDE plugs in the same way, metadata subtype plus the two hooks (
original_solis theOptimizationSolution); that is a follow-up on its side, nothing changes for it until then.Tested in DownstreamAD with a time-dependent and a stationary dummy discretizer through Zygote, Mooncake and Enzyme against ForwardDiff:
test/downstream/pde_solution_adjoints.jlpasses 87/87 on Julia 1.10.11 and 1.13.2, with Mooncake 0.5.65, Enzyme 0.13.216, Zygote 0.7.13 and SciMLSensitivity 7.119.13.MOL's side is SciML/MethodOfLines.jl#698. Its
test/SolutionAD/solution_ad.jlat b69db1c2 passes 43/43 on the same Julia versions, in an environment made fromtest/SolutionAD/Project.tomlwith MethodOfLines and this branch as path sources and MOL's SciMLBase compat (3.59, for the release this goes into) relaxed, with ModelingToolkit 11.45.4, SciMLSensitivity 7.119.13 and Mooncake 0.5.64. That needs nothing else unreleased: under Mooncake the test takes the compiled ODE path and sets the parameters through SciMLStructures. Mooncake on the DAE path ofdiscretizealso needs Mooncake 0.5.65 (chalk-lab/Mooncake.jl#1385), and parameters fromsetp_oopneed SciML/ModelingToolkit.jl#5288 (9f8d0fc82).