Skip to content

Default every time-dependent problem constructor to the system's tspan - #5085

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:tspan-defaults
Sep 7, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:tspan-defaults

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Ignore this PR until reviewed by @ChrisRackauckas.

Completes #5027, whose only review comment was "Missing many integrations, SDEProblem, DAEProblem, etc." The first commit here is @carldlund's original, cherry-picked with authorship preserved; the second finishes it. Fixes #847. If this lands, #5027 can be closed.

A System can now carry a time span, and every time-dependent problem constructor falls back to it when the caller omits one.

@mtkcompile sys = System([D(x) ~ -x], t; tspan = (0.0, 5.0))
prob = ODEProblem(sys, [])          # tspan == (0.0, 5.0)
prob = ODEProblem(sys, [], (0.0, 2.0))   # explicit still wins

What the first commit already did

Adds the tspan::Union{Nothing, Tuple} field to System, threads it through the inner constructor, the keyword constructor, flatten, copy and isapprox, and defaults it in two ODEProblem methods.

This adds no new public name. :tspan was already in SYS_PROPS, so get_tspan/has_tspan already existed, were already @public, were already in the pinned REEXPORTED_API QA list, and already had @docs entries in docs/src/API/System_accessors.md. Only the field was missing; the accessors were vestigial and threw.

What the second commit adds

Coverage. The default now applies to DAEProblem, DDEProblem, SDEProblem, SDDEProblem, BVProblem, DiscreteProblem and ImplicitDiscreteProblem, alongside ODEProblem. @fallback_iip_specialize propagates an optional positional argument to the bare and {iip} forms automatically, so each constructor needed one line. The ::Type{ODEProblem{iip, spec}} method in odeproblem.jl is the internal _ode_problem helper and is always called with an explicit tspan, so it deliberately has no default.

JumpProblem is excluded, deliberately. Giving it a default creates a two-argument JumpProblem(sys::System, op) with untyped op, which is ambiguous with JumpProcesses' own JumpProblem(prob, jumps...) family; Aqua reports exactly 14 ambiguities. Constraining op would fix it, but op legitimately ranges over vectors, dicts, tuples, NamedTuples, StaticArrays and nothing, so narrowing it is a guess. There is a comment saying so at the top of jumpproblem.jl, and a tspan_default flag on problem_docstring so its docstring does not advertise an option it does not have. This is the main thing to push back on if you disagree.

Omitting the tspan when neither source has one throws instead of silently succeeding. get_tspan returns nothing, and ODEProblem(sys, op, nothing) is legal and used internally, so defaulting to get_tspan(sys) would build an unsolvable problem with tspan === nothing. The default is default_tspan(sys), which throws MissingTspanError naming the system and both fixes. Default expressions only evaluate when the argument is omitted, so passing nothing explicitly still works.

Two bugs in #5027 as it stands. Base.copy(sys::System) called copy(get_tspan(sys)), and there is no copy(::Tuple), so copying any system with a timespan threw a MethodError. And symbolic_tspan was removed: unlike symbolic_tstops it does no namespacing and aggregates nothing from subsystems, a timespan is never symbolic, and get_tspan already exists.

extend does not forward tstops either, so tspan is left out there too, for parity. Deliberate, not an oversight.

Known gap, deliberately left for a follow-up

This PR is confined to lib/ModelingToolkitBase. There is one more site that drops the field, and it lives in the root package: src/systems/systems.jl rebuilds the System field by field on the SDE-with-brownians __mtkcompile path rather than going through @set!. Measured with full ModelingToolkit loaded:

plain ODE mtkcompile keeps tspan:      (0.0, 5.0)
SDE-with-brownians mtkcompile tspan:   nothing
SDEProblem default tspan: THROWS No timespan was given, and the system `sde` does not have one...

The one-line fix is to pass tspan = get_tspan(sys) alongside the existing tstops = symbolic_tstops(sys) there. I have not included it, because the root package would then need ModelingToolkitBase = "1.69", and a floor pointing at an unregistered version makes every downstream job fail to resolve:

Unsatisfiable requirements detected for package ModelingToolkitBase [7771a370]:
 ├─possible versions are: 1.0.0 - 1.68.3 or uninstalled
 └─restricted to versions 1.69.0 - 1 by ModelingToolkit [961ee093] — no versions left

That is what 14 red downstream checks on the first push of this PR were; not a single one was a test failure. The house pattern is for the root floor to point at an already-released sublibrary, so the correct sequencing is: merge this, release ModelingToolkitBase 1.69.0, then a follow-up PR carries the systems.jl line, the floor bump, and a regression test for it. Note that the MTKBase test suite cannot catch this gap on its own, since the offending method is only defined once the root package is loaded; the follow-up test has to live in the root suite.

Verification

All run locally on Julia 1.12.7, on the rebased branch unless noted.

New test file, 58 assertions:

`tspan` is stored on and retrieved from the system       |    8      8   4.3s
Problem constructors default to the system's `tspan`     |   32     32  38.1s
Omitting `tspan` for a system without one errors         |   16     16   0.4s
`MissingTspanError` message names the system and the fix |    2      2   0.0s
TEST exit 0

The same file on unmodified master:

MethodError: no method matching System(::Vector{Equation}, ...)
  System(::Vector{Equation}, ::Any, ::Any, ::Any, ::Any; poissonians, constraints, noise_eqs,
  jumps, costs, consolidate, preface, tstops, observed, bindings, ...)
Test Summary:                                      | Error  Total
ERROR: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.

tspan is absent from the accepted keyword list, which is the discriminating difference.

The ModelingToolkitBase InterfaceI group, on the exact tree of this PR:

Test Summary: | Pass  Broken  Total
              | 1668       5   1673
     Testing ModelingToolkitBase tests passed
EXIT 0

Runic --check ., typos, and git diff --check all exit 0 on the rebased branch.

Not verified

  • The two red checks on this PR are both pre-existing master failures. I compared each against a master run rather than taking it on trust:
  • GROUP=InterfaceII, the docs build, and the QA comparison above were run by an earlier pass on a superset of this branch, before the rebase onto current master and before the root-package half was split out. GROUP=InterfaceI was re-run on the exact tree and is reported above.
  • The four DynamicOptProblem constructors do take a tspan but live in the JuMP/InfiniteOpt/CasADi/Pyomo extensions, where process_tspan treats a symbolic final time as free-final-time. That needs its own design thought and its own tests, and those extensions could not be run locally. Left alone.
  • SteadyStateProblem, NonlinearProblem, LinearProblem, OptimizationProblem, IntervalNonlinearProblem and HomotopyNonlinearProblem take no tspan. The SciMLFunction constructors and InitializationProblem take a scalar t, not a span. remake operates on a built problem. All out of scope.

Versions

ModelingToolkitBase 1.68.3 → 1.69.0. A minor bump: this is additive public API, no existing signature changes, and behavior is unchanged whenever a tspan is passed explicitly. The root package is untouched by this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H5RuLDtEazwTKPkNbPeZVu

carldlund and others added 2 commits September 7, 2026 02:06
System can now carry its own default tspan, used by ODEProblem
when no tspan is passed explicitly. Symbolic (parameter-valued)
tspan resolution is not yet supported.
Extend the tspan default from ODEProblem to DAEProblem, DDEProblem,
SDEProblem, SDDEProblem, BVProblem, DiscreteProblem and
ImplicitDiscreteProblem. Omitting the timespan when the system has none
now throws MissingTspanError naming the system and both fixes, rather
than silently building a problem with a nothing timespan.

Drop symbolic_tspan, which namespaced nothing and duplicated the
already-public get_tspan, and fix Base.copy calling copy on a Tuple.

JumpProblem keeps its required timespan: a two-argument method with an
untyped operating point is ambiguous with JumpProcesses' own
JumpProblem(prob, jumps...) family.

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 7, 2026 09:40
@ChrisRackauckas
ChrisRackauckas merged commit 0de074a into SciML:master Sep 7, 2026
106 of 109 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
The SDE-with-brownians __mtkcompile path rebuilds the System field by
field rather than through @set!, so it dropped the tspan field added in
#5085. Carry it, raise the ModelingToolkitBase floor to the version that
has the field, and run the tspan suite from the root InterfaceII group,
where ModelingToolkit is loaded and this path is reachable.



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

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Opus 5 <[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.

Symbolic tspan

4 participants