Skip to content

Commit dd98e6b

Browse files
Merge pull request #3565 from AayushSabharwal/as/remove-timevaryingasfunc
refactor: remove `time_varying_as_func`
2 parents 443d3e9 + 0755daa commit dd98e6b

File tree

5 files changed

+6
-43
lines changed

5 files changed

+6
-43
lines changed

src/inputoutput.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function generate_control_function(sys::AbstractODESystem, inputs = unbound_inpu
218218
inputs = setdiff(inputs, disturbance_inputs)
219219
# ps = [ps; disturbance_inputs]
220220
end
221-
inputs = map(x -> time_varying_as_func(value(x), sys), inputs)
221+
inputs = map(value, inputs)
222222
disturbance_inputs = unwrap.(disturbance_inputs)
223223

224224
eqs = [eq for eq in full_equations(sys)]

src/systems/abstractsystem.jl

-14
Original file line numberDiff line numberDiff line change
@@ -1764,20 +1764,6 @@ function isaffine(sys::AbstractSystem)
17641764
all(isaffine(r, unknowns(sys)) for r in rhs)
17651765
end
17661766

1767-
function time_varying_as_func(x, sys::AbstractTimeDependentSystem)
1768-
# if something is not x(t) (the current unknown)
1769-
# but is `x(t-1)` or something like that, pass in `x` as a callable function rather
1770-
# than pass in a value in place of x(t).
1771-
#
1772-
# This is done by just making `x` the argument of the function.
1773-
if iscall(x) &&
1774-
issym(operation(x)) &&
1775-
!(length(arguments(x)) == 1 && isequal(arguments(x)[1], get_iv(sys)))
1776-
return operation(x)
1777-
end
1778-
return x
1779-
end
1780-
17811767
"""
17821768
$(SIGNATURES)
17831769

src/systems/callbacks.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ Notes
598598
"""
599599
function compile_condition(cb::SymbolicDiscreteCallback, sys, dvs, ps;
600600
expression = Val{true}, eval_expression = false, eval_module = @__MODULE__, kwargs...)
601-
u = map(x -> time_varying_as_func(value(x), sys), dvs)
602-
p = map.(x -> time_varying_as_func(value(x), sys), reorder_parameters(sys, ps))
601+
u = map(value, dvs)
602+
p = map.(value, reorder_parameters(sys, ps))
603603
t = get_iv(sys)
604604
condit = condition(cb)
605605
cs = collect_constants(condit)
@@ -685,8 +685,8 @@ function compile_affect(eqs::Vector{Equation}, cb, sys, dvs, ps; outputidxs = no
685685
_ps = ps
686686
ps = reorder_parameters(sys, ps)
687687
if checkvars
688-
u = map(x -> time_varying_as_func(value(x), sys), dvs)
689-
p = map.(x -> time_varying_as_func(value(x), sys), ps)
688+
u = map(value, dvs)
689+
p = map.(value, ps)
690690
else
691691
u = dvs
692692
p = ps

src/systems/codegen_utils.jl

-11
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,6 @@ function build_function_wrapper(sys::AbstractSystem, expr, args...; p_start = 2,
179179

180180
args = ntuple(Val(length(args))) do i
181181
arg = args[i]
182-
# for time-dependent systems, all arguments are passed through `time_varying_as_func`
183-
# TODO: This is legacy behavior and a candidate for removal in v10 since we have callable
184-
# parameters now.
185-
if is_time_dependent(sys)
186-
arg = if symbolic_type(arg) == NotSymbolic()
187-
arg isa AbstractArray ?
188-
map(x -> time_varying_as_func(unwrap(x), sys), arg) : arg
189-
else
190-
time_varying_as_func(unwrap(arg), sys)
191-
end
192-
end
193182
# Make sure to use the proper names for arguments
194183
if symbolic_type(arg) == NotSymbolic() && arg isa AbstractArray
195184
DestructuredArgs(arg, generated_argument_name(i); create_bindings)

test/odesystem.jl

+1-13
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,7 @@ du = zeros(3)
136136
tgrad_iip(du, u, p, t)
137137
@test du == [0.0, -u[2], 0.0]
138138

139-
@parameters σ′(t - 1)
140-
eqs = [D(x) ~ σ′ * (y - x),
141-
D(y) ~ x *- z) - y,
142-
D(z) ~ x * y - β * z * κ]
143-
@named de = ODESystem(eqs, t)
144-
test_diffeq_inference("global iv-varying", de, t, (x, y, z), (σ′, ρ, β))
145-
146-
f = generate_function(de, [x, y, z], [σ′, ρ, β], expression = Val{false})[2]
147-
du = [0.0, 0.0, 0.0]
148-
f(du, [1.0, 2.0, 3.0], [x -> x + 7, 2, 3], 5.0)
149-
@test du [11, -3, -7]
150-
151-
@parameters σ(..)
139+
@parameters::Function)(..)
152140
eqs = [D(x) ~ σ(t - 1) * (y - x),
153141
D(y) ~ x *- z) - y,
154142
D(z) ~ x * y - β * z * κ]

0 commit comments

Comments
 (0)