Skip to content

Make ArrayDiscretization the default discretization strategy - #618

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:array-default-flip
Closed

ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:array-default-flip

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Note

Draft — please ignore until reviewed by @ChrisRackauckas.

Follow-up to #604, which added ArrayDiscretization as opt-in. This makes it the default.

Why this is safe

The array path falls back to pointwise discretization for any pattern with no slice
representation, so those cases produce the identical scalar equations and identical
numbers. Where it does apply, solutions match ScalarizedDiscretization bitwise, because
each region reuses the scalar path's own weight computation rather than re-deriving
stencils.

A/B evidence. Two git worktrees at the same commit with identical package manifests,
differing only in this one default line, running all 23 functional test groups:

array default scalar default
groups passing 21/23 22/23

Both differences are accounted for and neither is a regression:

  • 2D_Diffusion fails in both arms — a pre-existing nonlinear-Laplacian rule failure
    with current dependency versions, unrelated to this change.
  • Array_Discretization failed only in the array arm because of the
    "default strategy is unchanged" guard test, which asserts the default is scalar.
    That test failing when the default flips is it doing its job; this PR inverts it.

The array test group passes 75/75 with the default flipped.

What it buys

Heat equation, discretization only:

grid scalar eqs array eqs scalar t array t speedup
1D 400 400 3 47.9 s 0.23 s 201×
2D 30×30 900 9 7.52 s 0.14 s 52×
3D 11×11×11 1331 27 7.78 s 0.13 s 60×

Equation count is 3^N for an N-dimensional problem regardless of grid resolution.

Why this is breaking (0.12.0)

mtkcompile still scalarizes, so solving is unaffected — same solver, same numbers,
same performance. But anything inspecting the symbolic system sees array equations where
it previously saw one scalar equation per grid point. Code doing length(get_eqs(sys)) or
pattern-matching on equation structure will see something different, hence the minor bump
rather than a patch.

ScalarizedDiscretization() remains available and unchanged for anything that wants the
pointwise form, and StrictArrayDiscretization() errors rather than falling back.

Not included

Documentation examples are unchanged: they call discretize(pdesys, discretization) and
are unaffected by which strategy produces the equations. The pages that describe the
strategies (MOLFiniteDifference.md, the docstrings) are updated here.

Coverage of the docs examples under the array form, and periodic-BC support (which the
Brusselator and several examples need), are being measured/implemented separately — see
#623 for the catalogue of what still falls back.

🤖 Generated with Claude Code

https://claude.ai/code/session_01S1dxUEPGysx27SSSpxtiQ9

The array form has a scalarize fallback, so any pattern without a slice representation
still produces the pointwise equations and identical numbers. An A/B run of the full test
suite with the default flipped -- identical package versions, differing only in this one
line -- passed every group the scalarized default passes.

What this buys, on the heat equation: the discretized system has 3^N equations for an
N-dimensional problem regardless of grid resolution (3 / 9 / 27 in 1D / 2D / 3D), against
one per grid point. Discretization takes 0.23 s rather than 47.9 s at 400 points in 1D,
0.14 s rather than 7.5 s at 30x30, and 0.13 s rather than 7.8 s at 11^3.

This is breaking, hence 0.12.0: mtkcompile still scalarizes, so solving is unaffected,
but anything inspecting the symbolic system sees array equations where it previously saw
one scalar equation per point.

ScalarizedDiscretization() remains available and unchanged for code that wants the
pointwise form, and StrictArrayDiscretization() errors rather than falling back.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01S1dxUEPGysx27SSSpxtiQ9
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

The requested default change is subsumed by the combined v1 draft at #650. The stale branch was not replayed because its current diff would revert newer array-discretization work; the combined draft implements the intent by removing strategy selection entirely. Please review that draft there; it should be ignored until reviewed by @ChrisRackauckas.

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.

2 participants