Skip to content

Commit

Permalink
Interface with MTK and allow using symbolic variables in get/set para…
Browse files Browse the repository at this point in the history
…m and get state (#190)

* fix the successful step function not having nan

* mtk integration works

* improve docs

* get state also works with symbolics!

* add changelog

* add MTK to test deps

* mention MTK interfacing in CoupledODEs

* rename current_state to observe_State

* MTK works woth stroboscopic

* ProjectedDS works as well

* remove unecessary set_parameter extensions

* finish MTK integration

* export the function referrencing the system

* use getu/setu directly on numeric containers

Requires SciML/SymbolicIndexingInterface.jl#33 to be merged!

* make sure tests pass

* simplify referrenced sys function: we only need sys now

* all tests pass!

* finish changelog

* better/clearer handling of observation index

* use the referrenced SciML Problem instead of System!

* correct retrieval of referrenced system

* allow `set_u` to set a specific component of the system! with symbolic!

* make sure function is only used with core systems

* Throw error if no referrenced MTK

* simplify set_state!@

* fix set state for parallel systems

* request merged and tagged functionality

* trigger tests

* fix tests

* update docs

* finish changelog

* correct set_paramters!

* remove examples from index

* fix stroboscopic tests

* fix successful step tests

* fix docs!
  • Loading branch information
Datseris authored Jan 25, 2024
1 parent c580bd2 commit ea3f650
Show file tree
Hide file tree
Showing 23 changed files with 459 additions and 15,404 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# v3.5.0

Dynamical systems that have been constructed from `DEProblem`s that themselves
have been constructed from ModelingToolkit.jl keep a reference to the symbolic
model and all symbolic variables. Accessing a `DynamicalSystem` using symbolic variables
is possible via the functions [`observe_state`](@ref), [`set_state!`](@ref),
[`current_parameter`](@ref) and [`set_parameter!`](@ref).
The referenced MTK model corresponding to the dynamical system can be obtained with
`model = referrenced_sciml_model(ds::DynamicalSystem)`.

See also the online overarching tutorial for an example.

At the moment this is only possible for `CoupledODEs` and its derivative systems, as these are the only systems that can be made by a `DEProblem`, however it should be easy to allow e.g., `DeterministicIterated` to be created by a `DiscreteProblem`.

The integration is supported by the functions `current_parameter`, `set_parameter!` where a symbolic MTK parameter can be given as an index. In `observe_state`, a state variable or observed variable symbol can be given.

Also:

- Crucial bugfix for `successful_step` that was not working properly for discrete time systems.

# v3.4.0

Better error handling for `diffeq` and `CoupledODEs`: passing a keyword was possible but should not have been.

# v3.3.0

Sorry, I forgot what goes here!

# v3.2.0
The keyword `Dt` can now be used instead of `Δt` in `trajectory` if access to unicode isn't available.

Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DynamicalSystemsBase"
uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git"
version = "3.4.3"
version = "3.5.0"

[deps]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand All @@ -13,6 +13,7 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StateSpaceSets = "40b095a5-5852-4c12-98c7-d43bf788e795"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"

[compat]
ForwardDiff = "0.10"
Expand All @@ -22,4 +23,5 @@ Roots = "1, 2"
SciMLBase = "1.19.5, 2"
StateSpaceSets = "1"
Statistics = "1"
SymbolicIndexingInterface = "0.3.4"
julia = "1.9"
14 changes: 11 additions & 3 deletions docs/juliadynamics-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// under documenter/_variables or documenter/_overrides. But some stuff are Bulma defaults
// as well, so you may need to look them up too: https://bulma.io/documentation/customize/variables/


////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Thse define the JuliaDynamics template:
Expand Down Expand Up @@ -87,6 +86,8 @@ $input-focus-border-color: $mainwhite;

$documenter-docstring-shadow: 3px 3px 4px invert($shadow-color);



// Admonition stuff
$admbg: lighten-color($body-background-color, 0.5);
$admonition-background: (
Expand All @@ -97,16 +98,23 @@ $admonition-header-background: (
'default': #ba3f1f, 'warning': #a88b17, 'danger': #c7524c,
'success': #42ac68, 'info': #28c);

// Deprecations
$admonition-body-color: null;
$admonition-body-color: null;
$admonition-header-color: null;

// All secondary themes have to be nested in a theme--$(themename) class. When Documenter
// switches themes, it applies this class to <html> and then disables the primary
// stylesheet.
@import "documenter/utilities";
@import "documenter/variables";
@import "bulma/utilities/all";
@import "bulma/base/minireset.sass";
@import "bulma/base/helpers.sass";
@import "bulma/helpers/_all.sass";

html.theme--#{$themename} {
@extend .is-size-7 !optional;

@import "bulma/base/generic.sass";

@import "documenter/overrides";
Expand All @@ -127,7 +135,7 @@ html.theme--#{$themename} {
@import "documenter/theme_overrides";

// $shadow-color: #202224;

#documenter .docs-sidebar { // This makes sidebar have shadow at all displays
border-right: none;
box-shadow: 1.2*$shadow-size 0rem 1*$shadow-blur invert($shadow-color);
Expand Down
13 changes: 11 additions & 2 deletions docs/juliadynamics-darkdefs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ $input-focus-border-color: $mainwhite;

$documenter-docstring-shadow: 3px 3px 4px invert($shadow-color);



// Admonition stuff
$admbg: lighten-color($body-background-color, 0.5);
$admonition-background: (
Expand All @@ -50,16 +52,23 @@ $admonition-header-background: (
'default': #ba3f1f, 'warning': #a88b17, 'danger': #c7524c,
'success': #42ac68, 'info': #28c);

// Deprecations
$admonition-body-color: null;
$admonition-body-color: null;
$admonition-header-color: null;

// All secondary themes have to be nested in a theme--$(themename) class. When Documenter
// switches themes, it applies this class to <html> and then disables the primary
// stylesheet.
@import "documenter/utilities";
@import "documenter/variables";
@import "bulma/utilities/all";
@import "bulma/base/minireset.sass";
@import "bulma/base/helpers.sass";
@import "bulma/helpers/_all.sass";

html.theme--#{$themename} {
@extend .is-size-7 !optional;

@import "bulma/base/generic.sass";

@import "documenter/overrides";
Expand All @@ -80,7 +89,7 @@ html.theme--#{$themename} {
@import "documenter/theme_overrides";

// $shadow-color: #202224;

#documenter .docs-sidebar { // This makes sidebar have shadow at all displays
border-right: none;
box-shadow: 1.2*$shadow-size 0rem 1*$shadow-blur invert($shadow-color);
Expand Down
9 changes: 4 additions & 5 deletions docs/juliadynamics-light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// under documenter/_variables or documenter/_overrides. But some stuff are Bulma defaults
// as well, so you may need to look them up too: https://bulma.io/documentation/customize/variables/


////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Thse define the JuliaDynamics template:
Expand Down Expand Up @@ -93,10 +92,6 @@ $documenter-sidebar-size: 1.0em; // the default is 1.0 as well
$input-hover-border-color: $secondcolor;
$input-focus-border-color: $mainwhite;

// Include the original theme which will now use the updated variables.
// This should be the last thing in the SCSS file.
@import "documenter-light";

#documenter .docs-sidebar { // This makes sidebar have shadow at all displays
border-right: none;
box-shadow: 1.2*$shadow-size 0rem 1*$shadow-blur $shadow-color;
Expand All @@ -112,3 +107,7 @@ $input-focus-border-color: $mainwhite;
}
}
}

// Include the original theme which will now use the updated variables.
// This should be the last thing in the SCSS file.
@import "documenter-light";
8 changes: 4 additions & 4 deletions docs/juliadynamics-lightdefs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ $documenter-sidebar-size: 1.0em; // the default is 1.0 as well
$input-hover-border-color: $secondcolor;
$input-focus-border-color: $mainwhite;

// Include the original theme which will now use the updated variables.
// This should be the last thing in the SCSS file.
@import "documenter-light";

#documenter .docs-sidebar { // This makes sidebar have shadow at all displays
border-right: none;
box-shadow: 1.2*$shadow-size 0rem 1*$shadow-blur $shadow-color;
Expand All @@ -65,3 +61,7 @@ $input-focus-border-color: $mainwhite;
}
}
}

// Include the original theme which will now use the updated variables.
// This should be the last thing in the SCSS file.
@import "documenter-light";
1 change: 0 additions & 1 deletion docs/juliadynamics-style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// under documenter/_variables or documenter/_overrides. But some stuff are Bulma defaults
// as well, so you may need to look them up too: https://bulma.io/documentation/customize/variables/


////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Thse define the JuliaDynamics template:
Expand Down
37 changes: 9 additions & 28 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
cd(@__DIR__)

import Downloads
Downloads.download(
"https://raw.githubusercontent.com/JuliaDynamics/doctheme/master/apply_style.jl",
joinpath(@__DIR__, "apply_style.jl")
)
include("apply_style.jl")

using DynamicalSystemsBase

DYNAMICALSYSTEMSBASE_PAGES = [
pages = [
"index.md",
]
using DynamicalSystemsBase.SciMLBase

makedocs(
modules = [DynamicalSystemsBase, SciMLBase, StateSpaceSets],
format = Documenter.HTML(
prettyurls = CI,
assets = [
asset("https://fonts.googleapis.com/css?family=Montserrat|Source+Code+Pro&display=swap", class=:css),
],
),
sitename = "DynamicalSystemsBase.jl",
authors = "George Datseris",
pages = DYNAMICALSYSTEMSBASE_PAGES,
doctest = false,
draft = false,
import Downloads
Downloads.download(
"https://raw.githubusercontent.com/JuliaDynamics/doctheme/master/build_docs_with_style.jl",
joinpath(@__DIR__, "build_docs_with_style.jl")
)
include("build_docs_with_style.jl")

if CI
deploydocs(
repo = "github.com/JuliaDynamics/DynamicalSystemsBase.jl.git",
target = "build",
push_preview = true
)
end
build_docs_with_style(pages,
DynamicalSystemsBase, SciMLBase, StateSpaceSets;
)
Loading

0 comments on commit ea3f650

Please sign in to comment.