Skip to content

Commit c66fb74

Browse files
AnHeuermannclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 05dd15d commit c66fb74

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/simulate.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ function run_simulate(ode_prob, model_dir::String,
3939
# to the log file so they don't clutter stdout.
4040
sol = Logging.with_logger(logger) do
4141
# Overwrite saveat, always use dense output.
42-
solve(ode_prob, Rodas5P(); saveat = Float64[], dense = true)
42+
# For stateless models (no unknowns) the adaptive solver takes no
43+
# internal steps and sol.t would be empty with saveat=[].
44+
# Supply explicit time points so observed variables can be evaluated.
45+
sys = ode_prob.f.sys
46+
saveat = isempty(ModelingToolkit.unknowns(sys)) ?
47+
collect(range(ode_prob.tspan[1], ode_prob.tspan[end]; length = 500)) :
48+
Float64[]
49+
solve(ode_prob, Rodas5P(); saveat = saveat, dense = true)
4350
end
4451
sim_time = time() - t0
4552
if sol.retcode == ReturnCode.Success

0 commit comments

Comments
 (0)