Parameter Definition
A parameter is a quantity that remains constant during the optimization process, specified by the user before calling the solver, such as vehicle body length and mass.
OPTIMake supports the following two types of parameters:
- stage-independent parameter
- stage-dependent parameter.
A stage-dependent parameter can have different values at different stages, while a stage-independent parameter has the same value across all stages (which can save storage and simplify setup).
Below is an example of defining parameters:
length = prob.parameter(name='length', stage_dependent=False)
mass = prob.parameter('mass')
xLowerBound = prob.parameter('xLowerBound', stage_dependent=True)
The function parameters are defined as follows:
-
name: str The name of the parameter
-
stage_dependent: bool, optional Whether the parameter is stage-dependent. The default value is True, meaning the parameter is stage-dependent
-
differentiable: bool, optional Whether the parameter is differentiable. The default value is False. See Differentiable Parameters below
Alternatively, parameters can be defined using a list:
length, mass, xLowerBound = prob.parameters(
['length', 'mass', 'xLowerBound'],
stage_dependent=False)
Differentiable Parameters
By setting differentiable=True, a parameter can be declared as a differentiable parameter. Both stage-independent and stage-dependent parameters are supported:
weight = prob.parameter('weight', differentiable=True)
xRef = prob.parameter('xRef', stage_dependent=True, differentiable=True)
x0, y0 = prob.parameters(['x0', 'y0'], differentiable=True)
When the model contains differentiable parameters, the generated code additionally provides a backward interface, which computes the gradient of a function of the optimal solution with respect to the differentiable parameters (e.g., the derivative of the first control input with respect to the initial state, or for parameter learning).
Differentiable parameters are set in the C code in the same way as ordinary parameters (via param and param_stage).
For the interface description, usage, and notes, see Extensions > Differentiable Parameters.