Skip to content

Commit f508be8

Browse files
Merge pull request #2466 from AayushSabharwal/as/changelog
docs: update NEWS.md with v9 update notes
2 parents 4b81cfa + 5a9667d commit f508be8

File tree

6 files changed

+62
-18
lines changed

6 files changed

+62
-18
lines changed

NEWS.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
1-
# ModelingToolkit v8 Release Notes
1+
# ModelingToolkit v9 Release Notes
22

33
### Upgrade guide
44

5-
- `connect` should not be overloaded by users anymore. `[connect = Flow]`
6-
informs ModelingToolkit that particular variable in a connector ought to sum
7-
to zero, and by default, variables are equal in a connection. Please check out
8-
[acausal components tutorial](https://docs.sciml.ai/ModelingToolkit/stable/tutorials/acausal_components/)
9-
for examples.
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)`.

src/systems/abstractsystem.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ $(TYPEDSIGNATURES)
376376
Mark a system as completed. If a system is complete, the system will no longer
377377
namespace its subsystems or variables, i.e. `isequal(complete(sys).v.i, v.i)`.
378378
"""
379-
function complete(sys::AbstractSystem)
380-
if has_index_cache(sys)
379+
function complete(sys::AbstractSystem; split = true)
380+
if split && has_index_cache(sys)
381381
@set! sys.index_cache = IndexCache(sys)
382382
end
383383
isdefined(sys, :complete) ? (@set! sys.complete = true) : sys
@@ -1388,12 +1388,19 @@ macro component(expr)
13881388
esc(component_post_processing(expr, false))
13891389
end
13901390

1391-
macro mtkbuild(expr)
1391+
macro mtkbuild(exprs...)
1392+
expr = exprs[1]
13921393
named_expr = ModelingToolkit.named_expr(expr)
13931394
name = named_expr.args[1]
1395+
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)))
1397+
else
1398+
(;)
1399+
end
1400+
@show kwargs
13941401
esc(quote
13951402
$named_expr
1396-
$name = $structural_simplify($name)
1403+
$name = $structural_simplify($name; $(kwargs)...)
13971404
end)
13981405
end
13991406

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ function process_DEProblem(constructor, sys::AbstractODESystem, u0map, parammap;
793793
ps = parameters(sys)
794794
iv = get_iv(sys)
795795

796-
u0, _, defs = get_u0_p(sys,
796+
u0, _p, defs = get_u0_p(sys,
797797
u0map,
798798
parammap;
799799
tofloat,
@@ -803,7 +803,11 @@ function process_DEProblem(constructor, sys::AbstractODESystem, u0map, parammap;
803803
u0 = u0_constructor(u0)
804804
end
805805

806-
p = MTKParameters(sys, parammap)
806+
if has_index_cache(sys) && get_index_cache(sys) !== nothing
807+
p = MTKParameters(sys, parammap)
808+
else
809+
p = _p
810+
end
807811

808812
if implicit_dae && du0map !== nothing
809813
ddvs = map(Differential(iv), dvs)

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ function process_NonlinearProblem(constructor, sys::NonlinearSystem, u0map, para
355355
ps = parameters(sys)
356356

357357
u0, p, defs = get_u0_p(sys, u0map, parammap; tofloat, use_union)
358-
p = MTKParameters(sys, parammap)
358+
if has_index_cache(sys) && get_index_cache(sys) !== nothing
359+
p = MTKParameters(sys, parammap)
360+
end
359361
check_eqs_u0(eqs, dvs, u0; kwargs...)
360362

361363
f = constructor(sys, dvs, ps, u0; jac = jac, checkbounds = checkbounds,

src/systems/optimization/optimizationsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0map,
631631
end
632632
end
633633

634-
function structural_simplify(sys::OptimizationSystem; kwargs...)
634+
function structural_simplify(sys::OptimizationSystem; split = true, kwargs...)
635635
sys = flatten(sys)
636636
cons = constraints(sys)
637637
econs = Equation[]
@@ -658,6 +658,6 @@ function structural_simplify(sys::OptimizationSystem; kwargs...)
658658
neweqs = fixpoint_sub.(equations(sys), (subs,))
659659
@set! sys.op = length(neweqs) == 1 ? first(neweqs) : neweqs
660660
@set! sys.unknowns = newsts
661-
sys = complete(sys)
661+
sys = complete(sys; split)
662662
return sys
663663
end

src/systems/systems.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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,
19+
function structural_simplify(sys::AbstractSystem, io = nothing; simplify = false, split = true,
2020
kwargs...)
2121
newsys′ = __structural_simplify(sys, io; simplify, kwargs...)
2222
if newsys′ isa Tuple
@@ -25,8 +25,8 @@ function structural_simplify(sys::AbstractSystem, io = nothing; simplify = false
2525
else
2626
newsys = newsys′
2727
end
28-
@set! newsys.parent = complete(sys)
29-
newsys = complete(newsys)
28+
@set! newsys.parent = complete(sys; split)
29+
newsys = complete(newsys; split)
3030
if newsys′ isa Tuple
3131
idxs = [parameter_index(newsys, i) for i in io[1]]
3232
return newsys, idxs

0 commit comments

Comments
 (0)