Skip to content

Take the discretized system's own tspan - #685

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:tspan-on-discretized-system
Sep 8, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:tspan-on-discretized-system

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

What changed and why

The discretized System now carries its own time span, so a caller who keeps only the system can build a problem from it without repeating the interval:

sys, _ = symbolic_discretize(pdesys, disc)
prob = ODEProblem(mtkcompile(sys), nothing)   # spans the PDESystem's t domain

Motivation: SciML/ModelOrderReduction.jl#29, whose other half landed in SciML/ModelOrderReduction.jl#181.

MethodOfLines itself needed no code change. It constructs no System: PDEBase.generate_system is the single place the discretized system is built, and that is where the tspan keyword is now passed — SciML/PDEBase.jl#116. Setting the span from here instead would have meant either duplicating that function or mutating a constructed System through a non-public setter (@set sys.tspan), since ModelingToolkitBase exposes tspan only as a constructor keyword. So this PR is the compat floor, the tests, and one docs paragraph.

Depends on PDEBase 0.1.35 being released. The compat floor here names a version that does not exist in the registry yet; CI will be red with Unsatisfiable requirements until SciML/PDEBase.jl#116 merges and registers. Please merge and register that first.

Deliberate decisions

  • symbolic_discretize keeps returning (sys, tspan). Dropping the tuple would break every caller that unpacks it, including ModelOrderReduction's test suite and MethodOfLines' own discretize, DAEProblem, ODEFunction, ODEFunctionExpr and staggered paths. The change is purely additive: the tuple stays, and the system additionally carries the span. The first new test asserts both halves.
  • discretize is unaffected. It calls symbolic_discretize and passes tspan explicitly into _dae_problem / _ode_problem, so the value it uses is the same one it always used. Same for DAEProblem(::PDESystem, ::MOLFiniteDifference). Nothing there needed touching, and nothing there changed behaviour. The benefit is confined to the symbolic_discretize entry point, where the span was previously only reachable through the tuple.
  • The steady-state path gains nothing. A PDESystem with no time variable discretizes through the t === nothing branch, which builds a NonlinearSystem with no tspan keyword. get_tspan on it is nothing, not a fabricated interval. The second new test asserts this, so a future change that starts setting the span unconditionally will fail here.
  • ModelingToolkit = "11.42" (was 11.39.1), ModelingToolkitBase = "1.69" (was 1.67). 1.69.0 is the release that added the System tspan field and 11.42.0 is the first ModelingToolkit that floors it; both are registered. Strictly, the ModelingToolkitBase = "1.69" floor alone is sufficient, and I verified the tests pass on ModelingToolkit 11.41.0 + ModelingToolkitBase 1.69.0 as well — but 11.42 is what ModelingToolkit itself declares as the supported pairing, so that is what is declared here.
  • Version bumped 1.3.1 → 1.4.0: new behaviour, no public API removed or changed.

Verification

Julia 1.12.7. ModelingToolkit v11.42.0 and ModelingToolkitBase v1.69.0 from the registry, PDEBase v0.1.35 dev'd from the branch in PDEBase#116.

The new tests fail without the fix

With the one added line (tspan = tspan,) removed from PDEBase.generate_system and everything else identical, running exactly the two new testsets:

discretized system carries its own tspan: Test Failed at .../problem_construction.jl:15
  Expression: ModelingToolkitBase.get_tspan(sys) == (0.0, 0.7)
   Evaluated: nothing == (0.0, 0.7)

discretized system carries its own tspan: Error During Test at .../problem_construction.jl:16
  Test threw exception
  Expression: (ODEProblem(mtkcompile(sys), nothing)).tspan == (0.0, 0.7)
  No timespan was given, and the system `pdesys` does not have one. Either pass the timespan to
  the problem constructor, or give the system a default timespan by constructing it with the
  `tspan` keyword argument, e.g. `System(eqs, t; tspan = (0.0, 1.0), name = :pdesys)`.
   [1] default_tspan
     @ ModelingToolkitBase/src/problems/compatibility.jl:290 [inlined]
   [2] ODEProblem(sys::System, op::Nothing)

Test Summary:                            | Pass  Fail  Error  Total     Time
discretized system carries its own tspan |    1     1      1      3  1m50.3s

That is MissingTspanError from ModelingToolkitBase, which is exactly the "no time span anywhere" path.

And pass with it

Test Summary:                            | Pass  Total     Time
discretized system carries its own tspan |    3      3  2m05.5s
Test Summary:                          | Pass  Total   Time
stationary discretization has no tspan |    2      2  15.7s

Full test groups

$ GROUP=Discretization julia +1 --project=. -e 'using Pkg; Pkg.test()'
Test Summary:           | Pass  Total      Time
Equation discretization | 3618   3618  52m02.4s
Test Summary:        | Pass  Total     Time
Problem construction |   54     54  1m13.2s
     Testing MethodOfLines tests passed
$ GROUP=QA julia +1 --project=. -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total     Time
QA            |   21     21  8m38.8s
     Testing MethodOfLines tests passed

(Both were also run and passed against ModelingToolkit 11.41.0 before the 11.42 compat bump: Equation discretization 3618/3618 53m08.3s, Problem construction 54/54, QA 21/21.)

Format, spelling, docs

$ julia +1 --project=@runic -m Runic --check .
(no output, exit 0)

$ typos .
(no output, exit 0)

$ julia +1 --project=docs docs/make.jl
[ Info: Automatic `version="1.4.0"` for inventory from ../Project.toml
(exit 0, with linkcheck disabled — see below)

Every @example block evaluated and the doctests ran clean. With linkcheck = true as docs/make.jl has it, the build terminates on status: 429 from api.github.com for a handful of source links — GitHub rate limiting this machine, unrelated to the change, and none of the rate-limited URLs are ones this PR touches. I reran with linkcheck = false to confirm the rest of the build is clean; that is the exit-0 above.

Not verified

  • Every other test group. Diffusion, Convection*, Burgers, Brusselator, 2D_Diffusion, Higher_Order, Integrals, Mixed_Derivatives, Nonlinear_Diffusion*, Nonlinlap_ADV, Sol_Interface, MOL_Interface1, MOL_Interface2, Components, Complex, Stationary, DAE, Wave_Eq_Staggered and NeuralNets were not run locally — the Discretization group alone takes ~53 minutes on this box. They exercise discretize, whose behaviour is unchanged, so I do not expect movement, but I have not confirmed it.
  • Downgrade CI. The lower bounds moved a long way and I did not run the downgrade job.
  • The linkcheck = true docs build, for the reason above.

What a reviewer should push back on

  • The cross-repo ordering: this PR cannot go green until PDEBase#116 is merged and registered. If you would rather not have a red PR sitting here, hold this one.
  • Whether the ModelingToolkit floor should be 11.42 or left at 11.39.1 with only the ModelingToolkitBase = "1.69" floor doing the work. The latter is looser and I verified it works; I took the stricter one on the argument that 11.41 + MTKBase 1.69 is a pairing ModelingToolkit does not itself declare.
  • Whether a 1.4.0 minor bump is right for behaviour that arrives entirely through a dependency's floor.

Ignore this PR until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H5RuLDtEazwTKPkNbPeZVu

Raise the PDEBase floor to 0.1.35, which sets `tspan` on the `System` that
`symbolic_discretize` returns, so a caller who keeps only the system can build
a problem from it without repeating the time span:

    sys, _ = symbolic_discretize(pdesys, disc)
    prob = ODEProblem(mtkcompile(sys), nothing)

`symbolic_discretize` still returns `(sys, tspan)`; the change is additive.
`discretize` and `DAEProblem(::PDESystem, ...)` already pass the span
explicitly and are unaffected. A time-independent `PDESystem` discretizes to
a `NonlinearSystem` and gains no span, which the second test asserts.

ModelingToolkitBase moves to 1.69 for the `System` tspan field, and
ModelingToolkit to 11.42, the first release that floors that version itself.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Agent-Harness: Claude Code 2.1.263
Agent-Model: claude-opus-5
Agent-Session: https://claude.ai/code/session_01H5RuLDtEazwTKPkNbPeZVu
Claude-Session: https://claude.ai/code/session_01H5RuLDtEazwTKPkNbPeZVu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 8, 2026 23:00
@ChrisRackauckas
ChrisRackauckas merged commit 50fe669 into SciML:master Sep 8, 2026
72 of 73 checks passed
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