DoMPCDifferentiator#
- class DoMPCDifferentiator(optimizer, **kwargs)[source]#
Bases:
NLPDifferentiatorNonlinear program (NLP) Differentiator for
do_mpcobjects. Can be used withdo_mpc.controller.MPCanddo_mpc.estimator.MHEobjects. The class inherits theNLPDifferentiatorclass and overwrites thedifferentiate()method.Example:
Setup a
do_mpcoptimizer object (e.g.do_mpc.controller.MPCordo_mpc.estimator.MHE).
model = ... mpc = do_mpc.controller.MPC(model) ... mpc.setup()
Initialize the differentiator with the
do_mpcoptimizer object.
nlp_diff = DoMPCDifferentiator(mpc)
Configure the differentiator settings with the
settingsattribute.
nlp_diff.settings.check_LICQ = False
Solve the NLP of the original
do_mpcoptimizer object.
mpc.make_step(x0)
Call the
differentiate()method of the differentiator object to compute the parametric sensitivities at the current optimal solution previously calculated withmake_step(). The current parameters and optimal solution are read from thedo_mpcoptimizer object.
dx_dp_num, dlam_dp_num = nlp_diff.differentiate()
Typically, we are interested in specific segments of the parametric sensitivities. These can be retrieved by powerindexing the
sens_numattribute.
du0dx0 = nlp_diff.sens_num['dxdp', indexf['_u', 0, 0], indexf['_x', 0, 0]]
This last step returns the parametric sensitivity of the first input with respect to the initial state.
- Parameters:
optimizer (
Optimizer) –do_mpcclass that inherits theOptimizerclass, that is, ado_mpc.controller.MPCordo_mpc.estimator.MHEobject.
Methods#
differentiate#
- differentiate(self)#
Main method of the class. Computes the parametric sensitivities of the underlying NLP of the MPC or MHE. Should be called after solving the underlying NLP. The current optimal solution and the corresponding parameters are read from the
do_mpcobject.
Attributes#
sens_num#
- DoMPCDifferentiator.sens_num#
The sensitivity structure of the NLP. This can be queried as follows:
from casadi.tools import indexf du0dx0 = nlp_diff.sens_num['dxdp', indexf['_u', 0, 0], indexf['_x0']]
The powerindices passed to
indexfare derived from the attributes:
settings#
- DoMPCDifferentiator.settings#
Settings of the NLP differentiator. This is an annotated dataclass that can also be printed for convenience. See
do_mpc.differentiator.helper.NLPDifferentiatorSettingsfor more information.Example:
nlp_diff = NLPDifferentiator(nlp, nlp_bounds) nlp_diff.settings.check_licq = False
Note
Settings can also be passed as keyword arguments to the constructor of
NLPDifferentiator.
status#
- DoMPCDifferentiator.status#
Status of the NLP differentiator. This is an annotated dataclass that can also be printed for convenience. See
do_mpc.differentiator.helper.NLPDifferentiatorStatusfor more information.