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 171 commits into
base: v10
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
31a7a0a
chore!: bump MAJOR version
AayushSabharwal Apr 14, 2025
8997693
ci: run workflows on PR to v10 branch
AayushSabharwal Apr 14, 2025
5da8129
docs: bump MTK compat
AayushSabharwal Apr 14, 2025
46c93e6
TEMP COMMIT: use branch of MTKStdlib
AayushSabharwal Apr 14, 2025
a408e11
feat: make `@named` always wrap arguments in `ParentScope`
AayushSabharwal Apr 3, 2025
c7569b4
test: test `@named` always wrapping in `ParentScope`
AayushSabharwal Apr 14, 2025
90696fd
refactor: remove `DelayParentScope`
AayushSabharwal Apr 14, 2025
7cdf184
refactor: remove `time_varying_as_func`
AayushSabharwal Apr 14, 2025
c193dcb
test: update tests with removed `time_varying_as_func`
AayushSabharwal Apr 14, 2025
edd0bab
refactor: remove input_idxs output
vyudu Apr 18, 2025
42e0d17
refactor: use new `structural_simplify` in linearization
vyudu Apr 21, 2025
fad65c2
fix: fix linearization tests
vyudu Apr 22, 2025
62b7ebf
test: test updates
vyudu Apr 24, 2025
96601aa
fix input output tests
vyudu Apr 24, 2025
56c83c8
more test fixes
vyudu Apr 25, 2025
352d001
fix: fix sort_eqs and check distrubances in markio
vyudu Apr 28, 2025
33fe355
test: fix input output test
AayushSabharwal May 7, 2025
49f14fa
test: fix usage of old `structural_simplify` io syntax
AayushSabharwal May 7, 2025
334861f
chore!: bump MAJOR version
AayushSabharwal Apr 14, 2025
34ace70
refactor: remove old `System` function
AayushSabharwal Apr 14, 2025
ea62f36
refactor: remove `odesystem.jl`
AayushSabharwal May 14, 2025
d1b96f3
refactor: add `_eq_unordered` to `utils.jl`
AayushSabharwal Apr 20, 2025
42c8493
refactor: move `flatten_equations` to `utils.jl`
AayushSabharwal May 14, 2025
3a899fe
refactor: remove `sdesystem.jl`
AayushSabharwal Apr 20, 2025
2b15625
refactor: move `__num_isdiag_noise`, `get_num_diag_noise` to location…
AayushSabharwal Apr 20, 2025
14dec7a
refactor: remove `discrete_system.jl`
AayushSabharwal Apr 20, 2025
14aa30e
refactor: remove `implicit_discrete_system.jl`
AayushSabharwal Apr 20, 2025
7edc9a9
remove jumpsystem.jl
AayushSabharwal May 14, 2025
4197b6d
refactor: move `JumpType` definition to `utils.jl`
AayushSabharwal Apr 22, 2025
9f2a319
refactor: remove `nonlinearsystem.jl`
AayushSabharwal Apr 20, 2025
a4e236a
refactor: remove `optimizationsystem.jl`
AayushSabharwal Apr 21, 2025
cb16af2
refactor: remove `constraints_system.jl`
AayushSabharwal Apr 21, 2025
e76436f
remove abstractodesystem.jl
AayushSabharwal May 14, 2025
0837615
refactor: do not rely on `ArrayPartition` when unit-checking jumps
AayushSabharwal May 14, 2025
9ae3291
feat: add unified `System` type
AayushSabharwal May 14, 2025
15c663d
feat: add getters for new `System` fields
AayushSabharwal Apr 14, 2025
6e43e51
feat: add hierarchical aggregator functions for jumps, brownians and …
AayushSabharwal Apr 14, 2025
7b5c2d6
refactor: move `constraints` to `abstractsystem.jl`
AayushSabharwal Apr 21, 2025
687bc18
refactor: don't warn about system supertype for `System`
AayushSabharwal Apr 14, 2025
f1ed066
refactor: port `stochastic_integral_transform` and `Girsanov_transform`
AayushSabharwal Apr 20, 2025
f69d5b1
refactor: move `eval_or_rgf` to `codegen_utils.jl`
AayushSabharwal Apr 27, 2025
b6ccf01
feat: allow `GeneratedFunctionWrapper` to compile functions and build…
AayushSabharwal Apr 27, 2025
a360e8e
feat: add `maybe_compile_function`
AayushSabharwal Apr 28, 2025
8f0a130
refactor: fix and document `delay_to_function`, implement it for `Sys…
AayushSabharwal Apr 15, 2025
cca6c28
feat: add initial codegen for `System`
AayushSabharwal Apr 13, 2025
d6e9509
refactor: port `build_explicit_observed_function` to `codegen.jl`
AayushSabharwal Apr 20, 2025
40b549c
feat: add `@fallback_iip_specialize`
AayushSabharwal Apr 14, 2025
df090a3
feat: add `check_compatible_system`
AayushSabharwal Apr 14, 2025
bf9b3aa
feat: implement `generate_initializesystem` for `System`
AayushSabharwal Apr 14, 2025
40c94ea
refactor: remove `generate_factorized_W`
AayushSabharwal Apr 16, 2025
9c3dcee
fix: fix `remake` for `IntervalNonlinearProblem`
AayushSabharwal Apr 16, 2025
9a2ef66
feat: add `replace` kwarg to `add_toterms!`
AayushSabharwal May 14, 2025
7c2f9a4
refactor: centralize problem kwargs handling
AayushSabharwal May 14, 2025
b65651b
refactor: move `filter_kwargs` and `SymbolicTstops` to `problem_utils…
AayushSabharwal Apr 21, 2025
60cf17f
feat: support returning `Expr` from `SymbolicTstops` and `ObservedFun…
AayushSabharwal Apr 28, 2025
16a6c1c
refactor: pass `u0` and `p` as kwargs in `process_SciMLProblem`
AayushSabharwal May 14, 2025
54918b1
feat: add `maybe_codegen_scimlfn` and `maybe_codegen_scimlproblem`
AayushSabharwal Apr 28, 2025
6f77f83
feat: implement `ODEProblem` and `ODEFunction` for `System`
AayushSabharwal Apr 14, 2025
477233a
feat: implement `DDEFunction`, `DDEProblem` for `System`
AayushSabharwal May 14, 2025
288ca82
feat: implement `DAEProblem` and `DAEFunction` for `System`
AayushSabharwal May 14, 2025
194488c
feat: implement `SDEProblem` and `SDEFunction` for `System`
AayushSabharwal May 14, 2025
4a2baf1
feat: implement `SDDEProblem`, `SDDEFunction` for `System`
AayushSabharwal Apr 16, 2025
0ef8ec5
feat: implement `NonlinearProblem`, `NonlinearFunction` for `System`
AayushSabharwal May 14, 2025
99227b9
feat: implement `IntervalNonlinearProblem`, `IntervalNonlinearFunctio…
AayushSabharwal Apr 16, 2025
8094180
feat: implement `ImplicitDiscreteProblem` `ImplicitDiscreteFunction` …
AayushSabharwal May 14, 2025
a40c43d
feat: implement `DiscreteProblem` and `DiscreteFunction` for `System`
AayushSabharwal May 14, 2025
25cf708
feat: allow manually choosing time-independent initialization
AayushSabharwal Apr 17, 2025
bbf3c20
feat: implement `OptimizationProblem` and `OptimizationFunction` for …
AayushSabharwal May 14, 2025
be9fb90
feat: implement `JumpProblem` for `System`
AayushSabharwal May 14, 2025
28aed41
feat: add `InitializationProblem`
AayushSabharwal May 14, 2025
6e50aa7
feat: implement `NonlinearLeastSquaresProblem` for `System`
AayushSabharwal Apr 20, 2025
5d47bca
refactor: port `SCCNonlinearProblem` to separate file
AayushSabharwal Apr 20, 2025
0be3bd2
feat: implement `BVProblem` for `System`
AayushSabharwal May 14, 2025
5a60814
feat: implement `SteadyStateProblem` for `System`
AayushSabharwal Apr 21, 2025
06d0d06
fix: fix `toexpr(::AbstractSystem)`
AayushSabharwal Apr 21, 2025
9955d02
fix: fix `extend(::AbstractSystem)`
AayushSabharwal Apr 21, 2025
39e07a1
fix: fix `substitute(::AbstractSystem, _...)`
AayushSabharwal Apr 21, 2025
9a2a6c4
fix: construct `System` in `@mtkmodel`
AayushSabharwal Apr 21, 2025
9c499d2
docs: fix docstring of `process_SciMLProblem`
AayushSabharwal Apr 21, 2025
f92537c
refactor: allow real values in `costs`
AayushSabharwal Apr 25, 2025
ea51ad0
refactor: remove old clock handling code, retain error messages
AayushSabharwal Apr 21, 2025
c2e96fa
fix: allow simplifying systems with noise
AayushSabharwal Apr 21, 2025
e7e3298
refactor: remove `schedule(sys)`
AayushSabharwal Apr 21, 2025
f3d4152
feat: set system scheduling information in `structural_simplify`
AayushSabharwal Apr 21, 2025
53ca2b4
refactor: remove references to `ODESystem` in source code
AayushSabharwal Apr 21, 2025
2681e2e
refactor: remove `__structural_simplify(::JumpSystem)`
AayushSabharwal Apr 21, 2025
1879c73
refactor: remove references to `SDESystem` in source code
AayushSabharwal Apr 21, 2025
5418f0b
refactor: remove references to `NonlinearSystem`
AayushSabharwal Apr 21, 2025
b52b5dc
refactor: remove references to `DiscreteSystem`
AayushSabharwal Apr 21, 2025
54f10e0
refactor: do not use `sys.substitutions`
AayushSabharwal Apr 22, 2025
db9bbf6
test: replace `ODESystem` with `System`
AayushSabharwal Apr 22, 2025
cc724e5
test: replace `NonlinearSystem` with `System`
AayushSabharwal Apr 22, 2025
67c74ab
test: replace `ImplicitDiscreteSystem` with `System`
AayushSabharwal Apr 22, 2025
aba9bac
test: replace `DiscreteSystem` with `System`
AayushSabharwal Apr 22, 2025
df80744
fix: ensure equations are `Vector{Equation}` in `generate_initializes…
AayushSabharwal Apr 25, 2025
8ea186e
test: fix usage of array equations in test
AayushSabharwal Apr 25, 2025
027b255
test: ensure equations passed to system are `Vector{Equation}`
AayushSabharwal Apr 25, 2025
3d95828
refactor: remove `process_equations`
AayushSabharwal Apr 25, 2025
2c4e42f
docs: document `collect_var!`
AayushSabharwal Apr 25, 2025
7925624
refactor: change default operator in `collect_vars!` to `Symbolics.Op…
AayushSabharwal Apr 25, 2025
5d6d3e7
feat: add `validate_operator`
AayushSabharwal Apr 25, 2025
6fb5e65
refactor: document `collect_vars!` and use `validate_operator`
AayushSabharwal Apr 25, 2025
be31e96
feat: add `is_floatingpoint_symtype`
AayushSabharwal Apr 25, 2025
4dd58e5
refactor: use `is_floatingpoint_symtype` in `is_variable_floatingpoint`
AayushSabharwal Apr 25, 2025
9acd045
test: don't pass dvs/ps to `ODEFunction`
AayushSabharwal Apr 25, 2025
1b0bd9e
test: fix shadowing of `System` in tests
AayushSabharwal Apr 25, 2025
34c80a6
test: pass `u0map` and `tspan` to `ODEProblem`
AayushSabharwal Apr 25, 2025
e36e5fe
test: create `JumpProblem` directly
AayushSabharwal Apr 25, 2025
835849e
test: pass `Vector{Equation}` to `System`
AayushSabharwal Apr 25, 2025
0558839
refactor: remove `build_torn_function`, `tearing_assignments`
AayushSabharwal Apr 27, 2025
9896f76
refactor: remove `get_substitutions`, `has_substitutions` field getters
AayushSabharwal Apr 27, 2025
e35f208
refactor: implement `empty_substitutions` and `get_substitutions` usi…
AayushSabharwal Apr 27, 2025
7ecaf28
refactor: remove `get_substitutions_and_solved_unknowns`
AayushSabharwal Apr 27, 2025
16dac6c
refactor: update `tearing_substitute_expr`, `full_equations` to use `…
AayushSabharwal Apr 27, 2025
da81dd2
refactor: do not use `get_substitutions` in `get_cmap`
AayushSabharwal Apr 27, 2025
842d9e5
test: fix mass matrix tests
AayushSabharwal Apr 27, 2025
702a040
test: fix odesystem tests
AayushSabharwal Apr 27, 2025
931f8dd
refactor: rename `generate_function` to `generate_rhs`
AayushSabharwal Apr 27, 2025
71213bf
fix: fix type-piracy of `Symbolics.rename`
AayushSabharwal Apr 29, 2025
5e03c09
refactor: remove `systems/diffeqs/modelingtoolkitize.jl`
AayushSabharwal Apr 29, 2025
f28f1b1
feat: add `modelingtoolkitize` for `ODEProblem`
AayushSabharwal Apr 29, 2025
64a52c0
feat: add `modelingtoolkitize` for `SDEProblem`
AayushSabharwal Apr 29, 2025
caf1aa4
feat: add `add_accumulations`
AayushSabharwal Apr 29, 2025
66736ed
fix: allow generating callbacks for `System`
AayushSabharwal Apr 29, 2025
b15a451
test: fix `odesystem` tests
AayushSabharwal Apr 29, 2025
65926ed
fix: validate that `Sample` operates on unknowns
AayushSabharwal Apr 29, 2025
cd3feaa
test: fix `test/structural_transformation/utils.jl`
AayushSabharwal Apr 29, 2025
46288c9
test: simplify test for metadata retention in `complete`
AayushSabharwal Apr 29, 2025
f3c839e
test: improve readability of dependency graph tests
AayushSabharwal Apr 29, 2025
e0a009d
test: fix usage of `ODEProblemExpr` in lowering test
AayushSabharwal Apr 29, 2025
7fd94ea
test: remove test for specifying type of system in `@mtkmodel`
AayushSabharwal Apr 29, 2025
8ea2859
test: fix parameter dependencies test
AayushSabharwal Apr 29, 2025
ef2b165
test: fix symbolic events test
AayushSabharwal Apr 29, 2025
4b738c5
test: fix modelingtoolkitize test
AayushSabharwal Apr 29, 2025
100d07f
test: remove outdated test
AayushSabharwal May 1, 2025
bdcf084
refactor: remove old `modelingtoolkitize(::OptimizationProblem)`
AayushSabharwal May 1, 2025
a8ffd99
feat: add `modelingtoolkitize(::OptimizationProblem)`
AayushSabharwal May 1, 2025
eec4378
refactor: remove old `modelingtoolkitize(::NonlinearProblem)`
AayushSabharwal May 1, 2025
84d1a7b
feat: add `modelingtoolkitize(::NonlinearProblem)`
AayushSabharwal May 1, 2025
991ea60
refactor: remove old `modelingtoolkitize(::ODEProblem)` and `::SDEPro…
AayushSabharwal May 1, 2025
5efb80e
feat: add `structural_simplify` for optimization systems
AayushSabharwal May 2, 2025
2f91845
fix: change default `consolidate` to `default_consolidate` in `@mtkmo…
AayushSabharwal May 7, 2025
aedbb36
fix: handle `Shift`s in `is_diff_equation`
AayushSabharwal May 8, 2025
78e55ab
feat: implement `calculate_hessian` and `hessian_sparsity` for `System`
AayushSabharwal May 8, 2025
492f334
feat: make delay processing more modular in `build_function_wrapper`
AayushSabharwal May 8, 2025
c2da34d
fix: fix `generate_cost` for time-dependent (BV) systems
AayushSabharwal May 8, 2025
4a97222
fix: default `build_initializeprob` to `supports_initialization(sys)`
AayushSabharwal May 8, 2025
589a721
fix: disallow simplification of jump systems
AayushSabharwal May 8, 2025
2c5d5ca
fix: remove usage of `is_scalar_noise` kwarg
AayushSabharwal May 8, 2025
613b263
feat: inspect jumps in `collect_scoped_vars!`
AayushSabharwal May 8, 2025
f312962
test: comment out jac/tgrad caching test
AayushSabharwal May 8, 2025
d5fc4fd
test: update BVProblem tests to new semantics
AayushSabharwal May 8, 2025
69604b8
test: update DDE tests to new semantics
AayushSabharwal May 8, 2025
9cafe4b
test: make debugging tests more reproducible
AayushSabharwal May 8, 2025
d4e680a
test: update discrete system tests to new semantics
AayushSabharwal May 8, 2025
e28802a
test: update implicit discrete system tests to new semantics
AayushSabharwal May 8, 2025
d2df47d
test: remove redundant initial values tests
AayushSabharwal May 8, 2025
84bb9d6
test: update initialization system tests to new semantics
AayushSabharwal May 8, 2025
eeaf7eb
test: fix jump system tests
AayushSabharwal May 8, 2025
b3ba2c9
test: remove redundant namespacing tests
AayushSabharwal May 8, 2025
589a501
fix: fix `independent_variables`
AayushSabharwal May 8, 2025
1aa8a6d
feat: export newly added functions
AayushSabharwal May 8, 2025
2d77456
feat: add `noise_to_brownians`
AayushSabharwal May 14, 2025
38098ed
feat: add `convert_system_indepvar`
AayushSabharwal May 14, 2025
333636d
fix: fix structural simplification for SDEs
AayushSabharwal May 14, 2025
8a278c9
refactor: remove `convert_system`
AayushSabharwal May 14, 2025
74129c6
test: fix nonlinearsystem tests
AayushSabharwal May 14, 2025
4eda210
test: fix optimizationsystem tests
AayushSabharwal May 14, 2025
8615d53
test: fix sdesystem tests
AayushSabharwal May 14, 2025
93bfd5e
fix: unwrap in `add_toterms!`, don't override existing values
AayushSabharwal May 14, 2025
3f6c6fc
fix: unwrap `varmap` and add toterms in `better_varmap_to_vars`
AayushSabharwal May 14, 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
1 change: 1 addition & 0 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- v10
tags: '*'
pull_request:

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- 'master'
- v10
tags: '*'
pull_request:

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- master
- 'release-'
- v10
paths-ignore:
- 'docs/**'
push:
Expand Down
10 changes: 8 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ModelingToolkit"
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
authors = ["Yingbo Ma <[email protected]>", "Chris Rackauckas <[email protected]> and contributors"]
version = "9.78.0"
version = "10.0.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -174,6 +174,7 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
OptimizationBase = "bca83a33-5cc9-4baa-983d-23429ab6bcbb"
OptimizationMOI = "fd9f6733-72f4-499f-8506-86b2bdd0dea1"
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Expand All @@ -193,5 +194,10 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[sources]
ModelingToolkitStandardLibrary = { url = "https://github.com/SciML/ModelingToolkitStandardLibrary.jl/", rev = "mtk-v10" }
OptimizationBase = { url = "https://github.com/AayushSabharwal/OptimizationBase.jl", rev = "as/mtk-v10" }
OptimizationMOI = { url = "https://github.com/AayushSabharwal/Optimization.jl", subdir = "lib/OptimizationMOI", rev = "as/mtk-v10" }

[targets]
test = ["AmplNLWriter", "BenchmarkTools", "BoundaryValueDiffEqMIRK", "BoundaryValueDiffEqAscher", "ControlSystemsBase", "DataInterpolations", "DelayDiffEq", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "OrdinaryDiffEq", "OrdinaryDiffEqCore", "OrdinaryDiffEqDefault", "REPL", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq", "Pkg", "JET", "OrdinaryDiffEqNonlinearSolve", "Logging"]
test = ["AmplNLWriter", "BenchmarkTools", "BoundaryValueDiffEqMIRK", "BoundaryValueDiffEqAscher", "ControlSystemsBase", "DataInterpolations", "DelayDiffEq", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "OrdinaryDiffEq", "OrdinaryDiffEqCore", "OrdinaryDiffEqDefault", "REPL", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq", "Pkg", "JET", "OrdinaryDiffEqNonlinearSolve", "Logging", "OptimizationBase"]
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Documenter = "1"
DynamicQuantities = "^0.11.2, 0.12, 1"
FMI = "0.14"
FMIZoo = "1"
ModelingToolkit = "8.33, 9"
ModelingToolkit = "10"
ModelingToolkitStandardLibrary = "2.19"
NonlinearSolve = "3, 4"
Optim = "1.7"
Expand Down
20 changes: 6 additions & 14 deletions docs/src/basics/Composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,42 +135,34 @@ sys.y = u * 1.1
In a hierarchical system, variables of the subsystem get namespaced by the name of the system they are in. This prevents naming clashes, but also enforces that every unknown and parameter is local to the subsystem it is used in. In some cases it might be desirable to have variables and parameters that are shared between subsystems, or even global. This can be accomplished as follows.

```julia
@parameters a b c d e f
@parameters a b c d

# a is a local variable
b = ParentScope(b) # b is a variable that belongs to one level up in the hierarchy
c = ParentScope(ParentScope(c)) # ParentScope can be nested
d = DelayParentScope(d) # skips one level before applying ParentScope
e = DelayParentScope(e, 2) # second argument allows skipping N levels
f = GlobalScope(f)
d = GlobalScope(d)

p = [a, b, c, d, e, f]
p = [a, b, c, d]

level0 = ODESystem(Equation[], t, [], p; name = :level0)
level1 = ODESystem(Equation[], t, [], []; name = :level1) level0
parameters(level1)
#level0₊a
#b
#c
#level0₊d
#level0₊e
#f
#d
level2 = ODESystem(Equation[], t, [], []; name = :level2) level1
parameters(level2)
#level1₊level0₊a
#level1₊b
#c
#level0₊d
#level1₊level0₊e
#f
#d
level3 = ODESystem(Equation[], t, [], []; name = :level3) level2
parameters(level3)
#level2₊level1₊level0₊a
#level2₊level1₊b
#level2₊c
#level2₊level0₊d
#level1₊level0₊e
#f
#d
```

## Structural Simplify
Expand Down
75 changes: 38 additions & 37 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 @@ -159,30 +157,39 @@ 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("systems/optimization/modelingtoolkitize.jl")
include("problems/compatibility.jl")
include("problems/odeproblem.jl")
include("problems/ddeproblem.jl")
include("problems/daeproblem.jl")
include("problems/sdeproblem.jl")
include("problems/sddeproblem.jl")
include("problems/nonlinearproblem.jl")
include("problems/intervalnonlinearproblem.jl")
include("problems/implicitdiscreteproblem.jl")
include("problems/discreteproblem.jl")
include("problems/optimizationproblem.jl")
include("problems/jumpproblem.jl")
include("problems/initializationproblem.jl")
include("problems/sccnonlinearproblem.jl")
include("problems/bvproblem.jl")

include("modelingtoolkitize/common.jl")
include("modelingtoolkitize/odeproblem.jl")
include("modelingtoolkitize/sdeproblem.jl")
include("modelingtoolkitize/optimizationproblem.jl")
include("modelingtoolkitize/nonlinearproblem.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 All @@ -204,11 +211,6 @@ include("structural_transformation/StructuralTransformations.jl")
@reexport using .StructuralTransformations
include("inputoutput.jl")

for S in subtypes(ModelingToolkit.AbstractSystem)
S = nameof(S)
@eval convert_system(::Type{<:$S}, sys::$S) = sys
end

const t_nounits = let
only(@independent_variables t)
end
Expand All @@ -226,7 +228,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 @@ -262,16 +264,14 @@ export AbstractTimeDependentSystem,
AbstractTimeIndependentSystem,
AbstractMultivariateSystem

export ODESystem,
ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system,
add_accumulations, System
export ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system_indepvar,
System, OptimizationSystem, JumpSystem, SDESystem, NonlinearSystem
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 @@ -280,7 +280,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 @@ -292,25 +291,27 @@ 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,
noise_to_brownians
export PDESystem
export Differential, expand_derivatives, @derivatives
export Equation, ConstrainedEquation
export Term, Sym
export SymScope, LocalScope, ParentScope, DelayParentScope, GlobalScope
export independent_variable, equations, controls, observed, full_equations
export SymScope, LocalScope, ParentScope, GlobalScope
export independent_variable, equations, controls, observed, full_equations, jumps, cost,
brownians
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,
generate_W
export calculate_jacobian, generate_jacobian, generate_rhs, generate_custom_function,
generate_W, calculate_hessian
export calculate_control_jacobian, generate_control_jacobian
export calculate_tgrad, generate_tgrad
export calculate_gradient, generate_gradient
export generate_cost, calculate_cost_gradient, generate_cost_gradient
export calculate_factorized_W, generate_factorized_W
export calculate_hessian, generate_hessian
export calculate_cost_hessian, generate_cost_hessian
export calculate_massmatrix, generate_diffusion_function
export stochastic_integral_transform
export TearingState
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
Loading