Skip to content

Commit c142d38

Browse files
🤖 Format .jl files (#387)
Co-authored-by: PierreMartinon <17044253+PierreMartinon@users.noreply.github.com>
1 parent 638e417 commit c142d38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+678
-657
lines changed

docs/make.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ using DocumenterMermaid
44
using CTDirect
55

66
# to add docstrings from external packages
7-
DocMeta.setdocmeta!(CTDirect, :DocTestSetup, :(using CTDirect); recursive = true)
7+
DocMeta.setdocmeta!(CTDirect, :DocTestSetup, :(using CTDirect); recursive=true)
88

99
repo_url = "github.com/control-toolbox/CTDirect.jl"
1010

1111
makedocs(;
12-
warnonly = [:cross_references, :autodocs_block],
13-
sitename = "CTDirect.jl",
14-
format = Documenter.HTML(
15-
repolink = "https://"*repo_url,
16-
prettyurls = false,
17-
assets = [
12+
warnonly=[:cross_references, :autodocs_block],
13+
sitename="CTDirect.jl",
14+
format=Documenter.HTML(
15+
repolink="https://"*repo_url,
16+
prettyurls=false,
17+
assets=[
1818
asset("https://control-toolbox.org/assets/css/documentation.css"),
1919
asset("https://control-toolbox.org/assets/js/documentation.js"),
2020
],
2121
),
22-
pages = ["Introduction" => "index.md", "API" => "api.md", "Developers" => "dev-api.md"],
22+
pages=["Introduction" => "index.md", "API" => "api.md", "Developers" => "dev-api.md"],
2323
)
2424

2525
deploydocs(;

ext/CTSolveExtIpopt.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ function CTDirect.solve_docp(
1717
solver_backend::CTDirect.IpoptBackend,
1818
docp::CTDirect.DOCP,
1919
nlp;
20-
display::Bool = CTDirect.__display(),
21-
max_iter::Integer = CTDirect.__max_iterations(),
22-
tol::Real = CTDirect.__tolerance(),
23-
print_level::Integer = CTDirect.__ipopt_print_level(),
24-
mu_strategy::String = CTDirect.__ipopt_mu_strategy(),
25-
linear_solver::String = CTDirect.__ipopt_linear_solver(),
20+
display::Bool=CTDirect.__display(),
21+
max_iter::Integer=CTDirect.__max_iterations(),
22+
tol::Real=CTDirect.__tolerance(),
23+
print_level::Integer=CTDirect.__ipopt_print_level(),
24+
mu_strategy::String=CTDirect.__ipopt_mu_strategy(),
25+
linear_solver::String=CTDirect.__ipopt_linear_solver(),
2626
kwargs...,
2727
)
2828

@@ -55,13 +55,13 @@ function CTDirect.solve_docp(
5555
docp_solution = solve!(
5656
solver,
5757
nlp,
58-
print_level = print_level,
59-
mu_strategy = mu_strategy,
60-
tol = tol,
61-
max_iter = max_iter,
62-
sb = "yes",
58+
print_level=print_level,
59+
mu_strategy=mu_strategy,
60+
tol=tol,
61+
max_iter=max_iter,
62+
sb="yes",
6363
#check_derivatives_for_naninf = "yes",
64-
linear_solver = linear_solver;
64+
linear_solver=linear_solver;
6565
kwargs...,
6666
)
6767

ext/CTSolveExtKnitro.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ function CTDirect.solve_docp(
1717
solver_backend::CTDirect.KnitroBackend,
1818
docp::CTDirect.DOCP,
1919
nlp;
20-
display::Bool = CTDirect.__display(),
21-
max_iter::Integer = CTDirect.__max_iterations(),
22-
tol::Real = CTDirect.__tolerance(),
23-
print_level::Integer = CTDirect.__knitro_print_level(),
20+
display::Bool=CTDirect.__display(),
21+
max_iter::Integer=CTDirect.__max_iterations(),
22+
tol::Real=CTDirect.__tolerance(),
23+
print_level::Integer=CTDirect.__knitro_print_level(),
2424
kwargs...,
2525
)
2626

ext/CTSolveExtMadNLP.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ function CTDirect.solve_docp(
1717
solver_backend::CTDirect.MadNLPBackend,
1818
docp::CTDirect.DOCP,
1919
nlp;
20-
display::Bool = CTDirect.__display(),
21-
max_iter::Integer = CTDirect.__max_iterations(),
22-
tol::Real = CTDirect.__tolerance(),
23-
linear_solver::String = CTDirect.__madnlp_linear_solver(), # ?
20+
display::Bool=CTDirect.__display(),
21+
max_iter::Integer=CTDirect.__max_iterations(),
22+
tol::Real=CTDirect.__tolerance(),
23+
linear_solver::String=CTDirect.__madnlp_linear_solver(), # ?
2424
kwargs...,
2525
)
2626

src/default.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ $(TYPEDSIGNATURES)
2222
Used to set the default initial guess.
2323
The default value is `nothing` and will correspond to 0.1 for all variables.
2424
"""
25-
__ocp_init() = nothing
25+
__ocp_init() = nothing
2626

2727
"""
2828
$(TYPEDSIGNATURES)
2929
3030
Used to set the default display toggle.
3131
The default value is true.
3232
"""
33-
__display() = true
33+
__display() = true
3434

3535
"""
3636
$(TYPEDSIGNATURES)

src/disc/common.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
2+
3+
14
#= Common parts for the discretization =#
25

36

7+
48
"""
59
$(TYPEDSIGNATURES)
610
@@ -9,7 +13,7 @@ Convention: stored at the end, hence not dependent on the discretization method
913
Vector output
1014
"""
1115
function get_OCP_variable(xu, docp::DOCP)
12-
return @view xu[(docp.dim_NLP_variables - docp.dims.NLP_v + 1):docp.dim_NLP_variables]
16+
return @view xu[(docp.dim_NLP_variables-docp.dims.NLP_v+1):docp.dim_NLP_variables]
1317
end
1418

1519

@@ -22,7 +26,7 @@ Vector output
2226
"""
2327
function get_OCP_state_at_time_step(xu, docp::DOCP, i)
2428
offset = (i-1) * docp.discretization._step_variables_block
25-
return @view xu[(offset + 1):(offset + docp.dims.OCP_x)]
29+
return @view xu[(offset+1):(offset+docp.dims.OCP_x)]
2630
end
2731
"""
2832
$(TYPEDSIGNATURES)
@@ -32,7 +36,7 @@ Convention: 1 <= i <= dim_NLP_steps+1 (no check for actual lagrange cost prese
3236
"""
3337
function get_lagrange_state_at_time_step(xu, docp::DOCP, i)
3438
offset = (i-1) * docp.discretization._step_variables_block
35-
return xu[offset + docp.dims.NLP_x]
39+
return xu[offset+docp.dims.NLP_x]
3640
end
3741

3842
"""
@@ -48,7 +52,7 @@ function get_OCP_control_at_time_step(xu, docp::DOCP, i)
4852
i = docp.time.steps
4953
end
5054
offset = (i-1) * docp.discretization._step_variables_block + docp.dims.NLP_x
51-
return @view xu[(offset + 1):(offset + docp.dims.NLP_u)]
55+
return @view xu[(offset+1):(offset+docp.dims.NLP_u)]
5256
end
5357

5458

@@ -62,7 +66,7 @@ Note that passing correct indices is up to the caller, no checks are made here.
6266
"""
6367
function get_stagevars_at_time_step(xu, docp::DOCP, i, j)
6468
offset = (i-1) * docp.discretization._step_variables_block + docp.dims.NLP_x + docp.dims.NLP_u + (j-1)*docp.dims.NLP_x
65-
return @view xu[(offset + 1):(offset + docp.dims.NLP_x)]
69+
return @view xu[(offset+1):(offset+docp.dims.NLP_x)]
6670
end
6771

6872

@@ -72,7 +76,7 @@ $(TYPEDSIGNATURES)
7276
Set optimization variables in the NLP variables (for initial guess)
7377
"""
7478
function set_optim_variable!(xu, v_init, docp)
75-
xu[(end - docp.dims.NLP_v + 1):end] .= v_init
79+
xu[(end-docp.dims.NLP_v+1):end] .= v_init
7680
end
7781

7882

@@ -86,7 +90,7 @@ function set_state_at_time_step!(xu, x_init, docp::DOCP, i)
8690
# initialize only actual state variables from OCP (not lagrange state)
8791
if !isnothing(x_init)
8892
offset = (i-1) * docp.discretization._step_variables_block
89-
xu[(offset + 1):(offset + docp.dims.OCP_x)] .= x_init
93+
xu[(offset+1):(offset+docp.dims.OCP_x)] .= x_init
9094
end
9195
end
9296

@@ -101,7 +105,7 @@ function set_control_at_time_step!(xu, u_init, docp::DOCP, i)
101105
if !isnothing(u_init)
102106
if i <= docp.time.steps || (docp.discretization._final_control && i <= docp.time.steps + 1)
103107
offset = (i-1) * docp.discretization._step_variables_block + docp.dims.NLP_x
104-
xu[(offset + 1):(offset + docp.dims.NLP_u)] .= u_init
108+
xu[(offset+1):(offset+docp.dims.NLP_u)] .= u_init
105109
end
106110
end
107111
end
@@ -122,9 +126,9 @@ $(TYPEDSIGNATURES)
122126
123127
Build sparsity pattern for Jacobian of constraints
124128
"""
125-
function DOCP_Jacobian_pattern(docp::DOCP{D}) where (D <: Discretization)
129+
function DOCP_Jacobian_pattern(docp::DOCP{D}) where (D<:Discretization)
126130
error("DOCP_Jacobian_pattern not implemented for discretization ", D,
127-
" Use option solve(...; adnlp_backend=:optimized)")
131+
" Use option solve(...; adnlp_backend=:optimized)")
128132
end
129133

130134

@@ -133,9 +137,9 @@ $(TYPEDSIGNATURES)
133137
134138
Build sparsity pattern for Hessian of Lagrangian
135139
"""
136-
function DOCP_Hessian_pattern(docp::DOCP{D}) where (D <: Discretization)
140+
function DOCP_Hessian_pattern(docp::DOCP{D}) where (D<:Discretization)
137141
error("DOCP_Hessian_pattern not implemented for discretization ", D,
138-
" Use option solve(...; adnlp_backend=:optimized)")
142+
" Use option solve(...; adnlp_backend=:optimized)")
139143
end
140144

141145

@@ -154,8 +158,8 @@ function add_nonzero_block!(M, i_start, i_end, j_start, j_end; sym=false)
154158
return
155159
end
156160
function add_nonzero_block!(M, i, j; sym=false)
157-
M[i,j] = true
158-
sym && (M[j,i] = true)
161+
M[i, j] = true
162+
sym && (M[j, i] = true)
159163
return
160164
end
161165
function add_nonzero_block!(Is, Js, i_start, i_end, j_start, j_end; sym=false)

src/disc/euler.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ struct Euler <: Discretization
2626

2727
# NLP variables size ([state, control]_1..N, final state, variable)
2828
dim_NLP_variables = dim_NLP_steps * step_variables_block + dim_NLP_x + dim_NLP_v
29-
29+
3030
# NLP constraints size ([dynamics, path]_1..N, final path, boundary, variable)
3131
dim_NLP_constraints = dim_NLP_steps * (state_stage_eqs_block + step_pathcons_block) + step_pathcons_block + dim_boundary_cons
3232

33-
if explicit
33+
if explicit
3434
info = "Euler (explicit), 1st order"
3535
else
3636
info = "Euler (implicit), 1st order"
@@ -54,12 +54,12 @@ function get_OCP_control_at_time_step(xu, docp::DOCP{Euler}, i)
5454
# final time case
5555
(i == docp.time.steps + 1) && (i = docp.time.steps)
5656
offset = (i-1) * docp.discretization._step_variables_block + docp.dims.NLP_x
57-
else
57+
else
5858
# initial time case
5959
(i == 1) && (i = 2)
6060
offset = (i-2) * docp.discretization._step_variables_block + docp.dims.NLP_x
6161
end
62-
return @view xu[(offset + 1):(offset + docp.dims.NLP_u)]
62+
return @view xu[(offset+1):(offset+docp.dims.NLP_u)]
6363
end
6464

6565

@@ -87,11 +87,11 @@ function setWorkArray(docp::DOCP{Euler}, xu, time_grid, v)
8787
u = get_OCP_control_at_time_step(xu, docp, index)
8888

8989
# OCP dynamics
90-
CTModels.dynamics(docp.ocp)((@view work[offset+1:offset+docp.dims.OCP_x]), t, x, u, v)
90+
CTModels.dynamics(docp.ocp)((@view work[(offset+1):(offset+docp.dims.OCP_x)]), t, x, u, v)
9191
# lagrange cost
9292
if docp.flags.lagrange
9393
work[offset+docp.dims.NLP_x] = CTModels.lagrange(docp.ocp)(t, x, u, v)
94-
end
94+
end
9595
end
9696
return work
9797
end
@@ -104,7 +104,7 @@ Set the constraints corresponding to the state equation
104104
Convention: 1 <= i <= dim_NLP_steps+1
105105
"""
106106
function setStepConstraints!(docp::DOCP{Euler}, c, xu, v, time_grid, i, work)
107-
107+
108108
# offset for previous steps
109109
offset = (i-1)*(docp.discretization._state_stage_eqs_block + docp.discretization._step_pathcons_block)
110110

@@ -121,20 +121,20 @@ function setStepConstraints!(docp::DOCP{Euler}, c, xu, v, time_grid, i, work)
121121
offset_dyn_i = (i-1)*docp.dims.NLP_x
122122

123123
# state equation: euler rule
124-
@views @. c[offset+1:offset+docp.dims.OCP_x] = xip1 - (xi + hi * work[offset_dyn_i+1:offset_dyn_i+docp.dims.OCP_x])
124+
@views @. c[(offset+1):(offset+docp.dims.OCP_x)] = xip1 - (xi + hi * work[(offset_dyn_i+1):(offset_dyn_i+docp.dims.OCP_x)])
125125
if docp.flags.lagrange
126126
c[offset+docp.dims.NLP_x] = get_lagrange_state_at_time_step(xu, docp, i+1) - (get_lagrange_state_at_time_step(xu, docp, i) + hi * work[offset_dyn_i+docp.dims.NLP_x])
127127
end
128128
offset += docp.dims.NLP_x
129129

130130
end
131-
131+
132132
# 2. path constraints
133133
if docp.discretization._step_pathcons_block > 0
134134
ui = get_OCP_control_at_time_step(xu, docp, i)
135-
CTModels.path_constraints_nl(docp.ocp)[2]((@view c[offset+1:offset+docp.dims.path_cons]), ti, xi, ui, v)
135+
CTModels.path_constraints_nl(docp.ocp)[2]((@view c[(offset+1):(offset+docp.dims.path_cons)]), ti, xi, ui, v)
136136
end
137-
137+
138138
end
139139

140140

@@ -213,7 +213,7 @@ function DOCP_Jacobian_pattern(docp::DOCP{Euler})
213213
uf_start = var_offset-docp.discretization._step_variables_block + docp.dims.NLP_x + 1
214214
uf_end = var_offset-docp.discretization._step_variables_block + docp.dims.NLP_x + docp.dims.NLP_u
215215
add_nonzero_block!(Is, Js, c_offset+1, c_offset+c_block, xf_start, xf_end)
216-
add_nonzero_block!(Is, Js, c_offset+1,c_offset+c_block, uf_start, uf_end)
216+
add_nonzero_block!(Is, Js, c_offset+1, c_offset+c_block, uf_start, uf_end)
217217
add_nonzero_block!(Is, Js, c_offset+1, c_offset+c_block, v_start, v_end)
218218

219219
# 3. boundary constraints (x0, xf, v)
@@ -258,7 +258,7 @@ function DOCP_Hessian_pattern(docp::DOCP{Euler})
258258
# -> grouped with term 3. for boundary conditions
259259
# 0.2 lagrange case (lf)
260260
# -> 2nd order term is zero
261-
261+
262262
# 1. main loop over steps
263263
# 1.0 v / v term
264264
add_nonzero_block!(Is, Js, v_start, v_end, v_start, v_end)
@@ -317,7 +317,7 @@ function DOCP_Hessian_pattern(docp::DOCP{Euler})
317317

318318
# 3.1 null initial condition for lagrangian cost state l0
319319
# -> 2nd order term is zero
320-
320+
321321
# build and return sparse matrix
322322
nnzj = length(Is)
323323
Vs = ones(Bool, nnzj)

0 commit comments

Comments
 (0)