Skip to content

Commit cd1f01e

Browse files
committed
Replace Expronicon with Moshi
1 parent 3a54d9e commit cd1f01e

8 files changed

+56
-60
lines changed

Project.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
2323
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
2424
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
2525
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
26-
Expronicon = "6b7a57c9-7cc1-4fdf-b7f5-e857abae3636"
2726
FindFirstFunctions = "64ca27bc-2ba2-4a57-88aa-44e436879224"
2827
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
2928
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
@@ -36,6 +35,7 @@ Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
3635
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
3736
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3837
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
38+
Moshi = "2e0e35c7-a2e4-4343-998d-7ef72827ed2d"
3939
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
4040
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
4141
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
@@ -105,7 +105,6 @@ DomainSets = "0.6, 0.7"
105105
DynamicQuantities = "^0.11.2, 0.12, 0.13, 1"
106106
EnumX = "1.0.4"
107107
ExprTools = "0.1.10"
108-
Expronicon = "0.8"
109108
FMI = "0.14"
110109
FindFirstFunctions = "1"
111110
ForwardDiff = "0.10.3"
@@ -124,6 +123,7 @@ LinearAlgebra = "1"
124123
Logging = "1"
125124
MLStyle = "0.4.17"
126125
ModelingToolkitStandardLibrary = "2.19"
126+
Moshi = "0.3"
127127
NaNMath = "0.3, 1"
128128
NonlinearSolve = "4.3"
129129
OffsetArrays = "1"
@@ -138,7 +138,7 @@ RecursiveArrayTools = "3.26"
138138
Reexport = "0.2, 1"
139139
RuntimeGeneratedFunctions = "0.5.9"
140140
SCCNonlinearSolve = "1.0.0"
141-
SciMLBase = "2.73"
141+
SciMLBase = "2.75"
142142
SciMLStructures = "1.0"
143143
Serialization = "1"
144144
Setfield = "0.7, 0.8, 1"

src/ModelingToolkit.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ using Compat
4545
using AbstractTrees
4646
using DiffEqBase, SciMLBase, ForwardDiff
4747
using SciMLBase: StandardODEProblem, StandardNonlinearProblem, handle_varmap, TimeDomain,
48-
PeriodicClock, Clock, SolverStepClock, Continuous, OverrideInit, NoInit
48+
PeriodicClock, Clock, SolverStepClock, ContinuousClock, OverrideInit,
49+
NoInit
4950
using Distributed
5051
import JuliaFormatter
5152
using MLStyle
53+
import Moshi
54+
using Moshi.Data: @data
5255
using NonlinearSolve
5356
import SCCNonlinearSolve
5457
using Reexport
@@ -290,7 +293,7 @@ export @variables, @parameters, @independent_variables, @constants, @brownian
290293
export @named, @nonamespace, @namespace, extend, compose, complete
291294
export debug_system
292295

293-
#export Continuous, Discrete, sampletime, input_timedomain, output_timedomain
296+
#export ContinuousClock, Discrete, sampletime, input_timedomain, output_timedomain
294297
#export has_discrete_domain, has_continuous_domain
295298
#export is_discrete_domain, is_continuous_domain, is_hybrid_domain
296299
export Sample, Hold, Shift, ShiftIndex, sampletime, SampleTime

src/clock.jl

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
module InferredClock
2-
3-
export InferredTimeDomain
4-
5-
using Expronicon.ADT: @adt, @match
6-
using SciMLBase: TimeDomain
7-
8-
@adt InferredTimeDomain begin
1+
@data InferredClock begin
92
Inferred
103
InferredDiscrete
114
end
125

13-
Base.Broadcast.broadcastable(x::InferredTimeDomain) = Ref(x)
6+
const InferredTimeDomain = InferredClock.Type
7+
using .InferredClock: Inferred, InferredDiscrete
148

15-
end
16-
17-
using .InferredClock
9+
Base.Broadcast.broadcastable(x::InferredTimeDomain) = Ref(x)
1810

1911
struct VariableTimeDomain end
2012
Symbolics.option_to_metadata_type(::Val{:timedomain}) = VariableTimeDomain
@@ -29,7 +21,7 @@ true if `x` contains only continuous-domain signals.
2921
See also [`has_continuous_domain`](@ref)
3022
"""
3123
function is_continuous_domain(x)
32-
issym(x) && return getmetadata(x, VariableTimeDomain, false) == Continuous()
24+
issym(x) && return getmetadata(x, VariableTimeDomain, false) == ContinuousClock()
3325
!has_discrete_domain(x) && has_continuous_domain(x)
3426
end
3527

@@ -50,16 +42,16 @@ has_time_domain(_, x) = has_time_domain(x)
5042
Determine if variable `x` has a time-domain attributed to it.
5143
"""
5244
function has_time_domain(x::Symbolic)
53-
# getmetadata(x, Continuous, nothing) !== nothing ||
45+
# getmetadata(x, ContinuousClock, nothing) !== nothing ||
5446
# getmetadata(x, Discrete, nothing) !== nothing
5547
getmetadata(x, VariableTimeDomain, nothing) !== nothing
5648
end
5749
has_time_domain(x::Num) = has_time_domain(value(x))
5850
has_time_domain(x) = false
5951

6052
for op in [Differential]
61-
@eval input_timedomain(::$op, arg = nothing) = Continuous()
62-
@eval output_timedomain(::$op, arg = nothing) = Continuous()
53+
@eval input_timedomain(::$op, arg = nothing) = ContinuousClock()
54+
@eval output_timedomain(::$op, arg = nothing) = ContinuousClock()
6355
end
6456

6557
"""
@@ -104,8 +96,8 @@ function is_discrete_domain(x)
10496
!has_discrete_domain(x) && has_continuous_domain(x)
10597
end
10698

107-
sampletime(c) = @match c begin
108-
PeriodicClock(dt, _...) => dt
99+
sampletime(c) = Moshi.Match.@match c begin
100+
PeriodicClock(dt) => dt
109101
_ => nothing
110102
end
111103

src/discretedomain.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,28 @@ Base.:-(k::ShiftIndex, i::Int) = k + (-i)
226226
"""
227227
input_timedomain(op::Operator)
228228
229-
Return the time-domain type (`Continuous` or `InferredDiscrete`) that `op` operates on.
229+
Return the time-domain type (`ContinuousClock()` or `InferredDiscrete()`) that `op` operates on.
230230
"""
231231
function input_timedomain(s::Shift, arg = nothing)
232232
if has_time_domain(arg)
233233
return get_time_domain(arg)
234234
end
235-
InferredDiscrete
235+
InferredDiscrete()
236236
end
237237

238238
"""
239239
output_timedomain(op::Operator)
240240
241-
Return the time-domain type (`Continuous` or `InferredDiscrete`) that `op` results in.
241+
Return the time-domain type (`ContinuousClock()` or `InferredDiscrete()`) that `op` results in.
242242
"""
243243
function output_timedomain(s::Shift, arg = nothing)
244244
if has_time_domain(t, arg)
245245
return get_time_domain(t, arg)
246246
end
247-
InferredDiscrete
247+
InferredDiscrete()
248248
end
249249

250-
input_timedomain(::Sample, _ = nothing) = Continuous()
250+
input_timedomain(::Sample, _ = nothing) = ContinuousClock()
251251
output_timedomain(s::Sample, _ = nothing) = s.clock
252252

253253
function input_timedomain(h::Hold, arg = nothing)
@@ -256,7 +256,7 @@ function input_timedomain(h::Hold, arg = nothing)
256256
end
257257
InferredDiscrete # the Hold accepts any discrete
258258
end
259-
output_timedomain(::Hold, _ = nothing) = Continuous()
259+
output_timedomain(::Hold, _ = nothing) = ContinuousClock()
260260

261261
sampletime(op::Sample, _ = nothing) = sampletime(op.clock)
262262
sampletime(op::ShiftIndex, _ = nothing) = sampletime(op.clock)

src/systems/abstractsystem.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ SymbolicUtils.promote_symtype(::Type{Initial}, T) = T
631631
SymbolicUtils.isbinop(::Initial) = false
632632
Base.nameof(::Initial) = :Initial
633633
Base.show(io::IO, x::Initial) = print(io, "Initial")
634-
input_timedomain(::Initial, _ = nothing) = Continuous()
635-
output_timedomain(::Initial, _ = nothing) = Continuous()
634+
input_timedomain(::Initial, _ = nothing) = ContinuousClock()
635+
output_timedomain(::Initial, _ = nothing) = ContinuousClock()
636636

637637
function (f::Initial)(x)
638638
# wrap output if wrapped input

src/systems/clock_inference.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ end
88
function ClockInference(ts::TransformationState)
99
@unpack structure = ts
1010
@unpack graph = structure
11-
eq_domain = TimeDomain[Continuous() for _ in 1:nsrcs(graph)]
12-
var_domain = TimeDomain[Continuous() for _ in 1:ndsts(graph)]
11+
eq_domain = TimeDomain[ContinuousClock() for _ in 1:nsrcs(graph)]
12+
var_domain = TimeDomain[ContinuousClock() for _ in 1:ndsts(graph)]
1313
inferred = BitSet()
1414
for (i, v) in enumerate(get_fullvars(ts))
1515
d = get_time_domain(ts, v)
@@ -151,7 +151,7 @@ function split_system(ci::ClockInference{S}) where {S}
151151
get!(clock_to_id, d) do
152152
cid = (cid_counter[] += 1)
153153
push!(id_to_clock, d)
154-
if d == Continuous()
154+
if d == ContinuousClock()
155155
continuous_id[] = cid
156156
end
157157
cid

src/systems/systemstructure.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ function structural_simplify!(state::TearingState, io = nothing; simplify = fals
662662
Dict(v => 0.0 for v in Iterators.flatten(inputs)))
663663
end
664664
ps = [sym isa CallWithMetadata ? sym :
665-
setmetadata(sym, VariableTimeDomain, get(time_domains, sym, Continuous()))
665+
setmetadata(
666+
sym, VariableTimeDomain, get(time_domains, sym, ContinuousClock()))
666667
for sym in get_ps(sys)]
667668
@set! sys.ps = ps
668669
else

test/clock.jl

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using ModelingToolkit, Test, Setfield, OrdinaryDiffEq, DiffEqCallbacks
2-
using ModelingToolkit: Continuous
2+
using ModelingToolkit: ContinuousClock
33
using ModelingToolkit: t_nounits as t, D_nounits as D
44

55
function infer_clocks(sys)
@@ -77,19 +77,19 @@ k = ShiftIndex(d)
7777

7878
d = Clock(dt)
7979
# Note that TearingState reorders the equations
80-
@test eqmap[1] == Continuous()
80+
@test eqmap[1] == ContinuousClock()
8181
@test eqmap[2] == d
8282
@test eqmap[3] == d
8383
@test eqmap[4] == d
84-
@test eqmap[5] == Continuous()
85-
@test eqmap[6] == Continuous()
84+
@test eqmap[5] == ContinuousClock()
85+
@test eqmap[6] == ContinuousClock()
8686

8787
@test varmap[yd] == d
8888
@test varmap[ud] == d
8989
@test varmap[r] == d
90-
@test varmap[x] == Continuous()
91-
@test varmap[y] == Continuous()
92-
@test varmap[u] == Continuous()
90+
@test varmap[x] == ContinuousClock()
91+
@test varmap[y] == ContinuousClock()
92+
@test varmap[u] == ContinuousClock()
9393

9494
@info "Testing shift normalization"
9595
dt = 0.1
@@ -192,10 +192,10 @@ eqs = [yd ~ Sample(dt)(y)
192192
@test varmap[ud1] == d
193193
@test varmap[yd2] == d2
194194
@test varmap[ud2] == d2
195-
@test varmap[r] == Continuous()
196-
@test varmap[x] == Continuous()
197-
@test varmap[y] == Continuous()
198-
@test varmap[u] == Continuous()
195+
@test varmap[r] == ContinuousClock()
196+
@test varmap[x] == ContinuousClock()
197+
@test varmap[y] == ContinuousClock()
198+
@test varmap[u] == ContinuousClock()
199199

200200
@info "test composed systems"
201201

@@ -241,14 +241,14 @@ eqs = [yd ~ Sample(dt)(y)
241241
ci, varmap = infer_clocks(cl)
242242

243243
@test varmap[f.x] == Clock(0.5)
244-
@test varmap[p.x] == Continuous()
245-
@test varmap[p.y] == Continuous()
244+
@test varmap[p.x] == ContinuousClock()
245+
@test varmap[p.y] == ContinuousClock()
246246
@test varmap[c.ud] == Clock(0.5)
247247
@test varmap[c.yd] == Clock(0.5)
248-
@test varmap[c.y] == Continuous()
248+
@test varmap[c.y] == ContinuousClock()
249249
@test varmap[f.y] == Clock(0.5)
250250
@test varmap[f.u] == Clock(0.5)
251-
@test varmap[p.u] == Continuous()
251+
@test varmap[p.u] == ContinuousClock()
252252
@test varmap[c.r] == Clock(0.5)
253253

254254
## Multiple clock rates
@@ -281,9 +281,9 @@ eqs = [yd ~ Sample(dt)(y)
281281
@test varmap[ud1] == d
282282
@test varmap[yd2] == d2
283283
@test varmap[ud2] == d2
284-
@test varmap[x] == Continuous()
285-
@test varmap[y] == Continuous()
286-
@test varmap[u] == Continuous()
284+
@test varmap[x] == ContinuousClock()
285+
@test varmap[y] == ContinuousClock()
286+
@test varmap[u] == ContinuousClock()
287287

288288
ss = structural_simplify(cl)
289289
ss_nosplit = structural_simplify(cl; split = false)
@@ -398,13 +398,13 @@ eqs = [yd ~ Sample(dt)(y)
398398

399399
ci, varmap = infer_clocks(expand_connections(_model))
400400

401-
@test varmap[_model.plant.input.u] == Continuous()
402-
@test varmap[_model.plant.u] == Continuous()
403-
@test varmap[_model.plant.x] == Continuous()
404-
@test varmap[_model.plant.y] == Continuous()
405-
@test varmap[_model.plant.output.u] == Continuous()
406-
@test varmap[_model.holder.output.u] == Continuous()
407-
@test varmap[_model.sampler.input.u] == Continuous()
401+
@test varmap[_model.plant.input.u] == ContinuousClock()
402+
@test varmap[_model.plant.u] == ContinuousClock()
403+
@test varmap[_model.plant.x] == ContinuousClock()
404+
@test varmap[_model.plant.y] == ContinuousClock()
405+
@test varmap[_model.plant.output.u] == ContinuousClock()
406+
@test varmap[_model.holder.output.u] == ContinuousClock()
407+
@test varmap[_model.sampler.input.u] == ContinuousClock()
408408
@test varmap[_model.controller.u] == d
409409
@test varmap[_model.holder.input.u] == d
410410
@test varmap[_model.controller.output.u] == d

0 commit comments

Comments
 (0)