Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft: add support for DDEAliasSpecifier #302

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ OrdinaryDiffEqNonlinearSolve = "1.2.2"
OrdinaryDiffEqRosenbrock = "1.2.0"
RecursiveArrayTools = "2, 3"
Reexport = "0.2, 1.0"
SciMLBase = "2.68"
SciMLBase = "2.70"
SimpleNonlinearSolve = "0.1, 1, 2"
SimpleUnPack = "1"
SymbolicIndexingInterface = "0.3.36"
Expand Down
1 change: 1 addition & 0 deletions src/DelayDiffEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using OrdinaryDiffEqNonlinearSolve: NLNewton, NLAnderson, NLFunctional, Abstract
using OrdinaryDiffEqRosenbrock: RosenbrockMutableCache

import SciMLBase
using SciMLBase: DDEAliasSpecifier

export Discontinuity, MethodOfSteps

Expand Down
43 changes: 43 additions & 0 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem,
allow_extrapolation = OrdinaryDiffEqCore.alg_extrapolates(alg),
initialize_integrator = true,
alias_u0 = false,
alias = DDEAliasSpecifier(),
# keyword arguments for DDEs
discontinuity_interp_points::Int = 10,
discontinuity_abstol = eltype(prob.tspan)(1 // Int64(10)^12),
Expand Down Expand Up @@ -107,6 +108,48 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem,
# unpack problem
@unpack f, u0, h, tspan, p, neutral, constant_lags, dependent_lags = prob

use_old_kwargs = haskey(kwargs, :alias_u0)

if haskey(kwargs, :alias_u0)
aliases = DDEAliasSpecifier()
message = "`alias_u0` keyword argument is deprecated, to set `alias_u0`,
please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_u0 = true))"
Base.depwarn(message, :init)
Base.depwarn(message, :solve)
aliases = DDEAliasSpecifier(alias_u0 = values(kwargs).alias_u0)
else
# If alias isa Bool, all fields of ODEAliases set to alias
if alias isa Bool
aliases = DDEAliasSpecifier(alias = alias)
elseif alias isa DDEAliasSpecifier
aliases = alias
end
end

if isnothing(aliases.alias_f) || aliases.alias_f
f = f
else
f = deepcopy(f)
end

if isnothing(aliases.alias_p) || aliases.alias_p
p = p
else
p = recursivecopy(p)
end

if !isnothing(aliases.alias_u0) && aliases.alias_u0
u = prob.u0
else
u = recursivecopy(prob.u0)
end

if isnothing(aliases.alias_u0)
alias_u0 = false
else
alias_u0 = aliases.alias_u0
end

# determine type and direction of time
tType = eltype(tspan)
t0 = first(tspan)
Expand Down
23 changes: 23 additions & 0 deletions test/interface/aliasing.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using DelayDiffEq, DDEProblemLibrary

# For now, testing if the old keyword works the same as the new alias keyword
prob_ip = prob_dde_constant_1delay_ip
prob_scalar = prob_dde_constant_1delay_scalar
ts = 0:0.1:10

noreuse = NLNewton(fast_convergence_cutoff = 0)

const working_algs = [ImplicitMidpoint(), SSPSDIRK2(), KenCarp5(nlsolve = noreuse),
ImplicitEuler(nlsolve = noreuse), Trapezoid(nlsolve = noreuse),
TRBDF2(nlsolve = noreuse)]

@testset "Algorithm $(nameof(typeof(alg)))" for alg in working_algs
println(nameof(typeof(alg)))

stepsalg = MethodOfSteps(alg)
sol_new_alias = solve(prob_ip, stepsalg; dt = 0.1, alias = DDEAliasSpecifier(alias_u0 = true))
sol_old_alias = solve(
prob_ip, stepsalg; dt = 0.1, alias = alias_u0 = true)

@test sol_new_alias == sol_old_alias
end
Loading