Skip to content

Commit f388613

Browse files
committed
rename Control -> DynamicOpt
1 parent feb9da4 commit f388613

File tree

8 files changed

+141
-139
lines changed

8 files changed

+141
-139
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ MTKChainRulesCoreExt = "ChainRulesCore"
7878
MTKDeepDiffsExt = "DeepDiffs"
7979
MTKFMIExt = "FMI"
8080
MTKInfiniteOptExt = "InfiniteOpt"
81-
MTKJuMPControlExt = ["JuMP", "DiffEqDevTools", "InfiniteOpt"]
81+
MTKJuMPDynamicOptExt = ["JuMP", "DiffEqDevTools", "InfiniteOpt"]
8282
MTKLabelledArraysExt = "LabelledArrays"
8383

8484
[compat]

ext/MTKJuMPControlExt.jl renamed to ext/MTKJuMPDynamicOptExt.jl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
module MTKJuMPControlExt
1+
module MTKJuMPDynamicOptExt
22
using ModelingToolkit
33
using JuMP, InfiniteOpt
44
using DiffEqDevTools, DiffEqBase
55
using LinearAlgebra
66
using StaticArrays
77
const MTK = ModelingToolkit
88

9-
struct JuMPControlProblem{uType, tType, isinplace, P, F, K} <:
10-
AbstractOptimalControlProblem{uType, tType, isinplace}
9+
struct JuMPDynamicOptProblem{uType, tType, isinplace, P, F, K} <:
10+
AbstractDynamicOptProblem{uType, tType, isinplace}
1111
f::F
1212
u0::uType
1313
tspan::tType
1414
p::P
1515
model::InfiniteModel
1616
kwargs::K
1717

18-
function JuMPControlProblem(f, u0, tspan, p, model, kwargs...)
18+
function JuMPDynamicOptProblem(f, u0, tspan, p, model, kwargs...)
1919
new{typeof(u0), typeof(tspan), SciMLBase.isinplace(f, 5),
2020
typeof(p), typeof(f), typeof(kwargs)}(f, u0, tspan, p, model, kwargs)
2121
end
2222
end
2323

24-
struct InfiniteOptControlProblem{uType, tType, isinplace, P, F, K} <:
25-
AbstractOptimalControlProblem{uType, tType, isinplace}
24+
struct InfiniteOptDynamicOptProblem{uType, tType, isinplace, P, F, K} <:
25+
AbstractDynamicOptProblem{uType, tType, isinplace}
2626
f::F
2727
u0::uType
2828
tspan::tType
2929
p::P
3030
model::InfiniteModel
3131
kwargs::K
3232

33-
function InfiniteOptControlProblem(f, u0, tspan, p, model, kwargs...)
33+
function InfiniteOptDynamicOptProblem(f, u0, tspan, p, model, kwargs...)
3434
new{typeof(u0), typeof(tspan), SciMLBase.isinplace(f),
3535
typeof(p), typeof(f), typeof(kwargs)}(f, u0, tspan, p, model, kwargs)
3636
end
3737
end
3838

3939
"""
40-
JuMPControlProblem(sys::ODESystem, u0, tspan, p; dt)
40+
JuMPDynamicOptProblem(sys::ODESystem, u0, tspan, p; dt)
4141
4242
Convert an ODESystem representing an optimal control system into a JuMP model
4343
for solving using optimization. Must provide either `dt`, the timestep between collocation
@@ -52,7 +52,7 @@ The constraints are:
5252
- The set of user constraints passed to the ODESystem via `constraints`
5353
- The solver constraints that encode the time-stepping used by the solver
5454
"""
55-
function MTK.JuMPControlProblem(sys::ODESystem, u0map, tspan, pmap;
55+
function MTK.JuMPDynamicOptProblem(sys::ODESystem, u0map, tspan, pmap;
5656
dt = nothing,
5757
steps = nothing,
5858
guesses = Dict(), kwargs...)
@@ -65,20 +65,20 @@ function MTK.JuMPControlProblem(sys::ODESystem, u0map, tspan, pmap;
6565
steps, is_free_t = MTK.process_tspan(tspan, dt, steps)
6666
model = init_model(sys, tspan, steps, u0map, pmap, u0; is_free_t)
6767

68-
JuMPControlProblem(f, u0, tspan, p, model, kwargs...)
68+
JuMPDynamicOptProblem(f, u0, tspan, p, model, kwargs...)
6969
end
7070

7171
"""
72-
InfiniteOptControlProblem(sys::ODESystem, u0map, tspan, pmap; dt)
72+
InfiniteOptDynamicOptProblem(sys::ODESystem, u0map, tspan, pmap; dt)
7373
7474
Convert an ODESystem representing an optimal control system into a InfiniteOpt model
7575
for solving using optimization. Must provide `dt` for determining the length
7676
of the interpolation arrays.
7777
78-
Related to `JuMPControlProblem`, but directly adds the differential equations
78+
Related to `JuMPDynamicOptProblem`, but directly adds the differential equations
7979
of the system as derivative constraints, rather than using a solver tableau.
8080
"""
81-
function MTK.InfiniteOptControlProblem(sys::ODESystem, u0map, tspan, pmap;
81+
function MTK.InfiniteOptDynamicOptProblem(sys::ODESystem, u0map, tspan, pmap;
8282
dt = nothing,
8383
steps = nothing,
8484
guesses = Dict(), kwargs...)
@@ -92,7 +92,7 @@ function MTK.InfiniteOptControlProblem(sys::ODESystem, u0map, tspan, pmap;
9292
model = init_model(sys, tspan, steps, u0map, pmap, u0; is_free_t)
9393

9494
add_infopt_solve_constraints!(model, sys, pmap; is_free_t)
95-
InfiniteOptControlProblem(f, u0, tspan, p, model, kwargs...)
95+
InfiniteOptDynamicOptProblem(f, u0, tspan, p, model, kwargs...)
9696
end
9797

9898
# Initialize InfiniteOpt model.
@@ -307,16 +307,16 @@ function add_jump_solve_constraints!(prob, tableau; is_free_t = false)
307307
end
308308

309309
"""
310-
Solve JuMPControlProblem. Arguments:
311-
- prob: a JumpControlProblem
310+
Solve JuMPDynamicOptProblem. Arguments:
311+
- prob: a JumpDynamicOptProblem
312312
- jump_solver: a LP solver such as HiGHS
313313
- ode_solver: Takes in a symbol representing the solver. Acceptable solvers may be found at https://docs.sciml.ai/DiffEqDevDocs/stable/internals/tableaus/. Note that the symbol may be different than the typical name of the solver, e.g. :Tsitouras5 rather than Tsit5.
314314
- silent: set the model silent (suppress model output)
315315
316-
Returns a JuMPControlSolution, which contains both the model and the ODE solution.
316+
Returns a DynamicOptSolution, which contains both the model and the ODE solution.
317317
"""
318318
function DiffEqBase.solve(
319-
prob::JuMPControlProblem, jump_solver, ode_solver::Symbol; silent = false)
319+
prob::JuMPDynamicOptProblem, jump_solver, ode_solver::Symbol; silent = false)
320320
model = prob.model
321321
tableau_getter = Symbol(:construct, ode_solver)
322322
@eval tableau = $tableau_getter()
@@ -343,15 +343,15 @@ end
343343
"""
344344
`derivative_method` kwarg refers to the method used by InfiniteOpt to compute derivatives. The list of possible options can be found at https://infiniteopt.github.io/InfiniteOpt.jl/stable/guide/derivative/. Defaults to FiniteDifference(Backward()).
345345
"""
346-
function DiffEqBase.solve(prob::InfiniteOptControlProblem, jump_solver;
346+
function DiffEqBase.solve(prob::InfiniteOptDynamicOptProblem, jump_solver;
347347
derivative_method = InfiniteOpt.FiniteDifference(Backward()), silent = false)
348348
model = prob.model
349349
silent && set_silent(model)
350350
set_derivative_method(model[:t], derivative_method)
351351
_solve(prob, jump_solver, derivative_method)
352352
end
353353

354-
function _solve(prob::AbstractOptimalControlProblem, jump_solver, solver)
354+
function _solve(prob::AbstractDynamicOptProblem, jump_solver, solver)
355355
model = prob.model
356356
set_optimizer(model, jump_solver)
357357
optimize!(model)
@@ -382,7 +382,7 @@ function _solve(prob::AbstractOptimalControlProblem, jump_solver, solver)
382382
input_sol, SciMLBase.ReturnCode.ConvergenceFailure))
383383
end
384384

385-
OptimalControlSolution(model, sol, input_sol)
385+
DynamicOptSolution(model, sol, input_sol)
386386
end
387387

388388
end

src/ModelingToolkit.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ export AnalysisPoint, get_sensitivity_function, get_comp_sensitivity_function,
349349
function FMIComponent end
350350

351351
include("systems/optimal_control_interface.jl")
352-
export AbstractOptimalControlProblem, JuMPControlProblem, InfiniteOptControlProblem,
353-
PyomoControlProblem, CasADiControlProblem
354-
export OptimalControlSolution
352+
export AbstractDynamicOptProblem, JuMPDynamicOptProblem, InfiniteOptDynamicOptProblem,
353+
PyomoDynamicOptProblem, CasADiDynamicOptProblem
354+
export DynamicOptSolution
355355
export
356356

357357
end # module

src/systems/optimal_control_interface.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
abstract type AbstractOptimalControlProblem{uType, tType, isinplace} <:
1+
abstract type AbstractDynamicOptProblem{uType, tType, isinplace} <:
22
SciMLBase.AbstractODEProblem{uType, tType, isinplace} end
33

4-
struct OptimalControlSolution
4+
struct DynamicOptSolution
55
model::Any
66
sol::ODESolution
77
input_sol::Union{Nothing, ODESolution}
88
end
99

10-
function Base.show(io::IO, sol::OptimalControlSolution)
10+
function Base.show(io::IO, sol::DynamicOptSolution)
1111
println("retcode: ", sol.sol.retcode, "\n")
1212

1313
println("Optimal control solution for following model:\n")
@@ -16,10 +16,10 @@ function Base.show(io::IO, sol::OptimalControlSolution)
1616
print("\n\nPlease query the model using sol.model, the solution trajectory for the system using sol.sol, or the solution trajectory for the controllers using sol.input_sol.")
1717
end
1818

19-
function JuMPControlProblem end
20-
function InfiniteOptControlProblem end
21-
function CasADiControlProblem end
22-
function PyomoControlProblem end
19+
function JuMPDynamicOptProblem end
20+
function InfiniteOptDynamicOptProblem end
21+
function CasADiDynamicOptProblem end
22+
function PyomoDynamicOptProblem end
2323

2424
function warn_overdetermined(sys, u0map)
2525
constraintsys = get_constraintsystem(sys)

test/downstream/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
44
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
55
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
66
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
7+
OrdinaryDiffEqNonlinearSolve = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8"
78
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
89

910
[compat]

test/dynamic_optimization/jump_control.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using DataInterpolations
2323
parammap ==> 1.5, β => 1.0, γ => 3.0, δ => 1.0]
2424

2525
# Test explicit method.
26-
jprob = JuMPControlProblem(sys, u0map, tspan, parammap, dt = 0.01)
26+
jprob = JuMPDynamicOptProblem(sys, u0map, tspan, parammap, dt = 0.01)
2727
@test JuMP.num_constraints(jprob.model) == 2 # initials
2828
jsol = solve(jprob, Ipopt.Optimizer, :RK4)
2929
oprob = ODEProblem(sys, u0map, tspan, parammap)
@@ -34,7 +34,7 @@ using DataInterpolations
3434
jsol2 = solve(jprob, Ipopt.Optimizer, :ImplicitEuler, silent = true) # 63.031 ms, 26.49 MiB
3535
osol2 = solve(oprob, ImplicitEuler(), dt = 0.01, adaptive = false) # 129.375 μs, 61.91 KiB
3636
@test (jsol2.sol.u, osol2.u, rtol = 0.001)
37-
iprob = InfiniteOptControlProblem(sys, u0map, tspan, parammap, dt = 0.01)
37+
iprob = InfiniteOptDynamicOptProblem(sys, u0map, tspan, parammap, dt = 0.01)
3838
isol = solve(iprob, Ipopt.Optimizer,
3939
derivative_method = InfiniteOpt.FiniteDifference(InfiniteOpt.Backward()),
4040
silent = true) # 11.540 ms, 4.00 MiB
@@ -46,13 +46,13 @@ using DataInterpolations
4646
constr = [x(0.6) ~ 3.5, x(0.3) ~ 7.0]
4747
@mtkbuild lksys = ODESystem(eqs, t; constraints = constr)
4848

49-
jprob = JuMPControlProblem(lksys, u0map, tspan, parammap; guesses = guess, dt = 0.01)
49+
jprob = JuMPDynamicOptProblem(lksys, u0map, tspan, parammap; guesses = guess, dt = 0.01)
5050
@test JuMP.num_constraints(jprob.model) == 2
5151
jsol = solve(jprob, Ipopt.Optimizer, :Tsitouras5, silent = true) # 12.190 s, 9.68 GiB
5252
@test jsol.sol(0.6)[1] 3.5
5353
@test jsol.sol(0.3)[1] 7.0
5454

55-
iprob = InfiniteOptControlProblem(
55+
iprob = InfiniteOptDynamicOptProblem(
5656
lksys, u0map, tspan, parammap; guesses = guess, dt = 0.01)
5757
isol = solve(iprob, Ipopt.Optimizer,
5858
derivative_method = InfiniteOpt.OrthogonalCollocation(3), silent = true) # 48.564 ms, 9.58 MiB
@@ -63,13 +63,13 @@ using DataInterpolations
6363
# Test whole-interval constraints
6464
constr = [x(t) 1, y(t) 1]
6565
@mtkbuild lksys = ODESystem(eqs, t; constraints = constr)
66-
iprob = InfiniteOptControlProblem(
66+
iprob = InfiniteOptDynamicOptProblem(
6767
lksys, u0map, tspan, parammap; guesses = guess, dt = 0.01)
6868
isol = solve(iprob, Ipopt.Optimizer,
6969
derivative_method = InfiniteOpt.OrthogonalCollocation(3), silent = true) # 48.564 ms, 9.58 MiB
7070
@test all(u -> u > [1, 1], isol.sol.u)
7171

72-
jprob = JuMPControlProblem(lksys, u0map, tspan, parammap; guesses = guess, dt = 0.01)
72+
jprob = JuMPDynamicOptProblem(lksys, u0map, tspan, parammap; guesses = guess, dt = 0.01)
7373
jsol = solve(jprob, Ipopt.Optimizer, :RadauIA3, silent = true) # 12.190 s, 9.68 GiB
7474
@test all(u -> u > [1, 1], jsol.sol.u)
7575
end
@@ -103,7 +103,7 @@ end
103103
u0map = [x(t) => 0.0, v(t) => 0.0]
104104
tspan = (0.0, 1.0)
105105
parammap = [u(t) => 0.0]
106-
jprob = JuMPControlProblem(block, u0map, tspan, parammap; dt = 0.01)
106+
jprob = JuMPDynamicOptProblem(block, u0map, tspan, parammap; dt = 0.01)
107107
jsol = solve(jprob, Ipopt.Optimizer, :Verner8)
108108
# Linear systems have bang-bang controls
109109
@test is_bangbang(jsol.input_sol, [-1.0], [1.0])
@@ -117,7 +117,7 @@ end
117117
osol = solve(oprob, Vern8(), dt = 0.01, adaptive = false)
118118
@test (jsol.sol.u, osol.u, rtol = 0.05)
119119

120-
iprob = InfiniteOptControlProblem(block, u0map, tspan, parammap; dt = 0.01)
120+
iprob = InfiniteOptDynamicOptProblem(block, u0map, tspan, parammap; dt = 0.01)
121121
isol = solve(iprob, Ipopt.Optimizer; silent = true)
122122
@test is_bangbang(isol.input_sol, [-1.0], [1.0])
123123
@test (isol.sol.u[end][1], 0.25, rtol = 1e-5)
@@ -141,10 +141,10 @@ end
141141
u0map = [w(t) => 40, q(t) => 2]
142142
pmap = [b => 1, c => 1, μ => 1, s => 1, ν => 1, α => 1]
143143

144-
jprob = JuMPControlProblem(beesys, u0map, tspan, pmap, dt = 0.01)
144+
jprob = JuMPDynamicOptProblem(beesys, u0map, tspan, pmap, dt = 0.01)
145145
jsol = solve(jprob, Ipopt.Optimizer, :Tsitouras5)
146146
@test is_bangbang(jsol.input_sol, [0.0], [1.0])
147-
iprob = InfiniteOptControlProblem(beesys, u0map, tspan, pmap, dt = 0.01)
147+
iprob = InfiniteOptDynamicOptProblem(beesys, u0map, tspan, pmap, dt = 0.01)
148148
isol = solve(iprob, Ipopt.Optimizer; silent = true)
149149
@test is_bangbang(isol.input_sol, [0.0], [1.0])
150150

@@ -186,11 +186,11 @@ end
186186
pmap = [
187187
g₀ => 1, m₀ => 1.0, h_c => 500, c => 0.5 * (g₀ * h₀), D_c => 0.5 * 620 * m₀ / g₀,
188188
Tₘ => 3.5 * g₀ * m₀, T(t) => 0.0, h₀ => 1, m_c => 0.6]
189-
jprob = JuMPControlProblem(rocket, u0map, (ts, te), pmap; dt = 0.005, cse = false)
189+
jprob = JuMPDynamicOptProblem(rocket, u0map, (ts, te), pmap; dt = 0.005, cse = false)
190190
jsol = solve(jprob, Ipopt.Optimizer, :RadauIIA5, silent = true)
191191
@test jsol.sol.u[end][1] > 1.012
192192

193-
iprob = InfiniteOptControlProblem(
193+
iprob = InfiniteOptDynamicOptProblem(
194194
rocket, u0map, (ts, te), pmap; dt = 0.005, cse = false)
195195
isol = solve(iprob, Ipopt.Optimizer,
196196
derivative_method = InfiniteOpt.OrthogonalCollocation(3), silent = true)
@@ -223,11 +223,11 @@ end
223223

224224
u0map = [x(t) => 17.5]
225225
pmap = [u(t) => 0.0, tf => 8]
226-
jprob = JuMPControlProblem(rocket, u0map, (0, tf), pmap; steps = 201)
226+
jprob = JuMPDynamicOptProblem(rocket, u0map, (0, tf), pmap; steps = 201)
227227
jsol = solve(jprob, Ipopt.Optimizer, :Tsitouras5)
228228
@test isapprox(jsol.sol.t[end], 10.0, rtol = 1e-3)
229229

230-
iprob = InfiniteOptControlProblem(rocket, u0map, (0, tf), pmap; steps = 200)
230+
iprob = InfiniteOptDynamicOptProblem(rocket, u0map, (0, tf), pmap; steps = 200)
231231
isol = solve(iprob, Ipopt.Optimizer)
232232
@test isapprox(isol.sol.t[end], 10.0, rtol = 1e-3)
233233
end
@@ -259,11 +259,11 @@ end
259259

260260
u0map = [D(x(t)) => 0.0, D(θ(t)) => 0.0, θ(t) => 0.0, x(t) => 0.0]
261261
pmap = [mₖ => 1.0, mₚ => 0.2, l => 0.5, g => 9.81, u => 0]
262-
jprob = JuMPControlProblem(cartpole, u0map, tspan, pmap; dt = 0.04)
262+
jprob = JuMPDynamicOptProblem(cartpole, u0map, tspan, pmap; dt = 0.04)
263263
jsol = solve(jprob, Ipopt.Optimizer, :RK4)
264264
@test jsol.sol.u[end] [π, 0, 0, 0]
265265

266-
iprob = InfiniteOptControlProblem(cartpole, u0map, tspan, pmap; dt = 0.04)
266+
iprob = InfiniteOptDynamicOptProblem(cartpole, u0map, tspan, pmap; dt = 0.04)
267267
isol = solve(iprob, Ipopt.Optimizer)
268268
@test isol.sol.u[end] [π, 0, 0, 0]
269269
end

test/extensions/ad.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Zygote
44
using SymbolicIndexingInterface
55
using SciMLStructures
66
using OrdinaryDiffEqTsit5
7+
using OrdinaryDiffEqNonlinearSolve
78
using NonlinearSolve
89
using SciMLSensitivity
910
using ForwardDiff

0 commit comments

Comments
 (0)