Skip to content

Commit 634c54b

Browse files
authored
Merge pull request #2802 from SciML/revert-2798-lowerplus
Revert "Bye bye ₊, use var symbols with ."
2 parents ba04751 + ae9a98d commit 634c54b

File tree

12 files changed

+70
-89
lines changed

12 files changed

+70
-89
lines changed

docs/src/basics/Composition.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ connected = compose(
3737
equations(connected)
3838
3939
#4-element Vector{Equation}:
40-
# Differential(t)(decay1.f(t)) ~ 0
41-
# decay2.f(t) ~ decay1.x(t)
42-
# Differential(t)(decay1.x(t)) ~ decay1.f(t) - (decay1.a*(decay1.x(t)))
43-
# Differential(t)(decay2.x(t)) ~ decay2.f(t) - (decay2.a*(decay2.x(t)))
40+
# Differential(t)(decay1f(t)) ~ 0
41+
# decay2f(t) ~ decay1x(t)
42+
# Differential(t)(decay1x(t)) ~ decay1f(t) - (decay1a*(decay1x(t)))
43+
# Differential(t)(decay2x(t)) ~ decay2f(t) - (decay2a*(decay2x(t)))
4444
4545
simplified_sys = structural_simplify(connected)
4646
@@ -149,27 +149,27 @@ p = [a, b, c, d, e, f]
149149
level0 = ODESystem(Equation[], t, [], p; name = :level0)
150150
level1 = ODESystem(Equation[], t, [], []; name = :level1) level0
151151
parameters(level1)
152-
#level0.a
152+
#level0a
153153
#b
154154
#c
155-
#level0.d
156-
#level0.e
155+
#level0d
156+
#level0e
157157
#f
158158
level2 = ODESystem(Equation[], t, [], []; name = :level2) level1
159159
parameters(level2)
160-
#level1.level0.a
161-
#level1.b
160+
#level1level0a
161+
#level1b
162162
#c
163-
#level0.d
164-
#level1.level0.e
163+
#level0d
164+
#level1level0e
165165
#f
166166
level3 = ODESystem(Equation[], t, [], []; name = :level3) level2
167167
parameters(level3)
168-
#level2.level1.level0.a
169-
#level2.level1.b
170-
#level2.c
171-
#level2.level0.d
172-
#level1.level0.e
168+
#level2level1level0a
169+
#level2level1b
170+
#level2c
171+
#level2level0d
172+
#level1level0e
173173
#f
174174
```
175175

docs/src/basics/Events.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ When accessing variables of a sub-system, it can be useful to rename them
172172
(alternatively, an affect function may be reused in different contexts):
173173

174174
```julia
175-
[x ~ 0] => (affect!, [resistor.v => :v, x], [p, q => :p2], [], ctx)
175+
[x ~ 0] => (affect!, [resistorv => :v, x], [p, q => :p2], [], ctx)
176176
```
177177

178-
Here, the symbolic variable `resistor.v` is passed as `v` while the symbolic
178+
Here, the symbolic variable `resistorv` is passed as `v` while the symbolic
179179
parameter `q` has been renamed `p2`.
180180

181181
As an example, here is the bouncing ball example from above using the functional

docs/src/tutorials/domain_connections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ end
115115
nothing #hide
116116
```
117117

118-
To see how the domain works, we can examine the set parameter values for each of the ports `src.port` and `vol.port`. First we assemble the system using `structural_simplify()` and then check the default value of `vol.port.ρ`, whichs points to the setter value `fluid.ρ`. Likewise, `src.port.ρ`, will also point to the setter value `fluid.ρ`. Therefore, there is now only 1 defined density value `fluid.ρ` which sets the density for the connected network.
118+
To see how the domain works, we can examine the set parameter values for each of the ports `src.port` and `vol.port`. First we assemble the system using `structural_simplify()` and then check the default value of `vol.port.ρ`, whichs points to the setter value `fluidρ`. Likewise, `src.port.ρ`, will also point to the setter value `fluidρ`. Therefore, there is now only 1 defined density value `fluidρ` which sets the density for the connected network.
119119

120120
```@repl domain
121121
sys = structural_simplify(odesys)
@@ -181,7 +181,7 @@ end
181181
nothing #hide
182182
```
183183

184-
After running `structural_simplify()` on `actsys2`, the defaults will show that `act.port_a.ρ` points to `fluid_a.ρ` and `act.port_b.ρ` points to `fluid_b.ρ`. This is a special case, in most cases a hydraulic system will have only 1 fluid, however this simple system has 2 separate domain networks. Therefore, we can connect a single fluid to both networks. This does not interfere with the mathematical equations of the system, since no unknown variables are connected.
184+
After running `structural_simplify()` on `actsys2`, the defaults will show that `act.port_a.ρ` points to `fluid_aρ` and `act.port_b.ρ` points to `fluid_bρ`. This is a special case, in most cases a hydraulic system will have only 1 fluid, however this simple system has 2 separate domain networks. Therefore, we can connect a single fluid to both networks. This does not interfere with the mathematical equations of the system, since no unknown variables are connected.
185185

186186
```@example domain
187187
@component function ActuatorSystem1(; name)

src/inputoutput.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ function is_bound(sys, u, stack = [])
7171
In the following scenario
7272
julia> observed(syss)
7373
2-element Vector{Equation}:
74-
sys.y(tv) ~ sys.x(tv)
75-
y(tv) ~ sys.x(tv)
76-
sys.y(t) is bound to the outer y(t) through the variable sys.x(t) and should thus return is_bound(sys.y(t)) = true.
77-
When asking is_bound(sys.y(t)), we know that we are looking through observed equations and can thus ask
78-
if var is bound, if it is, then sys.y(t) is also bound. This can lead to an infinite recursion, so we maintain a stack of variables we have previously asked about to be able to break cycles
74+
sysy(tv) ~ sysx(tv)
75+
y(tv) ~ sysx(tv)
76+
sysy(t) is bound to the outer y(t) through the variable sysx(t) and should thus return is_bound(sysy(t)) = true.
77+
When asking is_bound(sysy(t)), we know that we are looking through observed equations and can thus ask
78+
if var is bound, if it is, then sysy(t) is also bound. This can lead to an infinite recursion, so we maintain a stack of variables we have previously asked about to be able to break cycles
7979
=#
8080
u Set(stack) && return false # Cycle detected
8181
eqs = equations(sys)
@@ -119,17 +119,17 @@ function same_or_inner_namespace(u, var)
119119
nv = get_namespace(var)
120120
nu == nv || # namespaces are the same
121121
startswith(nv, nu) || # or nv starts with nu, i.e., nv is an inner namespace to nu
122-
occursin('.', string(getname(var))) &&
123-
!occursin('.', string(getname(u))) # or u is top level but var is internal
122+
occursin('', string(getname(var))) &&
123+
!occursin('', string(getname(u))) # or u is top level but var is internal
124124
end
125125

126126
function inner_namespace(u, var)
127127
nu = get_namespace(u)
128128
nv = get_namespace(var)
129129
nu == nv && return false
130130
startswith(nv, nu) || # or nv starts with nu, i.e., nv is an inner namespace to nu
131-
occursin('.', string(getname(var))) &&
132-
!occursin('.', string(getname(u))) # or u is top level but var is internal
131+
occursin('', string(getname(var))) &&
132+
!occursin('', string(getname(u))) # or u is top level but var is internal
133133
end
134134

135135
"""
@@ -139,11 +139,11 @@ Return the namespace of a variable as a string. If the variable is not namespace
139139
"""
140140
function get_namespace(x)
141141
sname = string(getname(x))
142-
parts = split(sname, '.')
142+
parts = split(sname, '')
143143
if length(parts) == 1
144144
return ""
145145
end
146-
join(parts[1:(end - 1)], '.')
146+
join(parts[1:(end - 1)], '')
147147
end
148148

149149
"""

src/systems/abstractsystem.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ function SymbolicIndexingInterface.is_variable(sys::AbstractSystem, sym::Symbol)
365365
return is_variable(ic, sym)
366366
end
367367
return any(isequal(sym), getname.(variable_symbols(sys))) ||
368-
count('.', string(sym)) == 1 &&
369-
count(isequal(sym), Symbol.(nameof(sys), :., getname.(variable_symbols(sys)))) ==
368+
count('', string(sym)) == 1 &&
369+
count(isequal(sym), Symbol.(nameof(sys), :, getname.(variable_symbols(sys)))) ==
370370
1
371371
end
372372

@@ -399,9 +399,9 @@ function SymbolicIndexingInterface.variable_index(sys::AbstractSystem, sym::Symb
399399
idx = findfirst(isequal(sym), getname.(variable_symbols(sys)))
400400
if idx !== nothing
401401
return idx
402-
elseif count('.', string(sym)) == 1
402+
elseif count('', string(sym)) == 1
403403
return findfirst(isequal(sym),
404-
Symbol.(nameof(sys), :., getname.(variable_symbols(sys))))
404+
Symbol.(nameof(sys), :, getname.(variable_symbols(sys))))
405405
end
406406
return nothing
407407
end
@@ -431,9 +431,9 @@ function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::Symbol
431431
return is_parameter(ic, sym)
432432
end
433433
return any(isequal(sym), getname.(parameter_symbols(sys))) ||
434-
count('.', string(sym)) == 1 &&
434+
count('', string(sym)) == 1 &&
435435
count(isequal(sym),
436-
Symbol.(nameof(sys), :., getname.(parameter_symbols(sys)))) == 1
436+
Symbol.(nameof(sys), :, getname.(parameter_symbols(sys)))) == 1
437437
end
438438

439439
function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym)
@@ -466,9 +466,9 @@ function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym::Sym
466466
idx = findfirst(isequal(sym), getname.(parameter_symbols(sys)))
467467
if idx !== nothing
468468
return idx
469-
elseif count('.', string(sym)) == 1
469+
elseif count('', string(sym)) == 1
470470
return findfirst(isequal(sym),
471-
Symbol.(nameof(sys), :., getname.(parameter_symbols(sys))))
471+
Symbol.(nameof(sys), :, getname.(parameter_symbols(sys))))
472472
end
473473
return nothing
474474
end
@@ -889,7 +889,7 @@ function renamespace(sys, x)
889889
elseif x isa AbstractSystem
890890
rename(x, renamespace(sys, nameof(x)))
891891
else
892-
Symbol(getname(sys), :., x)
892+
Symbol(getname(sys), :, x)
893893
end
894894
end
895895

@@ -1248,7 +1248,7 @@ function round_trip_eq(eq::Equation, var2name)
12481248
syss = get_systems(eq.rhs)
12491249
call = Expr(:call, connect)
12501250
for sys in syss
1251-
strs = split(string(nameof(sys)), ".")
1251+
strs = split(string(nameof(sys)), "")
12521252
s = Symbol(strs[1])
12531253
for st in strs[2:end]
12541254
s = Expr(:., s, Meta.quot(Symbol(st)))

src/systems/callbacks.jl

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -512,24 +512,6 @@ function generate_rootfinding_callback(cbs, sys::AbstractODESystem, dvs = unknow
512512
end
513513
end
514514

515-
# Put a wrapper on NamedTuple so that u.resistor.v indexes like u.var"resistor.v"
516-
# Required for hierarchical, but a hack that should be fixed in the future
517-
struct NamedTupleSymbolFix{T}
518-
x::T
519-
sym::Symbol
520-
end
521-
NamedTupleSymbolFix(x) = NamedTupleSymbolFix(x, Symbol(""))
522-
function Base.getproperty(u::NamedTupleSymbolFix, s::Symbol)
523-
newsym = getfield(u, :sym) == Symbol("") ? s : Symbol(getfield(u, :sym), ".", s)
524-
x = getfield(u, :x)
525-
if newsym in keys(x)
526-
getproperty(x, newsym)
527-
else
528-
NamedTupleSymbolFix(x, newsym)
529-
end
530-
end
531-
Base.getindex(u::NamedTupleSymbolFix, idxs::Int...) = getfield(u, :x)[idxs...]
532-
533515
function compile_user_affect(affect::FunctionalAffect, sys, dvs, ps; kwargs...)
534516
dvs_ind = Dict(reverse(en) for en in enumerate(dvs))
535517
v_inds = map(sym -> dvs_ind[sym], unknowns(affect))
@@ -544,10 +526,9 @@ function compile_user_affect(affect::FunctionalAffect, sys, dvs, ps; kwargs...)
544526
# HACK: filter out eliminated symbols. Not clear this is the right thing to do
545527
# (MTK should keep these symbols)
546528
u = filter(x -> !isnothing(x[2]), collect(zip(unknowns_syms(affect), v_inds))) |>
547-
NamedTuple |> NamedTupleSymbolFix
548-
529+
NamedTuple
549530
p = filter(x -> !isnothing(x[2]), collect(zip(parameters_syms(affect), p_inds))) |>
550-
NamedTuple |> NamedTupleSymbolFix
531+
NamedTuple
551532

552533
let u = u, p = p, user_affect = func(affect), ctx = context(affect)
553534
function (integ)

src/systems/connectors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function generate_isouter(sys::AbstractSystem)
129129
function isouter(sys)::Bool
130130
s = string(nameof(sys))
131131
isconnector(sys) || error("$s is not a connector!")
132-
idx = findfirst(isequal('.'), s)
132+
idx = findfirst(isequal(''), s)
133133
parent_name = Symbol(idx === nothing ? s : s[1:prevind(s, idx)])
134134
parent_name in outer_connectors
135135
end

test/funcaffect.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ i8 = findfirst(==(8.0), sol[:t])
123123
ctx = [0]
124124
function affect4!(integ, u, p, ctx)
125125
ctx[1] += 1
126-
@test u.resistor.v == 1
126+
@test u.resistorv == 1
127127
end
128128
s1 = compose(
129129
ODESystem(Equation[], t, [], [], name = :s1,
@@ -137,7 +137,7 @@ sol = solve(prob, Tsit5())
137137
include("../examples/rc_model.jl")
138138

139139
function affect5!(integ, u, p, ctx)
140-
@test integ.u[u.capacitor.v] 0.3
140+
@test integ.u[u.capacitorv] 0.3
141141
integ.ps[p.C] *= 200
142142
end
143143

test/input_output_handling.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ end
3434
@test get_namespace(x) == ""
3535
@test get_namespace(sys.x) == "sys"
3636
@test get_namespace(sys2.x) == "sys2"
37-
@test get_namespace(sys2.sys.x) == "sys2.sys"
38-
@test get_namespace(sys21.sys1.v) == "sys21.sys1"
37+
@test get_namespace(sys2.sys.x) == "sys2sys"
38+
@test get_namespace(sys21.sys1.v) == "sys21sys1"
3939

4040
@test !is_bound(sys, u)
4141
@test !is_bound(sys, x)

test/inputoutput.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ connected = ODESystem(Equation[], t, [], [], observed = connections,
1919

2020
sys = connected
2121

22-
@variables lorenz1.F lorenz2.F
23-
@test pins(connected) == Variable[lorenz1.F, lorenz2.F]
22+
@variables lorenz1F lorenz2F
23+
@test pins(connected) == Variable[lorenz1F, lorenz2F]
2424
@test isequal(observed(connected),
2525
[connections...,
2626
lorenz1.u ~ lorenz1.x + lorenz1.y - lorenz1.z,
@@ -40,7 +40,7 @@ simplifyeqs(eqs) = Equation.((x -> x.lhs).(eqs), simplify.((x -> x.rhs).(eqs)))
4040

4141
@test isequal(simplifyeqs(equations(connected)), simplifyeqs(collapsed_eqs))
4242

43-
# Variables indicated to be input/output
43+
# Variables indicated to be input/output
4444
@variables x [input = true]
4545
@test hasmetadata(x, Symbolics.option_to_metadata_type(Val(:input)))
4646
@test getmetadata(x, Symbolics.option_to_metadata_type(Val(:input))) == true

test/odesystem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,9 +1109,9 @@ function RealExpressionSystem(; name)
11091109
vars = @variables begin
11101110
x(t)
11111111
z(t)[1:1]
1112-
end # doing a collect on z doesn't work either.
1113-
@named e1 = RealExpression(y = x) # This works perfectly.
1114-
@named e2 = RealExpression(y = z[1]) # This bugs. However, `full_equations(e2)` works as expected.
1112+
end # doing a collect on z doesn't work either.
1113+
@named e1 = RealExpression(y = x) # This works perfectly.
1114+
@named e2 = RealExpression(y = z[1]) # This bugs. However, `full_equations(e2)` works as expected.
11151115
systems = [e1, e2]
11161116
ODESystem(Equation[], t, Iterators.flatten(vars), []; systems, name)
11171117
end
@@ -1166,7 +1166,7 @@ end
11661166
# Namespacing of array variables
11671167
@variables x(t)[1:2]
11681168
@named sys = ODESystem(Equation[], t)
1169-
@test getname(unknowns(sys, x)) == Symbol("sys.x")
1169+
@test getname(unknowns(sys, x)) == :sys₊x
11701170
@test size(unknowns(sys, x)) == size(x)
11711171

11721172
# Issue#2667

test/variable_scope.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ eqs = [0 ~ a
3131

3232
names = ModelingToolkit.getname.(unknowns(sys))
3333
@test :d in names
34-
@test Symbol("sub1.c") in names
35-
@test Symbol("sub1.sub2.b") in names
36-
@test Symbol("sub1.sub2.sub3.a") in names
37-
@test Symbol("sub1.sub2.sub4.a") in names
34+
@test Symbol("sub1c") in names
35+
@test Symbol("sub1sub2b") in names
36+
@test Symbol("sub1sub2sub3a") in names
37+
@test Symbol("sub1sub2sub4a") in names
3838

3939
@named foo = NonlinearSystem(eqs, [a, b, c, d], [])
4040
@named bar = NonlinearSystem(eqs, [a, b, c, d], [])
4141
@test ModelingToolkit.getname(ModelingToolkit.namespace_expr(
4242
ModelingToolkit.namespace_expr(b,
4343
foo),
44-
bar)) == Symbol("bar.b")
44+
bar)) == Symbol("barb")
4545

4646
function renamed(nss, sym)
4747
ModelingToolkit.getname(foldr(ModelingToolkit.renamespace, nss, init = sym))
4848
end
4949

50-
@test renamed([:foo :bar :baz], a) == Symbol("foo.bar.baz.a")
51-
@test renamed([:foo :bar :baz], b) == Symbol("foo.bar.b")
52-
@test renamed([:foo :bar :baz], c) == Symbol("foo.c")
50+
@test renamed([:foo :bar :baz], a) == Symbol("foobarbaza")
51+
@test renamed([:foo :bar :baz], b) == Symbol("foobarb")
52+
@test renamed([:foo :bar :baz], c) == Symbol("fooc")
5353
@test renamed([:foo :bar :baz], d) == :d
5454

5555
@parameters t a b c d e f
@@ -67,12 +67,12 @@ level3 = ODESystem(Equation[], t, [], []; name = :level3) ∘ level2
6767

6868
ps = ModelingToolkit.getname.(parameters(level3))
6969

70-
@test isequal(ps[1], Symbol("level2.level1.level0.a"))
71-
@test isequal(ps[2], Symbol("level2.level1.b"))
72-
@test isequal(ps[3], Symbol("level2.c"))
73-
@test isequal(ps[4], Symbol("level2.level0.d"))
74-
@test isequal(ps[5], Symbol("level1.level0.e"))
75-
@test isequal(ps[6], Symbol("f"))
70+
@test isequal(ps[1], :level2level1level0₊a)
71+
@test isequal(ps[2], :level2level1₊b)
72+
@test isequal(ps[3], :level2₊c)
73+
@test isequal(ps[4], :level2level0₊d)
74+
@test isequal(ps[5], :level1level0₊e)
75+
@test isequal(ps[6], :f)
7676

7777
# Issue@2252
7878
# Tests from PR#2354
@@ -82,4 +82,4 @@ arr0 = ODESystem(Equation[], t, [], arr_p; name = :arr0)
8282
arr1 = ODESystem(Equation[], t, [], []; name = :arr1) arr0
8383
arr_ps = ModelingToolkit.getname.(parameters(arr1))
8484
@test isequal(arr_ps[1], Symbol("xx"))
85-
@test isequal(arr_ps[2], Symbol("arr0.xx"))
85+
@test isequal(arr_ps[2], Symbol("arr0xx"))

0 commit comments

Comments
 (0)