From c66fb74910b2b8c657f91f00ff047be1711b6790 Mon Sep 17 00:00:00 2001 From: AnHeuermann <38031952+AnHeuermann@users.noreply.github.com> Date: Thu, 19 Mar 2026 11:45:14 +0100 Subject: [PATCH] Fix simulation of stateless models by supplying explicit saveat For models with no ODE unknowns the adaptive solver takes no internal steps, leaving sol.t empty and making observed-variable evaluation impossible. When the system has no unknowns, fall back to 500 evenly spaced save points across the experiment time span so that observed variables can be interpolated normally. Co-authored-by: Claude Sonnet 4.6 --- src/simulate.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/simulate.jl b/src/simulate.jl index d2d561b6..fe6723aa 100644 --- a/src/simulate.jl +++ b/src/simulate.jl @@ -39,7 +39,14 @@ function run_simulate(ode_prob, model_dir::String, # to the log file so they don't clutter stdout. sol = Logging.with_logger(logger) do # Overwrite saveat, always use dense output. - solve(ode_prob, Rodas5P(); saveat = Float64[], dense = true) + # For stateless models (no unknowns) the adaptive solver takes no + # internal steps and sol.t would be empty with saveat=[]. + # Supply explicit time points so observed variables can be evaluated. + sys = ode_prob.f.sys + saveat = isempty(ModelingToolkit.unknowns(sys)) ? + collect(range(ode_prob.tspan[1], ode_prob.tspan[end]; length = 500)) : + Float64[] + solve(ode_prob, Rodas5P(); saveat = saveat, dense = true) end sim_time = time() - t0 if sol.retcode == ReturnCode.Success