Skip to content

Commit

Permalink
Add description to all systems
Browse files Browse the repository at this point in the history
  • Loading branch information
hersle committed Oct 20, 2024
1 parent 8d7a652 commit ffc43d2
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ for prop in [:eqs
:ps
:tspan
:name
:description
:var_to_name
:ctrls
:defaults
Expand Down
11 changes: 8 additions & 3 deletions src/systems/diffeqs/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ struct ODESystem <: AbstractODESystem
"""
name::Symbol
"""
A description of the system.
"""
description::String
"""
The internal systems. These are required to have unique names.
"""
systems::Vector{ODESystem}
Expand Down Expand Up @@ -178,7 +182,7 @@ struct ODESystem <: AbstractODESystem
parent::Any

function ODESystem(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad,
jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses,
jac, ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses,
torn_matching, initializesystem, initialization_eqs, schedule,
connector_type, preface, cevents,
devents, parameter_dependencies,
Expand All @@ -199,7 +203,7 @@ struct ODESystem <: AbstractODESystem
check_units(u, deqs)
end
new(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, torn_matching,
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses, torn_matching,
initializesystem, initialization_eqs, schedule, connector_type, preface,
cevents, devents, parameter_dependencies, metadata,
gui_metadata, is_dde, tearing_state, substitutions, complete, index_cache,
Expand All @@ -213,6 +217,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
systems = ODESystem[],
tspan = nothing,
name = nothing,
description = "",
default_u0 = Dict(),
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
Expand Down Expand Up @@ -290,7 +295,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
end
ODESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
deqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, nothing, initializesystem,
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses, nothing, initializesystem,
initialization_eqs, schedule, connector_type, preface, cont_callbacks,
disc_callbacks, parameter_dependencies,
metadata, gui_metadata, is_dde, checks = checks)
Expand Down
15 changes: 10 additions & 5 deletions src/systems/diffeqs/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ struct SDESystem <: AbstractODESystem
"""
name::Symbol
"""
A description of the system.
"""
description::String
"""
The internal systems. These are required to have unique names.
"""
systems::Vector{SDESystem}
Expand Down Expand Up @@ -142,7 +146,7 @@ struct SDESystem <: AbstractODESystem
function SDESystem(tag, deqs, neqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed,
tgrad,
jac,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, connector_type,
cevents, devents, parameter_dependencies, metadata = nothing, gui_metadata = nothing,
complete = false, index_cache = nothing, parent = nothing, is_scalar_noise = false,
is_dde = false,
Expand All @@ -168,7 +172,7 @@ struct SDESystem <: AbstractODESystem
end
new(tag, deqs, neqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
ctrl_jac,
Wfact, Wfact_t, name, systems, defaults, connector_type, cevents, devents,
Wfact, Wfact_t, name, description, systems, defaults, connector_type, cevents, devents,
parameter_dependencies, metadata, gui_metadata, complete, index_cache, parent, is_scalar_noise,
is_dde, isscheduled)
end
Expand All @@ -183,6 +187,7 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs::AbstractArray, iv, dv
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
name = nothing,
description = "",
connector_type = nothing,
checks = true,
continuous_events = nothing,
Expand Down Expand Up @@ -234,7 +239,7 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs::AbstractArray, iv, dv
end
SDESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
deqs, neqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connector_type,
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, connector_type,
cont_callbacks, disc_callbacks, parameter_dependencies, metadata, gui_metadata,
complete, index_cache, parent, is_scalar_noise, is_dde; checks = checks)
end
Expand Down Expand Up @@ -349,7 +354,7 @@ function stochastic_integral_transform(sys::SDESystem, correction_factor)
end

SDESystem(deqs, get_noiseeqs(sys), get_iv(sys), unknowns(sys), parameters(sys),
name = name, parameter_dependencies = parameter_dependencies(sys), checks = false)
name = name, description = get_description(sys), parameter_dependencies = parameter_dependencies(sys), checks = false)
end

"""
Expand Down Expand Up @@ -457,7 +462,7 @@ function Girsanov_transform(sys::SDESystem, u; θ0 = 1.0)
# return modified SDE System
SDESystem(deqs, noiseeqs, get_iv(sys), unknown_vars, parameters(sys);
defaults = Dict=> θ0), observed = [weight ~ θ / θ0],
name = name, parameter_dependencies = parameter_dependencies(sys),
name = name, description = get_description(sys), parameter_dependencies = parameter_dependencies(sys),
checks = false)
end

Expand Down
12 changes: 9 additions & 3 deletions src/systems/discrete_system/discrete_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
"""
name::Symbol
"""
A description of the system.
"""
description::String
"""
The internal systems. These are required to have unique names.
"""
systems::Vector{DiscreteSystem}
Expand Down Expand Up @@ -95,7 +99,7 @@ struct DiscreteSystem <: AbstractTimeDependentSystem

function DiscreteSystem(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name,
observed,
name,
name, description,
systems, defaults, preface, connector_type, parameter_dependencies = Equation[],
metadata = nothing, gui_metadata = nothing,
tearing_state = nothing, substitutions = nothing,
Expand All @@ -111,7 +115,7 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
u = __get_unit_type(dvs, ps, iv)
check_units(u, discreteEqs)
end
new(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name, observed, name,
new(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name, observed, name, description,
systems,
defaults,
preface, connector_type, parameter_dependencies, metadata, gui_metadata,
Expand All @@ -128,6 +132,7 @@ function DiscreteSystem(eqs::AbstractVector{<:Equation}, iv, dvs, ps;
systems = DiscreteSystem[],
tspan = nothing,
name = nothing,
description = "",
default_u0 = Dict(),
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
Expand Down Expand Up @@ -164,7 +169,7 @@ function DiscreteSystem(eqs::AbstractVector{<:Equation}, iv, dvs, ps;
throw(ArgumentError("System names must be unique."))
end
DiscreteSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
eqs, iv′, dvs′, ps′, tspan, var_to_name, observed, name, systems,
eqs, iv′, dvs′, ps′, tspan, var_to_name, observed, name, description, systems,
defaults, preface, connector_type, parameter_dependencies, metadata, gui_metadata, kwargs...)
end

Expand Down Expand Up @@ -221,6 +226,7 @@ function flatten(sys::DiscreteSystem, noeqs = false)
observed = observed(sys),
defaults = defaults(sys),
name = nameof(sys),
description = get_description(sys),
checks = false)
end
end
Expand Down
9 changes: 6 additions & 3 deletions src/systems/jumps/jumpsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
observed::Vector{Equation}
"""The name of the system."""
name::Symbol
"""A description of the system."""
description::String
"""The internal systems. These are required to have unique names."""
systems::Vector{JumpSystem}
"""
Expand Down Expand Up @@ -116,7 +118,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
index_cache::Union{Nothing, IndexCache}
isscheduled::Bool

function JumpSystem{U}(tag, ap::U, iv, unknowns, ps, var_to_name, observed, name,
function JumpSystem{U}(tag, ap::U, iv, unknowns, ps, var_to_name, observed, name, description,
systems,
defaults, connector_type, devents, parameter_dependencies,
metadata = nothing, gui_metadata = nothing,
Expand All @@ -131,7 +133,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
u = __get_unit_type(unknowns, ps, iv)
check_units(u, ap, iv)
end
new{U}(tag, ap, iv, unknowns, ps, var_to_name, observed, name, systems, defaults,
new{U}(tag, ap, iv, unknowns, ps, var_to_name, observed, name, description, systems, defaults,
connector_type, devents, parameter_dependencies, metadata, gui_metadata,
complete, index_cache, isscheduled)
end
Expand All @@ -147,6 +149,7 @@ function JumpSystem(eqs, iv, unknowns, ps;
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
name = nothing,
description = "",
connector_type = nothing,
checks = true,
continuous_events = nothing,
Expand Down Expand Up @@ -193,7 +196,7 @@ function JumpSystem(eqs, iv, unknowns, ps;
disc_callbacks = SymbolicDiscreteCallbacks(discrete_events)
parameter_dependencies, ps = process_parameter_dependencies(parameter_dependencies, ps)
JumpSystem{typeof(ap)}(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
ap, value(iv), unknowns, ps, var_to_name, observed, name, systems,
ap, value(iv), unknowns, ps, var_to_name, observed, name, description, systems,
defaults, connector_type, disc_callbacks, parameter_dependencies,
metadata, gui_metadata, checks = checks)
end
Expand Down
12 changes: 9 additions & 3 deletions src/systems/nonlinear/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
"""
name::Symbol
"""
A description of the system.
"""
description::String
"""
The internal systems. These are required to have unique names.
"""
systems::Vector{NonlinearSystem}
Expand Down Expand Up @@ -91,7 +95,7 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
parent::Any
isscheduled::Bool

function NonlinearSystem(tag, eqs, unknowns, ps, var_to_name, observed, jac, name,
function NonlinearSystem(tag, eqs, unknowns, ps, var_to_name, observed, jac, name, description,
systems,
defaults, connector_type, parameter_dependencies = Equation[], metadata = nothing,
gui_metadata = nothing,
Expand All @@ -102,7 +106,7 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
u = __get_unit_type(unknowns, ps)
check_units(u, eqs)
end
new(tag, eqs, unknowns, ps, var_to_name, observed, jac, name, systems, defaults,
new(tag, eqs, unknowns, ps, var_to_name, observed, jac, name, description, systems, defaults,
connector_type, parameter_dependencies, metadata, gui_metadata, tearing_state,
substitutions, complete, index_cache, parent, isscheduled)
end
Expand All @@ -111,6 +115,7 @@ end
function NonlinearSystem(eqs, unknowns, ps;
observed = [],
name = nothing,
description = "",
default_u0 = Dict(),
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
Expand Down Expand Up @@ -157,7 +162,7 @@ function NonlinearSystem(eqs, unknowns, ps;
parameter_dependencies, ps = process_parameter_dependencies(
parameter_dependencies, ps)
NonlinearSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
eqs, unknowns, ps, var_to_name, observed, jac, name, systems, defaults,
eqs, unknowns, ps, var_to_name, observed, jac, name, description, systems, defaults,
connector_type, parameter_dependencies, metadata, gui_metadata, checks = checks)
end

Expand Down Expand Up @@ -554,6 +559,7 @@ function flatten(sys::NonlinearSystem, noeqs = false)
observed = observed(sys),
defaults = defaults(sys),
name = nameof(sys),
description = get_description(sys),
checks = false)
end
end
Expand Down
11 changes: 8 additions & 3 deletions src/systems/optimization/constraints_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct ConstraintsSystem <: AbstractTimeIndependentSystem
"""
name::Symbol
"""
A description of the system.
"""
description::String
"""
The internal systems. These are required to have unique names.
"""
systems::Vector{ConstraintsSystem}
Expand Down Expand Up @@ -79,7 +83,7 @@ struct ConstraintsSystem <: AbstractTimeIndependentSystem
index_cache::Union{Nothing, IndexCache}

function ConstraintsSystem(tag, constraints, unknowns, ps, var_to_name, observed, jac,
name,
name, description,
systems,
defaults, connector_type, metadata = nothing,
tearing_state = nothing, substitutions = nothing,
Expand All @@ -89,7 +93,7 @@ struct ConstraintsSystem <: AbstractTimeIndependentSystem
u = __get_unit_type(unknowns, ps)
check_units(u, constraints)
end
new(tag, constraints, unknowns, ps, var_to_name, observed, jac, name, systems,
new(tag, constraints, unknowns, ps, var_to_name, observed, jac, name, description, systems,
defaults,
connector_type, metadata, tearing_state, substitutions, complete, index_cache)
end
Expand All @@ -100,6 +104,7 @@ equations(sys::ConstraintsSystem) = constraints(sys) # needed for Base.show
function ConstraintsSystem(constraints, unknowns, ps;
observed = [],
name = nothing,
description = "",
default_u0 = Dict(),
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
Expand Down Expand Up @@ -142,7 +147,7 @@ function ConstraintsSystem(constraints, unknowns, ps;
isempty(observed) || collect_var_to_name!(var_to_name, (eq.lhs for eq in observed))

ConstraintsSystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
cstr, unknowns, ps, var_to_name, observed, jac, name, systems,
cstr, unknowns, ps, var_to_name, observed, jac, name, description, systems,
defaults,
connector_type, metadata, checks = checks)
end
Expand Down
9 changes: 6 additions & 3 deletions src/systems/optimization/optimizationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct OptimizationSystem <: AbstractOptimizationSystem
constraints::Vector{Union{Equation, Inequality}}
"""The name of the system."""
name::Symbol
"""A description of the system."""
description::String
"""The internal systems. These are required to have unique names."""
systems::Vector{OptimizationSystem}
"""
Expand Down Expand Up @@ -67,7 +69,7 @@ struct OptimizationSystem <: AbstractOptimizationSystem
isscheduled::Bool

function OptimizationSystem(tag, op, unknowns, ps, var_to_name, observed,
constraints, name, systems, defaults, metadata = nothing,
constraints, name, description, systems, defaults, metadata = nothing,
gui_metadata = nothing, complete = false, index_cache = nothing, parent = nothing,
isscheduled = false;
checks::Union{Bool, Int} = true)
Expand All @@ -78,7 +80,7 @@ struct OptimizationSystem <: AbstractOptimizationSystem
check_units(u, constraints)
end
new(tag, op, unknowns, ps, var_to_name, observed,
constraints, name, systems, defaults, metadata, gui_metadata, complete,
constraints, name, description, systems, defaults, metadata, gui_metadata, complete,
index_cache, parent, isscheduled)
end
end
Expand All @@ -92,6 +94,7 @@ function OptimizationSystem(op, unknowns, ps;
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
name = nothing,
description = "",
systems = OptimizationSystem[],
checks = true,
metadata = nothing,
Expand Down Expand Up @@ -125,7 +128,7 @@ function OptimizationSystem(op, unknowns, ps;
op′, unknowns′, ps′, var_to_name,
observed,
constraints,
name, systems, defaults, metadata, gui_metadata;
name, description, systems, defaults, metadata, gui_metadata;
checks = checks)
end

Expand Down
7 changes: 6 additions & 1 deletion src/systems/pde/pdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
"""
name::Symbol
"""
A description of the system.
"""
description::String
"""
Metadata for the system, to be used by downstream packages.
"""
metadata::Any
Expand All @@ -96,6 +100,7 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
gui_metadata = nothing,
eval_module = @__MODULE__,
checks::Union{Bool, Int} = true,
description = "",
name)
if checks == true || (checks & CheckUnits) > 0
u = __get_unit_type(dvs, ivs, ps)
Expand Down Expand Up @@ -127,7 +132,7 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
end

new(eqs, bcs, domain, ivs, dvs, ps, defaults, connector_type, systems, analytic,
analytic_func, name, metadata, gui_metadata)
analytic_func, name, description, metadata, gui_metadata)
end
end

Expand Down

0 comments on commit ffc43d2

Please sign in to comment.