Skip to content

Set the time span on the system symbolic_discretize returns - #116

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

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

Copy link
Copy Markdown
Member

What changed and why

generate_system already receives the tspan it returns alongside the system. It now also passes it to the System constructor, so the discretized system carries its own time span (the tspan field added to System in ModelingToolkitBase 1.69.0, SciML/ModelingToolkit.jl#5085). A caller that keeps only the system can then write ODEProblem(sys, u0) and get the PDE's own time interval, rather than threading the tuple's second element out of band.

Motivation: SciML/ModelOrderReduction.jl#29.

The return type is unchanged. symbolic_discretize still returns (system, tspan) and generate_system still returns that tuple; downstream code that unpacks it, including ModelOrderReduction's test suite, is unaffected. This is purely additive.

The steady-state branch (t === nothing) builds a NonlinearSystem and is untouched, so a time-independent PDESystem does not acquire a bogus time span. That is asserted in the new test.

[compat] bump: ModelingToolkitBase = "1.69" (was "1.58"). 1.69.0 is registered and merged (JuliaRegistries/General#167382), so this resolves today. PDEBase depends on ModelingToolkitBase directly, so declaring the floor here is sufficient — it does not depend on the ModelingToolkit 11.42.0 release. Version bumped 0.1.34 → 0.1.35.

Why here and not in MethodOfLines

The task this came from was framed as a MethodOfLines change, but MethodOfLines constructs no System of its own — it consumes PDEBase.symbolic_discretize, and PDEBase.generate_system is the single place the discretized System is built. Setting the span from MethodOfLines would mean either duplicating this function or mutating a constructed System through a non-public setter (@set sys.tspan), since ModelingToolkitBase exposes tspan only as a constructor keyword. Doing it at the construction site is one line and fixes every PDEBase-based discretizer, not just MOLFiniteDifference.

The companion MethodOfLines PR is SciML/MethodOfLines.jl#685 — it bumps the PDEBase floor and adds the end-to-end test through a real MOLFiniteDifference discretization.

Verification

Julia 1.12.7, ModelingToolkitBase v1.69.0 and ModelingToolkit v11.41.0 from the registry.

The new test fails without the fix

With the one added line (tspan = tspan,) deleted from generate_system and everything else identical:

$ GROUP=Core julia +1 --project=. -e 'using Pkg; Pkg.test()'
Discretized system carries the time span: Test Failed at .../PDEBase/test/system_tspan.jl:43
  Expression: get_tspan(sys) == (0.0, 2.5)
   Evaluated: nothing == (0.0, 2.5)

Discretized system carries the time span: Error During Test at .../PDEBase/test/system_tspan.jl:45
  Test threw exception
  Expression: (ODEProblem(mtkcompile(sys), [w1 => 1.0, w2 => 0.0])).tspan == (0.0, 2.5)
  No timespan was given, and the system `pdebase_tspan_test` 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 = :pdebase_tspan_test)`.
   [1] default_tspan
     @ ModelingToolkitBase/src/problems/compatibility.jl:290 [inlined]
   [2] SciMLBase.ODEProblem(sys::ModelingToolkitBase.System, op::Vector{Pair{Symbolics.Num, Float64}})

Test Summary:                              | Pass  Fail  Error  Total     Time
Core/system_tspan.jl                       |    3     1      1      5  1m07.9s
ERROR: Package PDEBase errored during testing

The two assertions that pass either way are the nothing-tspan (steady-state) ones, which is the point of including them.

And passes with it

$ GROUP=Core julia +1 --project=. -e 'using Pkg; Pkg.test()'
Test Summary:       | Pass  Total   Time
Core/alloc_tests.jl |   12     12  26.4s
Test Summary:           | Pass  Total  Time
Core/array_variables.jl |   11     11  7.2s
Test Summary:                   | Pass  Total   Time
Core/discrete_initialization.jl |   18     18  10.7s
Test Summary:        | Pass  Total  Time
Core/docs_project.jl |    1      1  0.0s
Test Summary:     | Pass  Total   Time
Core/interface.jl |   25     25  13.5s
Test Summary:      | Pass  Total  Time
Core/public_api.jl |   46     46  0.1s
Test Summary:        | Pass  Total     Time
Core/system_tspan.jl |    5      5  1m31.3s
     Testing PDEBase tests passed
$ GROUP=QA julia +1 --project=. -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total     Time
QA/qa.jl      |   20     20  1m39.9s
     Testing PDEBase tests passed
$ julia +1 --project=@runic -m Runic --check .
(no output, exit 0)

$ typos .
(no output, exit 0)

I also checked separately that the span survives the rest of the pipeline, since that is what makes the field useful here — a hand-built System(...; tspan = (0.0, 3.0)) keeps it through complete, through mtkcompile, and into ODEProblem(simp, nothing).tspan == (0.0, 3.0).

Not verified

  • Downstream packages other than MethodOfLines. Pkg.test() here does not exercise them, and the compat floor bump means downstreams need a release before they see this.
  • The docs build (docs/make.jl) — the only docs change is one paragraph inside an existing generate_system docstring, no new entries.

What a reviewer should push back on

  • Whether the ModelingToolkitBase floor jumping 1.58 → 1.69 is acceptable, or whether the field should be set behind a has_tspan-style feature check to keep the floor low. I chose the hard floor because a soft check would silently give the old, tspan-less behaviour on an older ModelingToolkitBase and make the MethodOfLines test flaky depending on resolution.
  • Whether the generate_system docstring change reads as an instruction to third-party discretizers (it is meant to: a discretizer implementing this hook should set the span too).

Ignore this PR until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H5RuLDtEazwTKPkNbPeZVu

generate_system already receives the tspan it returns alongside the system;
pass it to the System constructor as well so the discretized system carries
its own time span. A caller that keeps only the system can then write
ODEProblem(sys, u0) and get the PDE's time interval, instead of having to
thread the tuple's second element out of band.

The return value is unchanged: symbolic_discretize still returns
(system, tspan), which downstream code unpacks.

The steady-state branch (t === nothing) builds a NonlinearSystem and is
untouched, so a time-independent PDESystem does not acquire a time span.

Requires ModelingToolkitBase 1.69, which added the System tspan field.

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 09:02
@ChrisRackauckas
ChrisRackauckas merged commit 8208ff5 into SciML:master Sep 8, 2026
23 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