Skip to content

Commit 8447408

Browse files
committed
Add description to all systems
1 parent ab184c5 commit 8447408

File tree

9 files changed

+59
-20
lines changed

9 files changed

+59
-20
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ for prop in [:eqs
986986
:ps
987987
:tspan
988988
:name
989+
:description
989990
:var_to_name
990991
:ctrls
991992
:defaults

src/systems/diffeqs/odesystem.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ struct ODESystem <: AbstractODESystem
7979
"""
8080
name::Symbol
8181
"""
82+
A description of the system.
83+
"""
84+
description::String
85+
"""
8286
The internal systems. These are required to have unique names.
8387
"""
8488
systems::Vector{ODESystem}
@@ -178,7 +182,7 @@ struct ODESystem <: AbstractODESystem
178182
parent::Any
179183

180184
function ODESystem(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad,
181-
jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses,
185+
jac, ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses,
182186
torn_matching, initializesystem, initialization_eqs, schedule,
183187
connector_type, preface, cevents,
184188
devents, parameter_dependencies,
@@ -199,7 +203,7 @@ struct ODESystem <: AbstractODESystem
199203
check_units(u, deqs)
200204
end
201205
new(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
202-
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, torn_matching,
206+
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses, torn_matching,
203207
initializesystem, initialization_eqs, schedule, connector_type, preface,
204208
cevents, devents, parameter_dependencies, metadata,
205209
gui_metadata, is_dde, tearing_state, substitutions, complete, index_cache,
@@ -213,6 +217,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
213217
systems = ODESystem[],
214218
tspan = nothing,
215219
name = nothing,
220+
description = "",
216221
default_u0 = Dict(),
217222
default_p = Dict(),
218223
defaults = _merge(Dict(default_u0), Dict(default_p)),
@@ -290,7 +295,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
290295
end
291296
ODESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
292297
deqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
293-
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, nothing, initializesystem,
298+
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses, nothing, initializesystem,
294299
initialization_eqs, schedule, connector_type, preface, cont_callbacks,
295300
disc_callbacks, parameter_dependencies,
296301
metadata, gui_metadata, is_dde, checks = checks)

src/systems/diffeqs/sdesystem.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ struct SDESystem <: AbstractODESystem
8080
"""
8181
name::Symbol
8282
"""
83+
A description of the system.
84+
"""
85+
description::String
86+
"""
8387
The internal systems. These are required to have unique names.
8488
"""
8589
systems::Vector{SDESystem}
@@ -142,7 +146,7 @@ struct SDESystem <: AbstractODESystem
142146
function SDESystem(tag, deqs, neqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed,
143147
tgrad,
144148
jac,
145-
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
149+
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, connector_type,
146150
cevents, devents, parameter_dependencies, metadata = nothing, gui_metadata = nothing,
147151
complete = false, index_cache = nothing, parent = nothing, is_scalar_noise = false,
148152
is_dde = false,
@@ -168,7 +172,7 @@ struct SDESystem <: AbstractODESystem
168172
end
169173
new(tag, deqs, neqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
170174
ctrl_jac,
171-
Wfact, Wfact_t, name, systems, defaults, connector_type, cevents, devents,
175+
Wfact, Wfact_t, name, description, systems, defaults, connector_type, cevents, devents,
172176
parameter_dependencies, metadata, gui_metadata, complete, index_cache, parent, is_scalar_noise,
173177
is_dde, isscheduled)
174178
end
@@ -183,6 +187,7 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs::AbstractArray, iv, dv
183187
default_p = Dict(),
184188
defaults = _merge(Dict(default_u0), Dict(default_p)),
185189
name = nothing,
190+
description = "",
186191
connector_type = nothing,
187192
checks = true,
188193
continuous_events = nothing,
@@ -234,7 +239,7 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs::AbstractArray, iv, dv
234239
end
235240
SDESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
236241
deqs, neqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
237-
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
242+
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, connector_type,
238243
cont_callbacks, disc_callbacks, parameter_dependencies, metadata, gui_metadata,
239244
complete, index_cache, parent, is_scalar_noise, is_dde; checks = checks)
240245
end
@@ -349,7 +354,7 @@ function stochastic_integral_transform(sys::SDESystem, correction_factor)
349354
end
350355

351356
SDESystem(deqs, get_noiseeqs(sys), get_iv(sys), unknowns(sys), parameters(sys),
352-
name = name, parameter_dependencies = parameter_dependencies(sys), checks = false)
357+
name = name, description = get_description(sys), parameter_dependencies = parameter_dependencies(sys), checks = false)
353358
end
354359

355360
"""
@@ -457,7 +462,7 @@ function Girsanov_transform(sys::SDESystem, u; θ0 = 1.0)
457462
# return modified SDE System
458463
SDESystem(deqs, noiseeqs, get_iv(sys), unknown_vars, parameters(sys);
459464
defaults = Dict=> θ0), observed = [weight ~ θ / θ0],
460-
name = name, parameter_dependencies = parameter_dependencies(sys),
465+
name = name, description = get_description(sys), parameter_dependencies = parameter_dependencies(sys),
461466
checks = false)
462467
end
463468

src/systems/discrete_system/discrete_system.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
4242
"""
4343
name::Symbol
4444
"""
45+
A description of the system.
46+
"""
47+
description::String
48+
"""
4549
The internal systems. These are required to have unique names.
4650
"""
4751
systems::Vector{DiscreteSystem}
@@ -95,7 +99,7 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
9599

96100
function DiscreteSystem(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name,
97101
observed,
98-
name,
102+
name, description,
99103
systems, defaults, preface, connector_type, parameter_dependencies = Equation[],
100104
metadata = nothing, gui_metadata = nothing,
101105
tearing_state = nothing, substitutions = nothing,
@@ -111,7 +115,7 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
111115
u = __get_unit_type(dvs, ps, iv)
112116
check_units(u, discreteEqs)
113117
end
114-
new(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name, observed, name,
118+
new(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name, observed, name, description,
115119
systems,
116120
defaults,
117121
preface, connector_type, parameter_dependencies, metadata, gui_metadata,
@@ -128,6 +132,7 @@ function DiscreteSystem(eqs::AbstractVector{<:Equation}, iv, dvs, ps;
128132
systems = DiscreteSystem[],
129133
tspan = nothing,
130134
name = nothing,
135+
description = "",
131136
default_u0 = Dict(),
132137
default_p = Dict(),
133138
defaults = _merge(Dict(default_u0), Dict(default_p)),
@@ -164,7 +169,7 @@ function DiscreteSystem(eqs::AbstractVector{<:Equation}, iv, dvs, ps;
164169
throw(ArgumentError("System names must be unique."))
165170
end
166171
DiscreteSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
167-
eqs, iv′, dvs′, ps′, tspan, var_to_name, observed, name, systems,
172+
eqs, iv′, dvs′, ps′, tspan, var_to_name, observed, name, description, systems,
168173
defaults, preface, connector_type, parameter_dependencies, metadata, gui_metadata, kwargs...)
169174
end
170175

@@ -221,6 +226,7 @@ function flatten(sys::DiscreteSystem, noeqs = false)
221226
observed = observed(sys),
222227
defaults = defaults(sys),
223228
name = nameof(sys),
229+
description = get_description(sys),
224230
checks = false)
225231
end
226232
end

src/systems/jumps/jumpsystem.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
7474
observed::Vector{Equation}
7575
"""The name of the system."""
7676
name::Symbol
77+
"""A description of the system."""
78+
description::String
7779
"""The internal systems. These are required to have unique names."""
7880
systems::Vector{JumpSystem}
7981
"""
@@ -116,7 +118,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
116118
index_cache::Union{Nothing, IndexCache}
117119
isscheduled::Bool
118120

119-
function JumpSystem{U}(tag, ap::U, iv, unknowns, ps, var_to_name, observed, name,
121+
function JumpSystem{U}(tag, ap::U, iv, unknowns, ps, var_to_name, observed, name, description,
120122
systems,
121123
defaults, connector_type, devents, parameter_dependencies,
122124
metadata = nothing, gui_metadata = nothing,
@@ -131,7 +133,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
131133
u = __get_unit_type(unknowns, ps, iv)
132134
check_units(u, ap, iv)
133135
end
134-
new{U}(tag, ap, iv, unknowns, ps, var_to_name, observed, name, systems, defaults,
136+
new{U}(tag, ap, iv, unknowns, ps, var_to_name, observed, name, description, systems, defaults,
135137
connector_type, devents, parameter_dependencies, metadata, gui_metadata,
136138
complete, index_cache, isscheduled)
137139
end
@@ -147,6 +149,7 @@ function JumpSystem(eqs, iv, unknowns, ps;
147149
default_p = Dict(),
148150
defaults = _merge(Dict(default_u0), Dict(default_p)),
149151
name = nothing,
152+
description = "",
150153
connector_type = nothing,
151154
checks = true,
152155
continuous_events = nothing,
@@ -193,7 +196,7 @@ function JumpSystem(eqs, iv, unknowns, ps;
193196
disc_callbacks = SymbolicDiscreteCallbacks(discrete_events)
194197
parameter_dependencies, ps = process_parameter_dependencies(parameter_dependencies, ps)
195198
JumpSystem{typeof(ap)}(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
196-
ap, value(iv), unknowns, ps, var_to_name, observed, name, systems,
199+
ap, value(iv), unknowns, ps, var_to_name, observed, name, description, systems,
197200
defaults, connector_type, disc_callbacks, parameter_dependencies,
198201
metadata, gui_metadata, checks = checks)
199202
end

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
4444
"""
4545
name::Symbol
4646
"""
47+
A description of the system.
48+
"""
49+
description::String
50+
"""
4751
The internal systems. These are required to have unique names.
4852
"""
4953
systems::Vector{NonlinearSystem}
@@ -91,7 +95,7 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
9195
parent::Any
9296
isscheduled::Bool
9397

94-
function NonlinearSystem(tag, eqs, unknowns, ps, var_to_name, observed, jac, name,
98+
function NonlinearSystem(tag, eqs, unknowns, ps, var_to_name, observed, jac, name, description,
9599
systems,
96100
defaults, connector_type, parameter_dependencies = Equation[], metadata = nothing,
97101
gui_metadata = nothing,
@@ -111,6 +115,7 @@ end
111115
function NonlinearSystem(eqs, unknowns, ps;
112116
observed = [],
113117
name = nothing,
118+
description = "",
114119
default_u0 = Dict(),
115120
default_p = Dict(),
116121
defaults = _merge(Dict(default_u0), Dict(default_p)),
@@ -157,7 +162,7 @@ function NonlinearSystem(eqs, unknowns, ps;
157162
parameter_dependencies, ps = process_parameter_dependencies(
158163
parameter_dependencies, ps)
159164
NonlinearSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
160-
eqs, unknowns, ps, var_to_name, observed, jac, name, systems, defaults,
165+
eqs, unknowns, ps, var_to_name, observed, jac, name, description, systems, defaults,
161166
connector_type, parameter_dependencies, metadata, gui_metadata, checks = checks)
162167
end
163168

@@ -554,6 +559,7 @@ function flatten(sys::NonlinearSystem, noeqs = false)
554559
observed = observed(sys),
555560
defaults = defaults(sys),
556561
name = nameof(sys),
562+
description = get_description(sys),
557563
checks = false)
558564
end
559565
end

src/systems/optimization/constraints_system.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ struct ConstraintsSystem <: AbstractTimeIndependentSystem
4545
"""
4646
name::Symbol
4747
"""
48+
A description of the system.
49+
"""
50+
description::String
51+
"""
4852
The internal systems. These are required to have unique names.
4953
"""
5054
systems::Vector{ConstraintsSystem}
@@ -100,6 +104,7 @@ equations(sys::ConstraintsSystem) = constraints(sys) # needed for Base.show
100104
function ConstraintsSystem(constraints, unknowns, ps;
101105
observed = [],
102106
name = nothing,
107+
description = "",
103108
default_u0 = Dict(),
104109
default_p = Dict(),
105110
defaults = _merge(Dict(default_u0), Dict(default_p)),
@@ -142,7 +147,7 @@ function ConstraintsSystem(constraints, unknowns, ps;
142147
isempty(observed) || collect_var_to_name!(var_to_name, (eq.lhs for eq in observed))
143148

144149
ConstraintsSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
145-
cstr, unknowns, ps, var_to_name, observed, jac, name, systems,
150+
cstr, unknowns, ps, var_to_name, observed, jac, name, description, systems,
146151
defaults,
147152
connector_type, metadata, checks = checks)
148153
end

src/systems/optimization/optimizationsystem.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct OptimizationSystem <: AbstractOptimizationSystem
3737
constraints::Vector{Union{Equation, Inequality}}
3838
"""The name of the system."""
3939
name::Symbol
40+
"""A description of the system."""
41+
description::String
4042
"""The internal systems. These are required to have unique names."""
4143
systems::Vector{OptimizationSystem}
4244
"""
@@ -67,7 +69,7 @@ struct OptimizationSystem <: AbstractOptimizationSystem
6769
isscheduled::Bool
6870

6971
function OptimizationSystem(tag, op, unknowns, ps, var_to_name, observed,
70-
constraints, name, systems, defaults, metadata = nothing,
72+
constraints, name, description, systems, defaults, metadata = nothing,
7173
gui_metadata = nothing, complete = false, index_cache = nothing, parent = nothing,
7274
isscheduled = false;
7375
checks::Union{Bool, Int} = true)
@@ -92,6 +94,7 @@ function OptimizationSystem(op, unknowns, ps;
9294
default_p = Dict(),
9395
defaults = _merge(Dict(default_u0), Dict(default_p)),
9496
name = nothing,
97+
description = "",
9598
systems = OptimizationSystem[],
9699
checks = true,
97100
metadata = nothing,
@@ -125,7 +128,7 @@ function OptimizationSystem(op, unknowns, ps;
125128
op′, unknowns′, ps′, var_to_name,
126129
observed,
127130
constraints,
128-
name, systems, defaults, metadata, gui_metadata;
131+
name, description, systems, defaults, metadata, gui_metadata;
129132
checks = checks)
130133
end
131134

src/systems/pde/pdesystem.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
7878
"""
7979
name::Symbol
8080
"""
81+
A description of the system.
82+
"""
83+
description::String
84+
"""
8185
Metadata for the system, to be used by downstream packages.
8286
"""
8387
metadata::Any
@@ -96,6 +100,7 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
96100
gui_metadata = nothing,
97101
eval_module = @__MODULE__,
98102
checks::Union{Bool, Int} = true,
103+
description = "",
99104
name)
100105
if checks == true || (checks & CheckUnits) > 0
101106
u = __get_unit_type(dvs, ivs, ps)
@@ -127,7 +132,7 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
127132
end
128133

129134
new(eqs, bcs, domain, ivs, dvs, ps, defaults, connector_type, systems, analytic,
130-
analytic_func, name, metadata, gui_metadata)
135+
analytic_func, name, description, metadata, gui_metadata)
131136
end
132137
end
133138

0 commit comments

Comments
 (0)