Skip to content

feat: add unified System type #3543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 176 commits into
base: v10
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
1d9c6ee
feat: add unified `System` type
AayushSabharwal Apr 7, 2025
f28a525
feat: add `is_discrete_system`
AayushSabharwal Apr 13, 2025
d5bb3a8
feat: add initial codegen for `System`
AayushSabharwal Apr 13, 2025
d214774
feat: add `is_dde` to `System`
AayushSabharwal Apr 13, 2025
6b6f47d
feat: add more codegen implementation
AayushSabharwal Apr 13, 2025
b91115a
refactor: remove old `System` function
AayushSabharwal Apr 14, 2025
0e494a3
refactor: change defaults of `costs` and `consolidate`
AayushSabharwal Apr 14, 2025
84cd0c6
feat: implement `is_time_dependent` for `System`
AayushSabharwal Apr 14, 2025
d0e2b88
feat: add getters for new `System` fields
AayushSabharwal Apr 14, 2025
ad09ce5
feat: add hierarchical aggregator functions for jumps, brownians and …
AayushSabharwal Apr 14, 2025
aa7b87f
feat: add `check_complete`
AayushSabharwal Apr 14, 2025
5d24923
feat: add `@fallback_iip_specialize`
AayushSabharwal Apr 14, 2025
bae1201
feat: add `check_compatible_system`
AayushSabharwal Apr 14, 2025
eab2273
feat: implement `ODEProblem` and `ODEFunction` for `System`
AayushSabharwal Apr 14, 2025
fd305d5
feat: implement `generate_initializesystem` for `System`
AayushSabharwal Apr 14, 2025
1d9700c
refactor: don't warn about system supertype for `System`
AayushSabharwal Apr 14, 2025
133ffb7
feat: add `flatten(::System)`
AayushSabharwal Apr 14, 2025
6c0246e
refactor: compile functions in `generate_*`
AayushSabharwal Apr 16, 2025
09cbaea
refactor: use new compiled `generate_*` functions
AayushSabharwal Apr 15, 2025
d59434a
refactor: centralize mass matrix and W sparsity handling
AayushSabharwal Apr 15, 2025
69762a9
refactor: centralize problem `kwargs` handling
AayushSabharwal Apr 15, 2025
2f22ef3
refactor: modularize compatibility checks
AayushSabharwal Apr 15, 2025
6219b7f
refactor: fix and document `delay_to_function`, implement it for `Sys…
AayushSabharwal Apr 15, 2025
71599bf
feat: implement `DDEProblem` and `DDEFunction` for `System`
AayushSabharwal Apr 15, 2025
08994d5
feat: implement `DAEProblem` and `DAEFunction` for `System`
AayushSabharwal Apr 15, 2025
afb0039
refactor: remove `generate_factorized_W`
AayushSabharwal Apr 16, 2025
6216694
feat: support `SDEProblem` and `SDEFunction` for `System`
AayushSabharwal Apr 16, 2025
2186981
feat: implement `SDDEProblem`, `SDDEFunction` for `System`
AayushSabharwal Apr 16, 2025
e7d368a
feat: implement `NonlinearProblem` and `NonlinearFunction` for `System`
AayushSabharwal Apr 16, 2025
19fbb43
fix: fix `remake` for `IntervalNonlinearProblem`
AayushSabharwal Apr 16, 2025
ccbd6a0
feat: implement `IntervalNonlinearProblem`, `IntervalNonlinearFunctio…
AayushSabharwal Apr 16, 2025
9da8b36
feat: implement `DiscreteProblem` and `DiscreteFunction` for `System`
AayushSabharwal Apr 17, 2025
1e004cb
feat: add `check_is_continuous` to relevant compatibility checks
AayushSabharwal Apr 17, 2025
69073d0
feat: implement `ImplicitDiscreteProblem`, `ImplicitDiscreteFunction`…
AayushSabharwal Apr 17, 2025
ec2ed57
feat: allow manually choosing time-independent initialization
AayushSabharwal Apr 17, 2025
282545c
feat: implement `BVProblem` for `System`
AayushSabharwal Apr 17, 2025
036a9fa
feat: implement `OptimizationProblem`, `OptimizationFunction` for `Sy…
AayushSabharwal Apr 18, 2025
5d210a9
feat: implement `supports_initialization(::System)`
AayushSabharwal Apr 19, 2025
1cb451c
feat: implement `JumpProblem` for `System`
AayushSabharwal Apr 19, 2025
3c2fb63
refactor: move `InitializationProblem` to its own file
AayushSabharwal Apr 19, 2025
9ba48b9
feat: add `isscheduled` to `System`
AayushSabharwal Apr 19, 2025
f6f8915
refactor: move improved handling of ODE costs/constraints to `System`
AayushSabharwal Apr 19, 2025
47978dd
feat: implement `Base.:(==)` for `System`
AayushSabharwal Apr 19, 2025
b3d7a4d
refactor: remove `odesystem.jl`
AayushSabharwal Apr 20, 2025
b8a00b5
refactor: add `_eq_unordered` to `utils.jl`
AayushSabharwal Apr 20, 2025
bf72507
refactor: port `build_explicit_observed_function` to `codegen.jl`
AayushSabharwal Apr 20, 2025
cd4edc4
refactor: remove `sdesystem.jl`
AayushSabharwal Apr 20, 2025
2aa44b3
refactor: port `stochastic_integral_transform` and `Girsanov_transform`
AayushSabharwal Apr 20, 2025
4cc06d1
refactor: move `__num_isdiag_noise` to location where it is used
AayushSabharwal Apr 20, 2025
a8ae8cf
refactor: move `shift_u0map_forward` to `discreteproblem.jl`
AayushSabharwal Apr 20, 2025
32774c9
refactor: remove `discrete_system.jl`
AayushSabharwal Apr 20, 2025
11e9169
refactor: remove `implicit_discrete_system.jl`
AayushSabharwal Apr 20, 2025
ff4692a
refactor: move jumpsystem functions to generalized locations
AayushSabharwal Apr 20, 2025
72de6b5
refactor: remove `jumpsystem.jl`
AayushSabharwal Apr 20, 2025
c41b0cc
feat: implement `NonlinearLeastSquaresProblem` for `System`
AayushSabharwal Apr 20, 2025
81bbe70
refactor: port `SCCNonlinearProblem` to separate file
AayushSabharwal Apr 20, 2025
83a82c6
refactor: remove `nonlinearsystem.jl`
AayushSabharwal Apr 20, 2025
413d41d
refactor: move `constraints` to `abstractsystem.jl`
AayushSabharwal Apr 21, 2025
9e34b0a
refactor: remove `optimizationsystem.jl`
AayushSabharwal Apr 21, 2025
62fc4e9
refactor: remove `constraints_system.jl`
AayushSabharwal Apr 21, 2025
0c4dc17
docs: add docstring for new `BVProblem` constructor
AayushSabharwal Apr 21, 2025
7eb1ff1
refactor: improve `BVProblem` validation
AayushSabharwal Apr 21, 2025
8c3a391
feat: implement `SteadyStateProblem` for `System`
AayushSabharwal Apr 21, 2025
9aaf7dc
fix: fix `toexpr(::AbstractSystem)`
AayushSabharwal Apr 21, 2025
9078b61
fix: fix `extend(::AbstractSystem)`
AayushSabharwal Apr 21, 2025
3236f71
fix: fix `substitute(::AbstractSystem, _...)`
AayushSabharwal Apr 21, 2025
d069036
fix: construct `System` in `@mtkmodel`
AayushSabharwal Apr 21, 2025
e90da41
docs: fix docstring of `process_SciMLProblem`
AayushSabharwal Apr 21, 2025
8593c7d
refactor: move `filter_kwargs` and `SymbolicTstops` to `problem_utils…
AayushSabharwal Apr 21, 2025
1900978
feat: add `schedule` field in `System`
AayushSabharwal Apr 21, 2025
3c749f3
refactor: move `flatten_equations` to `utils.jl`
AayushSabharwal Apr 21, 2025
27e617a
refactor: remove old clock handling code, retain error messages
AayushSabharwal Apr 21, 2025
75f9d9a
fix: add temporary error message when simplifying systems with `noise…
AayushSabharwal Apr 21, 2025
92f3d56
refactor: remove `abstractodesystem.jl`
AayushSabharwal Apr 21, 2025
919a641
refactor: remove `schedule(sys)`
AayushSabharwal Apr 21, 2025
0de53f1
feat: set system scheduling information in `structural_simplify`
AayushSabharwal Apr 21, 2025
262bde1
refactor: remove `AbstractODESystem`
AayushSabharwal Apr 21, 2025
cd1ffc8
refactor: remove references to `ODESystem` in source code
AayushSabharwal Apr 21, 2025
b171279
refactor: remove `__structural_simplify(::JumpSystem)`
AayushSabharwal Apr 21, 2025
4caf8c5
refactor: remove references to `SDESystem` in source code
AayushSabharwal Apr 21, 2025
b8c5352
refactor: remove references to `NonlinearSystem`
AayushSabharwal Apr 21, 2025
fd1cacb
refactor: remove references to `DiscreteSystem`
AayushSabharwal Apr 21, 2025
1b9f91c
refactor: do not use `sys.substitutions`
AayushSabharwal Apr 22, 2025
6945337
refactor: move `JumpType` definition to `utils.jl`
AayushSabharwal Apr 22, 2025
ff084c0
feat: `include` newly added files
AayushSabharwal Apr 22, 2025
df03117
feat: add fallback for `_eq_unordered` in non-array case
AayushSabharwal Apr 22, 2025
e1e8c2a
refactor: improve `System` constructors
AayushSabharwal Apr 22, 2025
aaa9636
fix: fix `==` and `hash` implementations for `System`
AayushSabharwal Apr 22, 2025
cc984fb
feat: add utility constructors for `OptimizationSystem` and `JumpSystem`
AayushSabharwal Apr 22, 2025
3848460
test: replace `ODESystem` with `System`
AayushSabharwal Apr 22, 2025
b277af2
feat: add utility constructor for `SDESystem`
AayushSabharwal Apr 22, 2025
c04a0aa
test: replace `NonlinearSystem` with `System`
AayushSabharwal Apr 22, 2025
4aeb8fb
test: replace `ImplicitDiscreteSystem` with `System`
AayushSabharwal Apr 22, 2025
5f64721
test: replace `DiscreteSystem` with `System`
AayushSabharwal Apr 22, 2025
367bd22
refactor: do not accept `dvs` and `ps` in `XFunction` constructors
AayushSabharwal Apr 25, 2025
24d930e
fix: ensure equations are `Vector{Equation}` in `generate_initializes…
AayushSabharwal Apr 25, 2025
02f8809
test: fix usage of array equations in test
AayushSabharwal Apr 25, 2025
54fa64c
test: ensure equations passed to system are `Vector{Equation}`
AayushSabharwal Apr 25, 2025
3f120e8
refactor: remove `process_equations`
AayushSabharwal Apr 25, 2025
1ac662b
docs: document `collect_var!`
AayushSabharwal Apr 25, 2025
a063b00
refactor: change default operator in `collect_vars!` to `Symbolics.Op…
AayushSabharwal Apr 25, 2025
58648af
feat: add `validate_operator`
AayushSabharwal Apr 25, 2025
f8c0568
refactor: document `collect_vars!` and use `validate_operator`
AayushSabharwal Apr 25, 2025
cac9011
fix: fix error message for events in time-independent systems
AayushSabharwal Apr 25, 2025
bbdb6fb
refactor: do not use `process_equations` in `System` constructor
AayushSabharwal Apr 25, 2025
bf69b49
fix: fix default `costs` in `System` constructor
AayushSabharwal Apr 25, 2025
efecbe5
feat: add `is_floatingpoint_symtype`
AayushSabharwal Apr 25, 2025
519938f
refactor: use `is_floatingpoint_symtype` in `is_variable_floatingpoint`
AayushSabharwal Apr 25, 2025
29e38e8
refactor: allow real values in `costs`
AayushSabharwal Apr 25, 2025
4570a2f
feat: add `initializesystem` field to `System`
AayushSabharwal Apr 25, 2025
010ec83
fix: fix brownians passed to `System` constructor
AayushSabharwal Apr 25, 2025
274745d
feat: add `System(::Equation, ...)` constructor
AayushSabharwal Apr 25, 2025
6d4f366
fix: fix `flatten(::System)`
AayushSabharwal Apr 25, 2025
1d22c63
fix: unwrap costs in `System` constructor
AayushSabharwal Apr 25, 2025
424a582
test: don't pass dvs/ps to `ODEFunction`
AayushSabharwal Apr 25, 2025
d7e4cd5
test: fix shadowing of `System` in tests
AayushSabharwal Apr 25, 2025
aeebf31
test: pass `u0map` and `tspan` to `ODEProblem`
AayushSabharwal Apr 25, 2025
5bda914
test: create `JumpProblem` directly
AayushSabharwal Apr 25, 2025
9e42c77
test: pass `Vector{Equation}` to `System`
AayushSabharwal Apr 25, 2025
acef5e2
fix: correctly order unknowns in `System` constructor
AayushSabharwal Apr 27, 2025
aee746a
refactor: remove `build_torn_function`, `tearing_assignments`
AayushSabharwal Apr 27, 2025
27094a8
refactor: remove `get_substitutions`, `has_substitutions` field getters
AayushSabharwal Apr 27, 2025
1f578cc
refactor: implement `empty_substitutions` and `get_substitutions` usi…
AayushSabharwal Apr 27, 2025
bb286e0
refactor: remove `get_substitutions_and_solved_unknowns`
AayushSabharwal Apr 27, 2025
e5e06dd
refactor: update `tearing_substitute_expr`, `full_equations` to use `…
AayushSabharwal Apr 27, 2025
a6bc774
refactor: do not use `get_substitutions` in `get_cmap`
AayushSabharwal Apr 27, 2025
2a35cfd
fix: fix noise equations unit checking
AayushSabharwal Apr 27, 2025
d678ac2
fix: convert `constraints` to appropriate type
AayushSabharwal Apr 27, 2025
fb4ee04
test: fix mass matrix tests
AayushSabharwal Apr 27, 2025
926c460
test: fix odesystem tests
AayushSabharwal Apr 27, 2025
a9d6985
fix: fix bugs in `@fallback_iip_specialize`, handle static array prob…
AayushSabharwal Apr 27, 2025
69e6dc3
refactor: rename `generate_function` to `generate_rhs`
AayushSabharwal Apr 27, 2025
d599ff2
refactor: move `eval_or_rgf` to `codegen_utils.jl`
AayushSabharwal Apr 27, 2025
251d7dd
feat: allow `GeneratedFunctionWrapper` to compile functions and build…
AayushSabharwal Apr 27, 2025
7a01657
feat: add `maybe_compile_function`
AayushSabharwal Apr 28, 2025
3a26132
refactor: use `maybe_compile_function` in codegen
AayushSabharwal Apr 28, 2025
44d3032
feat: support returning `Expr` from `SymbolicTstops` and `ObservedFun…
AayushSabharwal Apr 28, 2025
a41e141
feat: handle `expression = Val{true}` in `process_kwargs`
AayushSabharwal Apr 28, 2025
48b9ea5
feat: add `maybe_codegen_scimlfn` and `maybe_codegen_scimlproblem`
AayushSabharwal Apr 28, 2025
0645dce
feat: add `expression` kwarg to `ODEFunction`, `ODEProblem`
AayushSabharwal Apr 28, 2025
9e58feb
feat: add `expression` kwarg to `SteadyStateProblem`
AayushSabharwal Apr 28, 2025
54e13a0
feat: add `expression` kwarg to `BVProblem`
AayushSabharwal Apr 28, 2025
760ea13
feat: add `expression` kwarg to `DAEFunction`, `DAEProblem`
AayushSabharwal Apr 28, 2025
6c2f20d
feat: add `expression` kwarg to `DDEFunction`, `DDEProblem`
AayushSabharwal Apr 28, 2025
29ed82e
feat: add `expression` kwarg to `SDEFunction`, `SDEProblem`
AayushSabharwal Apr 28, 2025
ac3de03
feat: add `expression` kwarg to `SDDEFunction`, `SDDEProblem`
AayushSabharwal Apr 28, 2025
58530f1
feat: add `expression` kwarg to `DiscreteFunction`, `DiscreteProblem`
AayushSabharwal Apr 28, 2025
6fe32dc
feat: add `expression` kwarg for `NonlinearFunction`, `NonlinearProbl…
AayushSabharwal Apr 28, 2025
7024bcf
feat: add `expression` kwarg to `OptimizationFunction`, `Optimization…
AayushSabharwal Apr 28, 2025
54d7f6d
feat: add `expression` kwarg to `ImplicitDiscreteFunction`, `Implicit…
AayushSabharwal Apr 28, 2025
585fc80
feat: add `expression` kwarg to `IntervalNonlinearFunction`, `Interva…
AayushSabharwal Apr 28, 2025
7400e58
fix: fix type-piracy of `Symbolics.rename`
AayushSabharwal Apr 29, 2025
3efe756
refactor: remove `systems/diffeqs/modelingtoolkitize.jl`
AayushSabharwal Apr 29, 2025
8005721
feat: add `modelingtoolkitize` for `ODEProblem`
AayushSabharwal Apr 29, 2025
3a6a460
feat: add `modelingtoolkitize` for `SDEProblem`
AayushSabharwal Apr 29, 2025
b749d26
feat: add `add_accumulations`
AayushSabharwal Apr 29, 2025
3ed5385
fix: allow generating callbacks for `System`
AayushSabharwal Apr 29, 2025
9f9aa1f
feat: add `preface` to `System`
AayushSabharwal Apr 29, 2025
ad26dfb
test: fix `odesystem` tests
AayushSabharwal Apr 29, 2025
c619111
refactor: store jumps as `Vector{JumpType}`
AayushSabharwal Apr 29, 2025
40a5670
fix: validate units of jumps
AayushSabharwal Apr 29, 2025
54f321e
fix: respect scoping in `System` constructor variable discovery
AayushSabharwal Apr 29, 2025
d58945c
fix: fix `flatten(::System)`
AayushSabharwal Apr 29, 2025
cc47cfd
feat: export `jumps`
AayushSabharwal Apr 29, 2025
63d4679
fix: validate that `Sample` operates on unknowns
AayushSabharwal Apr 29, 2025
90bb6d1
test: fix `test/structural_transformation/utils.jl`
AayushSabharwal Apr 29, 2025
9e5fbc7
test: simplify test for metadata retention in `complete`
AayushSabharwal Apr 29, 2025
ba1ed91
test: improve readability of dependency graph tests
AayushSabharwal Apr 29, 2025
198a80c
test: fix usage of `ODEProblemExpr` in lowering test
AayushSabharwal Apr 29, 2025
3818e75
test: remove test for specifying type of system in `@mtkmodel`
AayushSabharwal Apr 29, 2025
e8c5254
test: fix parameter dependencies test
AayushSabharwal Apr 29, 2025
48db08f
test: fix symbolic events test
AayushSabharwal Apr 29, 2025
294b3b1
fix: fix `calculate_jacobian`
AayushSabharwal Apr 29, 2025
145d87b
fix: respect `return_sparsity` in `generate_cost_hessian`
AayushSabharwal Apr 29, 2025
5e43f70
test: use `System` in `examples/*.jl`
AayushSabharwal Apr 29, 2025
79b2b05
test: fix modelingtoolkitize test
AayushSabharwal Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions examples/electrical_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ using ModelingToolkit: t_nounits as t, D_nounits as D

@connector function Pin(; name)
sts = @variables v(t) [guess = 1.0] i(t) [guess = 1.0, connect = Flow]
ODESystem(Equation[], t, sts, []; name = name)
System(Equation[], t, sts, []; name = name)
end

@component function Ground(; name)
@named g = Pin()
eqs = [g.v ~ 0]
compose(ODESystem(eqs, t, [], []; name = name), g)
compose(System(eqs, t, [], []; name = name), g)
end

@component function OnePort(; name)
Expand All @@ -20,7 +20,7 @@ end
eqs = [v ~ p.v - n.v
0 ~ p.i + n.i
i ~ p.i]
compose(ODESystem(eqs, t, sts, []; name = name), p, n)
compose(System(eqs, t, sts, []; name = name), p, n)
end

@component function Resistor(; name, R = 1.0)
Expand All @@ -30,7 +30,7 @@ end
eqs = [
v ~ i * R
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
extend(System(eqs, t, [], ps; name = name), oneport)
end

@component function Capacitor(; name, C = 1.0)
Expand All @@ -40,7 +40,7 @@ end
eqs = [
D(v) ~ i / C
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
extend(System(eqs, t, [], ps; name = name), oneport)
end

@component function ConstantVoltage(; name, V = 1.0)
Expand All @@ -50,7 +50,7 @@ end
eqs = [
V ~ v
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
extend(System(eqs, t, [], ps; name = name), oneport)
end

@component function Inductor(; name, L = 1.0)
Expand All @@ -60,12 +60,12 @@ end
eqs = [
D(i) ~ v / L
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
extend(System(eqs, t, [], ps; name = name), oneport)
end

@connector function HeatPort(; name)
@variables T(t) [guess = 293.15] Q_flow(t) [guess = 0.0, connect = Flow]
ODESystem(Equation[], t, [T, Q_flow], [], name = name)
System(Equation[], t, [T, Q_flow], [], name = name)
end

@component function HeatingResistor(; name, R = 1.0, TAmbient = 293.15, alpha = 1.0)
Expand All @@ -79,7 +79,7 @@ end
h.Q_flow ~ -v * p.i # -LossPower
v ~ p.v - n.v
0 ~ p.i + n.i]
compose(ODESystem(eqs, t, [v, RTherm], [R, TAmbient, alpha],
compose(System(eqs, t, [v, RTherm], [R, TAmbient, alpha],
name = name), p, n, h)
end

Expand All @@ -90,6 +90,6 @@ end
eqs = [
D(h.T) ~ h.Q_flow / C
]
compose(ODESystem(eqs, t, [], [rho, V, cp],
compose(System(eqs, t, [], [rho, V, cp],
name = name), h)
end
2 changes: 1 addition & 1 deletion examples/rc_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ rc_eqs = [connect(source.p, resistor.p)
connect(capacitor.n, source.n)
connect(capacitor.n, ground.g)]

@named rc_model = ODESystem(rc_eqs, t)
@named rc_model = System(rc_eqs, t)
rc_model = compose(rc_model, [resistor, capacitor, source, ground])
4 changes: 2 additions & 2 deletions examples/serial_inductor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ eqs = [connect(source.p, resistor.p)
connect(source.n, inductor2.n)
connect(inductor2.n, ground.g)]

@named ll_model = ODESystem(eqs, t)
@named ll_model = System(eqs, t)
ll_model = compose(ll_model, [source, resistor, inductor1, inductor2, ground])

@named source = ConstantVoltage(V = 10.0)
Expand All @@ -29,5 +29,5 @@ eqs = [connect(source.p, inductor1.p)
connect(resistor2.n, inductor2.p)
connect(source.n, inductor2.n)
connect(inductor2.n, ground.g)]
@named ll2_model = ODESystem(eqs, t)
@named ll2_model = System(eqs, t)
ll2_model = compose(ll2_model, [source, resistor1, resistor2, inductor1, inductor2, ground])
57 changes: 31 additions & 26 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ TODO
abstract type AbstractSystem end
abstract type AbstractTimeDependentSystem <: AbstractSystem end
abstract type AbstractTimeIndependentSystem <: AbstractSystem end
abstract type AbstractODESystem <: AbstractTimeDependentSystem end
abstract type AbstractMultivariateSystem <: AbstractSystem end
abstract type AbstractOptimizationSystem <: AbstractTimeIndependentSystem end
abstract type AbstractDiscreteSystem <: AbstractTimeDependentSystem end

function independent_variable end

Expand Down Expand Up @@ -158,30 +156,40 @@ include("systems/connectors.jl")
include("systems/analysis_points.jl")
include("systems/imperative_affect.jl")
include("systems/callbacks.jl")
include("systems/system.jl")
include("systems/codegen_utils.jl")
include("systems/codegen.jl")
include("systems/problem_utils.jl")
include("linearization.jl")

include("systems/optimization/constraints_system.jl")
include("systems/optimization/optimizationsystem.jl")
include("problems/compatibility.jl")
include("problems/odeproblem.jl")
include("problems/daeproblem.jl")
include("problems/ddeproblem.jl")
include("problems/sdeproblem.jl")
include("problems/sddeproblem.jl")
include("problems/bvproblem.jl")
include("problems/discreteproblem.jl")
include("problems/implicitdiscreteproblem.jl")
include("problems/nonlinearproblem.jl")
include("problems/intervalnonlinearproblem.jl")
include("problems/sccnonlinearproblem.jl")
include("problems/initializationproblem.jl")
include("problems/jumpproblem.jl")
include("problems/optimizationproblem.jl")

include("modelingtoolkitize/common.jl")
include("modelingtoolkitize/odeproblem.jl")
include("modelingtoolkitize/sdeproblem.jl")

include("systems/optimization/modelingtoolkitize.jl")

include("systems/nonlinear/nonlinearsystem.jl")
include("systems/nonlinear/homotopy_continuation.jl")
include("systems/diffeqs/odesystem.jl")
include("systems/diffeqs/sdesystem.jl")
include("systems/diffeqs/abstractodesystem.jl")
include("systems/nonlinear/modelingtoolkitize.jl")
include("systems/nonlinear/initializesystem.jl")
include("systems/diffeqs/first_order_transform.jl")
include("systems/diffeqs/modelingtoolkitize.jl")
include("systems/diffeqs/basic_transformations.jl")

include("systems/discrete_system/discrete_system.jl")
include("systems/discrete_system/implicit_discrete_system.jl")

include("systems/jumps/jumpsystem.jl")

include("systems/pde/pdesystem.jl")

include("systems/sparsematrixclil.jl")
Expand Down Expand Up @@ -225,7 +233,7 @@ const D = Differential(t)
PrecompileTools.@compile_workload begin
using ModelingToolkit
@variables x(ModelingToolkit.t_nounits)
@named sys = ODESystem([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits)
@named sys = System([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits)
prob = ODEProblem(structural_simplify(sys), [x => 30.0], (0, 100), [], jac = true)
@mtkmodel __testmod__ begin
@constants begin
Expand Down Expand Up @@ -261,16 +269,14 @@ export AbstractTimeDependentSystem,
AbstractTimeIndependentSystem,
AbstractMultivariateSystem

export ODESystem,
ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system,
add_accumulations, System
export ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system,
System, OptimizationSystem, JumpSystem, SDESystem
export DAEFunctionExpr, DAEProblemExpr
export SDESystem, SDEFunction, SDEFunctionExpr, SDEProblemExpr
export SDEFunction, SDEFunctionExpr, SDEProblemExpr
export SystemStructure
export DiscreteSystem, DiscreteProblem, DiscreteFunction, DiscreteFunctionExpr
export ImplicitDiscreteSystem, ImplicitDiscreteProblem, ImplicitDiscreteFunction,
export DiscreteProblem, DiscreteFunction, DiscreteFunctionExpr
export ImplicitDiscreteProblem, ImplicitDiscreteFunction,
ImplicitDiscreteFunctionExpr
export JumpSystem
export ODEProblem, SDEProblem
export NonlinearFunction, NonlinearFunctionExpr
export NonlinearProblem, NonlinearProblemExpr
Expand All @@ -279,7 +285,6 @@ export IntervalNonlinearProblem, IntervalNonlinearProblemExpr
export OptimizationProblem, OptimizationProblemExpr, constraints
export SteadyStateProblem, SteadyStateProblemExpr
export JumpProblem
export NonlinearSystem, OptimizationSystem, ConstraintsSystem
export alias_elimination, flatten
export connect, domain_connect, @connector, Connection, AnalysisPoint, Flow, Stream,
instream
Expand All @@ -291,19 +296,19 @@ export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbanc
hasunit, getunit, hasconnect, getconnect,
hasmisc, getmisc, state_priority
export ode_order_lowering, dae_order_lowering, liouville_transform,
change_independent_variable, substitute_component
change_independent_variable, substitute_component, add_accumulations
export PDESystem
export Differential, expand_derivatives, @derivatives
export Equation, ConstrainedEquation
export Term, Sym
export SymScope, LocalScope, ParentScope, GlobalScope
export independent_variable, equations, controls, observed, full_equations
export independent_variable, equations, controls, observed, full_equations, jumps
export initialization_equations, guesses, defaults, parameter_dependencies, hierarchy
export structural_simplify, expand_connections, linearize, linearization_function,
LinearizationProblem
export solve

export calculate_jacobian, generate_jacobian, generate_function, generate_custom_function,
export calculate_jacobian, generate_jacobian, generate_rhs, generate_custom_function,
generate_W
export calculate_control_jacobian, generate_control_jacobian
export calculate_tgrad, generate_tgrad
Expand Down
26 changes: 26 additions & 0 deletions src/discretedomain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SymbolicUtils.promote_symtype(::Type{<:SampleTime}, t...) = Real
Base.nameof(::SampleTime) = :SampleTime
SymbolicUtils.isbinop(::SampleTime) = false

function validate_operator(op::SampleTime, args, iv; context = nothing) end

# Shift

"""
Expand Down Expand Up @@ -68,6 +70,13 @@ Base.hash(D::Shift, u::UInt) = hash(D.steps, hash(D.t, xor(u, 0x055640d6d952f101
Base.:^(D::Shift, n::Integer) = Shift(D.t, D.steps * n)
Base.literal_pow(f::typeof(^), D::Shift, ::Val{n}) where {n} = Shift(D.t, D.steps * n)

function validate_operator(op::Shift, args, iv; context = nothing)
isequal(op.t, iv) || throw(OperatorIndepvarMismatchError(op, iv, context))
op.steps <= 0 || error("""
Only non-positive shifts are allowed. Found shift of $(op.steps) in $context.
""")
end

hasshift(eq::Equation) = hasshift(eq.lhs) || hasshift(eq.rhs)

"""
Expand Down Expand Up @@ -128,6 +137,18 @@ Base.show(io::IO, D::Sample) = print(io, "Sample(", D.clock, ")")
Base.:(==)(D1::Sample, D2::Sample) = isequal(D1.clock, D2.clock)
Base.hash(D::Sample, u::UInt) = hash(D.clock, xor(u, 0x055640d6d952f101))

function validate_operator(op::Sample, args, iv; context = nothing)
arg = unwrap(only(args))
if !is_variable_floatingpoint(arg)
throw(ContinuousOperatorDiscreteArgumentError(op, arg, context))
end
if isparameter(arg)
throw(ArgumentError("""
Expected argument of $op to be an unknown, found $arg which is a parameter.
"""))
end
end

"""
hassample(O)

Expand Down Expand Up @@ -156,6 +177,11 @@ SymbolicUtils.isbinop(::Hold) = false

Hold(x) = Hold()(x)

function validate_operator(op::Hold, args, iv; context = nothing)
# TODO: maybe validate `VariableTimeDomain`?
return nothing
end

"""
hashold(O)

Expand Down
12 changes: 6 additions & 6 deletions src/inputoutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ has_var(ex, x) = x ∈ Set(get_variables(ex))

"""
(f_oop, f_ip), x_sym, p_sym, io_sys = generate_control_function(
sys::AbstractODESystem,
sys::System,
inputs = unbound_inputs(sys),
disturbance_inputs = nothing;
implicit_dae = false,
Expand Down Expand Up @@ -193,7 +193,7 @@ t = 0
f[1](x, inputs, p, t)
```
"""
function generate_control_function(sys::AbstractODESystem, inputs = unbound_inputs(sys),
function generate_control_function(sys::AbstractSystem, inputs = unbound_inputs(sys),
disturbance_inputs = disturbances(sys);
disturbance_argument = false,
implicit_dae = false,
Expand Down Expand Up @@ -344,7 +344,7 @@ The structure represents a model of a disturbance, along with the input variable
# Fields:

- `input`: The variable affected by the disturbance.
- `model::M`: A model of the disturbance. This is typically an `ODESystem`, but type that implements [`ModelingToolkit.get_disturbance_system`](@ref)`(dist::DisturbanceModel) -> ::ODESystem` is supported.
- `model::M`: A model of the disturbance. This is typically a `System`, but type that implements [`ModelingToolkit.get_disturbance_system`](@ref)`(dist::DisturbanceModel) -> ::System` is supported.
"""
struct DisturbanceModel{M}
input::Any
Expand All @@ -354,7 +354,7 @@ end
DisturbanceModel(input, model; name) = DisturbanceModel(input, model, name)

# Point of overloading for libraries, e.g., to be able to support disturbance models from ControlSystemsBase
function get_disturbance_system(dist::DisturbanceModel{<:ODESystem})
function get_disturbance_system(dist::DisturbanceModel{System})
dist.model
end

Expand Down Expand Up @@ -395,7 +395,7 @@ c = 10 # Damping coefficient
eqs = [connect(torque.flange, inertia1.flange_a)
connect(inertia1.flange_b, spring.flange_a, damper.flange_a)
connect(inertia2.flange_a, spring.flange_b, damper.flange_b)]
model = ODESystem(eqs, t; systems = [torque, inertia1, inertia2, spring, damper],
model = System(eqs, t; systems = [torque, inertia1, inertia2, spring, damper],
name = :model)
model = complete(model)
model_outputs = [model.inertia1.w, model.inertia2.w, model.inertia1.phi, model.inertia2.phi]
Expand Down Expand Up @@ -427,7 +427,7 @@ function add_input_disturbance(sys, dist::DisturbanceModel, inputs = nothing; kw

eqs = [dsys.input.u[1] ~ d
dist.input ~ u + dsys.output.u[1]]
augmented_sys = ODESystem(eqs, t, systems = [dsys], name = gensym(:outer))
augmented_sys = System(eqs, t, systems = [dsys], name = gensym(:outer))
augmented_sys = extend(augmented_sys, sys)

(f_oop, f_ip), dvs, p, io_sys = generate_control_function(augmented_sys, all_inputs,
Expand Down
10 changes: 5 additions & 5 deletions src/linearization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The `simplified_sys` has undergone [`structural_simplify`](@ref) and had any occ

# Arguments:

- `sys`: An [`ODESystem`](@ref). This function will automatically apply simplification passes on `sys` and return the resulting `simplified_sys`.
- `sys`: A [`System`](@ref) of ODEs. This function will automatically apply simplification passes on `sys` and return the resulting `simplified_sys`.
- `inputs`: A vector of variables that indicate the inputs of the linearized input-output model.
- `outputs`: A vector of variables that indicate the outputs of the linearized input-output model.
- `simplify`: Apply simplification in tearing.
Expand Down Expand Up @@ -640,15 +640,15 @@ function plant(; name)
@variables u(t)=0 y(t)=0
eqs = [D(x) ~ -x + u
y ~ x]
ODESystem(eqs, t; name = name)
System(eqs, t; name = name)
end

function ref_filt(; name)
@variables x(t)=0 y(t)=0
@variables u(t)=0 [input = true]
eqs = [D(x) ~ -2 * x + u
y ~ x]
ODESystem(eqs, t, name = name)
System(eqs, t, name = name)
end

function controller(kp; name)
Expand All @@ -657,7 +657,7 @@ function controller(kp; name)
eqs = [
u ~ kp * (r - y),
]
ODESystem(eqs, t; name = name)
System(eqs, t; name = name)
end

@named f = ref_filt()
Expand All @@ -668,7 +668,7 @@ connections = [f.y ~ c.r # filtered reference to controller reference
c.u ~ p.u # controller output to plant input
p.y ~ c.y]

@named cl = ODESystem(connections, t, systems = [f, c, p])
@named cl = System(connections, t, systems = [f, c, p])

lsys0, ssys = linearize(cl, [f.u], [p.x])
desired_order = [f.x, p.x]
Expand Down
Loading
Loading