@@ -9,6 +9,8 @@ struct Schedule{V <: BipartiteGraphs.Matching}
9
9
dummy_sub:: Dict{Any, Any}
10
10
end
11
11
12
+ const MetadataT = Base. ImmutableDict{DataType, Any}
13
+
12
14
struct System <: AbstractSystem
13
15
tag:: UInt
14
16
eqs:: Vector{Equation}
@@ -38,7 +40,7 @@ struct System <: AbstractSystem
38
40
discrete_events:: Vector{SymbolicDiscreteCallback}
39
41
connector_type:: Any
40
42
assertions:: Dict{BasicSymbolic, String}
41
- metadata:: Any
43
+ metadata:: MetadataT
42
44
gui_metadata:: Any # ?
43
45
is_dde:: Bool
44
46
tstops:: Vector{Any}
@@ -60,7 +62,7 @@ struct System <: AbstractSystem
60
62
brownians, iv, observed, parameter_dependencies, var_to_name, name, description,
61
63
defaults, guesses, systems, initialization_eqs, continuous_events, discrete_events,
62
64
connector_type, assertions = Dict {BasicSymbolic, String} (),
63
- metadata = nothing , gui_metadata = nothing ,
65
+ metadata = MetadataT () , gui_metadata = nothing ,
64
66
is_dde = false , tstops = [], tearing_state = nothing , namespacing = true ,
65
67
complete = false , index_cache = nothing , ignored_connections = nothing ,
66
68
preface = nothing , parent = nothing , initializesystem = nothing ,
@@ -119,8 +121,9 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
119
121
guesses = Dict (), systems = System[], initialization_eqs = Equation[],
120
122
continuous_events = SymbolicContinuousCallback[], discrete_events = SymbolicDiscreteCallback[],
121
123
connector_type = nothing , assertions = Dict {BasicSymbolic, String} (),
122
- metadata = nothing , gui_metadata = nothing , is_dde = nothing , tstops = [],
123
- tearing_state = nothing , ignored_connections = nothing , parent = nothing ,
124
+ metadata = MetadataT (), gui_metadata = nothing ,
125
+ is_dde = nothing , tstops = [], tearing_state = nothing ,
126
+ ignored_connections = nothing , parent = nothing ,
124
127
description = " " , name = nothing , discover_from_metadata = true ,
125
128
initializesystem = nothing , is_initializesystem = false , preface = [],
126
129
checks = true )
@@ -185,6 +188,17 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
185
188
186
189
assertions = Dict {BasicSymbolic, String} (unwrap (k) => v for (k, v) in assertions)
187
190
191
+ if isempty (metadata)
192
+ metadata = MetadataT ()
193
+ elseif metadata isa MetadataT
194
+ metadata = metadata
195
+ else
196
+ meta = MetadataT ()
197
+ for kvp in metadata
198
+ meta = Base. ImmutableDict (meta, kvp)
199
+ end
200
+ metadata = meta
201
+ end
188
202
System (Threads. atomic_add! (SYSTEM_COUNT, UInt (1 )), eqs, noise_eqs, jumps, constraints,
189
203
costs, consolidate, dvs, ps, brownians, iv, observed, parameter_dependencies,
190
204
var_to_name, name, description, defaults, guesses, systems, initialization_eqs,
@@ -621,6 +635,17 @@ function Base.hash(sys::System, h::UInt)
621
635
return h
622
636
end
623
637
638
+ function SymbolicUtils. getmetadata (sys:: AbstractSystem , k:: DataType , default)
639
+ meta = get_metadata (sys)
640
+ return get (meta, k, default)
641
+ end
642
+
643
+ function SymbolicUtils. setmetadata (sys:: AbstractSystem , k:: DataType , v)
644
+ meta = get_metadata (sys)
645
+ meta = Base. ImmutableDict (meta, k => v):: MetadataT
646
+ @set sys. metadata = meta
647
+ end
648
+
624
649
"""
625
650
$(TYPEDSIGNATURES)
626
651
"""
0 commit comments