Closed jbcaillau closed 2 weeks ago
@jbcaillau To update:
5 possible nonlinear (= defined by functions, now inplace) constraints to treat, associated respectively with ξ, η, ψ, ϕ, θ
:
(type, f::BoundaryConstraint, lb, ub) && if type ∈ [:initial, :final, :boundary] end # ϕ
(:control, f::ControlConstraint, lb, ub) # ξ
(:state, f::StateConstraint, lb, ub) # η
(:mixed, f::MixedConstraint, lb, ub) # ψ
(:variable, f::VariableConstraint, lb, ub) # θ
Also (see fun_range
):
function constraint!(
ocp::OptimalControlModel{T, V},
type::Symbol;
rg::Union{OrdinalRange{<:Integer}, Index, Integer, Nothing}=nothing,
f::Union{Function, Nothing}=nothing,
lb::Union{ctVector, Nothing}=nothing,
ub::Union{ctVector, Nothing}=nothing,
val::Union{ctVector, Nothing}=nothing,
label::Symbol=__constraint_label()) where {T <: TimeDependence, V <: VariableDependence}
Also:
function constraint(ocp::OptimalControlModel{T, V}, label::Symbol) where {T <: TimeDependence, V <: VariableDependence}
p_constraint!(p, ocp, e1, e2, e3, label=gensym(); log=false)
p_dynamics!(p, ocp, x, t, e, label=nothing; log=false)
p_lagrange!(p, ocp, e, type; log=false)
p_mayer!(p, ocp, e, type; log=false)
p_bolza!(p, ocp, e1, e2, type; log=false)
NB.
function
for long funs (blue style)code =
then __wrap(code, p.lnum, p.line)
in every p_...
@allocates
views
, see https://github.com/control-toolbox/CTBase.jl/pull/271#discussion_r1741275180is_in_place(ocp)
now availablefalse
(default for functional syntax), nothing changedtrue
for abstract, ensuring to map problems towards efficient functional codeDynamics
, Lagrange
, Mayer
(in addition to the 5 nonlinear constraint types)Type -> Type_
for all optimal_control_model-setters
Mayer_(ocp, f_::Function; variable::Bool = false) = is_in_place(ocp) ? Mayer!(f_; variable) : Mayer(f_; variable)
Mayer_ = is_in_place(ocp) ? Mayer! : Mayer
also works@PierreMartinon any preliminary comments?
@PierreMartinon aiming to providing inplace function as a result of
nlp_constraints!
, having inplace signatures forξ, η, ψ, ϕ, θ
:julia> (ξl, ξ, ξu), (ηl, η, ηu), (ψl, ψ, ψu), (ϕl, ϕ, ϕu), (θl, θ, θu), (ul, uind, uu), (xl, xind, xu), (vl, vind, vu) = nlp_constraints!(ocp)
Related to: control-toolbox/CTDirect.jl#188
@PierreMartinon back on this issue. on your side, ready for inplace in CTDirect.jl with trapezoidal scheme? Target above: https://github.com/control-toolbox/CTBase.jl/issues/232#issue-2458120989
@ocots I'll need some help to update the unit tests.
@ocots we'll need to be able to run tests like
@def o begin
t ∈ [ 0, 1 ], time
x = [ r, v ] ∈ R², state
u ∈ R, control
w = r + 2v
r(0) == 0, (1)
v(0) == 1, (♡)
ẋ(t) == [ v(t), w(t)^2 ]
∫( u(t)^2 + x₁(t) ) → min
end
x = [ 1, 2 ]
x0 = 2 * x
xf = 3 * x
u = 3
@test constraint(o, :eq1)(x0, xf) == x0[1]
@test constraint(o, Symbol("♡"))(x0, xf) == x0[2]
@test o.dynamics(x, u) == [ x[2], (x[1] + 2x[2])^2 ]
@test o.lagrange(x, u) == u^2 + x[1]
It is better not to rewrite test but to update the getters (such as constraint
) so that they take care of the functions now being in place. My question: can you please remind me what getters are available for dynamics and the three different costs? (Using getters in the test would be nicer, too.)
@ocots excellent. do think you could vscode
update test_onepass.jl to replace field accesses by these getters? Then it should be fairly easy to reuse the existing tests with in place functions.
Getters: [...]
@ocots just for the record: no bolza
getter, subsumed by lagrange
+ mayer
ones, I suppose? YES
Hi guys, While you're at it, can you make it so that initial conditions are always before final conditions when building the boundary conditions ? Also, iirc mayer exists only in autonomous version ?
@PierreMartinon
Hi guys, While you're at it, can you make it so that initial conditions are always before final conditions when building the boundary conditions ?
OK
Also, iirc mayer exists only in autonomous version ?
Not sure that the question makes sense:
Same thing for (nonlinear) boundary conditions, BTW.
Am I missing sth?
@PierreMartinon meeting tomorrow (tuesday) 14:00 https://inria.webex.com/meet/jean-baptiste.caillau
@ocots @joseph-gergaud welcome to join if you're around!
@PierreMartinon Parametric type:
struct TypeParamExample{T<:Number}
x::T
end
and for a function:
julia> function f(x::T, y::T) where {T <: Number}
return x + y
end
f (generic function with 1 method)
julia> f(1, 2)
3
julia> f(1, 2.0)
ERROR: MethodError: no method matching f(::Int64, ::Float64)
Closest candidates are:
f(::T, ::T) where T<:Number
@ Main REPL[5]:1
Stacktrace:
[1] top-level scope
@ REPL[7]:1
@jbcaillau The scalar case for the constraints must be treated.
@PierreMartinon Voir :
@jbcaillau The scalar case for the constraints must be treated.
@joseph-gergaud @PierreMartinon should be OK provided in place functions returned by nlp_constraints!
are called with a (slice of) vector as first arg. may be an exception for Lagrange cost, to be checked. in any case, the possible generated error should be clear enough 🤞🏾
constraint
, dynamics
, lagrange
, mayer
) to transform in place into out of place inside unitary tests@PierreMartinon catch-up this Monday 9/9 at 14:00 on zoom https://univ-cotedazur.zoom.us/my/caillau
@ocots @joseph-gergaud welcome if you're around!
Hi guys, While you're at it, can you make it so that initial conditions are always before final conditions when building the boundary conditions ? Also, iirc mayer exists only in autonomous version ?
@PierreMartinon closing this issue, in favour of https://github.com/control-toolbox/CTBase.jl/issues/288 (please answer there!)
@PierreMartinon aiming to providing inplace function as a result of
nlp_constraints!
, having inplace signatures forξ, η, ψ, ϕ, θ
:Related to: https://github.com/control-toolbox/CTDirect.jl/issues/188
@ocots I'll need some help to update the unit tests.