Skip to content

Commit 62d8b2a

Browse files
authored
Merge pull request #2078 from SciML/myb/gui
Add GUIMetadata
2 parents 81c19e6 + 3dc2652 commit 62d8b2a

File tree

8 files changed

+74
-23
lines changed

8 files changed

+74
-23
lines changed

src/systems/abstractsystem.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
const SYSTEM_COUNT = Threads.Atomic{UInt}(0)
22

3+
struct GUIMetadata
4+
icon_name::String
5+
layout::Any
6+
end
7+
8+
GUIMetadata(icon_name) = GUIMetadata(icon_name, nothing)
9+
310
"""
411
```julia
512
calculate_tgrad(sys::AbstractTimeDependentSystem)
@@ -219,6 +226,7 @@ for prop in [:eqs
219226
:tearing_state
220227
:substitutions
221228
:metadata
229+
:gui_metadata
222230
:discrete_subsystems
223231
:unknown_states]
224232
fname1 = Symbol(:get_, prop)

src/systems/diffeqs/odesystem.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ struct ODESystem <: AbstractODESystem
115115
"""
116116
metadata::Any
117117
"""
118+
gui_metadata: metadata for MTK GUI.
119+
"""
120+
gui_metadata::Union{Nothing, GUIMetadata}
121+
"""
118122
tearing_state: cache for intermediate tearing state
119123
"""
120124
tearing_state::Any
@@ -139,7 +143,8 @@ struct ODESystem <: AbstractODESystem
139143
function ODESystem(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad,
140144
jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults,
141145
torn_matching, connector_type, preface, cevents,
142-
devents, metadata = nothing, tearing_state = nothing,
146+
devents, metadata = nothing, gui_metadata = nothing,
147+
tearing_state = nothing,
143148
substitutions = nothing, complete = false,
144149
discrete_subsystems = nothing, unknown_states = nothing;
145150
checks::Union{Bool, Int} = true)
@@ -154,8 +159,9 @@ struct ODESystem <: AbstractODESystem
154159
end
155160
new(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
156161
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, torn_matching,
157-
connector_type, preface, cevents, devents, metadata, tearing_state,
158-
substitutions, complete, discrete_subsystems, unknown_states)
162+
connector_type, preface, cevents, devents, metadata, gui_metadata,
163+
tearing_state, substitutions, complete, discrete_subsystems,
164+
unknown_states)
159165
end
160166
end
161167

@@ -173,7 +179,8 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
173179
continuous_events = nothing,
174180
discrete_events = nothing,
175181
checks = true,
176-
metadata = nothing)
182+
metadata = nothing,
183+
gui_metadata = nothing)
177184
name === nothing &&
178185
throw(ArgumentError("The `name` keyword must be provided. Please consider using the `@named` macro"))
179186
deqs = scalarize(deqs)
@@ -211,7 +218,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
211218
deqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
212219
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, nothing,
213220
connector_type, preface, cont_callbacks, disc_callbacks,
214-
metadata, checks = checks)
221+
metadata, gui_metadata, checks = checks)
215222
end
216223

217224
function ODESystem(eqs, iv = nothing; kwargs...)

src/systems/diffeqs/sdesystem.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ struct SDESystem <: AbstractODESystem
108108
"""
109109
metadata::Any
110110
"""
111+
gui_metadata: metadata for MTK GUI.
112+
"""
113+
gui_metadata::Union{Nothing, GUIMetadata}
114+
"""
111115
complete: if a model `sys` is complete, then `sys.x` no longer performs namespacing.
112116
"""
113117
complete::Bool
@@ -116,7 +120,8 @@ struct SDESystem <: AbstractODESystem
116120
tgrad,
117121
jac,
118122
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
119-
cevents, devents, metadata = nothing, complete = false;
123+
cevents, devents, metadata = nothing, gui_metadata = nothing,
124+
complete = false;
120125
checks::Union{Bool, Int} = true)
121126
if checks == true || (checks & CheckComponents) > 0
122127
check_variables(dvs, iv)
@@ -130,7 +135,7 @@ struct SDESystem <: AbstractODESystem
130135
new(tag, deqs, neqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
131136
ctrl_jac,
132137
Wfact, Wfact_t, name, systems, defaults, connector_type, cevents, devents,
133-
metadata, complete)
138+
metadata, gui_metadata, complete)
134139
end
135140
end
136141

@@ -147,7 +152,8 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs::AbstractArray, iv, dv
147152
checks = true,
148153
continuous_events = nothing,
149154
discrete_events = nothing,
150-
metadata = nothing)
155+
metadata = nothing,
156+
gui_metadata = nothing)
151157
name === nothing &&
152158
throw(ArgumentError("The `name` keyword must be provided. Please consider using the `@named` macro"))
153159
deqs = scalarize(deqs)
@@ -183,7 +189,7 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs::AbstractArray, iv, dv
183189
SDESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
184190
deqs, neqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
185191
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
186-
cont_callbacks, disc_callbacks, metadata; checks = checks)
192+
cont_callbacks, disc_callbacks, metadata, gui_metadata; checks = checks)
187193
end
188194

189195
function SDESystem(sys::ODESystem, neqs; kwargs...)

src/systems/discrete_system/discrete_system.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
7171
"""
7272
metadata::Any
7373
"""
74+
gui_metadata: metadata for MTK GUI.
75+
"""
76+
gui_metadata::Union{Nothing, GUIMetadata}
77+
"""
7478
tearing_state: cache for intermediate tearing state
7579
"""
7680
tearing_state::Any
@@ -87,7 +91,7 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
8791
observed,
8892
name,
8993
systems, defaults, preface, connector_type,
90-
metadata = nothing,
94+
metadata = nothing, gui_metadata = nothing,
9195
tearing_state = nothing, substitutions = nothing,
9296
complete = false; checks::Union{Bool, Int} = true)
9397
if checks == true || (checks & CheckComponents) > 0
@@ -100,7 +104,8 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
100104
new(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, name,
101105
systems,
102106
defaults,
103-
preface, connector_type, metadata, tearing_state, substitutions, complete)
107+
preface, connector_type, metadata, gui_metadata,
108+
tearing_state, substitutions, complete)
104109
end
105110
end
106111

@@ -121,6 +126,7 @@ function DiscreteSystem(eqs::AbstractVector{<:Equation}, iv, dvs, ps;
121126
preface = nothing,
122127
connector_type = nothing,
123128
metadata = nothing,
129+
gui_metadata = nothing,
124130
kwargs...)
125131
name === nothing &&
126132
throw(ArgumentError("The `name` keyword must be provided. Please consider using the `@named` macro"))
@@ -148,7 +154,7 @@ function DiscreteSystem(eqs::AbstractVector{<:Equation}, iv, dvs, ps;
148154
end
149155
DiscreteSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
150156
eqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, name, systems,
151-
defaults, preface, connector_type, metadata, kwargs...)
157+
defaults, preface, connector_type, metadata, gui_metadata, kwargs...)
152158
end
153159

154160
function DiscreteSystem(eqs, iv = nothing; kwargs...)

src/systems/jumps/jumpsystem.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,18 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
9393
"""
9494
metadata::Any
9595
"""
96+
gui_metadata: metadata for MTK GUI.
97+
"""
98+
gui_metadata::Union{Nothing, GUIMetadata}
99+
"""
96100
complete: if a model `sys` is complete, then `sys.x` no longer performs namespacing.
97101
"""
98102
complete::Bool
99103

100104
function JumpSystem{U}(tag, ap::U, iv, states, ps, var_to_name, observed, name, systems,
101105
defaults, connector_type, devents,
102-
metadata = nothing, complete = false;
106+
metadata = nothing, gui_metadata = nothing,
107+
complete = false;
103108
checks::Union{Bool, Int} = true) where {U <: ArrayPartition}
104109
if checks == true || (checks & CheckComponents) > 0
105110
check_variables(states, iv)
@@ -109,7 +114,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
109114
all_dimensionless([states; ps; iv]) || check_units(ap, iv)
110115
end
111116
new{U}(tag, ap, iv, states, ps, var_to_name, observed, name, systems, defaults,
112-
connector_type, devents, metadata, complete)
117+
connector_type, devents, metadata, gui_metadata, complete)
113118
end
114119
end
115120

@@ -125,6 +130,7 @@ function JumpSystem(eqs, iv, states, ps;
125130
continuous_events = nothing,
126131
discrete_events = nothing,
127132
metadata = nothing,
133+
gui_metadata = nothing,
128134
kwargs...)
129135
name === nothing &&
130136
throw(ArgumentError("The `name` keyword must be provided. Please consider using the `@named` macro"))
@@ -163,7 +169,7 @@ function JumpSystem(eqs, iv, states, ps;
163169

164170
JumpSystem{typeof(ap)}(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
165171
ap, value(iv), states, ps, var_to_name, observed, name, systems,
166-
defaults, connector_type, disc_callbacks, metadata,
172+
defaults, connector_type, disc_callbacks, metadata, gui_metadata,
167173
checks = checks)
168174
end
169175

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
6060
"""
6161
metadata::Any
6262
"""
63+
gui_metadata: metadata for MTK GUI.
64+
"""
65+
gui_metadata::Union{Nothing, GUIMetadata}
66+
"""
6367
tearing_state: cache for intermediate tearing state
6468
"""
6569
tearing_state::Any
@@ -75,13 +79,14 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
7579
function NonlinearSystem(tag, eqs, states, ps, var_to_name, observed, jac, name,
7680
systems,
7781
defaults, connector_type, metadata = nothing,
82+
gui_metadata = nothing,
7883
tearing_state = nothing, substitutions = nothing,
7984
complete = false; checks::Union{Bool, Int} = true)
8085
if checks == true || (checks & CheckUnits) > 0
8186
all_dimensionless([states; ps]) || check_units(eqs)
8287
end
8388
new(tag, eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
84-
connector_type, metadata, tearing_state, substitutions, complete)
89+
connector_type, metadata, gui_metadata, tearing_state, substitutions, complete)
8590
end
8691
end
8792

@@ -96,7 +101,8 @@ function NonlinearSystem(eqs, states, ps;
96101
continuous_events = nothing, # this argument is only required for ODESystems, but is added here for the constructor to accept it without error
97102
discrete_events = nothing, # this argument is only required for ODESystems, but is added here for the constructor to accept it without error
98103
checks = true,
99-
metadata = nothing)
104+
metadata = nothing,
105+
gui_metadata = nothing)
100106
continuous_events === nothing || isempty(continuous_events) ||
101107
throw(ArgumentError("NonlinearSystem does not accept `continuous_events`, you provided $continuous_events"))
102108
discrete_events === nothing || isempty(discrete_events) ||
@@ -132,7 +138,7 @@ function NonlinearSystem(eqs, states, ps;
132138

133139
NonlinearSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
134140
eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
135-
connector_type, metadata, checks = checks)
141+
connector_type, metadata, gui_metadata, checks = checks)
136142
end
137143

138144
function calculate_jacobian(sys::NonlinearSystem; sparse = false, simplify = false)

src/systems/optimization/optimizationsystem.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,25 @@ struct OptimizationSystem <: AbstractOptimizationSystem
4949
"""
5050
metadata::Any
5151
"""
52+
gui_metadata: metadata for MTK GUI.
53+
"""
54+
gui_metadata::Union{Nothing, GUIMetadata}
55+
"""
5256
complete: if a model `sys` is complete, then `sys.x` no longer performs namespacing.
5357
"""
5458
complete::Bool
5559

5660
function OptimizationSystem(tag, op, states, ps, var_to_name, observed,
5761
constraints, name, systems, defaults, metadata = nothing,
58-
complete = false; checks::Union{Bool, Int} = true)
62+
gui_metadata = nothing, complete = false;
63+
checks::Union{Bool, Int} = true)
5964
if checks == true || (checks & CheckUnits) > 0
6065
unwrap(op) isa Symbolic && check_units(op)
6166
check_units(observed)
6267
all_dimensionless([states; ps]) || check_units(constraints)
6368
end
6469
new(tag, op, states, ps, var_to_name, observed,
65-
constraints, name, systems, defaults, metadata, complete)
70+
constraints, name, systems, defaults, metadata, gui_metadata, complete)
6671
end
6772
end
6873

@@ -77,7 +82,8 @@ function OptimizationSystem(op, states, ps;
7782
name = nothing,
7883
systems = OptimizationSystem[],
7984
checks = true,
80-
metadata = nothing)
85+
metadata = nothing,
86+
gui_metadata = nothing)
8187
name === nothing &&
8288
throw(ArgumentError("The `name` keyword must be provided. Please consider using the `@named` macro"))
8389
constraints = value.(scalarize(constraints))
@@ -105,7 +111,8 @@ function OptimizationSystem(op, states, ps;
105111
op′, states′, ps′, var_to_name,
106112
observed,
107113
constraints,
108-
name, systems, defaults, metadata; checks = checks)
114+
name, systems, defaults, metadata, gui_metadata;
115+
checks = checks)
109116
end
110117

111118
function calculate_gradient(sys::OptimizationSystem)

src/systems/pde/pdesystem.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,25 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
6868
metadata: metadata for the system, to be used by downstream packages.
6969
"""
7070
metadata::Any
71+
"""
72+
gui_metadata: metadata for MTK GUI.
73+
"""
74+
gui_metadata::Union{Nothing, GUIMetadata}
7175
@add_kwonly function PDESystem(eqs, bcs, domain, ivs, dvs,
7276
ps = SciMLBase.NullParameters();
7377
defaults = Dict(),
7478
systems = [],
7579
connector_type = nothing,
7680
metadata = nothing,
81+
gui_metadata = nothing,
7782
checks::Union{Bool, Int} = true,
7883
name)
7984
if checks == true || (checks & CheckUnits) > 0
8085
all_dimensionless([dvs; ivs; ps]) || check_units(eqs)
8186
end
8287
eqs = eqs isa Vector ? eqs : [eqs]
8388
new(eqs, bcs, domain, ivs, dvs, ps, defaults, connector_type, systems, name,
84-
metadata)
89+
metadata, gui_metadata)
8590
end
8691
end
8792

0 commit comments

Comments
 (0)