Skip to content

Commit 1dedcdb

Browse files
fix: fix callable parameters in remake_buffer
1 parent f2d00b0 commit 1dedcdb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/systems/parameter_buffer.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ end
444444

445445
function validate_parameter_type(ic::IndexCache, stype, sz, sym, index, val)
446446
(; portion) = index
447+
if stype <: FnType
448+
stype = fntype_to_function_type(stype)
449+
end
447450
# Nonnumeric parameters have to match the type
448451
if portion === NONNUMERIC_PORTION
449452
val isa stype && return nothing

test/initial_values.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ModelingToolkit
22
using ModelingToolkit: t_nounits as t, D_nounits as D, get_u0
33
using OrdinaryDiffEq
4+
using DataInterpolations
45
using SymbolicIndexingInterface: getu
56

67
@variables x(t)[1:3]=[1.0, 2.0, 3.0] y(t) z(t)[1:2]
@@ -219,3 +220,19 @@ end
219220
@test_throws ["a(t)", "c(t)"] ODEProblem(
220221
sys, [e => 2, a => b, b => a + 1, c => d, d => c + 1], (0, 1))
221222
end
223+
224+
@testset "Issue#3490: `remake` works with callable parameters" begin
225+
ts = collect(0.0:0.1:10.0)
226+
spline = LinearInterpolation(ts .^ 2, ts)
227+
Tspline = typeof(spline)
228+
@variables x(t)
229+
@parameters (interp::Tspline)(..)
230+
231+
@mtkbuild sys = ODESystem(D(x) ~ interp(t), t)
232+
233+
prob = ODEProblem(sys, [x => 0.0], (0.0, 1.0), [interp => spline])
234+
spline2 = LinearInterpolation(ts .^ 2, ts .^ 2)
235+
p_new = [interp => spline2]
236+
prob2 = remake(prob; p = p_new)
237+
@test prob2.ps[interp] == spline2
238+
end

0 commit comments

Comments
 (0)