You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bfc0f7c
Browse filesBrowse the repository at this point in the historyBrowse files
docs: update MTK example for ModelingToolkit v11 (#200)
* docs: update MTK example for ModelingToolkit v11
The `@mtkmodel` DSL was removed in ModelingToolkit v11 in favor of the
functional component form (`@component function ... System(eqs, t; name) end`).
This updates the quad-tank parameter-fitting example accordingly:
- `@mtkmodel QuadtankModel begin ... end` -> `@component function QuadtankModel(; name) ... end`
- array variable defaults must match size: `h(t)[1:4] = 0` -> `= zeros(4)`
- `ModelingToolkit.defaults(io_sys)[pi]` -> `ModelingToolkit.getdefault(pi)`
Verified end-to-end on ModelingToolkit v11.36.0; the estimated parameters
still match the true values. Output block, benchmark timing, and the
tested-version note in the warning are updated to match.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs: fix wrapper name in MTK example prose
The prose referred to `discrete_dynamics_mtk` but the code defines the
wrapper as `discrete_dynamics_wrapper`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@@ -59,7 +58,7 @@ We then specify the inputs and outputs of this model, since they are arrays in t
59
58
```math
60
59
\dot x = f(x, u, p, t)
61
60
```
62
-
from MTK, we call `ModelingToolkit.generate_control_function`. This example assumes that the system model has an external input, ``u``. If your example does not have this, you may leave this argument empty. This returns two versions of this function, where the second one operates in place (modifying its first argument). This function also returns the state variables chosen, the parameters of the model as well as a simplified system with inputs and outputs. The function returned from `ModelingToolkit.generate_control_function` expects all the parameters of the system to be provided, but we only want to optimize a few of them. We thus wrap this function in `discrete_dynamics_mtk` in order to insert the optimized parameters into a parameter array that contains also the non-optimized parameters. We make use of the function `similar` to ensure that the final parameter array has the correct type (Dual numbers for AD will be used).
61
+
from MTK, we call `ModelingToolkit.generate_control_function`. This example assumes that the system model has an external input, ``u``. If your example does not have this, you may leave this argument empty. This returns two versions of this function, where the second one operates in place (modifying its first argument). This function also returns the state variables chosen, the parameters of the model as well as a simplified system with inputs and outputs. The function returned from `ModelingToolkit.generate_control_function` expects all the parameters of the system to be provided, but we only want to optimize a few of them. We thus wrap this function in `discrete_dynamics_wrapper` in order to insert the optimized parameters into a parameter array that contains also the non-optimized parameters. We make use of the function `similar` to ensure that the final parameter array has the correct type (Dual numbers for AD will be used).
63
62
64
63
For good performance, we wrap all the glue code in a function `get_mtk_dynamics` so that we avoid the use of too many global variables.
65
64
@@ -77,7 +76,7 @@ function get_mtk_dynamics(mtkmodel, inputs, outputs, tunable_p) # A wrapper func
77
76
continuous_dynamics = f_oop # This is ẋ = f(x, u, p, t)
ModelingToolkit is a fast moving target that breaks frequently. The example below was tested with ModelingToolkit v10.0.1, but is not run as part of the build process for this documentation and is not to be considered a supported interface between ControlSystemIdentification and ModelingToolkit.
169
+
ModelingToolkit is a fast moving target that breaks frequently. This example was tested with ModelingToolkit v11.36.0, but is not run as part of the build process for this documentation and is not to be considered a supported interface between ControlSystemIdentification and ModelingToolkit.
0 commit comments