Repository navigation
Keep discretized dependent variables as array-valued unknowns - #701
Merged
ChrisRackauckas merged 6 commits intoOct 13, 2026
Merged
ChrisRackauckas merged 6 commits into
ChrisRackauckas merged 6 commits into
Conversation
`discretize_dep_vars` builds the array variable `u(t)[1:n, ...]` and scalarizes it, and PDEBase's `generate_system` then registered every element as an unknown of the system, so `unknowns(sys)` grew with the grid. Implement PDEBase's new `get_system_unknowns` hook to register the array variable itself (or the scalar `u(t)` for a variable of `t` alone); the elements in `discvars` still drive stencil generation and the boundary and initial-condition maps. The DAE path is adjusted for the new representation: the operating point and the BrownFullBasicInit safety check enumerate the scalar elements of each unknown, and the solution wrapper locates a grid value through `variable_index`, which resolves both scalar unknowns and elements of array unknowns and replaces the linear `findfirst` over `unknowns(sys)`. Requires PDEBase 0.1.37 for the hook and ModelingToolkitBase 1.72 for problem construction from a `complete`d system with array unknowns. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.280 Agent-Model: claude-fable-5-1 Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/MethodOfLines.jl/jobs/695-claude/log.txt on amdci2.julia.csail.mit.edu
The pseudospectral tests counted scalar unknowns to check the number of grid degrees of freedom; they now check the shape of the single array unknown instead. The 1D heat problem-construction test asserts that the system has one unknown whose elements are the discrete grid values returned by `get_discrete`. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.280 Agent-Model: claude-fable-5-1 Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/MethodOfLines.jl/jobs/695-claude/log.txt on amdci2.julia.csail.mit.edu
This was referenced Sep 23, 2026
`unknowns(sys)` of the system returned by `symbolic_discretize` changes shape and cardinality, which is a breaking change for callers that enumerate it, so the version is 2.0.0 rather than 1.6.0 and NEWS marks the change as breaking. The docs project accepts the new major version. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.280 Agent-Model: claude-fable-5-1 Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/MethodOfLines.jl/jobs/695-claude/log.txt on amdci2.julia.csail.mit.edu
Bring in the Schroedinger phase regression fix from SciML#703 so Complex CI can be re-evaluated against current master.
The array-unknown hook landed in PDEBase 0.1.38, not 0.1.37. Downgrade CI pinned 0.1.37 and failed to import the hook at load time. Co-Authored-By: Chris Rackauckas <[email protected]> Agent-Harness: Cursor CLI autopilot Agent-Model: Composer Agent-Session: /home/crackauc/.cursor/projects/home-crackauc-sandbox-fleet-master-jobs-nw-methodoflines-701/agent-transcripts/c1d3babe-56b1-4ef0-8d67-be79a9031b5f/c1d3babe-56b1-4ef0-8d67-be79a9031b5f.jsonl Co-authored-by: Cursor <[email protected]>
Resolve the Project.toml version conflict by keeping 2.0.0 (master is 1.5.2). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Agent-Harness: Claude Code Agent-Model: claude-opus-5-5[1m] Agent-Session: https://claude.ai/code/session_01WYPUXLxE9jVu2jXLFRd8ax
ChrisRackauckas
marked this pull request as ready for review
October 13, 2026 16:39
This was referenced Oct 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
The discretized
Systemnow has one unknown per dependent variable, the array variableu(t)[1:n, 1:m]thatdiscretize_dep_varsalready builds, instead of one scalar unknown per grid point. MethodOfLines implements PDEBase's newget_system_unknownshook (SciML/PDEBase.jl#124) to register the array variable (or the scalaru(t)for a variable oftalone);discvarskeeps the scalarized elements for stencil generation and the boundary/initial-condition maps, exactly as before.The two problem-construction paths are affected differently:
discretize(pdesys, disc)for a time-dependent system builds aDAEProblemfrom the residual equations withoutmtkcompile(_dae_problem;DAEProblem(pdesys, disc)is the same path), falling back to the compiled ODE path only for systems it cannot pose as a first-order DAE. This path now consumes the array unknowns directly:_dae_operating_pointandbrown_init_offendersenumerate the scalar elements of each unknown, and ModelingToolkitBase ≥ 1.72 laysu0out as the flat concatenation of the unknowns, so the state vector is unchanged.ODEProblem(mtkcompile(sys), nothing, tspan)on the result ofsymbolic_discretize(and theanalytic =and fallback branches ofdiscretize) is unchanged in behaviour becausemtkcompilestill scalarizes array unknowns; its cost only drops oncemtkcompilekeeps them, which is a separate ModelingToolkit question.The solution wrappers locate a grid value with
SymbolicIndexingInterface.variable_index(O(1) through the index cache, and correct for elements of array unknowns) instead of a linearfindfirstoverunknowns(sys).This is a breaking change: version
1.5.1 → 2.0.0.unknowns(sys)of the system returned bysymbolic_discretizechanges shape and cardinality (one array per variable instead of one scalar per grid point), so code that enumerates it, builds an operating point from it, or filters it by name must scalarize first or work onmtkcompile(sys).discretize,DAEProblem(pdesys, disc),get_discrete,sol[u(t, x)],sol(t, x)and the problems'u0are unchanged. NEWS.md has the breaking-change entry. Compat:PDEBase = "0.1.37"(the hook) andModelingToolkitBase = "1.72"(problem construction from acompleted system with array unknowns, SciML/ModelingToolkit.jl#5131);docs/Project.tomlaccepts the new major. CI cannot resolve until PDEBase 0.1.37 is registered; this PR is stacked on SciML/PDEBase.jl#124.Tests: the pseudospectral tests counted scalar unknowns to check the number of grid degrees of freedom and now check the shape of the single array unknown; the 1D heat problem-construction test asserts one unknown whose elements are the
get_discretegrid values.Before/after on the 2D heat equation (
Dt(u) ~ Dxx(u) + Dyy(u), Dirichlet BCs,x => n, y => n)Julia 1.11.9, ModelingToolkitBase 1.76.0, SciMLBase 3.55.0, Symbolics 7.40.1; "before" is master (3f312ba) with registered PDEBase 0.1.36, "after" is this branch with the PDEBase PR developed. Second call of each (first call is compilation, ~65 s for
symbolic_discretizein both). The explicit compiled path was not run at n = 100 (over two minutes at n = 50). Script:scratch/bench.jlin the transcript directory.length(unknowns(sys))before → afterlength(u0)symbolic_discretizebefore → afterDAEProblem(pdesys, disc)before → afterODEProblem(mtkcompile(sys))before → afterSo the unknown count is now O(1) in the grid, but problem-construction time is essentially unchanged. A profile of the n = 100
DAEProblemcall (scratch/profile_dae2.jl) puts 96% of the 40 s insideModelingToolkitBase.evaluate_varmap!(problem_utils.jl:541) called fromvarmap_to_varsin__process_SciMLProblem: for every one of the 20,000 flat unknowns and derivatives it does ageton the operating point that, for an element of an array unknown, scans the array (_any(_is_...)overgetindex), which is quadratic in the grid size. Passing two array-valued entries (u => Matrix,D(u) => Matrix) instead of 20,000 element entries produces identicalu0/du0and the same 37–40 s (scratch/probe_op.jl), so the cost is not in how MethodOfLines writes the operating point; it needs an upstream change and is reported in REPORT.md rather than worked around here. Thesymbolic_discretizeimprovement at n = 100 comes fromgenerate_systemno longer flatteningdiscvars.Verification
Environment: a scratch project developing this branch and the PDEBase PR branch (
Pkg.develop), thenGROUP=<name> julia +1.11 --project=<scratch> -e 'using Pkg; Pkg.test("MethodOfLines")'for every group intest/runtests.jl, six at a time. All 24 functional groups exit 0 (the Broken column is pre-existing@test_broken):The Complex group passing is not evidence of complex-valued correctness: its assertions compare normalized squared magnitudes, and a phase-sensitive probe (
im*Dt(ψ) ~ Dxx(ψ), initial(1+2im)*sinpi(x)) fails identically on master and on this branch because PDEBase's real/imaginary split loses the coupling. That is a pre-existing PDEBase defect outside this diff; the orchestrator is filing it separately.Tail of the group this PR touches most:
Failing-before evidence for the new assertions: on master
symbolic_discretizeof the 1D heat test gives 21 scalar unknowns, so@test length(unknowns(sys)) == 1fails there and passes here (the benchmark table above shows the same 25 → 1 / 10,000 → 1 counts on master vs this branch).QA:
GROUP=QAthroughPkg.testcannot resolve (PDEBaserestricted to0.1.37byMethodOfLines, no registered version), sotest/qa/qa.jlwas run in a scratch copy oftest/qa/Project.tomlwith both packages developed:The one error is Aqua's persistent-tasks manifest walk:
Unable to locate CUDA_Runtime_jll, a dependency of CUDA(CUDA appears only as a weak dependency of ArrayInterface/DiffEqBase/LinearSolve/RecursiveArrayTools in that manifest). The identical manual run against master (3f312ba, registered PDEBase 0.1.36) gives the same result, 20 pass / 1 error with the sameCUDA_Runtime_jllmessage, so it is pre-existing and environmental, not introduced here.Unaddressed limitation (pre-existing, recorded, not worked around):
DAEProblem(pdesys, disc; build_initializeprob = true)fails on master and on this branch with(1D heat,
x => 21;scratch/probe_initprob.jl, logsscratch/probe_initprob_{before,after}.log). The failure is in ModelingToolkit's initialization system for residual-form equations over slices (D(u[2:n-1]) - f ~ 0), independent of whether the unknowns are scalar or array-valued. The DAE constructor's defaultbuild_initializeprob = falseis therefore a limitation this PR inherits and does not resolve, not a recommended usage; the orchestrator is filing the upstream issue.Docs:
docs/make.jlwith this branch (at 1.6.0, before the 2.0.0 bump; the bump only changes the version, NEWS and the docs compat, and the docs project re-resolves with 2.0.0) and the PDEBase branch developed,linkcheck = false(the link check hit GitHub HTTP 429 rate limits on this machine, unrelated to the content), builds to completion: doctests run, all@exampleblocks execute, HTML rendered; the only warnings are the pre-existingapi/discretization.mdsize-threshold warning and deployment auto-detection. Runic (--check) andtyposare clean on every changed file.Not verified
NeuralNetsgroup (own environment, not in "All"); the extension does not touch unknowns.GROUP=QAthrough the realPkg.testpath (blocked on the PDEBase release).For the reviewer
unknowns(sys)fromsymbolic_discretizechanges for users (review round 1 finding). The problem-level API is unchanged.get_system_unknowns(s::DiscreteSpace)derives the array from the first element ofs.discvars[u]rather than storing it in a newDiscreteSpacefield, to leave the struct and its three constructors untouched.length(get_unknowns(sys)) == nassertions were rewritten as shape checks on the single array unknown (same degrees of freedom, new representation).evaluate_varmap!behaviour in MTKBase is now the dominant cost at 100×100 and is outside this PR.Closes #695. Stacked on SciML/PDEBase.jl#124.
🤖 Generated with Claude Code 2.1.280 (model: claude-fable-5-1); local session, transcript at /home/crackauc/sandbox/agent-jobs/MethodOfLines.jl/jobs/695-claude/log.txt on amdci2.julia.csail.mit.edu
CI triage (2026-09-25)
Triage of failures on head
7eeb213f(before this pass), compared to master tipb5ce4116(all green). Fixes pushed: merge2dd10848, PDEBase floor38aea25f.atol=0.01phase regression; master tip Complex lts success after #703UndefVarError: get_system_unknowns not definedwith PDEBase v0.1.37; hook exists only in PDEBase 0.1.38. Bumped compat. Master Downgrade success (no hook import).empty intersection between [email protected] and project compatibility 1. PDESystemLibrary pinsMethodOfLines = "1". Needs a coordinated PDESystemLibrary compat bump; not fixable in this repo alone. Master Downstream success on MoL 1.x.Risk assessment
unknowns(sys)(documented break).isdefined(PDEBase, :get_system_unknowns)); existing Discretization tests coverlength(unknowns(sys)) == 1.🤖 Posted by an AI agent — harness: Cursor CLI autopilot · model: Composer
Conversation: /home/crackauc/.cursor/projects/home-crackauc-sandbox-fleet-master-jobs-nw-methodoflines-701/agent-transcripts/c1d3babe-56b1-4ef0-8d67-be79a9031b5f/c1d3babe-56b1-4ef0-8d67-be79a9031b5f.jsonl