11@data ClockVertex begin
2+ # A variable identified by its index in `fullvars`
23 Variable (Int)
4+ # An equation identified by its index in `equations(state)`
35 Equation (Int)
6+ # An initialization equation identified by its index in `initialization_equations(state.sys)`
47 InitEquation (Int)
8+ # A concrete, known clock
59 Clock (SciMLBase. AbstractClock)
10+ # An unnamed, unnknown clock identified by some UUID stored in `ShiftIndex`
611 InferredClock (UUID)
12+ # An arbitrary expression for which we want to preserve clocking information
13+ Expression (SymbolicT)
14+ # Compatibility for ModelingToolkit's `DiscreteSystem` semantics.
715 IntegerSequence
816end
917
@@ -21,6 +29,10 @@ struct ClockInference{S <: StateSelection.TransformationState}
2129 inference_graph:: HyperGraph{ClockVertex.Type}
2230 """ The set of variables with concrete domains."""
2331 inferred:: BitSet
32+ """ A mapping from every argument of every clock operator to the clock it is on. More \
33+ generally extensible to any expression for which it is deemed necessary to preserve \
34+ clock information."""
35+ expression_clocks:: Dict{SymbolicT, TimeDomain}
2436end
2537
2638function ClockInference (ts:: StateSelection.TransformationState )
@@ -73,7 +85,7 @@ function ClockInference(ts::StateSelection.TransformationState)
7385 add_edge! (inference_graph, (varvert, dvert))
7486 end
7587 ClockInference {typeof(ts)} (ts, eq_domain, init_eq_domain, var_domain, inference_graph,
76- inferred)
88+ inferred, Dict {SymbolicT, TimeDomain} () )
7789end
7890
7991struct NotInferredTimeDomain end
@@ -262,6 +274,7 @@ function (ivc::InferVariableClosure)(var::SymbolicT)
262274 nested_ivc (v)
263275 end
264276
277+ push! (arg_hyperedge, ClockVertex. Expression (arg))
265278 # NOTE: Ensure all branches here add `arg_hyperedge` to the inference graph. It
266279 # is the parent hyperedge for `nested_ivc`, so this closure is responsible for
267280 # adding it to the graph.
@@ -422,6 +435,7 @@ function infer_clocks!(ci::ClockInference)
422435 ClockVertex. Clock (_) => nothing
423436 ClockVertex. InferredClock (_) => nothing
424437 ClockVertex. IntegerSequence () => nothing
438+ ClockVertex. Expression (expr) => (ci. expression_clocks[expr] = clock)
425439 end
426440 end
427441 end
0 commit comments