Repository navigation
Differentiate the PDE solution interface in reverse mode - #698
utkuyilmaz1903 wants to merge 1 commit into
Conversation
92ff563 to
c3977b6
Compare
c3977b6 to
c40e559
Compare
c40e559 to
ff8df71
Compare
| function ChainRulesCore.rrule( | ||
| config::ChainRulesCore.RuleConfig{>:ChainRulesCore.HasReverseMode}, | ||
| A::SciMLBase.PDETimeSeriesSolution{T, N, S, D}, | ||
| args::Vararg{Union{Num, Number, AbstractArray, Colon}}; dv = nothing | ||
| ) where {T, N, S, D <: MOLMetadata} | ||
| y = A(args...; dv) | ||
| Δargs = map(_ -> NoTangent(), args) | ||
| function call_pullback(Δ) | ||
| Δ = unthunk(Δ) | ||
| Δ isa AbstractZero && return (NoTangent(), Δargs...) | ||
| Δsol = NoTangent() | ||
| if dv === nothing | ||
| grid_args = _grid_args(A, args) | ||
| for (dvi, Δi) in zip(A.dvs, Δ) | ||
| (Δi === nothing || Δi isa AbstractZero) && continue | ||
| Δsol = Δsol + interpolation_cotangent( | ||
| config, A, dvi, _dv_args(A, dvi, grid_args), Δi | ||
| ) | ||
| end | ||
| else | ||
| cdv = indexed_dependent_variable(A, dv) | ||
| cdv === nothing && throw(not_implemented(dv)) | ||
| Δsol = interpolation_cotangent(config, A, cdv, _grid_args(A, args, cdv), Δ) | ||
| end | ||
| return (Tangent{typeof(A)}(; original_sol = Δsol), Δargs...) | ||
| end | ||
| return y, call_pullback | ||
| end |
There was a problem hiding this comment.
This is piracy. Also, it hits more pieces. How does this do with NeuralPDE.jl's solution?
|
Moving the rules up behind a hook as discussed on Slack; will revisit this PR after that lands. |
c4c99ac to
b69db1c
Compare
b69db1c to
e757fcf
Compare
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a1980a-14d4-7d31-abbd-ecfc546a05d1, reviewed head e757fcf
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: Adds reverse-mode cotangent hooks for MethodOfLines solution indexing and interpolation, including observed boundary values and evaluation coordinates. The required SciMLBase release is unavailable to the resolver, so the new AD tests never execute and G2 requires changes before merge. Blast radius: MOLMetadata-backed PDETimeSeriesSolution and PDENoTimeSolution indexing and interpolation under reverse-mode AD; observed boundary contributions and coordinate cotangents. Evidence: The blind assessment was sealed in INITIAL.md before author context. The exact head matches the live headRefOid. One Julia 1.13.2 attempt to develop the head in an isolated SolutionAD environment exited 1 during resolution: SciMLBase has available versions through 3.58.0 but the PR requires 3.59.0 or later. The inspected SolutionAD CI job fails identically before executing tests. ForwardDiff comparisons are present, but neither Zygote nor Mooncake execution was established by this review or the PR CI. Blocking findings
Non-blocking findingsNone. What I ranAll commands below are relative to the review directory; git commands used
What I did not verifyThe added test file did not execute at the head, so passing-after is unverified. I did not run it at the merge-base, so failing-before is also unverified; this is an AD feature, and I claim no demonstrated bug-fix regression pair. The supplied ForwardDiff references use a separate differentiation implementation rather than copied expected gradient values, but their agreement with reverse mode remains unverified. No Zygote, Mooncake, Enzyme, GPU, or MPI path was exercised locally, and the inspected PR CI did not reach SolutionAD execution. I did not substitute an unreleased path dependency, relax compatibility, update registries, run a whole package suite, run Pkg.test(), benchmark the performance claim, or execute downstream suites locally. Only one Julia process was started. No upstream writes were made. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5 |
Implements the reverse-mode hooks of SciML/SciMLBase.jl#1630 for MOL, in place of the ChainRules rules this PR first added here. Depends on that PR: the SciMLBase compat is bumped to 3.59, so CI resolves once that release is out.
The hooks map a cotangent of
sol[u(t, x)]orsol(t, x; dv)back to the solver's solution, for time-dependent and stationary solutions. A grid point that is an unknown takes its share from the state vector by index, and the observed ones, such as eliminated boundary points, go through one observed function of all of them, the way #718 builds the wrapper. On a 21×21 compiled grid that makes a Zygote gradient 4x faster than going through the observed function of the whole field, and Mooncake no longer overflows the stack there. An interpolated value goes to the corners of its cell, and the call hook also returns the coordinate cotangents.test/SolutionAD(lts, 1) checks fields, slices, repeated indices, interpolation at points and lines, coordinates, a time-last field and parameters in observed boundary values against ForwardDiff:Under Mooncake, parameters set with
setp_oopneed SciML/ModelingToolkit.jl#5288. With it the neural network tutorial trains with Mooncake throughsol[u(t, x)], so the docs move from Zygote to Mooncake once it is released. Enzyme is blocked by EnzymeAD/Enzyme.jl#3855.