Skip to content

Commit 81d8c72

Browse files
Merge pull request #3607 from AayushSabharwal/as/fix-docs
docs: fix `generate_control_function` docs
2 parents 866f820 + bec6305 commit 81d8c72

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

docs/src/basics/InputOutput.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Now we can test the generated function `f` with random input and state values
7070
p = [1]
7171
x = [rand()]
7272
u = [rand()]
73-
@test f[1](x, u, p, 1) ≈ -p[] * (x + u) # Test that the function computes what we expect D(x) = -k*(x + u)
73+
@test f(x, u, p, 1) ≈ -p[] * (x + u) # Test that the function computes what we expect D(x) = -k*(x + u)
7474
```
7575

7676
## Generating an output function, ``g``

docs/src/tutorials/disturbance_modeling.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ disturbance_inputs = [ssys.d1, ssys.d2]
184184
P = ssys.system_model
185185
outputs = [P.inertia1.phi, P.inertia2.phi, P.inertia1.w, P.inertia2.w]
186186
187-
(f_oop, f_ip), x_sym, p_sym, io_sys = ModelingToolkit.generate_control_function(
187+
f, x_sym, p_sym, io_sys = ModelingToolkit.generate_control_function(
188188
model_with_disturbance, inputs, disturbance_inputs; disturbance_argument = true)
189189
190190
g = ModelingToolkit.build_explicit_observed_function(
@@ -195,12 +195,12 @@ x0, _ = ModelingToolkit.get_u0_p(io_sys, op, op)
195195
p = MTKParameters(io_sys, op)
196196
u = zeros(1) # Control input
197197
w = zeros(length(disturbance_inputs)) # Disturbance input
198-
@test f_oop(x0, u, p, t, w) == zeros(5)
198+
@test f(x0, u, p, t, w) == zeros(5)
199199
@test g(x0, u, p, 0.0) == [0, 0, 0, 0]
200200
201201
# Non-zero disturbance inputs should result in non-zero state derivatives. We call `sort` since we do not generally know the order of the state variables
202202
w = [1.0, 2.0]
203-
@test sort(f_oop(x0, u, p, t, w)) == [0, 0, 0, 1, 2]
203+
@test sort(f(x0, u, p, t, w)) == [0, 0, 0, 1, 2]
204204
```
205205

206206
## Input signal library

src/inputoutput.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,17 @@ has_var(ex, x) = x ∈ Set(get_variables(ex))
160160
# Build control function
161161

162162
"""
163-
(f_oop, f_ip), x_sym, p_sym, io_sys = generate_control_function(
163+
f, x_sym, p_sym, io_sys = generate_control_function(
164164
sys::AbstractODESystem,
165165
inputs = unbound_inputs(sys),
166166
disturbance_inputs = nothing;
167167
implicit_dae = false,
168168
simplify = false,
169169
)
170170
171-
For a system `sys` with inputs (as determined by [`unbound_inputs`](@ref) or user specified), generate a function with additional input argument `in`
171+
For a system `sys` with inputs (as determined by [`unbound_inputs`](@ref) or user specified), generate a function with additional input argument `u`
172172
173+
The returned function `f` can be called in the out-of-place or in-place form:
173174
```
174175
f_oop : (x,u,p,t) -> rhs
175176
f_ip : (xout,x,u,p,t) -> nothing
@@ -190,7 +191,7 @@ f, x_sym, ps = generate_control_function(sys, expression=Val{false}, simplify=fa
190191
p = varmap_to_vars(defaults(sys), ps)
191192
x = varmap_to_vars(defaults(sys), x_sym)
192193
t = 0
193-
f[1](x, inputs, p, t)
194+
f(x, inputs, p, t)
194195
```
195196
"""
196197
function generate_control_function(sys::AbstractODESystem, inputs = unbound_inputs(sys),

src/systems/optimal_control_interface.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function SciMLBase.ODEInputFunction{iip, specialize}(sys::ODESystem,
5050
initialization_data = nothing,
5151
cse = true,
5252
kwargs...) where {iip, specialize}
53-
(f), _, _ = generate_control_function(
53+
f, _, _ = generate_control_function(
5454
sys, inputs, disturbance_inputs; eval_module, cse, kwargs...)
5555

5656
if tgrad

0 commit comments

Comments
 (0)