Skip to content

Reconstruct array observables once per PDE field - #676

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:batch-array-reconstruction
Sep 7, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:batch-array-reconstruction

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

PDE solution packaging currently requests a separate observed function for each spatial grid point. For array-based reduced systems, this reintroduces compilation that grows with the grid. Evaluate each matching array observation once per saved time and reshape its numeric values; retain the existing scalar fallback.

Companion to SciML/ModelOrderReduction.jl#178. This fixes automatic PDE reconstruction as well as explicit whole-array evaluation. Matching and data movement still scale with the grid; the number of generated observation functions scales with the number of fields.

Ignore this draft until reviewed by @ChrisRackauckas.

Verification

The same regression on unmodified master at b1d818f3 requested 12 and 26 distinct scalar observations for two fields on grids with 6 and 13 points:

Expression: length(record.requests) == 2
Evaluated: 12 == 2
Evaluated: 26 == 2
array reconstruction queries are field-based | 4 passed  2 failed  6 total

The focused regression passes after the fix:

array reconstruction queries are field-based | 6 passed  6 total

The complete relevant test group passes through Pkg.test():

GROUP=Sol_Interface julia +1.12 --project -e 'using Pkg; Pkg.test()'
# Sol_Interface | 18 passed 18 total
# Testing MethodOfLines tests passed

After rebasing onto 62f07c32, all validation above was repeated successfully: 18 solution-interface tests, 21 QA checks, and 106 MOR Core assertions with both local checkouts. Repository-wide Runic, typos, and git diff --check pass. QA passes through the package's standard runner:

GROUP=QA julia +1.12 --project -e 'using Pkg; Pkg.test()'
# QA | 21 passed 21 total
# Testing MethodOfLines tests passed
``` The regression also checks reconstructed values with time as either the first or last field argument. No new dependency or public API is introduced. Documentation build is not applicable to this implementation-only change. The complete PDE test matrix and downgrade/LTS/prerelease jobs were not run locally.

An independently reproduced small-grid discretization failure is tracked at https://github.com/SciML/MethodOfLines.jl/issues/677. It occurs before solution reconstruction.

The existing Dependabot auto-merge workflow fails during startup before creating any jobs: https://github.com/SciML/MethodOfLines.jl/actions/runs/33965016166. The same startup failure occurred on the preceding upstream branch: https://github.com/SciML/MethodOfLines.jl/actions/runs/33950511092. This is separate from the validation checks reported above.

All **69 PR validation checks** passed for rebased commit https://github.com/SciML/MethodOfLines.jl/commit/7260461ff17ac1d22a3c6b06ff3b507c8e808186, including the complete declared CI test matrix, QA, documentation, downgrade, downstream, and benchmark checks. Test matrix: https://github.com/SciML/MethodOfLines.jl/actions/runs/33965016329; downstream: https://github.com/SciML/MethodOfLines.jl/actions/runs/33965016298.

### End-to-end MOR measurement

With both local branches, a real reduced `DAEProblem` and its PDE metadata (two POD/DEIM modes, three saved times) give these fresh-process measurements. Package loading, discretization, offline reduction, and problem construction precede the measured call:

| Spatial intervals | PDE reconstruction elapsed | Compilation |
|---:|---:|---:|
| 32 | 6.812 s | 6.802 s |
| 512 | 5.741 s | 5.725 s |

<details><summary>Measurement script</summary>

```julia
using ModelOrderReduction, MethodOfLines, ModelingToolkit, Symbolics, SymbolicUtils, SciMLBase
using SciMLBase: symbolic_discretize
function trial(intervals)
    @independent_variables t x
    @variables v(..)
    D = Differential(t)
    @named pde = PDESystem([D(v(t, x)) ~ -v(t, x) - v(t, x)^3], [v(0, x) ~ 1 + x],
        [t ∈ (0.0, 0.2), x ∈ (0.0, 1.0)], [t, x], [v(t, x)])
    source, _ = symbolic_discretize(pde, MOLFiniteDifference([x => 1 / intervals], t))
    metadata = SymbolicUtils.getmetadata(source, ModelingToolkit.ProblemTypeCtx, nothing)
    n = length(unknowns(source))
    snapshots = [sin(0.13i*j) + cos(0.07i*(j+1)) for i in 1:n, j in 1:8]
    rom = deim(source, snapshots, 2)
    prob = DAEProblem(rom, nothing, (0.0, 0.2); build_initializeprob=false)
    raw = SciMLBase.build_solution(prob, nothing, [0.0, 0.1, 0.2], [copy(prob.u0) for _ in 1:3])
    result = @timed SciMLBase.PDETimeSeriesSolution(raw, metadata)
    @assert size(result.value[v(t,x)]) == (3, intervals + 1)
    println((intervals=intervals, reconstruction_seconds=result.time,
        reconstruction_compile_seconds=result.compile_time))
end
trial(parse(Int, only(ARGS)))

Run in an environment with this MethodOfLines checkout and the MOR companion checkout, once per size: julia --project pde-reconstruction-scaling.jl 32 and julia --project pde-reconstruction-scaling.jl 512. The actual runs used Julia 1.12.7 with --check-bounds=yes --depwarn=yes --warn-overwrite=yes --startup-file=no.

🤖 Generated with Codex CLI 0.153.4 (model: gpt-6-astra; local session: 01a070dd-d97a-7180-9b71-095f2a5f5489). Transcript: /home/crackauc/.codex/sessions/2026/09/05/rollout-2026-09-05T05-19-42-01a070dd-d97a-7180-9b71-095f2a5f5489.jsonl.

Evaluate complete array observations before reshaping spatial values, avoiding a separately generated observed function for each grid point. Preserve the scalar fallback and cover both time-axis positions.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: gpt-6-astra
Agent-Session: /home/crackauc/.codex/sessions/2026/09/05/rollout-2026-09-05T05-19-42-01a070dd-d97a-7180-9b71-095f2a5f5489.jsonl
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 7, 2026 06:14
@ChrisRackauckas
ChrisRackauckas merged commit 0df2f16 into SciML:master Sep 7, 2026
69 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- Trim the array-form capability list from MOLFiniteDifference. (#673)
- Stop infinite expansion when a PDE unknown is missing from the system. (#674)
- Support vector-valued functions in ArrayDiscretization (#675)
- Test ModelingToolkitNeuralNets terms and fix the compiled ODE path (#678)
- Add a tutorial on training a neural network term in a PDE (#679)
- Stack vector field inputs and batch network calls in ArrayDiscretization (#680)
- Add a tutorial on learning the Brusselator reaction with a neural network (#681)
- Stack scalar inputs with field slices in ArrayDiscretization (#682)
- Test callable diffusion coefficients (#683)
- Reconstruct array observables once per PDE field (#676)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
xtalax added a commit that referenced this pull request Oct 20, 2026
On a compiled system the observed equation of a field is one array literal
with a statement per grid point. array_observed_solution evaluated it, and
compiling that function grew faster than the grid: wrapping a 2D heat
solution took 22 s at 6,241 states. Read the unknown elements by state index
and evaluate the observed ones together. A field with no unknowns, such as a
reduced order reconstruction (#676), still goes through the array function.

Agent-Harness: Claude Code 2.1.296
Agent-Model: claude-opus-5-5
Agent-Session: 644ed0ff-c8c9-4cc3-b4c6-f326231a4030
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
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