Skip to content

Commit a297ee4

Browse files
authored
Merge pull request #2471 from SciML/myb/array
Format
2 parents ea31448 + bf562bb commit a297ee4

File tree

7 files changed

+52
-47
lines changed

7 files changed

+52
-47
lines changed

NEWS.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,43 @@
22

33
### Upgrade guide
44

5-
- The function `states` is renamed to `unknowns`. In a similar vein:
6-
- `unknown_states` is now `solved_unknowns`.
7-
- `get_states` is `get_unknowns`.
8-
- `get_unknown_states` is now `get_solved_unknowns`.
9-
- The default backend for using units in models is now `DynamicQuantities.jl` instead of
10-
`Unitful.jl`.
11-
- ModelingToolkit.jl now exports common definitions of `t` (time independent variable)
12-
and `D` (the first derivative with respect to `t`). Any models made using ModelingToolkit.jl
13-
should leverage these common definitions. There are three variants:
14-
- `t` and `D` use DynamicQuantities.jl units. This is the default for standard library
15-
components.
16-
- `t_unitful` and `D_unitful` use Unitful.jl units.
17-
- `t_nounits` and `D_nounits` are unitless.
18-
- `ODAEProblem` is deprecated in favor of `ODEProblem`.
19-
- Specifying the independent variable for an `ODESystem` is now mandatory. The `ODESystem(eqs)`
20-
constructor is removed.
21-
- Systems must be marked as `complete` before creating `*Function`/`*FunctionExpr`/`*Problem`/
22-
`*ProblemExpr`. Typically this involved using `@mtkbuild` to create the system or calling
23-
`structural_simplify` on an existing system.
24-
- All systems will perform parameter splitting by default. Problems created using ModelingToolkit.jl
25-
systems will have a custom struct instead of a `Vector` of parameters. The internals of this
26-
type are undocumented and subject to change without notice or a breaking release. Parameter values
27-
can be queried, updated or manipulated using SciMLStructures.jl or SymbolicIndexingInterface.jl.
28-
This also requires that the symbolic type of a parameter match its assigned value. For example,
29-
`@parameters p` will always use a `Float64` value for `p`. To use `Int` instead, use
30-
`@parameters p::Int`. Array-valued parameters must be array symbolics; `@parameters p = [1.0, 2.0]`
31-
is now invalid and must be changed to `@parameters p[1:2] = [1.0, 2.0]`. The index of a parameter
32-
in the system is also not guaranteed to be an `Int`, and will instead be a custom undocumented type.
33-
To restore the old behavior:
34-
- Pass the `split = false` keyword to `structural_simplify`. E.g. `ss = structural_simplify(sys; split = false)`.
35-
- Pass `split = false` to `@mtkbuild`. E.g. `@mtkbuild sys = ODESystem(...) split = false`.
36-
- Discrete-time system using `Difference` are unsupported. Instead, use the new `Clock`-based syntax.
37-
- Automatic scalarization has been removed, meaning that vector variables need to be treated with proper vector
38-
equations. For example, `[p[1] => 1.0, p[2] => 2.0]` is no longer allowed in default equations, use
39-
`[p => [1.0, 2.0]]` instead. Also, array equations like for `@variables u[1:2]` have `D(u) ~ A*u` as an
40-
array equation. If the scalarized version is desired, use `scalarize(u)`.
5+
- The function `states` is renamed to `unknowns`. In a similar vein:
6+
7+
+ `unknown_states` is now `solved_unknowns`.
8+
+ `get_states` is `get_unknowns`.
9+
+ `get_unknown_states` is now `get_solved_unknowns`.
10+
11+
- The default backend for using units in models is now `DynamicQuantities.jl` instead of
12+
`Unitful.jl`.
13+
- ModelingToolkit.jl now exports common definitions of `t` (time independent variable)
14+
and `D` (the first derivative with respect to `t`). Any models made using ModelingToolkit.jl
15+
should leverage these common definitions. There are three variants:
16+
17+
+ `t` and `D` use DynamicQuantities.jl units. This is the default for standard library
18+
components.
19+
+ `t_unitful` and `D_unitful` use Unitful.jl units.
20+
+ `t_nounits` and `D_nounits` are unitless.
21+
- `ODAEProblem` is deprecated in favor of `ODEProblem`.
22+
- Specifying the independent variable for an `ODESystem` is now mandatory. The `ODESystem(eqs)`
23+
constructor is removed.
24+
- Systems must be marked as `complete` before creating `*Function`/`*FunctionExpr`/`*Problem`/
25+
`*ProblemExpr`. Typically this involved using `@mtkbuild` to create the system or calling
26+
`structural_simplify` on an existing system.
27+
- All systems will perform parameter splitting by default. Problems created using ModelingToolkit.jl
28+
systems will have a custom struct instead of a `Vector` of parameters. The internals of this
29+
type are undocumented and subject to change without notice or a breaking release. Parameter values
30+
can be queried, updated or manipulated using SciMLStructures.jl or SymbolicIndexingInterface.jl.
31+
This also requires that the symbolic type of a parameter match its assigned value. For example,
32+
`@parameters p` will always use a `Float64` value for `p`. To use `Int` instead, use
33+
`@parameters p::Int`. Array-valued parameters must be array symbolics; `@parameters p = [1.0, 2.0]`
34+
is now invalid and must be changed to `@parameters p[1:2] = [1.0, 2.0]`. The index of a parameter
35+
in the system is also not guaranteed to be an `Int`, and will instead be a custom undocumented type.
36+
To restore the old behavior:
37+
38+
+ Pass the `split = false` keyword to `structural_simplify`. E.g. `ss = structural_simplify(sys; split = false)`.
39+
+ Pass `split = false` to `@mtkbuild`. E.g. `@mtkbuild sys = ODESystem(...) split = false`.
40+
- Discrete-time system using `Difference` are unsupported. Instead, use the new `Clock`-based syntax.
41+
- Automatic scalarization has been removed, meaning that vector variables need to be treated with proper vector
42+
equations. For example, `[p[1] => 1.0, p[2] => 2.0]` is no longer allowed in default equations, use
43+
`[p => [1.0, 2.0]]` instead. Also, array equations like for `@variables u[1:2]` have `D(u) ~ A*u` as an
44+
array equation. If the scalarized version is desired, use `scalarize(u)`.

docs/src/basics/Validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Units may be assigned with the following syntax.
1010
using ModelingToolkit, Unitful
1111
@variables t [unit = u"s"] x(t) [unit = u"m"] g(t) w(t) [unit = "Hz"]
1212
13-
@variables(t, [unit = u"s"], x(t), [unit = u"m"], g(t), w(t),[unit = "Hz"])
13+
@variables(t, [unit = u"s"], x(t), [unit = u"m"], g(t), w(t), [unit = "Hz"])
1414
1515
@variables(begin
1616
t, [unit = u"s"],

src/systems/abstractsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,11 +1393,11 @@ macro mtkbuild(exprs...)
13931393
named_expr = ModelingToolkit.named_expr(expr)
13941394
name = named_expr.args[1]
13951395
kwargs = if length(exprs) > 1
1396-
NamedTuple{Tuple(ex.args[1] for ex in Base.tail(exprs))}(Tuple(ex.args[2] for ex in Base.tail(exprs)))
1396+
NamedTuple{Tuple(ex.args[1] for ex in Base.tail(exprs))}(Tuple(ex.args[2]
1397+
for ex in Base.tail(exprs)))
13971398
else
13981399
(;)
13991400
end
1400-
@show kwargs
14011401
esc(quote
14021402
$named_expr
14031403
$name = $structural_simplify($name; $(kwargs)...)

src/systems/systems.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ The optional argument `io` may take a tuple `(inputs, outputs)`.
1616
This will convert all `inputs` to parameters and allow them to be unconnected, i.e.,
1717
simplification will allow models where `n_unknowns = n_equations - n_inputs`.
1818
"""
19-
function structural_simplify(sys::AbstractSystem, io = nothing; simplify = false, split = true,
19+
function structural_simplify(
20+
sys::AbstractSystem, io = nothing; simplify = false, split = true,
2021
kwargs...)
2122
newsys′ = __structural_simplify(sys, io; simplify, kwargs...)
2223
if newsys′ isa Tuple

test/dq_units.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ ODESystem(eqs, t, name = :sys, checks = false)
4343
# connection validation
4444
@connector function Pin(; name)
4545
sts = @variables(v(t)=1.0, [unit = u"V"],
46-
i(t)=1.0,[unit = u"A", connect = Flow])
46+
i(t)=1.0, [unit = u"A", connect = Flow])
4747
ODESystem(Equation[], t, sts, []; name = name)
4848
end
4949
@connector function OtherPin(; name)
5050
sts = @variables(v(t)=1.0, [unit = u"mV"],
51-
i(t)=1.0,[unit = u"mA", connect = Flow])
51+
i(t)=1.0, [unit = u"mA", connect = Flow])
5252
ODESystem(Equation[], t, sts, []; name = name)
5353
end
5454
@connector function LongPin(; name)

test/modelingtoolkitize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ problem = ODEProblem(SIR!, u0, tspan, p)
253253
sys = complete(modelingtoolkitize(problem))
254254

255255
@parameters t
256-
@test all(isequal.(parameters(sys), getproperty.(@variables(β, η, ω, φ, σ,μ), :val)))
257-
@test all(isequal.(Symbol.(unknowns(sys)), Symbol.(@variables(S(t), I(t), R(t),C(t)))))
256+
@test all(isequal.(parameters(sys), getproperty.(@variables(β, η, ω, φ, σ, μ), :val)))
257+
@test all(isequal.(Symbol.(unknowns(sys)), Symbol.(@variables(S(t), I(t), R(t), C(t)))))
258258

259259
# https://github.com/SciML/ModelingToolkit.jl/issues/1158
260260

test/units.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ ODESystem(eqs, t, name = :sys, checks = false)
6666
# connection validation
6767
@connector function Pin(; name)
6868
sts = @variables(v(t)=1.0, [unit = u"V"],
69-
i(t)=1.0,[unit = u"A", connect = Flow])
69+
i(t)=1.0, [unit = u"A", connect = Flow])
7070
ODESystem(Equation[], t, sts, []; name = name)
7171
end
7272
@connector function OtherPin(; name)
7373
sts = @variables(v(t)=1.0, [unit = u"mV"],
74-
i(t)=1.0,[unit = u"mA", connect = Flow])
74+
i(t)=1.0, [unit = u"mA", connect = Flow])
7575
ODESystem(Equation[], t, sts, []; name = name)
7676
end
7777
@connector function LongPin(; name)
7878
sts = @variables(v(t)=1.0, [unit = u"V"],
7979
i(t)=1.0, [unit = u"A", connect = Flow],
80-
x(t)=1.0,[unit = NoUnits])
80+
x(t)=1.0, [unit = NoUnits])
8181
ODESystem(Equation[], t, sts, []; name = name)
8282
end
8383
@named p1 = Pin()

0 commit comments

Comments
 (0)