- class DoMPCDifferentiator(optimizer, **kwargs)[source]#
Nonlinear program (NLP) Differentiator for
do_mpcobjects. Can be used with
do_mpc.estimator.MHEobjects. The class inherits the
NLPDifferentiatorclass and overwrites the
do_mpcoptimizer object (e.g.
model = ... mpc = do_mpc.controller.MPC(model) ... mpc.setup()
Initialize the differentiator with the
nlp_diff = DoMPCDifferentiator(mpc)
Configure the differentiator settings with the
nlp_diff.settings.check_LICQ = False
Solve the NLP of the original
differentiate()method of the differentiator object to compute the parametric sensitivities at the current optimal solution previously calculated with
make_step(). The current parameters and optimal solution are read from the
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
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.
do_mpcclass that inherits the
Optimizerclass, that is, a
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
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 of the NLP differentiator. This is an annotated dataclass that can also be printed for convenience. See
do_mpc.differentiator.helper.NLPDifferentiatorSettingsfor more information.
nlp_diff = NLPDifferentiator(nlp, nlp_bounds) nlp_diff.settings.check_licq = False
Settings can also be passed as keyword arguments to the constructor of
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.