Skip to content

Differentiate the PDE solution interface in reverse mode - #698

Draft
utkuyilmaz1903 wants to merge 1 commit into
SciML:masterfrom
utkuyilmaz1903:solution-interface-ad
Draft

utkuyilmaz1903 wants to merge 1 commit into
SciML:masterfrom
utkuyilmaz1903:solution-interface-ad

Conversation

@utkuyilmaz1903

@utkuyilmaz1903 utkuyilmaz1903 commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

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)] or sol(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:

Zygote Mooncake
DAE path ✓ ✓
compiled ODE path ✓ ✓
stationary ✓ ✓
complex-valued fields error

Under Mooncake, parameters set with setp_oop need SciML/ModelingToolkit.jl#5288. With it the neural network tutorial trains with Mooncake through sol[u(t, x)], so the docs move from Zygote to Mooncake once it is released. Enzyme is blocked by EnzymeAD/Enzyme.jl#3855.

@utkuyilmaz1903
utkuyilmaz1903 marked this pull request as ready for review September 28, 2026 15:14
Comment thread src/interface/solution/chainrules.jl Outdated
Comment on lines +158 to +185
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is piracy. Also, it hits more pieces. How does this do with NeuralPDE.jl's solution?

@utkuyilmaz1903

Copy link
Copy Markdown
Member Author

Moving the rules up behind a hook as discussed on Slack; will revisit this PR after that lands.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a1980a-14d4-7d31-abbd-ecfc546a05d1, reviewed head e757fcf

  • Verdict: CHANGES
  • Risk: medium (M1: existing solution indexing and interpolation calls acquire custom reverse-mode behavior; ML4 also applies to the SciMLBase lower-bound increase).
  • Round / slot: 1 / 1
  • Blocking priorities: P1

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

  1. [P1] Make the required SciMLBase release resolvable and exercise SolutionAD before merge — Project.toml:57 and test/SolutionAD/solution_ad.jl:1 (confirmed by running). Developing this exact head exits 1 with Unsatisfiable requirements detected for package SciMLBase: available versions end at 3.58.0, while MethodOfLines restricts them to 3.59.0–3. The inspected SolutionAD CI job reports the same failure; documentation, downgrade, downstream and benchmark logs also fail on this bound. Consequently the expected Zygote/Mooncake-versus-ForwardDiff checks never start, so the changed AD paths lack the execution required by G2. Wait for registration of a SciMLBase release containing the hooks, retain a bound that guarantees those hooks, and obtain successful SolutionAD runs on the supported CI versions before merging. Merely lowering the bound to a release without the hooks would not fix this.

Non-blocking findings

None.

What I ran

All commands below are relative to the review directory; git commands used src as their working directory. Read-only GitHub queries and file reads exited 0 unless noted.

  • gh pr view 698 --repo SciML/MethodOfLines.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid: OPEN, draft, head e757fcf; PR base metadata b4c1e87.
  • git fetch origin '+refs/pull/698/head:refs/remotes/pr/698' master; git checkout --detach pr/698; git fetch origin '+refs/heads/master:refs/remotes/origin/master'; git rev-parse HEAD origin/master; git merge-base origin/master HEAD; git diff --stat origin/master...HEAD; git diff origin/master...HEAD: exit 0. Head matches the target; fetched master is fcf63be, and the merge-base is b4c1e87. Reviewed all ten changed files and the surrounding solution constructors, indexing, and interpolation helpers. No repository-root AGENTS.md or CLAUDE.md was present.
  • sha256sum INITIAL.md > INITIAL.sha256: exit 0 before reading author context. codex --version: codex-cli 0.166.0. git log -1 --format=%B e757fcf6ed48e2a878f38ada4b3515fd792abcad: no Agent-Harness or Agent-Model trailers.
  • After sealing, gh pr view 698 --repo SciML/MethodOfLines.jl --json title,body,commits,statusCheckRollup,baseRefOid; gh api repos/SciML/SciMLBase.jl/pulls/1630; gh issue view 718 --repo SciML/MethodOfLines.jl --json title,body; gh issue view 5288 --repo SciML/ModelingToolkit.jl --json title,body; gh issue view 3855 --repo EnzymeAD/Enzyme.jl --json title,body: inspected dependency/interface context and stated limitations; did not treat author reports of external runs as reviewer or PR CI evidence.
  • cp src/test/SolutionAD/Project.toml env/Project.toml, then one Julia invocation of run-head.jl. The script prints VERSION, calls Pkg.activate(joinpath(@__DIR__, "env")), Pkg.develop(path = joinpath(@__DIR__, "src")), Pkg.instantiate(; update_registry = false, allow_autoprecomp = false), and include(joinpath(@__DIR__, "src", "test", "SolutionAD", "solution_ad.jl")). Path-neutral rendering of the invocation (the actual command used the literal depot from TARGET.md): JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_SHARED_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia --startup-file=no run-head.jl, where REVIEW_SHARED_DEPOT denotes the shared depot specified in TARGET.md. Julia 1.13.2; exit 1 in Pkg.develop. Output: possible versions are: 1.0.0 - 3.58.0 or uninstalled; restricted to versions 3.59.0 - 3 by MethodOfLines ... no versions left. No test assertions ran; registries were not updated.
  • gh pr checks 698 --repo SciML/MethodOfLines.jl: exit 1, SolutionAD lts and 1 both fail. General pre-version test groups pass, but SolutionAD is not scheduled on pre. gh run view 39484795053 --repo SciML/MethodOfLines.jl --job 118842466205 --log-failed with an isolated XDG_CACHE_HOME: exit 0, confirms the dependency-resolution error in the SolutionAD job. The initial whole-run log request could not complete because the default cache was read-only; a subsequent whole-run request required narrowing to a job, which the command above did.
  • gh run view <id> --repo SciML/MethodOfLines.jl --log-failed, with isolated XDG_CACHE_HOME, exited 0 for the inspected failing documentation run, downgrade run, downstream run, and benchmark run. All show the unavailable SciMLBase bound; the benchmark also reports a missing cache-cleanup script.
  • gh run list --repo SciML/MethodOfLines.jl --branch master --event push --limit 5 --json databaseId,headSha,status,conclusion,url: all five recent completed runs succeed at fetched master fcf63be. gh run view 40801815196 --repo SciML/MethodOfLines.jl --json name,conclusion,url,jobs: the master downstream job succeeds. The PR's resolver failure is not excused as an identical master test failure.

What I did not verify

The 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
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants