Skip to content

Commit 00d7ae0

Browse files
refactor: replace is_synchronous_operator with is_timevarying_operator
1 parent bea6a41 commit 00d7ae0

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

src/discretedomain.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ is_transparent_operator(::Type) = false
1313
"""
1414
$(TYPEDSIGNATURES)
1515
16-
Trait to be implemented for operators which determines whether they are synchronous operators.
17-
Synchronous operators must implement `input_timedomain` and `output_timedomain`.
16+
Trait to be implemented for operators which determines whether the operator is applied to
17+
a time-varying quantity and results in a time-varying quantity. For example, `Initial` and
18+
`Pre` are not time-varying since while they are applied to variables, the application
19+
results in a non-discrete-time parameter. `Differential`, `Shift`, `Sample` and `Hold` are
20+
all time-varying operators. All time-varying operators must implement `input_timedomain` and
21+
`output_timedomain`.
1822
"""
19-
is_synchronous_operator(x) = is_synchronous_operator(typeof(x))
20-
is_synchronous_operator(::Type) = false
23+
is_timevarying_operator(x) = is_timevarying_operator(typeof(x))
24+
is_timevarying_operator(::Type{<:Symbolics.Operator}) = true
25+
is_timevarying_operator(::Type) = false
2126

2227
"""
2328
function SampleTime()
@@ -61,7 +66,6 @@ struct Shift <: Operator
6166
end
6267
Shift(steps::Int) = new(nothing, steps)
6368
normalize_to_differential(s::Shift) = Differential(s.t)^s.steps
64-
is_synchronous_operator(::Type{Shift}) = true
6569
Base.nameof(::Shift) = :Shift
6670
SymbolicUtils.isbinop(::Shift) = false
6771

@@ -148,7 +152,6 @@ struct Sample <: Operator
148152
Sample(clock::Union{TimeDomain, InferredTimeDomain} = InferredDiscrete()) = new(clock)
149153
end
150154

151-
is_synchronous_operator(::Type{Sample}) = true
152155
is_transparent_operator(::Type{Sample}) = true
153156

154157
function Sample(arg::Real)
@@ -204,7 +207,6 @@ struct Hold <: Operator
204207
end
205208

206209
is_transparent_operator(::Type{Hold}) = true
207-
is_synchronous_operator(::Type{Hold}) = true
208210

209211
(D::Hold)(x) = Term{symtype(x)}(D, Any[x])
210212
(D::Hold)(x::Num) = Num(D(value(x)))

src/systems/abstractsystem.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,12 @@ The `Initial` operator. Used by initialization to store constant constraints on
486486
of a system. See the documentation section on initialization for more information.
487487
"""
488488
struct Initial <: Symbolics.Operator end
489+
is_timevarying_operator(::Type{Initial}) = false
489490
Initial(x) = Initial()(x)
490491
SymbolicUtils.promote_symtype(::Type{Initial}, T) = T
491492
SymbolicUtils.isbinop(::Initial) = false
492493
Base.nameof(::Initial) = :Initial
493494
Base.show(io::IO, x::Initial) = print(io, "Initial")
494-
input_timedomain(::Initial, _ = nothing) = ContinuousClock()
495-
output_timedomain(::Initial, _ = nothing) = ContinuousClock()
496495

497496
function (f::Initial)(x)
498497
# wrap output if wrapped input

src/systems/callbacks.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,11 @@ before the callback is triggered.
143143
"""
144144
struct Pre <: Symbolics.Operator end
145145
Pre(x) = Pre()(x)
146+
is_timevarying_operator(::Type{Pre}) = false
146147
SymbolicUtils.promote_symtype(::Type{Pre}, T) = T
147148
SymbolicUtils.isbinop(::Pre) = false
148149
Base.nameof(::Pre) = :Pre
149150
Base.show(io::IO, x::Pre) = print(io, "Pre")
150-
input_timedomain(::Pre, _ = nothing) = ContinuousClock()
151-
output_timedomain(::Pre, _ = nothing) = ContinuousClock()
152151
unPre(x::Num) = unPre(unwrap(x))
153152
unPre(x::Symbolics.Arr) = unPre(unwrap(x))
154153
unPre(x::Symbolic) = (iscall(x) && operation(x) isa Pre) ? only(arguments(x)) : x

src/systems/clock_inference.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ function infer_clocks!(ci::ClockInference)
142142
# now we only care about synchronous operators
143143
iscall(var) || continue
144144
op = operation(var)
145-
if (!is_synchronous_operator(op)) && !(op isa Differential)
146-
continue
147-
end
145+
is_timevarying_operator(op) || continue
148146

149147
# arguments and corresponding time domains
150148
args = arguments(var)

0 commit comments

Comments
 (0)