Skip to content

Commit e9c429c

Browse files
committed
drop DataInteprolations
1 parent 6505082 commit e9c429c

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

Project.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
3131
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
3232
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
3333
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
34-
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
3534
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
3635
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
3736
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
@@ -67,17 +66,14 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
6766
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
6867
CasADi = "c49709b8-5c63-11e9-2fb2-69db5844192f"
6968
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
70-
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
7169
DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"
72-
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
7370
FMI = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
7471
InfiniteOpt = "20393b10-9daf-11e9-18c9-8db751c92c57"
75-
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
7672
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
7773

7874
[extensions]
7975
MTKBifurcationKitExt = "BifurcationKit"
80-
MTKCasADiDynamicOptExt = ["CasADi", "DataInterpolations"]
76+
MTKCasADiDynamicOptExt = "CasADi"
8177
MTKChainRulesCoreExt = "ChainRulesCore"
8278
MTKDeepDiffsExt = "DeepDiffs"
8379
MTKFMIExt = "FMI"
@@ -104,7 +100,6 @@ DeepDiffs = "1"
104100
DelayDiffEq = "5.50"
105101
DiffEqBase = "6.170.1"
106102
DiffEqCallbacks = "2.16, 3, 4"
107-
DiffEqDevTools = "2.48.0"
108103
DiffEqNoiseProcess = "5"
109104
DiffRules = "0.1, 1.0"
110105
DifferentiationInterface = "0.6.47"

ext/MTKCasADiDynamicOptExt.jl

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,32 @@ struct CasADiDynamicOptProblem{uType, tType, isinplace, P, F, K} <:
2020
end
2121
end
2222

23+
# Default linear interpolation for MX objects, likely to change down the line when we support interpolation with the collocation polynomial.
24+
struct MXLinearInterpolation
25+
u::MX
26+
t::Vector{Float64}
27+
dt::Float64
28+
end
29+
2330
struct CasADiModel
2431
opti::Opti
25-
U::AbstractInterpolation
26-
V::AbstractInterpolation
32+
U::MXLinearInterpolation
33+
V::MXLinearInterpolation
2734
tₛ::Union{Number, MX}
2835
end
2936

37+
function (M::MXLinearInterpolation)(τ)
38+
nt =- M.t) / M.dt
39+
i = 1 + floor(Int, nt)
40+
Δ = nt - i + 1
41+
42+
(i > length(M.t) || i < 1) && error("Cannot extrapolate past the tspan.")
43+
M.u[i] + Δ*(M.u[i + 1] - M.u[i])
44+
end
45+
3046
function MTK.CasADiDynamicOptProblem(sys::ODESystem, u0map, tspan, pmap;
3147
dt = nothing,
3248
steps = nothing,
33-
interpolation_method::AbstractInterpolation = LinearInterpolation,
3449
guesses = Dict(), kwargs...)
3550
MTK.warn_overdetermined(sys, u0map)
3651
_u0map = has_alg_eqs(sys) ? u0map : merge(Dict(u0map), Dict(guesses))
@@ -39,10 +54,10 @@ function MTK.CasADiDynamicOptProblem(sys::ODESystem, u0map, tspan, pmap;
3954

4055
pmap = Dict{Any, Any}(pmap)
4156
steps, is_free_t = MTK.process_tspan(tspan, dt, steps)
42-
model = init_model()
57+
model = init_model(sys, tspan, steps, u0map, pmap, u0; is_free_t)
4358
end
4459

45-
function init_model(sys, tspan, steps, u0map, pmap, u0; is_free_t = false, interp_type::AbstractInterpolation)
60+
function init_model(sys, tspan, steps, u0map, pmap, u0; is_free_t = false)
4661
ctrls = MTK.unbound_inputs(sys)
4762
states = unknowns(sys)
4863
opti = CasADi.Opti()
@@ -61,8 +76,8 @@ function init_model(sys, tspan, steps, u0map, pmap, u0; is_free_t = false, inter
6176
U = CasADi.variable!(opti, length(states), steps)
6277
V = CasADi.variable!(opti, length(ctrls), steps)
6378

64-
U_interp = interp_type(Matrix(U), tsteps)
65-
V_interp = interp_type(Matrix(V), tsteps)
79+
U_interp = MXLinearInterpolation(U, tsteps, tsteps[2]-tsteps[1])
80+
V_interp = MXLinearInterpolation(V, tsteps, tsteps[2]-tsteps[1])
6681

6782
CasADiModel(opti, U_interp, V_interp, tₛ)
6883
end
@@ -220,9 +235,8 @@ function add_solve_constraints!(prob, tableau; is_free_t)
220235
end
221236
end
222237

223-
224238
"""
225-
solve(prob::CasADiDynamicOptProblem, casadi_solver, ode_solver; plugin_options, solver_options)
239+
solve(prob::CasADiDynamicOptProblem, casadi_solver, ode_solver; plugin_options, solver_options, silent)
226240
227241
`plugin_options` and `solver_options` get propagated to the Opti object in CasADi.
228242
"""
@@ -247,7 +261,6 @@ function DiffEqBase.solve(prob::CasADiDynamicOptProblem, solver::Union{String, S
247261
catch ErrorException
248262
value_getter = x -> CasADi.debug_value(opti, x)
249263
failed = true
250-
continue
251264
end
252265

253266
ts = value_getter(tₛ) * U.t
@@ -270,5 +283,4 @@ function DiffEqBase.solve(prob::CasADiDynamicOptProblem, solver::Union{String, S
270283

271284
DynamicOptSolution(cmodel, sol, input_sol)
272285
end
273-
274286
end

test/downstream/jump_control.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ using SimpleDiffEq
55
using OrdinaryDiffEqSDIRK, OrdinaryDiffEqVerner, OrdinaryDiffEqTsit5, OrdinaryDiffEqFIRK
66
using Ipopt
77
using DataInterpolations
8-
include("../dynamic_opt_systems.jl")
8+
using CasADi
9+
910
const M = ModelingToolkit
1011

1112
@testset "ODE Solution, no cost" begin

0 commit comments

Comments
 (0)