From 32e3ffa1ee71451e06de9d46146c7d4f7f72a845 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 29 Oct 2024 12:16:38 +0530 Subject: [PATCH] fix: fix remake with value dependent on indepvar --- src/remake.jl | 3 +++ test/downstream/modelingtoolkit_remake.jl | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/remake.jl b/src/remake.jl index 4930ed6e3..e4540cd68 100644 --- a/src/remake.jl +++ b/src/remake.jl @@ -713,6 +713,9 @@ function _updated_u0_p_symmap(prob, u0, ::Val{true}, p, ::Val{true}, t0) end varmap = merge(u0, p) + if is_time_dependent(prob) + varmap[only(independent_variable_symbols(prob))] = t0 + end for (k, v) in u0 u0[k] = symbolic_type(v) === NotSymbolic() ? v : symbolic_evaluate(v, varmap) end diff --git a/test/downstream/modelingtoolkit_remake.jl b/test/downstream/modelingtoolkit_remake.jl index e8d1a797c..d0df44658 100644 --- a/test/downstream/modelingtoolkit_remake.jl +++ b/test/downstream/modelingtoolkit_remake.jl @@ -239,3 +239,12 @@ end prob2 = remake(prob; u0 = [x => p], p = [:p => 2.0]) @test prob2[x] ≈ 2.0 end + +@testset "remake dependent on indepvar" begin + @variables x(t) + @parameters p + @mtkbuild sys = ODESystem([D(x) ~ x * p], t) + prob = ODEProblem(sys, [x => 1.0], (0.0, 1.0), [p => 1.0]) + prob2 = remake(prob; u0 = [x => t + 3.0]) + @test prob2[x] ≈ 3.0 +end