Skip to content

Commit 5f64b56

Browse files
authored
Merge pull request #51 from control-toolbox/47-dev-examodels
dev-examodels
2 parents a3ccd37 + 1e55f38 commit 5f64b56

7 files changed

Lines changed: 1331 additions & 195 deletions

File tree

src/onepass.jl

Lines changed: 489 additions & 85 deletions
Large diffs are not rendered by default.

src/utils.jl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# utils
2+
# todo: check todo's in source
23

34
"""
45
$(TYPEDSIGNATURES)
@@ -63,6 +64,93 @@ end
6364
"""
6465
$(TYPEDSIGNATURES)
6566
67+
Substitute x[i] by y[i, j], whatever i, in e.
68+
69+
# Examples
70+
```@example
71+
julia> e = :(x0[1] * 2xf[3] - cos(xf[2]) * 2x0[2])
72+
:(x0[1] * (2 * xf[3]) - cos(xf[2]) * (2 * x0[2]))
73+
74+
julia> subs2(subs2(e, :x0, :x, 0), :xf, :x, :N)
75+
:(x[1, 0] * (2 * x[3, N]) - cos(x[2, N]) * (2 * x[2, 0]))
76+
77+
julia> e = :(x0 * 2xf[3] - cos(xf) * 2x0[2])
78+
:(x0 * (2 * xf[3]) - cos(xf) * (2 * x0[2]))
79+
80+
julia> subs2(subs2(e, :x0, :x, 0), :xf, :x, :N)
81+
:(x0 * (2 * x[3, N]) - cos(xf) * (2 * x[2, 0]))
82+
```
83+
"""
84+
function subs2(e, x, y, j)
85+
foo(x, y, j) = (h, args...) -> begin
86+
f = Expr(h, args...)
87+
@match f begin
88+
:($xx[$i]) && if (xx == x) end => :($y[$i, $j])
89+
_ => f
90+
end
91+
end
92+
expr_it(e, foo(x, y, j), x -> x)
93+
end
94+
95+
"""
96+
$(TYPEDSIGNATURES)
97+
98+
Substitute x[rg] by y[i, j], whatever rg, in e.
99+
100+
# Examples
101+
```@example
102+
julia> e = :(x0[1:2:d] * 2xf[1:3])
103+
:(x0[1:2:d] * (2 * xf[1:3]))
104+
105+
julia> subs3(e, :x0, :x, :i, 0)
106+
:(x[i, 0] * (2 * xf[1:3]))
107+
108+
julia> subs3(e, :xf, :x, 1, :N)
109+
:(x0[1:2:d] * (2 * x[1, N]))
110+
```
111+
"""
112+
function subs3(e, x, y, i, j)
113+
foo(x, y, i, j) = (h, args...) -> begin
114+
f = Expr(h, args...)
115+
@match f begin
116+
:($xx[$rg]) && if (xx == x) end => :($y[$i, $j])
117+
_ => f
118+
end
119+
end
120+
expr_it(e, foo(x, y, i, j), x -> x)
121+
end
122+
123+
"""
124+
$(TYPEDSIGNATURES)
125+
126+
Substitute x[rg] by y[i], whatever rg, in e.
127+
128+
# Examples
129+
```@example
130+
julia> e = :(v[1:2:d] * 2xf[1:3])
131+
:(v[1:2:d] * (2 * xf[1:3]))
132+
133+
julia> subs4(e, :v, :v, :i)
134+
:(v[i] * (2 * xf[1:3]))
135+
136+
julia> subs4(e, :xf, :xf, 1)
137+
:(v[1:2:d] * (2 * xf[1]))
138+
```
139+
"""
140+
function subs4(e, x, y, i) # todo: remove since unused (check)
141+
foo(x, y, i) = (h, args...) -> begin
142+
f = Expr(h, args...)
143+
@match f begin
144+
:($xx[$rg]) && if (xx == x) end => :($y[$i])
145+
_ => f
146+
end
147+
end
148+
expr_it(e, foo(x, y, i), x -> x)
149+
end
150+
151+
"""
152+
$(TYPEDSIGNATURES)
153+
66154
Replace calls in e of the form `(...x...)(t)` by `(...y...)`.
67155
68156
# Example

test/Project.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
34
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
45
CTModels = "34c4fa32-2049-4079-8329-de33c2a22e2d"
6+
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
7+
ExaModels = "1037b233-b668-4ce9-9b63-f9f681f55dd2"
8+
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
9+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
10+
MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6"
11+
MadNLPGPU = "d72a61cc-809d-412f-99be-fd81f4b8a598"
512
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
613

714
[compat]
815
Aqua = "0.8"
16+
BenchmarkTools = "1.6"
917
CTBase = "0.16"
1018
CTModels = "0.3"
19+
CUDA = "5.7"
20+
ExaModels = "0.8"
21+
Interpolations = "0.15"
22+
KernelAbstractions = "0.9"
23+
MadNLP = "0.8"
24+
MadNLPGPU = "0.7"
1125
Test = "1"

test/runtests.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
using Test
22
using Aqua
3-
import CTParser: CTParser, subs, replace_call, has, constraint_type, set_prefix, set_e_prefix, @def
3+
import CTParser: CTParser, subs, subs2, subs3, subs4, replace_call, has, constraint_type, parsing_backend!, prefix!, e_prefix!, @def
44
import CTBase: CTBase, ParsingError
55
import CTModels: CTModels, initial_time, final_time, time_name, variable_dimension, variable_components, variable_name, state_dimension, state_components, state_name, control_dimension, control_components, control_name, constraint, dynamics, mayer, lagrange, criterion, Model
6+
import ExaModels
7+
using MadNLP
8+
using MadNLPGPU
9+
using CUDA
10+
using KernelAbstractions
11+
using BenchmarkTools
12+
using Interpolations
613

7-
#
814
@testset verbose = true showtiming = true "CTParser tests" begin
9-
for name in (:aqua, :utils, :onepass)
10-
#for name in (:utils,)
15+
for name (:aqua, :utils, :onepass_fun, :onepass_exa)
16+
#for name (:aqua, :utils, :onepass_exa)
1117
@testset "$(name)" begin
1218
test_name = Symbol(:test_, name)
1319
include("$(test_name).jl")
1420
@eval $test_name()
1521
end
1622
end
17-
end
23+
end

0 commit comments

Comments
 (0)