Skip to content

Commit 5cda1f0

Browse files
committed
Add tag in all hierarchical models
1 parent 823a413 commit 5cda1f0

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ macro named(expr)
917917
var = gensym(name)
918918
ex = quote
919919
$var = $(_named(name, call))
920-
$name = map(i->$rename($var, Symbol($(Meta.quot(name)), :_, i)), $idxs)
920+
$name = map(i -> $rename($var, Symbol($(Meta.quot(name)), :_, i)), $idxs)
921921
end
922922
esc(ex)
923923
else

src/systems/diffeqs/sdesystem.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ noiseeqs = [0.1*x,
2727
```
2828
"""
2929
struct SDESystem <: AbstractODESystem
30+
"""
31+
tag: a tag for the system. If two system have the same tag, then they are
32+
structurally identical.
33+
"""
34+
tag::UInt
3035
"""The expressions defining the drift term."""
3136
eqs::Vector{Equation}
3237
"""The expressions defining the diffusion term."""
@@ -105,7 +110,8 @@ struct SDESystem <: AbstractODESystem
105110
"""
106111
complete::Bool
107112

108-
function SDESystem(deqs, neqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad, jac,
113+
function SDESystem(tag, deqs, neqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad,
114+
jac,
109115
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
110116
cevents, devents, metadata = nothing, complete = false;
111117
checks::Union{Bool, Int} = true)
@@ -118,7 +124,8 @@ struct SDESystem <: AbstractODESystem
118124
if checks == true || (checks & CheckUnits) > 0
119125
all_dimensionless([dvs; ps; iv]) || check_units(deqs, neqs)
120126
end
121-
new(deqs, neqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad, jac, ctrl_jac,
127+
new(tag, deqs, neqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad, jac,
128+
ctrl_jac,
122129
Wfact, Wfact_t, name, systems, defaults, connector_type, cevents, devents,
123130
metadata, complete)
124131
end
@@ -169,7 +176,8 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs, iv, dvs, ps;
169176
cont_callbacks = SymbolicContinuousCallbacks(continuous_events)
170177
disc_callbacks = SymbolicDiscreteCallbacks(discrete_events)
171178

172-
SDESystem(deqs, neqs, iv′, dvs′, ps′, var_to_name, ctrl′, observed, tgrad, jac,
179+
SDESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
180+
deqs, neqs, iv′, dvs′, ps′, var_to_name, ctrl′, observed, tgrad, jac,
173181
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
174182
cont_callbacks, disc_callbacks, metadata; checks = checks)
175183
end

src/systems/discrete_system/discrete_system.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ eqs = [D(x) ~ σ*(y-x),
2424
```
2525
"""
2626
struct DiscreteSystem <: AbstractTimeDependentSystem
27+
"""
28+
tag: a tag for the system. If two system have the same tag, then they are
29+
structurally identical.
30+
"""
31+
tag::UInt
2732
"""The differential equations defining the discrete system."""
2833
eqs::Vector{Equation}
2934
"""Independent variable."""
@@ -76,7 +81,8 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
7681
"""
7782
complete::Bool
7883

79-
function DiscreteSystem(discreteEqs, iv, dvs, ps, var_to_name, ctrls, observed, name,
84+
function DiscreteSystem(tag, discreteEqs, iv, dvs, ps, var_to_name, ctrls, observed,
85+
name,
8086
systems, defaults, preface, connector_type,
8187
metadata = nothing,
8288
tearing_state = nothing, substitutions = nothing,
@@ -88,7 +94,8 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
8894
if checks == true || (checks & CheckUnits) > 0
8995
all_dimensionless([dvs; ps; iv; ctrls]) || check_units(discreteEqs)
9096
end
91-
new(discreteEqs, iv, dvs, ps, var_to_name, ctrls, observed, name, systems, defaults,
97+
new(tag, discreteEqs, iv, dvs, ps, var_to_name, ctrls, observed, name, systems,
98+
defaults,
9299
preface, connector_type, metadata, tearing_state, substitutions, complete)
93100
end
94101
end
@@ -134,7 +141,8 @@ function DiscreteSystem(eqs::AbstractVector{<:Equation}, iv, dvs, ps;
134141
if length(unique(sysnames)) != length(sysnames)
135142
throw(ArgumentError("System names must be unique."))
136143
end
137-
DiscreteSystem(eqs, iv′, dvs′, ps′, var_to_name, ctrl′, observed, name, systems,
144+
DiscreteSystem(hreads.atomic_add!(SYSTEM_COUNT, UInt(1)),
145+
eqs, iv′, dvs′, ps′, var_to_name, ctrl′, observed, name, systems,
138146
defaults, preface, connector_type, metadata, kwargs...)
139147
end
140148

src/systems/jumps/jumpsystem.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ j₃ = MassActionJump(2*β+γ, [R => 1], [S => 1, R => -1])
4848
```
4949
"""
5050
struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
51+
"""
52+
tag: a tag for the system. If two system have the same tag, then they are
53+
structurally identical.
54+
"""
55+
tag::UInt
5156
"""
5257
The jumps of the system. Allowable types are `ConstantRateJump`,
5358
`VariableRateJump`, `MassActionJump`.
@@ -92,7 +97,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
9297
"""
9398
complete::Bool
9499

95-
function JumpSystem{U}(ap::U, iv, states, ps, var_to_name, observed, name, systems,
100+
function JumpSystem{U}(tag, ap::U, iv, states, ps, var_to_name, observed, name, systems,
96101
defaults, connector_type, devents,
97102
metadata = nothing, complete = false;
98103
checks::Union{Bool, Int} = true) where {U <: ArrayPartition}
@@ -103,7 +108,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
103108
if checks == true || (checks & CheckUnits) > 0
104109
all_dimensionless([states; ps; iv]) || check_units(ap, iv)
105110
end
106-
new{U}(ap, iv, states, ps, var_to_name, observed, name, systems, defaults,
111+
new{U}(tag, ap, iv, states, ps, var_to_name, observed, name, systems, defaults,
107112
connector_type, devents, metadata, complete)
108113
end
109114
end
@@ -156,7 +161,8 @@ function JumpSystem(eqs, iv, states, ps;
156161
error("JumpSystems currently only support discrete events.")
157162
disc_callbacks = SymbolicDiscreteCallbacks(discrete_events)
158163

159-
JumpSystem{typeof(ap)}(ap, value(iv), states, ps, var_to_name, observed, name, systems,
164+
JumpSystem{typeof(ap)}(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
165+
ap, value(iv), states, ps, var_to_name, observed, name, systems,
160166
defaults, connector_type, disc_callbacks, metadata,
161167
checks = checks)
162168
end

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ eqs = [0 ~ σ*(y-x),
1919
```
2020
"""
2121
struct NonlinearSystem <: AbstractTimeIndependentSystem
22+
"""
23+
tag: a tag for the system. If two system have the same tag, then they are
24+
structurally identical.
25+
"""
26+
tag::UInt
2227
"""Vector of equations defining the system."""
2328
eqs::Vector{Equation}
2429
"""Unknown variables."""
@@ -67,14 +72,15 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
6772
"""
6873
complete::Bool
6974

70-
function NonlinearSystem(eqs, states, ps, var_to_name, observed, jac, name, systems,
75+
function NonlinearSystem(tag, eqs, states, ps, var_to_name, observed, jac, name,
76+
systems,
7177
defaults, connector_type, metadata = nothing,
7278
tearing_state = nothing, substitutions = nothing,
7379
complete = false; checks::Union{Bool, Int} = true)
7480
if checks == true || (checks & CheckUnits) > 0
7581
all_dimensionless([states; ps]) || check_units(eqs)
7682
end
77-
new(eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
83+
new(tag, eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
7884
connector_type, metadata, tearing_state, substitutions, complete)
7985
end
8086
end
@@ -124,7 +130,8 @@ function NonlinearSystem(eqs, states, ps;
124130
process_variables!(var_to_name, defaults, ps)
125131
isempty(observed) || collect_var_to_name!(var_to_name, (eq.lhs for eq in observed))
126132

127-
NonlinearSystem(eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
133+
NonlinearSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
134+
eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
128135
connector_type, metadata, checks = checks)
129136
end
130137

src/systems/optimization/optimizationsystem.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ op = a*(y-x) + x*(b-z)-y + x*y - c*z
1717
```
1818
"""
1919
struct OptimizationSystem <: AbstractTimeIndependentSystem
20+
"""
21+
tag: a tag for the system. If two system have the same tag, then they are
22+
structurally identical.
23+
"""
24+
tag::UInt
2025
"""Objective function of the system."""
2126
op::Any
2227
"""Unknown variables."""
@@ -46,15 +51,15 @@ struct OptimizationSystem <: AbstractTimeIndependentSystem
4651
"""
4752
complete::Bool
4853

49-
function OptimizationSystem(op, states, ps, var_to_name, observed,
54+
function OptimizationSystem(tag, op, states, ps, var_to_name, observed,
5055
constraints, name, systems, defaults, metadata = nothing,
5156
complete = false; checks::Union{Bool, Int} = true)
5257
if checks == true || (checks & CheckUnits) > 0
5358
unwrap(op) isa Symbolic && check_units(op)
5459
check_units(observed)
5560
all_dimensionless([states; ps]) || check_units(constraints)
5661
end
57-
new(op, states, ps, var_to_name, observed,
62+
new(tag, op, states, ps, var_to_name, observed,
5863
constraints, name, systems, defaults, metadata, complete)
5964
end
6065
end
@@ -92,7 +97,8 @@ function OptimizationSystem(op, states, ps;
9297
process_variables!(var_to_name, defaults, ps′)
9398
isempty(observed) || collect_var_to_name!(var_to_name, (eq.lhs for eq in observed))
9499

95-
OptimizationSystem(value(op), states′, ps′, var_to_name,
100+
OptimizationSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
101+
value(op), states′, ps′, var_to_name,
96102
observed,
97103
constraints,
98104
name, systems, defaults, metadata; checks = checks)

0 commit comments

Comments
 (0)