API Reference

This page is auto-generated from the source code and is intended to be used as an API reference. See Quickstart Guide to get started the easy way.

MetaOptimizationProblem

class rtc_tools_meta.meta_optimization_problem.MetaOptimizationProblem(**kwargs)[source]

Bases: rtctools.optimization.optimization_problem.OptimizationProblem

An optimization problem of aggregated submodels and a global objective

Use this class to define a meta optimization problem. A meta problem consists of submodels, which interact via variable_mappings.

To optimize the meta model, call the optimize() method. This will:

  1. Optimize aggregated model
  2. Impose interface constraints on submodels
  3. Optimize submodels

Results will be located in their respective submodel output directories.

interface_variables

Tuple of interface variables

Note: This property is extracted from self.variable_mappings

Return type:Tuple[str]
meta_objective()[source]

Symbolic expression to be minimized

For example, here is a quadratic minimization objective:

def meta_objective(self):
    return ca.sum1(self.states_in("ModelA::var_name")) ** 2.0
Return type:MX
optimize(preprocessing=True, postprocessing=True, log_solver_failure_as_error=True)[source]

Perform one initialize-transcribe-solve-finalize cycle.

Parameters:
  • preprocessing – True to enable a call to pre preceding the optimization.
  • postprocessing – True to enable a call to post following the optimization.
Returns:

True on success.

pop_submodel(variable)[source]

Function to split submodel name from variable

The submodel a variable is stored in is indicated by preceding that variable’s name with the model name, seperated by ::. For example,

>>> self.pop_submodel("submodel_name::variable_name")
("submodel_name", "variable_name")
>>> self.pop_submodel("submodelA_name::submodelB_name::variable_name")
("submodelA_name", "submodelB_name::variable_name")  # Nested models
Parameters:variable (str) – Submodel name and variable name in a single string
Return type:Tuple[str, str]
Returns:Submodel name and variable name as separate strings
Raises:AssertionError, ValueError
post()[source]

Execute post() method of all submodels

pre()[source]

Execute pre() method of all submodels

submodels

Dictionary of submodels

This variable is where we store the submodel instances. The models are indexed by a unique short name. For example:

# Meta Problem Optimizing ModelA and ModelB
submodels = {
    "ModelA": collect_model_instance('ModelA', path_to_a),
    "ModelB": collect_model_instance('ModelB', path_to_b),
}
Return type:Dict[str, OptimizationProblem]
transcribe()[source]

Transcribe all submodels and aggregate them into a single nlp problem

variable_mappings

Mappings that constrain variables in separate submodels to be equal

To define how submodels interact with each other, we set variable_mappings equal to a list of 3-tuples. The 3-tuples have the structure (var1, var2, sign). For example:

# Meta Problem Optimizing ModelA and ModelB
variable_mappings = [
    (
        "ModelA::some_variable",
        "ModelB::another_variable",
        "-",  # Either "-" (if vars are equal) or "+" (if they sum to 0)
    )
]
Return type:List[Tuple[str, str, str]]

MetaMixin

class rtc_tools_meta.meta_mixin.MetaMixin(**kwargs)[source]

Bases: rtctools.optimization.optimization_problem.OptimizationProblem

Adds Compatibility with MetaOptimizationProblem models

This mixin allows MetaOptimizationProblem models to assimilate your RTC-Tools model into its meta problem and impose constraints back onto your model. Resistance is futile.

collect_model_instance()

rtc_tools_meta.util.collect_model_instance(model_name, module_path, base_folder='..')[source]

Collect an object from a python file anywhere in your file system

Parameters:
  • model_name (str) – Name of the model that you want to collect and instantiate
  • module_path (str) – Path to the file where the model is defined
  • base_folder (str) – Path to the base folder of the model. Default is ".."
Raises:

AssertionError