Skip to content

Conversation

@baggepinnen
Copy link
Contributor

Allows to use both known and unknown disturbance inputs at the same time. Should be backwards compatible


These functions support two types of disturbance inputs:

- **Unknown disturbances** (`disturbance_inputs`): Variables that are part of ``w`` but NOT added as function arguments to ``f``. MTK assumes these variables are zero, but any dynamics associated with them (such as disturbance models) are included in the generated function. This allows a state estimator to estimate the state of the disturbance model, provided that this state is [observable](https://en.wikipedia.org/wiki/Observability) from measured outputs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
- **Unknown disturbances** (`disturbance_inputs`): Variables that are part of ``w`` but NOT added as function arguments to ``f``. MTK assumes these variables are zero, but any dynamics associated with them (such as disturbance models) are included in the generated function. This allows a state estimator to estimate the state of the disturbance model, provided that this state is [observable](https://en.wikipedia.org/wiki/Observability) from measured outputs.
- **Unknown disturbances** (`disturbance_inputs`): Variables that are part of ``w`` but NOT added as function arguments to ``f``. MTK assumes these variables are zero, but any dynamics associated with them (such as disturbance models) are included in the generated function. This allows a state estimator to estimate the state of the disturbance model, provided that this state is [observable](https://en.wikipedia.org/wiki/Observability) from measured outputs.


- **Unknown disturbances** (`disturbance_inputs`): Variables that are part of ``w`` but NOT added as function arguments to ``f``. MTK assumes these variables are zero, but any dynamics associated with them (such as disturbance models) are included in the generated function. This allows a state estimator to estimate the state of the disturbance model, provided that this state is [observable](https://en.wikipedia.org/wiki/Observability) from measured outputs.

- **Known disturbances** (`known_disturbance_inputs`): Variables that are part of ``w`` AND added as function arguments to ``f``, resulting in ``f(x, u, p, t, w)``. Use this when disturbances can be measured or are otherwise known.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
- **Known disturbances** (`known_disturbance_inputs`): Variables that are part of ``w`` AND added as function arguments to ``f``, resulting in ``f(x, u, p, t, w)``. Use this when disturbances can be measured or are otherwise known.
- **Known disturbances** (`known_disturbance_inputs`): Variables that are part of ``w`` AND added as function arguments to ``f``, resulting in ``f(x, u, p, t, w)``. Use this when disturbances can be measured or are otherwise known.

Comment on lines +210 to +213
Base.depwarn("The `disturbance_argument` keyword argument is deprecated. Use `known_disturbance_inputs` instead. " *
"For `disturbance_argument=true`, pass `known_disturbance_inputs=disturbance_inputs, disturbance_inputs=nothing`. " *
"For `disturbance_argument=false`, use `disturbance_inputs` as before.",
:generate_control_function)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Base.depwarn("The `disturbance_argument` keyword argument is deprecated. Use `known_disturbance_inputs` instead. " *
"For `disturbance_argument=true`, pass `known_disturbance_inputs=disturbance_inputs, disturbance_inputs=nothing`. " *
"For `disturbance_argument=false`, use `disturbance_inputs` as before.",
:generate_control_function)
Base.depwarn(
"The `disturbance_argument` keyword argument is deprecated. Use `known_disturbance_inputs` instead. " *
"For `disturbance_argument=true`, pass `known_disturbance_inputs=disturbance_inputs, disturbance_inputs=nothing`. " *
"For `disturbance_argument=false`, use `disturbance_inputs` as before.",
:generate_control_function)


if !isscheduled(sys)
sys = mtkcompile(sys; inputs, disturbance_inputs, split)
sys = mtkcompile(sys; inputs, disturbance_inputs=all_disturbances, split)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
sys = mtkcompile(sys; inputs, disturbance_inputs=all_disturbances, split)
sys = mtkcompile(sys; inputs, disturbance_inputs = all_disturbances, split)


# Prepare disturbance arrays for substitution and function arguments
unknown_disturbances = disturbance_inputs === nothing ? [] : unwrap.(disturbance_inputs)
known_disturbances = known_disturbance_inputs === nothing ? [] : unwrap.(known_disturbance_inputs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
known_disturbances = known_disturbance_inputs === nothing ? [] : unwrap.(known_disturbance_inputs)
known_disturbances = known_disturbance_inputs === nothing ? [] :
unwrap.(known_disturbance_inputs)

Comment on lines +1104 to +1107
Base.depwarn("The `disturbance_argument` keyword argument is deprecated. Use `known_disturbance_inputs` instead. " *
"For `disturbance_argument=true`, pass `known_disturbance_inputs=disturbance_inputs, disturbance_inputs=nothing`. " *
"For `disturbance_argument=false`, use `disturbance_inputs` as before.",
:build_explicit_observed_function)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Base.depwarn("The `disturbance_argument` keyword argument is deprecated. Use `known_disturbance_inputs` instead. " *
"For `disturbance_argument=true`, pass `known_disturbance_inputs=disturbance_inputs, disturbance_inputs=nothing`. " *
"For `disturbance_argument=false`, use `disturbance_inputs` as before.",
:build_explicit_observed_function)
Base.depwarn(
"The `disturbance_argument` keyword argument is deprecated. Use `known_disturbance_inputs` instead. " *
"For `disturbance_argument=true`, pass `known_disturbance_inputs=disturbance_inputs, disturbance_inputs=nothing`. " *
"For `disturbance_argument=false`, use `disturbance_inputs` as before.",
:build_explicit_observed_function)

@github-actions
Copy link
Contributor

Benchmark Results (Julia vlts)

Time benchmarks
master 111ec0e... master / 111ec0e...
ODEProblem 0.0969 ± 0.0054 s 0.094 ± 0.006 s 1.03 ± 0.087
init 0.0591 ± 0.0017 ms 0.058 ± 0.0015 ms 1.02 ± 0.039
large_parameter_init/ODEProblem 0.994 ± 0.0044 s 1.01 ± 0.016 s 0.986 ± 0.016
large_parameter_init/init 0.108 ± 0.0025 ms 0.109 ± 0.0023 ms 0.992 ± 0.031
mtkcompile 0.035 ± 0.0018 s 0.034 ± 0.0022 s 1.03 ± 0.083
time_to_load 5.14 ± 0.07 s 5.05 ± 0.022 s 1.02 ± 0.015
Memory benchmarks
master 111ec0e... master / 111ec0e...
ODEProblem 0.659 M allocs: 22.1 MB 0.659 M allocs: 22.1 MB 1
init 0.892 k allocs: 0.046 MB 0.892 k allocs: 0.046 MB 1
large_parameter_init/ODEProblem 4.21 M allocs: 0.163 GB 4.22 M allocs: 0.163 GB 1
large_parameter_init/init 1.74 k allocs: 0.0856 MB 1.74 k allocs: 0.0856 MB 1
mtkcompile 0.229 M allocs: 8.46 MB 0.229 M allocs: 8.46 MB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

@github-actions
Copy link
Contributor

Benchmark Results (Julia v1)

Time benchmarks
master 111ec0e... master / 111ec0e...
ODEProblem 0.113 ± 0.0062 s 0.0957 ± 0.0058 s 1.18 ± 0.097
init 0.0478 ± 0.012 ms 0.0442 ± 0.011 ms 1.08 ± 0.39
large_parameter_init/ODEProblem 1.27 ± 0.031 s 1.15 ± 0.031 s 1.1 ± 0.04
large_parameter_init/init 0.0892 ± 0.019 ms 0.0795 ± 0.017 ms 1.12 ± 0.33
mtkcompile 0.0411 ± 0.0035 s 0.0366 ± 0.0015 s 1.12 ± 0.11
time_to_load 5.45 ± 0.15 s 4.79 ± 0.039 s 1.14 ± 0.033
Memory benchmarks
master 111ec0e... master / 111ec0e...
ODEProblem 0.672 M allocs: 22.1 MB 0.673 M allocs: 22.2 MB 0.997
init 0.797 k allocs: 30.5 kB 0.797 k allocs: 30.5 kB 1
large_parameter_init/ODEProblem 4.49 M allocs: 0.166 GB 4.46 M allocs: 0.164 GB 1.01
large_parameter_init/init 1.64 k allocs: 0.0594 MB 1.64 k allocs: 0.0594 MB 1
mtkcompile 0.234 M allocs: 8 MB 0.234 M allocs: 8 MB 0.999
time_to_load 0.149 k allocs: 11.1 kB 0.149 k allocs: 11.1 kB 1

@AayushSabharwal AayushSabharwal merged commit ed73524 into master Nov 25, 2025
54 of 78 checks passed
@AayushSabharwal AayushSabharwal deleted the distinputs branch November 25, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants