Skip to content

Start using Moshi compatible syntax for singleton ADT variants #3353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ RecursiveArrayTools = "3.26"
Reexport = "0.2, 1"
RuntimeGeneratedFunctions = "0.5.9"
SCCNonlinearSolve = "1.0.0"
SciMLBase = "2.71.1"
SciMLBase = "2.72.1"
SciMLStructures = "1.0"
Serialization = "1"
Setfield = "0.7, 0.8, 1"
Expand Down
6 changes: 3 additions & 3 deletions src/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ true if `x` contains only continuous-domain signals.
See also [`has_continuous_domain`](@ref)
"""
function is_continuous_domain(x)
issym(x) && return getmetadata(x, VariableTimeDomain, false) == Continuous
issym(x) && return getmetadata(x, VariableTimeDomain, false) == Continuous()
!has_discrete_domain(x) && has_continuous_domain(x)
end

Expand Down Expand Up @@ -58,8 +58,8 @@ has_time_domain(x::Num) = has_time_domain(value(x))
has_time_domain(x) = false

for op in [Differential]
@eval input_timedomain(::$op, arg = nothing) = Continuous
@eval output_timedomain(::$op, arg = nothing) = Continuous
@eval input_timedomain(::$op, arg = nothing) = Continuous()
@eval output_timedomain(::$op, arg = nothing) = Continuous()
end

"""
Expand Down
4 changes: 2 additions & 2 deletions src/discretedomain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function output_timedomain(s::Shift, arg = nothing)
InferredDiscrete
end

input_timedomain(::Sample, _ = nothing) = Continuous
input_timedomain(::Sample, _ = nothing) = Continuous()
output_timedomain(s::Sample, _ = nothing) = s.clock

function input_timedomain(h::Hold, arg = nothing)
Expand All @@ -256,7 +256,7 @@ function input_timedomain(h::Hold, arg = nothing)
end
InferredDiscrete # the Hold accepts any discrete
end
output_timedomain(::Hold, _ = nothing) = Continuous
output_timedomain(::Hold, _ = nothing) = Continuous()

sampletime(op::Sample, _ = nothing) = sampletime(op.clock)
sampletime(op::ShiftIndex, _ = nothing) = sampletime(op.clock)
Expand Down
6 changes: 3 additions & 3 deletions src/systems/clock_inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ end
function ClockInference(ts::TransformationState)
@unpack structure = ts
@unpack graph = structure
eq_domain = TimeDomain[Continuous for _ in 1:nsrcs(graph)]
var_domain = TimeDomain[Continuous for _ in 1:ndsts(graph)]
eq_domain = TimeDomain[Continuous() for _ in 1:nsrcs(graph)]
var_domain = TimeDomain[Continuous() for _ in 1:ndsts(graph)]
inferred = BitSet()
for (i, v) in enumerate(get_fullvars(ts))
d = get_time_domain(ts, v)
Expand Down Expand Up @@ -151,7 +151,7 @@ function split_system(ci::ClockInference{S}) where {S}
get!(clock_to_id, d) do
cid = (cid_counter[] += 1)
push!(id_to_clock, d)
if d == Continuous
if d == Continuous()
continuous_id[] = cid
end
cid
Expand Down
2 changes: 1 addition & 1 deletion src/systems/systemstructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ function structural_simplify!(state::TearingState, io = nothing; simplify = fals
Dict(v => 0.0 for v in Iterators.flatten(inputs)))
end
ps = [sym isa CallWithMetadata ? sym :
setmetadata(sym, VariableTimeDomain, get(time_domains, sym, Continuous))
setmetadata(sym, VariableTimeDomain, get(time_domains, sym, Continuous()))
for sym in get_ps(sys)]
@set! sys.ps = ps
else
Expand Down
30 changes: 15 additions & 15 deletions test/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ k = ShiftIndex(d)

d = Clock(dt)
# Note that TearingState reorders the equations
@test eqmap[1] == Continuous
@test eqmap[1] == Continuous()
@test eqmap[2] == d
@test eqmap[3] == d
@test eqmap[4] == d
@test eqmap[5] == Continuous
@test eqmap[6] == Continuous
@test eqmap[5] == Continuous()
@test eqmap[6] == Continuous()

@test varmap[yd] == d
@test varmap[ud] == d
@test varmap[r] == d
@test varmap[x] == Continuous
@test varmap[y] == Continuous
@test varmap[u] == Continuous
@test varmap[x] == Continuous()
@test varmap[y] == Continuous()
@test varmap[u] == Continuous()

@info "Testing shift normalization"
dt = 0.1
Expand Down Expand Up @@ -192,10 +192,10 @@ eqs = [yd ~ Sample(dt)(y)
@test varmap[ud1] == d
@test varmap[yd2] == d2
@test varmap[ud2] == d2
@test varmap[r] == Continuous
@test varmap[x] == Continuous
@test varmap[y] == Continuous
@test varmap[u] == Continuous
@test varmap[r] == Continuous()
@test varmap[x] == Continuous()
@test varmap[y] == Continuous()
@test varmap[u] == Continuous()

@info "test composed systems"

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

@test varmap[f.x] == Clock(0.5)
@test varmap[p.x] == Continuous
@test varmap[p.y] == Continuous
@test varmap[p.x] == Continuous()
@test varmap[p.y] == Continuous()
@test varmap[c.ud] == Clock(0.5)
@test varmap[c.yd] == Clock(0.5)
@test varmap[c.y] == Continuous
@test varmap[c.y] == Continuous()
@test varmap[f.y] == Clock(0.5)
@test varmap[f.u] == Clock(0.5)
@test varmap[p.u] == Continuous
@test varmap[p.u] == Continuous()
@test varmap[c.r] == Clock(0.5)

## Multiple clock rates
Expand Down Expand Up @@ -474,7 +474,7 @@ eqs = [yd ~ Sample(dt)(y)

## Test continuous clock

c = ModelingToolkit.SolverStepClock
c = ModelingToolkit.SolverStepClock()
k = ShiftIndex(c)

@mtkmodel CounterSys begin
Expand Down
Loading