Skip to content

Document interactive integrator workflow - #5055

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:codex/interactive-integrator-workflow
Sep 6, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:codex/interactive-integrator-workflow

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Ignore this PR until it has been reviewed by @ChrisRackauckas.

What changed and why

Add a basic example for interactive and externally driven simulations. It initializes one integrator over the full horizon, mutates a symbolic input through integrator.ps, advances fixed wall-clock blocks with step!(integrator, Δt, true), and reads current and accumulated results without reinit!.

The page also distinguishes ordinary parameters from registered discrete inputs and directs known-time changes to symbolic events. This documents the simpler workflow requested in #5006 (comment).

This depends on the parameter-cache invalidation fix in SciML/SciMLBase.jl#1575. The documentation environment used that local SciMLBase branch for executable validation. The pre-existing Berkeley link timeout encountered by full docs is fixed separately in #5056; its full documentation CI passed at https://github.com/SciML/ModelingToolkit.jl/actions/runs/33472398454/job/99744640476.

Verification

The documented loop ran with analytic value assertions after each one-second block:

(display_times = [1.0, 2.0, 3.0, 4.0],
 display_values = [0.0, 0.6319011220085275, -0.39965118092464247, -0.14702457157937263],
 display_inputs = [0.0, 1.0, -1.0, 0.0],
 saved_points = 81)
[exit code 0]

The same workflow was also run against the mass-spring model in the issue comment:

(block_end = [1.0, 2.0, 3.0, 4.0],
 position = [0.0, 0.4597655446581379, 1.8760519582895256, 3.866004436795883],
 input = [0.0, 1.0, 2.0, 3.0],
 saved_points = 81)
[exit code 0]
$ GROUP=QA julia --startup-file=no --project=. -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total     Time
QA            |   40     40  4m58.9s
Testing ModelingToolkit tests passed

$ GROUP=SymbolicIndexingInterface julia --startup-file=no --project=. -e 'using Pkg; Pkg.test()'
Test Summary:             | Pass  Total     Time
SymbolicIndexingInterface | 1984   1984  6m49.3s
Testing ModelingToolkit tests passed

$ julia --startup-file=no -m Runic --check docs/pages.jl
[exit code 0]

$ typos docs/pages.jl docs/src/examples/interactive_simulation.md
[exit code 0]

$ git diff --check upstream/master...HEAD
[exit code 0]

$ TMPDIR=/home/crackauc/sandbox/tmp_20260831_125419_177237/.tmp julia --startup-file=no --project=docs docs/make.jl
[observed: doctests, template expansion, cross-references, document checks, index population, and HTML rendering completed; local deployment was skipped]

The full docs run used the one-link replacement from #5056 for the pre-existing Berkeley PDF timeout identified on master. The temporary link edit was removed after validation so this workflow PR remains focused.

Review notes and unverified paths

No public API changes. Everything, GPU, Julia pre-release, and unrelated test groups were not run locally.

🤖 Generated with Codex CLI 0.151.0 (model: gpt-5.6-sol; session: local session ID 01a057e2-edc7-7342-9835-8122a5c647eb).

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Implementation plan and dependency record:

  1. Keep one integrator alive across the full simulation horizon.
  2. Assign symbolic inputs through integrator.ps[...] and advance externally determined blocks with step!(integrator, Δt, true).
  3. Document current-value access, accumulated solution access, restart semantics, and the ordinary-parameter versus registered-discrete history distinction.
  4. Land the cache invalidation prerequisite in Invalidate integrator caches after parameter mutation SciMLBase.jl#1575.
  5. Land the separate replacement for the stale Berkeley documentation link before relying on the full docs CI result from this branch.

Local validation covered the documented loop, the exact mass-spring model from the issue, GROUP=QA, GROUP=SymbolicIndexingInterface, Runic, typos, diff checking, and full docs with both prerequisites applied.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

The focused master link-check prerequisite is now available as draft #5056. It replaces only the timed-out Berkeley Pantelides citation; this workflow branch remains unchanged.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

CI analysis: the documentation job https://github.com/SciML/ModelingToolkit.jl/actions/runs/33464853659/job/99722482774 failed solely because the pre-existing Berkeley Pantelides PDF timed out with curl exit 28. The new SymbolicIndexingInterface documentation link returned HTTP 200, and no error originated from this PR's page. The focused prerequisite remains #5056; no unrelated link edit will be added here.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Prerequisite update: #5056 is clean, and its full docs retry passed in 1h09m35s: https://github.com/SciML/ModelingToolkit.jl/actions/runs/33472398454/job/99744640476. This PR's remaining red docs result is therefore fully explained by its older base still containing the Berkeley URL; no source change belongs on this branch.

ChrisRackauckas and others added 2 commits September 6, 2026 02:52
Show how to mutate symbolic parameters and advance one long-lived integrator, including the distinction between ordinary parameters and saved time-varying inputs.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: OpenAI Codex <[email protected]>
Agent-Harness: Codex CLI 0.151.0
Agent-Model: gpt-5.6-sol
Agent-Session: local session ID 01a057e2-edc7-7342-9835-8122a5c647eb
Co-Authored-By: Chris Rackauckas <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>

Agent-Harness: Codex CLI 0.151.0

Agent-Model: gpt-5.6-sol

Agent-Session: local session ID 01a057e2-edc7-7342-9835-8122a5c647eb
@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the codex/interactive-integrator-workflow branch from b7361a6 to bc83371 Compare September 6, 2026 06:52
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 6, 2026 10:25
@ChrisRackauckas
ChrisRackauckas merged commit 542ad62 into SciML:master Sep 6, 2026
4 checks passed
that integrator. Reinitializing between intervals is unnecessary and can rerun ModelingToolkit
initialization or discard solver state.

The following model uses a parameter as an externally controlled input:

@baggepinnen baggepinnen Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason it could not mtkcompile with inputs = [input]? That would make the tutorial closer to what would be used in practice when using stdlib components

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course that's a part of it, it's just sequencing it wrong.

Comment on lines +51 to +67
## Parameters and time-varying inputs

A value declared with `@parameters` is treated as time-invariant when a saved solution evaluates
parameter-dependent observables. Mutating one during an interactive run updates future
dynamics, but it does not create a history of its previous values. Record the input in the
application, as the example does for display values, when only the live interface needs that
history.

When the input is part of the model's saved history, declare it with `@discretes input(t)`.
Discrete variables represent piecewise-constant, time-dependent values. Updates performed by
ModelingToolkit callbacks can be saved and later retrieved through symbolic solution indexing;
see [Saving discrete values](@ref save_discretes).

If all input-change times are known before the solve, a symbolic discrete event is usually a
better model than an external stepping loop. The long-lived-integrator pattern is intended for
inputs that arrive while the simulation is running, such as UI controls or measurements from
another process.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AayushSabharwal wouldn't it make sense to recommend the compilation with inputs kwarg to have MTK automatically convert an input variable to a parameter here? The approach recommended in this tutorial right now is not quite applicable to models making use of the stdlib, and goes against all other tutorials we have on using inputs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what it should do, and that's next.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and done: #5087.

The page now leads with the input declared as a variable and named to mtkcompile, which converts it to a parameter the integrator steps with:

@variables x(t) u(t)
sys = mtkcompile(System([D(x) ~ -x + u], t; name = :sys); inputs = [u])
is_parameter(sys, u)   # true

and adds the component-library case this was really about — a stdlib mass-spring-damper with force.f left unconnected:

sys = mtkcompile(model; inputs = [force.f.u])
integrator = init(ODEProblem(sys, u0, (0.0, 4.0)), Tsit5(); saveat = 0.0:0.05:4.0)

for level in (0.0, 10.0, -10.0, 0.0)
    integrator.ps[force.f.u] = level
    step!(integrator, 1.0, true)
    current_position = integrator[mass.s]
end

The @parameters form is kept for the scalar case, and the page now also shows the ExtraVariablesSystemException you get from omitting the keyword, since nothing in that error points at the unconnected connector.

One thing I left out deliberately, in case you have context on it: I had drafted a note recommending unbound_inputs(model) to discover the connector name, but it reports force.f.u for an unconnected Force while returning empty for a Voltage whose RealInput is equally unconnected. I could not establish why — a namespace-prefix hypothesis did not reproduce — so I did not want to document it. Happy to file that separately.

🤖 Generated with Claude Code

https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam

ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/ModelingToolkit.jl that referenced this pull request Sep 7, 2026
The interactive-integrator page reached for a top-level `@parameters` declaration
as the external signal. That works for a scalar you declare yourself, but it does
not apply to models assembled from component libraries, where the input arrives
as an unconnected `RealInput` connector and there is nothing to declare — and it
diverges from every other input tutorial, which uses `mtkcompile(...; inputs)`.

Lead with the `inputs` keyword instead: an input variable named to `mtkcompile`
becomes a parameter of the compiled system, so the same
`integrator.ps[u] = value; step!(integrator, dt, true)` loop drives it. Add a
ModelingToolkitStandardLibrary example that leaves a `Force` input connector
unconnected, and show the unbalanced-system error that results from omitting the
keyword. The `@parameters` form is kept for the scalar case.

Raised in review of SciML#5055.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
The interactive-integrator page reached for a top-level `@parameters` declaration
as the external signal. That works for a scalar you declare yourself, but it does
not apply to models assembled from component libraries, where the input arrives
as an unconnected `RealInput` connector and there is nothing to declare — and it
diverges from every other input tutorial, which uses `mtkcompile(...; inputs)`.

Lead with the `inputs` keyword instead: an input variable named to `mtkcompile`
becomes a parameter of the compiled system, so the same
`integrator.ps[u] = value; step!(integrator, dt, true)` loop drives it. Add a
ModelingToolkitStandardLibrary example that leaves a `Force` input connector
unconnected, and show the unbalanced-system error that results from omitting the
keyword. The `@parameters` form is kept for the scalar case.

Raised in review of #5055.



Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[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