-
Notifications
You must be signed in to change notification settings - Fork 1
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
added: NonLinMPC
and MovingHorizonEstimator
integration with DI.jl
#174
base: main
Are you sure you want to change the base?
Conversation
It is no longer necessary with `DI.Constant` context.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #174 +/- ##
==========================================
+ Coverage 98.85% 98.87% +0.01%
==========================================
Files 25 25
Lines 4180 4160 -20
==========================================
- Hits 4132 4113 -19
+ Misses 48 47 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Heads up, DI v0.6.46 supports nested tuples and named tuples of arrays as caches |
Thanks for the info, right now I do: mycontext = (
Constant(a),
Cache(b),
Cache(c),
Cache(d),
)
grad_prep = prepare_gardient!(myfunc, grad_backend, x, mycontext...; strict=Val(true)) and a similar splatting for the context in |
I don't think it is problematic, but for some users it is a bit painful: when you have tens of caches you may want to structure the more neatly, so I give that option too. |
Alright thanks! I thinks it's neat enough in the code like that. |
This is "safer" like that. And it allows the user to verify what are the DI backends in a given MPC/MHE object. Also useful for the tests.
debug: temporarily fake a "filled" window for MHE gradient preparation (needed for some backend like FiniteDiff)
@baggepinnen It's ready to be merged, if you have some comments. You can have a look a edit: I'm running the benchmarks of our papers in this version, and there is no significative difference on the performances, good news ❤️ |
If you want to play around some more, a parameter that might impact performance is the coloring algorithm used by SparseMatrixColorings, more specifically the vertex ordering. Feel free to switch the default |
I did not played a lot with sparse jacobians for now. The pendulum exemples in our paper was small in term of number of decision variables, thus it is expected that no matter the chosen coloring/compression/etc algorithm, it will always be a bit slower then a dense formulation (for the same AD backend). It's like classical matrix operations e.g. product: if the matrices are relatively small, dense operations are generally faster even if they include many zeros. And that was indeed the case from my quick tests. That is, on the inverted pendulum model with a control horizon of
I may improve a little bit 3. by tweaking the colouring algorithm here, but IMO that's not the good case study to adequately benchmark sparse computations. |
@gdalle I just read that for Right now I pass a |
Nonlinear MPC and moving horzion estimator now use
DifferentiationInterface.jl
Both
NonLinMPC
andMovingHorizonEstimator
constructor now accept agradient
andjacobian
keyword arguments, receiving aAbstractADType
to switch the backend of the objective gradient and constraint Jacobians, respectively. Note that the nonlinear inequality and equality constraints will both use the backend provided by thejacobian
argument. The possibility to provide a hessian will be added in a future PR (the LBFGS approximation is used insideIpopt
for now, as it was the case before)By default, denses
AutoForwardDiff()
is use everywhere, except forNonLinMPC
with non-SingleShooting
transcription method, in which this backend is used:For both objects, the differentiation make use of
DifferentiationInterface.Constant()
andDifferentiationInterface.Cache()
functionalities. As a consequence, they does not rely onPreallocationTools.DiffCache
s anymore. But, I still need to keep this dependency sincelinearize!
and allDiffSolver
s still rely on them for now.Documentation now use
DocumenterInterLink.jl
Some URL were very long in the docstrings. The are now way shorter. It also ease the maintenance for the documentation of external dependencies.
The doc preview is here: https://juliacontrol.github.io/ModelPredictiveControl.jl/previews/PR174