Optimizer

Model ElementOptimizer is an object that contains all the elements required for optimization.

Class Name

Optimizer

Attribute Summary

Name Property Modifiable by Command? Designable
label Str ()    
objectives Double () Yes
method Str ()  
weights Double (1.0E-3)  
eqConstraints List () Yes
ineqConstraints List () Yes
maxit Int (50)  
accuracy Double (1.0e-3) NO  
dsa Str ()    
fdStep Double (1.0e-6)  
type Str ()  
end Double ()  
dtout Double ()  
simFunction Function ()  
plot Bool ()  

Usage

opt = Optimizer (objective=listOfResponses, optional_attributes)

Attributes

Mandatory Attributes
objectives
List of response variable to be optimized.
The responses should be defined using the library response classes described in the previous section.
objectives is mandatory.
Optional Arguments
label
Label for optimizer [String].
label is optional.
Default: "Optimzer".
type
Analysis type [String].
Choose from one of the following: "KINEMATICS", "STATICS", "QUASISTATICS", "DYNAMICS", "STATICS".
type is optional.
Default: "STATICS".
end
End time for simulation [Double].
end is optional.
Default: 0.0.
dtout
Output interval [Double].
dtout is optional.
Default:0.01.
method
Optimization method [String].
Currently, we only support "SLSQP". More optimization methods will be added in the future.
method is optional.
Default: "SLSQP".
weights
List of weights for each response variable [Double].
weights are optional.
Default: 1.0 for each response variable.
eqConstraints
List of response variables names that form equality constraint. These responses would be equal to zero at the end of a successful optimization.
eqConstraints is optional.
ineqConstraints
List of responses variables names which form inequality constraint. These responses would be greater than zero at the end of a successful optimization.
ineqConstraints is optional.
simFunction
A user defined function which can be used in optimization in place of type+end+dtout.
simFunction is optional. simFunction and type+end+dtout are mutually exclusive.
maxit
Maximum number of iterations [Int]
maxit is optional.
Default: 50.
accuracy
Accuracy for terminating optimization [Double].
accuracy is optional.
Default: 1.0e-3.
dsa
DSA type [String]. See Comment 1.
Options include: "ADJOINT", "DIRECT", "AUTO", "NONE", "FD", "FD_Serial".
dsa is optional.
Default: "AUTO".
fdStepType
Determines how to compute step size for the Finite Difference Method. Must be one of the following:
  • UNIFORM
  • PROPORTIONAL
  • AUTO
  • AUTOUNIFORM
  • AUTOPROPORTIONAL
See comment 4 for more details.
[String]
fdStepType is optional.
Default: “AUTOACTUAL”.
fdStep
The step-size to be used for sensitivity calculation using Finite Difference Method; applicable only when dsa="FD". This property will be ignored when fdStepType is “AUTO”, “AUTOACTUAL” or “AUTORELATIVE”. See Comment 4 for more details.
You can either specify the factor of perturbation (assigning a float number) or define the step directly (assigning a list of numbers whose length is equal to number of Dvs).
[Double]
fdStep is optional.
Default: 1.0e-3.
updatefdStep
The number of iterations after which the step size of the Finite Difference Method is updated. When specified, MotionSolve updates the step size by some method (determined by fdStepType) during the optimization.
plot
When set to True, plots of response variable values are produced during optimization.
[Bool]
plot is optional.
Default: True)

Example:

# Create an optimization object and start an optimization
def optimizationJob (self):
    obj = [self.a2x, self.a2y, self.a2psi] # Define the 3 objectives
    wt = [1, 1, 1] # Define the weights
    opt = Optimizer ( # Define the optimizer
            label = "Optimize RMS2", # Label
            objective = obj, # Objectives
            weights = wt, # Weights
            type = "KINEMATICS", # Simulation Type
            end = 2, # End Time
            dtout = 0.01, # No. of steps
            plot = True, # Display plots
            dsa = "AUTO", # DSA type)
            accuracy=1e-3
    )
# Run an optimization
x = self.opt.optimize()
return x

Comments:

  1. See Properties for an explanation about what properties are, why they are used, and how you can extend these.
  2. Types of DSA
    dsa = "AUTO" will select the best approach based on the problem.
    • If the number of design variables > number of responses, the Adjoint method is used.
    • If the number of design variables < number of responses, the Direct method is used.
    • If the analysis is of type Dynamics, the FD method is always used.

      dsa = "DIRECT" selects the direct differentiation method for computing the design sensitivity matrix.

      dsa = "ADJOINT" selects the adjoint method for computing the design sensitivity matrix.

      dsa = "FD" selects the finite differencing method for computing the design sensitivity matrix. Finite differencing is done in parallel.

  3. After the completion of optimization run, the optimizer returns the following values:
    status
    Exit mode for optimizer (see below).
    success
    Flag showing if the optimizer converged successfully or not (True/False).
    njev
    Total number of iterations.
    nfev
    Number of function evaluations.
    fun
    Final cost of the function.
    x
    List of optimized design variable values (array).
    message
    Exit code message (see below).
    jac
    Jacobian of the optimized design variables to each response (array).
    nit
    Number of gradient evaluations.
    Exit modes are defined as follows:
    -1
    Gradient evaluation required (g & a).
    0
    Optimization terminated successfully.
    1
    Function evaluation required (f & c).
    2
    More equality constraints than independent variables.
    3
    More than 3*n iterations in LSQ sub-problem.
    4
    Inequality constraints incompatible.
    5
    Singular matrix E in LSQ sub-problem.
    6
    Singular matrix C in LSQ sub-problem.
    7
    Rank-deficient equality constraint sub-problem HFTI.
    8
    Positive directional derivative for linesearch.
    9
    Iteration limit exceeded.
    10
    Error happened getting objective function value.
    11
    Error happened getting gradient value of objective function.
    12
    Approaching close enough to local convergence with current boundary.

    See the Multibody Optimization User's Guide in the MotionSolve User's Guide for usage.

  4. There are five approaches available to compute step size for the Finite Difference Method:
    UNIFORM
    Uniform step size is used for all Dvs. For each Dv, the perturbation is Δ= fdStep.
    PROPORTIONAL
    The step size for each Dv is proportional to its magnitude. For Dvi, the perturbation is Δ= fdStep * max (1.0, Dvi|)|.
    AUTO
    Use optimal step size for each Dv. MotionSolve has an internal routine to compute the optimal step size for each Dv based on the local error and an estimation of the second derivative. The sensitivity computed by this approach is the most accurate but it introduces additional computational cost. You might want to consider “AUTOACTUAL” or “AUTORELATIVE” when the additional cost is unacceptable for you.
    AUTOUNIFORM
    MotionSolve computes the optimal step size on the first Dv. Other Dvs use the same step size.
    AUTOPROPORTIONAL
    MotionSolve computes the optimal step size on the first Dv. The step sizes of the other Dvs are proportional to their magnitudes.