Skip to content

Commit

Permalink
fix: support non-tunable parameters with SDDEs
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Oct 30, 2024
1 parent 2d1554a commit d128997
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/systems/diffeqs/abstractodesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function generate_function(sys::AbstractODESystem, dvs = unknowns(sys),
if isdde
build_function(rhss, u, DDE_HISTORY_FUN, p..., t; kwargs...,
wrap_code = wrap_code .∘ wrap_mtkparameters(sys, false, 3) .∘
wrap_array_vars(sys, rhss; dvs, ps) .∘
wrap_array_vars(sys, rhss; dvs, ps, history = true) .∘
wrap_parameter_dependencies(sys, false))
else
pre, sol_states = get_substitutions_and_solved_unknowns(sys)
Expand Down Expand Up @@ -598,17 +598,14 @@ function DiffEqBase.SDDEFunction{iip}(sys::AbstractODESystem, dvs = unknowns(sys
expression_module = eval_module, checkbounds = checkbounds,
kwargs...)
f_oop, f_iip = eval_or_rgf.(f_gen; eval_expression, eval_module)
f(u, h, p, t) = f_oop(u, h, p, t)
f(du, u, h, p, t) = f_iip(du, u, h, p, t)

g_gen = generate_diffusion_function(sys, dvs, ps; expression = Val{true},
isdde = true, kwargs...)
g_oop, g_iip = eval_or_rgf.(g_gen; eval_expression, eval_module)
f(u, h, p, t) = f_oop(u, h, p, t)
f(u, h, p::MTKParameters, t) = f_oop(u, h, p..., t)
f(du, u, h, p, t) = f_iip(du, u, h, p, t)
f(du, u, h, p::MTKParameters, t) = f_iip(du, u, h, p..., t)
g(u, h, p, t) = g_oop(u, h, p, t)
g(u, h, p::MTKParameters, t) = g_oop(u, h, p..., t)
g(du, u, h, p, t) = g_iip(du, u, h, p, t)
g(du, u, h, p::MTKParameters, t) = g_iip(du, u, h, p..., t)

SDDEFunction{iip}(f, g, sys = sys)
end
Expand Down
6 changes: 5 additions & 1 deletion src/systems/diffeqs/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ function generate_diffusion_function(sys::SDESystem, dvs = unknowns(sys),
(map(x -> time_varying_as_func(value(x), sys), ps),)
end
if isdde
return build_function(eqs, u, DDE_HISTORY_FUN, p..., get_iv(sys); kwargs...)
return build_function(eqs, u, DDE_HISTORY_FUN, p..., get_iv(sys); kwargs...,
wrap_code = get(kwargs, :wrap_code, identity) .∘
wrap_mtkparameters(sys, false, 3) .∘
wrap_array_vars(sys, eqs; dvs, ps, history = true) .∘
wrap_parameter_dependencies(sys, false))
else
return build_function(eqs, u, p..., get_iv(sys); kwargs...)
end
Expand Down
11 changes: 11 additions & 0 deletions test/dde.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,15 @@ end

alg = MethodOfSteps(Vern7())
@test_nowarn solve(prob, alg)

@brownian r
eqs = [D(x(t)) ~ -w * x(t - τ) + r]
@named sys = System(eqs, t)
sys = structural_simplify(sys)
prob = SDDEProblem(sys,
[],
(0.0, 10.0),
constant_lags = [τ])

@test_nowarn solve(prob, RKMil())
end

0 comments on commit d128997

Please sign in to comment.