Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

232 preparing for inplace nlp #271

Merged
merged 37 commits into from
Sep 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7c76c71
first commit
jbcaillau Aug 9, 2024
968ae6e
__wrap(code, ...) everywhere
jbcaillau Aug 29, 2024
98aff2a
solved conflicts in onepass.jl
jbcaillau Aug 29, 2024
fc292cb
Merge branch 'main' into 232-preparing-for-inplace-nlp
jbcaillau Aug 30, 2024
2341da6
added in_place info
jbcaillau Aug 30, 2024
c9e51bc
solved minor conflicts in CTBase.jl (export list)
jbcaillau Sep 2, 2024
75f8af2
added in place ξ!(val, t, u, v) # nonlinear control constraints; adde…
jbcaillau Sep 2, 2024
cc62bd2
added in place for all fun (= nonlinear) constraints
jbcaillau Sep 2, 2024
5a7ed3a
added in place types; to be tested
jbcaillau Sep 5, 2024
09785e0
added missing Types_ = is_in_place(oc
jbcaillau Sep 5, 2024
8dd6f02
fix unit tests
ocots Sep 5, 2024
53e0521
moved Type_ defs. at the beginning of constraint\!
jbcaillau Sep 5, 2024
6b5e28e
scalar range
jbcaillau Sep 6, 2024
670d3fb
treated scalar case with r[:] .= __view(..., rg)
jbcaillau Sep 6, 2024
0ae0f8d
added to_out_place in utils
jbcaillau Sep 6, 2024
3f974ac
added to_out_place in utils
jbcaillau Sep 6, 2024
cdcead8
added to_out_place in utils
jbcaillau Sep 6, 2024
5b01703
fixed utils test + updated tests in onepass with __
jbcaillau Sep 6, 2024
23fbaa8
fix: exported __constraint et al used for test
jbcaillau Sep 6, 2024
fc22616
fix in exports
jbcaillau Sep 6, 2024
4bf88fc
updated test_model with __getters
jbcaillau Sep 6, 2024
c1bed0a
removed useless change to __getter in test_model, as everything is fu…
jbcaillau Sep 6, 2024
57c8fa5
removed useless @_def; added nothing case in to_out_of_place
jbcaillau Sep 6, 2024
e2b1733
updated onepass to generate in place functions; called by @def that g…
jbcaillau Sep 6, 2024
807e6f1
fix: added __view of vector with an Index
jbcaillau Sep 6, 2024
9ff4907
fix: missing r in ControlConstraint! and some wrong sizes in lb / ub …
jbcaillau Sep 6, 2024
d516f63
fix: old dim error in test_onepass
jbcaillau Sep 6, 2024
fe95823
foo
jbcaillau Sep 6, 2024
0eff660
added in place tests in test_model
jbcaillau Sep 7, 2024
317fbc9
fix: test_model.jl
jbcaillau Sep 7, 2024
7151bd2
fix: test_model.jl
jbcaillau Sep 7, 2024
159476b
Update test_model.jl
jbcaillau Sep 7, 2024
6d538c5
test_model: pass
jbcaillau Sep 8, 2024
34f2d99
test_model: pass
jbcaillau Sep 8, 2024
ff75ab0
added @views in generated functions (onepass)
jbcaillau Sep 9, 2024
a9f1c7c
replace __view by @views r[:] .= ...
jbcaillau Sep 9, 2024
8abc547
replaced view(x, ...) by @view(x[...]) for further perf. improvements
jbcaillau Sep 9, 2024
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
Prev Previous commit
Next Next commit
__wrap(code, ...) everywhere
jbcaillau committed Aug 29, 2024
commit 968ae6e888dc80e18011b057a6033e5ab23f0018
44 changes: 26 additions & 18 deletions src/onepass.jl
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ parse!(p, ocp, e; log=false) = begin
:( [$names] ∈ R^$n, state ) => p_state!(p, ocp, a, n; components_names=names, log)
:( ($names) ∈ R^$m, control ) => p_control!(p, ocp, a, m; components_names=names, log)
:( [$names] ∈ R^$m, control ) => p_control!(p, ocp, a, m; components_names=names, log)
_ => p_alias!(p, ocp, a, e1; log) # alias
_ => p_alias!(p, ocp, a, e1; log) # alias
end
# variable
:( $v ∈ R^$q, variable ) => p_variable!(p, ocp, v, q; log)
@@ -172,13 +172,14 @@ p_variable!(p, ocp, v, q; components_names=nothing, log=false) = begin
for i ∈ 1:qq p.aliases[Symbol(v, ctindices(i))] = :( $v[$i] ) end
for i ∈ 1:9 p.aliases[Symbol(v, ctupperscripts(i))] = :( $v^$i ) end
if (isnothing(components_names))
__wrap(:( variable!($ocp, $q, $vv) ), p.lnum, p.line)
code = :( variable!($ocp, $q, $vv) )
else
qq==length(components_names.args) || return __throw("the number of variable components must be $qq", p.lnum, p.line)
for i ∈ 1:qq p.aliases[components_names.args[i]] = :( $v[$i] ) end
ss = QuoteNode(string.(components_names.args))
__wrap(:( variable!($ocp, $q, $vv, $ss) ), p.lnum, p.line)
code = :( variable!($ocp, $q, $vv, $ss) )
end
return __wrap(code, p.lnum, p.line)
end

p_alias!(p, ocp, a, e; log=false) = begin
@@ -188,7 +189,8 @@ p_alias!(p, ocp, a, e; log=false) = begin
ee = QuoteNode(e)
for i ∈ 1:9 p.aliases[Symbol(a, ctupperscripts(i))] = :( $a^$i ) end
p.aliases[a] = e
__wrap(:( LineNumberNode(0, "alias: " * string($aa) * " = " * string($ee)) ), p.lnum, p.line)
code = :( LineNumberNode(0, "alias: " * string($aa) * " = " * string($ee)) )
return __wrap(code, p.lnum, p.line)
end

p_time!(p, ocp, t, t0, tf; log=false) = begin
@@ -222,7 +224,7 @@ p_time!(p, ocp, t, t0, tf; log=false) = begin
_ =>
return __throw("bad time declaration", p.lnum, p.line) end
end
__wrap(code, p.lnum, p.line)
return __wrap(code, p.lnum, p.line)
end

p_state!(p, ocp, x, n; components_names=nothing, log=false) = begin
@@ -235,13 +237,14 @@ p_state!(p, ocp, x, n; components_names=nothing, log=false) = begin
for i ∈ 1:9 p.aliases[Symbol(x, ctupperscripts(i))] = :( $x^$i ) end
p.aliases[Symbol(Unicode.normalize(string(x,"̇")))] = :( ∂($x) )
if (isnothing(components_names))
__wrap(:( state!($ocp, $n, $xx) ), p.lnum, p.line)
code = :( state!($ocp, $n, $xx) )
else
nn==length(components_names.args) || return __throw("the number of state components must be $nn", p.lnum, p.line)
for i ∈ 1:nn p.aliases[components_names.args[i]] = :( $x[$i] ) end
ss = QuoteNode(string.(components_names.args))
__wrap(:( state!($ocp, $n, $xx, $ss) ), p.lnum, p.line)
code = :( state!($ocp, $n, $xx, $ss) )
end
return __wrap(code, p.lnum, p.line)
end

p_control!(p, ocp, u, m; components_names=nothing, log=false) = begin
@@ -253,13 +256,14 @@ p_control!(p, ocp, u, m; components_names=nothing, log=false) = begin
for i ∈ 1:mm p.aliases[Symbol(u, ctindices(i))] = :( $u[$i] ) end
for i ∈ 1:9 p.aliases[Symbol(u, ctupperscripts(i))] = :( $u^$i ) end
if (isnothing(components_names))
__wrap(:( control!($ocp, $m, $uu) ), p.lnum, p.line)
code = :( control!($ocp, $m, $uu) )
else
mm==length(components_names.args) || return __throw("the number of control components must be $mm", p.lnum, p.line)
for i ∈ 1:mm p.aliases[components_names.args[i]] = :( $u[$i] ) end
ss = QuoteNode(string.(components_names.args))
__wrap(:( control!($ocp, $m, $uu, $ss) ), p.lnum, p.line)
code = :( control!($ocp, $m, $uu, $ss) )
end
return __wrap(code, p.lnum, p.line)
end

p_constraint!(p, ocp, e1, e2, e3, label=gensym(); log=false) = begin
@@ -335,7 +339,7 @@ p_constraint!(p, ocp, e1, e2, e3, label=gensym(); log=false) = begin
end end
_ => return __throw("bad constraint declaration", p.lnum, p.line)
end
__wrap(code, p.lnum, p.line)
return __wrap(code, p.lnum, p.line)
end

p_dynamics!(p, ocp, x, t, e, label=nothing; log=false) = begin
@@ -353,12 +357,13 @@ p_dynamics!(p, ocp, x, t, e, label=nothing; log=false) = begin
p.t_dep = p.t_dep || has(e, t)
gs = gensym()
args = [ ]; __t_dep(p) && push!(args, p.t); push!(args, xt, ut); __v_dep(p) && push!(args, p.v)
__wrap(quote
code = quote
function $gs($(args...))
$e
end
dynamics!($ocp, $gs)
end, p.lnum, p.line)
end
return __wrap(code, p.lnum, p.line)
end

p_lagrange!(p, ocp, e, type; log=false) = begin
@@ -373,12 +378,13 @@ p_lagrange!(p, ocp, e, type; log=false) = begin
ttype = QuoteNode(type)
gs = gensym()
args = [ ]; __t_dep(p) && push!(args, p.t); push!(args, xt, ut); __v_dep(p) && push!(args, p.v)
__wrap(quote
code = quote
function $gs($(args...))
$e
end
objective!($ocp, :lagrange, $gs, $ttype)
end, p.lnum, p.line)
end
return __wrap(code, p.lnum, p.line)
end

p_mayer!(p, ocp, e, type; log=false) = begin
@@ -394,12 +400,13 @@ p_mayer!(p, ocp, e, type; log=false) = begin
e = replace_call(e, p.x, p.tf, xf)
ttype = QuoteNode(type)
args = [ x0, xf ]; __v_dep(p) && push!(args, p.v)
__wrap(quote
code = quote
function $gs($(args...))
$e
end
objective!($ocp, :mayer, $gs, $ttype)
end, p.lnum, p.line)
end
return __wrap(code, p.lnum, p.line)
end

p_bolza!(p, ocp, e1, e2, type; log=false) = begin
@@ -422,15 +429,16 @@ p_bolza!(p, ocp, e1, e2, type; log=false) = begin
p.t_dep = p.t_dep || has(e2, p.t)
args2 = [ ]; __t_dep(p) && push!(args2, p.t); push!(args2, xt, ut); __v_dep(p) && push!(args2, p.v)
ttype = QuoteNode(type)
__wrap(quote
code = quote
function $gs1($(args1...))
$e1
end
function $gs2($(args2...))
$e2
end
objective!($ocp, :bolza, $gs1, $gs2, $ttype)
end, p.lnum, p.line)
end
return __wrap(code, p.lnum, p.line)
end

"""