Repository navigation
Document interactive integrator workflow - #5055
ChrisRackauckas merged 2 commits into
Conversation
|
Implementation plan and dependency record:
Local validation covered the documented loop, the exact mass-spring model from the issue, |
|
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. |
|
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 |
|
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. |
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
b7361a6 to
bc83371
Compare
| 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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Of course that's a part of it, it's just sequencing it wrong.
| ## 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. |
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
Yeah that's what it should do, and that's next.
There was a problem hiding this comment.
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) # trueand 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]
endThe @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
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
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]>
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 withstep!(integrator, Δt, true), and reads current and accumulated results withoutreinit!.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:
The same workflow was also run against the mass-spring model in the issue comment:
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).