Data

class do_mpc.data.Data(model)[source]

do-mpc data container. An instance of this class is created for the active do-mpc classes, e.g. do_mpc.simulator.Simulator, do_mpc.estimator.MHE.

The class is initialized with an instance of the do_mpc.model.Model which contains all information about variables (e.g. states, inputs etc.).

The Data class has a public API but is mostly used by other do-mpc classes, e.g. updated in the .make_step calls.

__getitem__(ind)[source]

Query data fields. This method can be used to obtain the stored results in the Data instance.

The full list of available fields can be inspected with:

print(data.data_fields)

The dict also denotes the dimension of each field.

The method allows for power indexing the results for the fields _x, _u, _z, _tvp, _p, _aux, _y where further indices refer to the configured variables in the do_mpc.model.Model instance.

Example:

# Assume the following model was used (excerpt):
model = do_mpc.model.Model('continuous')

model.set_variable('_x', 'Temperature', shape=(5,1)) # Vector
model.set_variable('_p', 'disturbance', shape=(3,3)) # Matrix
model.set_variable('_u', 'heating')                  # scalar

...

# the model was used (among others) for the MPC controller
mpc = do_mpc.controller.MPC(model)

...

# Query the mpc.data instance:
mpc.data['_x']                      # Return all states
mpc.data['_x', 'Temperature']       # Return the 5 temp states
mpc.data['_x', 'Temperature', :2]   # Return the first 2 temp. states
mpc.data['_p', 'disturbance', 0, 2] # Matrix allows for further indices

# Other fields can also be queried, e.g.:
mpc.data['_time']                   # current time
mpc.data['t_wall_S']               # optimizer runtime
# These do not allow further indices.
Returns:Returns the queried data field (for all time instances)
Return type:numpy.ndarray

Methods

Data.export The export method returns a dictionary of the stored data.
Data.init_storage Create new (empty) arrays for all variables.
Data.set_meta Set meta data for the current instance of the data object.
Data.update Update value(s) of the data structure with key word arguments.

This page is auto-generated. Page source is not available on Github.