Skip to content

Commit 2a5ba1f

Browse files
committed
input->pin; output->observed
1 parent a02272f commit 2a5ba1f

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export Differential, expand_derivatives, @derivatives
132132
export IntervalDomain, ProductDomain, , CircleDomain
133133
export Equation, ConstrainedEquation
134134
export Operation, Expression, Variable
135-
export independent_variable, states, parameters, equations, inputs, outputs
135+
export independent_variable, states, parameters, equations, pins, observed
136136

137137
export calculate_jacobian, generate_jacobian, generate_function
138138
export calculate_tgrad, generate_tgrad

src/systems/abstractsystem.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ function Base.getproperty(sys::AbstractSystem, name::Symbol)
145145
end
146146
end
147147

148-
if :outputs fieldnames(typeof(sys))
149-
i = findfirst(x->convert(Variable,x.lhs).name==name,sys.outputs)
148+
if :observed fieldnames(typeof(sys))
149+
i = findfirst(x->convert(Variable,x.lhs).name==name,sys.observed)
150150
if i !== nothing
151-
return rename(convert(Variable,sys.outputs[i].lhs),renamespace(sys.name,name))(getfield(sys,:iv)())
151+
return rename(convert(Variable,sys.observed[i].lhs),renamespace(sys.name,name))(getfield(sys,:iv)())
152152
end
153153
end
154154

@@ -165,8 +165,8 @@ function namespace_parameters(sys::AbstractSystem)
165165
[rename(x,renamespace(sys.name,x.name)) for x in parameters(sys)]
166166
end
167167

168-
function namespace_inputs(sys::AbstractSystem)
169-
[rename(x,renamespace(sys.name,x.name)) for x in inputs(sys)]
168+
function namespace_pins(sys::AbstractSystem)
169+
[rename(x,renamespace(sys.name,x.name)) for x in pins(sys)]
170170
end
171171

172172
namespace_equations(sys::AbstractSystem) = namespace_equation.(equations(sys),sys.name,sys.iv.name)
@@ -190,11 +190,11 @@ namespace_operation(O::Constant,name,ivname) = O
190190
independent_variable(sys::AbstractSystem) = sys.iv
191191
states(sys::AbstractSystem) = isempty(sys.systems) ? sys.states : [sys.states;reduce(vcat,namespace_variables.(sys.systems))]
192192
parameters(sys::AbstractSystem) = isempty(sys.systems) ? sys.ps : [sys.ps;reduce(vcat,namespace_parameters.(sys.systems))]
193-
inputs(sys::AbstractSystem) = isempty(sys.systems) ? sys.inputs : [sys.inputs;reduce(vcat,namespace_inputs.(sys.systems))]
194-
function outputs(sys::AbstractSystem)
195-
[sys.outputs;
193+
pins(sys::AbstractSystem) = isempty(sys.systems) ? sys.pins : [sys.pins;reduce(vcat,namespace_pins.(sys.systems))]
194+
function observed(sys::AbstractSystem)
195+
[sys.observed;
196196
reduce(vcat,
197-
(namespace_equation.(s.outputs, s.name, s.iv.name) for s in sys.systems),
197+
(namespace_equation.(s.observed, s.name, s.iv.name) for s in sys.systems),
198198
init=Equation[])]
199199
end
200200

@@ -208,8 +208,8 @@ function parameters(sys::AbstractSystem,name::Symbol)
208208
rename(x,renamespace(sys.name,x.name))()
209209
end
210210

211-
function inputs(sys::AbstractSystem,name::Symbol)
212-
x = sys.inputs[findfirst(x->x.name==name,sys.ps)]
211+
function pins(sys::AbstractSystem,name::Symbol)
212+
x = sys.pins[findfirst(x->x.name==name,sys.ps)]
213213
rename(x,renamespace(sys.name,x.name))(sys.iv())
214214
end
215215

@@ -228,7 +228,7 @@ function equations(sys::ModelingToolkit.AbstractSystem; remove_aliases = true)
228228
if !remove_aliases
229229
return eqs
230230
end
231-
aliases = outputs(sys)
231+
aliases = observed(sys)
232232
dict = Dict(lhss(aliases) .=> rhss(aliases))
233233

234234
# Substitute aliases
@@ -259,7 +259,7 @@ function islinear(sys::AbstractSystem)
259259
all(islinear(r, dvs) for r in rhs)
260260
end
261261

262-
function inputs(sys::AbstractSystem,args...)
262+
function pins(sys::AbstractSystem,args...)
263263
name = last(args)
264264
extra_names = reduce(Symbol,[Symbol(:₊,x.name) for x in args[1:end-1]])
265265
newname = renamespace(extra_names,name)

src/systems/diffeqs/odesystem.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct ODESystem <: AbstractODESystem
3131
states::Vector{Variable}
3232
"""Parameter variables."""
3333
ps::Vector{Variable}
34-
inputs::Vector{Variable}
35-
outputs::Vector{Equation}
34+
pins::Vector{Variable}
35+
observed::Vector{Equation}
3636
"""
3737
Time-derivative matrix. Note: this field will not be defined until
3838
[`calculate_tgrad`](@ref) is called on the system.
@@ -64,8 +64,8 @@ struct ODESystem <: AbstractODESystem
6464
end
6565

6666
function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
67-
inputs = Variable[],
68-
outputs = Operation[],
67+
pins = Variable[],
68+
observed = Operation[],
6969
systems = ODESystem[],
7070
name=gensym(:ODESystem))
7171
iv′ = convert(Variable,iv)
@@ -75,7 +75,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
7575
jac = RefValue{Any}(Matrix{Expression}(undef, 0, 0))
7676
Wfact = RefValue(Matrix{Expression}(undef, 0, 0))
7777
Wfact_t = RefValue(Matrix{Expression}(undef, 0, 0))
78-
ODESystem(deqs, iv′, dvs′, ps′, inputs, outputs, tgrad, jac, Wfact, Wfact_t, name, systems)
78+
ODESystem(deqs, iv′, dvs′, ps′, pins, observed, tgrad, jac, Wfact, Wfact_t, name, systems)
7979
end
8080

8181
var_from_nested_derivative(x::Constant) = (missing, missing)

src/systems/diffeqs/sdesystem.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ struct SDESystem <: AbstractODESystem
3737
states::Vector{Variable}
3838
"""Parameter variables."""
3939
ps::Vector{Variable}
40-
inputs::Vector{Variable}
41-
outputs::Vector{Equation}
40+
pins::Vector{Variable}
41+
observed::Vector{Equation}
4242
"""
4343
Time-derivative matrix. Note: this field will not be defined until
4444
[`calculate_tgrad`](@ref) is called on the system.
@@ -70,8 +70,8 @@ struct SDESystem <: AbstractODESystem
7070
end
7171

7272
function SDESystem(deqs::AbstractVector{<:Equation}, neqs, iv, dvs, ps;
73-
inputs = Variable[],
74-
outputs = Operation[],
73+
pins = Variable[],
74+
observed = Operation[],
7575
systems = SDESystem[],
7676
name = gensym(:SDESystem))
7777
iv′ = convert(Variable,iv)
@@ -81,7 +81,7 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs, iv, dvs, ps;
8181
jac = RefValue(Matrix{Expression}(undef, 0, 0))
8282
Wfact = RefValue(Matrix{Expression}(undef, 0, 0))
8383
Wfact_t = RefValue(Matrix{Expression}(undef, 0, 0))
84-
SDESystem(deqs, neqs, iv′, dvs′, ps′, inputs, outputs, tgrad, jac, Wfact, Wfact_t, name, systems)
84+
SDESystem(deqs, neqs, iv′, dvs′, ps′, pins, observed, tgrad, jac, Wfact, Wfact_t, name, systems)
8585
end
8686

8787
function generate_diffusion_function(sys::SDESystem, dvs = sys.states, ps = sys.ps; kwargs...)

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ struct NonlinearSystem <: AbstractSystem
2525
states::Vector{Variable}
2626
"""Parameters."""
2727
ps::Vector{Variable}
28-
inputs::Vector{Variable}
29-
outputs::Vector{Equation}
28+
pins::Vector{Variable}
29+
observed::Vector{Equation}
3030
"""
3131
Name: the name of the system
3232
"""
@@ -38,11 +38,11 @@ struct NonlinearSystem <: AbstractSystem
3838
end
3939

4040
function NonlinearSystem(eqs, states, ps;
41-
inputs = Variable[],
42-
outputs = Operation[],
41+
pins = Variable[],
42+
observed = Operation[],
4343
name = gensym(:NonlinearSystem),
4444
systems = NonlinearSystem[])
45-
NonlinearSystem(eqs, convert.(Variable,states), convert.(Variable,ps), inputs, outputs, name, systems)
45+
NonlinearSystem(eqs, convert.(Variable,states), convert.(Variable,ps), pins, observed, name, systems)
4646
end
4747

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

src/systems/optimization/optimizationsystem.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct OptimizationSystem <: AbstractSystem
2323
states::Vector{Variable}
2424
"""Parameters."""
2525
ps::Vector{Variable}
26-
inputs::Vector{Variable}
27-
outputs::Vector{Equation}
26+
pins::Vector{Variable}
27+
observed::Vector{Equation}
2828
"""
2929
Name: the name of the system
3030
"""
@@ -36,11 +36,11 @@ struct OptimizationSystem <: AbstractSystem
3636
end
3737

3838
function OptimizationSystem(op, states, ps;
39-
inputs = Variable[],
40-
outputs = Operation[],
39+
pins = Variable[],
40+
observed = Operation[],
4141
name = gensym(:OptimizationSystem),
4242
systems = OptimizationSystem[])
43-
OptimizationSystem(op, convert.(Variable,states), convert.(Variable,ps), inputs, outputs, name, systems)
43+
OptimizationSystem(op, convert.(Variable,states), convert.(Variable,ps), pins, observed, name, systems)
4444
end
4545

4646
function calculate_gradient(sys::OptimizationSystem)

src/systems/reaction/reactionsystem.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,25 @@ struct ReactionSystem <: AbstractSystem
129129
states::Vector{Variable}
130130
"""Parameter variables."""
131131
ps::Vector{Variable}
132-
inputs::Vector{Variable}
133-
outputs::Vector{Equation}
132+
pins::Vector{Variable}
133+
observed::Vector{Equation}
134134
"""The name of the system"""
135135
name::Symbol
136136
"""systems: The internal systems"""
137137
systems::Vector{ReactionSystem}
138138
end
139139

140140
function ReactionSystem(eqs, iv, species, params;
141-
inputs = Variable[],
142-
outputs = Operation[],
141+
pins = Variable[],
142+
observed = Operation[],
143143
systems = ReactionSystem[],
144144
name = gensym(:ReactionSystem))
145145

146146
isempty(species) && error("ReactionSystems require at least one species.")
147147
paramvars = map(v -> convert(Variable,v), params)
148148
specvars = map(s -> convert(Variable,s), species)
149149
ReactionSystem(eqs, convert(Variable,iv), specvars, paramvars,
150-
inputs, outputs, name, systems)
150+
pins, observed, name, systems)
151151
end
152152

153153
"""

test/inputoutput.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ eqs = [D(x) ~ σ*(y-x) + F,
99
D(z) ~ x*y - β*z]
1010

1111
aliases = [u ~ x + y - z]
12-
lorenz1 = ODESystem(eqs,inputs=[F],outputs=aliases,name=:lorenz1)
13-
lorenz2 = ODESystem(eqs,inputs=[F],outputs=aliases,name=:lorenz2)
12+
lorenz1 = ODESystem(eqs,pins=[F],observed=aliases,name=:lorenz1)
13+
lorenz2 = ODESystem(eqs,pins=[F],observed=aliases,name=:lorenz2)
1414

1515
connections = [lorenz1.F ~ lorenz2.u,
1616
lorenz2.F ~ lorenz1.u]
17-
connected = ODESystem(Equation[],t,[],[],outputs=connections,systems=[lorenz1,lorenz2])
17+
connected = ODESystem(Equation[],t,[],[],observed=connections,systems=[lorenz1,lorenz2])
1818

1919
sys = connected
2020

2121
@variables lorenz1₊F lorenz2₊F
22-
@test inputs(connected) == Variable[lorenz1₊F, lorenz2₊F]
23-
@test isequal(outputs(connected),
22+
@test pins(connected) == Variable[lorenz1₊F, lorenz2₊F]
23+
@test isequal(observed(connected),
2424
[connections...,
2525
lorenz1.u ~ lorenz1.x + lorenz1.y - lorenz1.z,
2626
lorenz2.u ~ lorenz2.x + lorenz2.y - lorenz2.z])

0 commit comments

Comments
 (0)