modopt.Problem
- class modopt.Problem(**kwargs)[source]
Base class for defining optimization problems in modOpt.
- Attributes
- problem_namestr
Problem name assigned by the user.
- x0np.ndarray
Initial guess (scaled) for design variables.
- xarray_manager.Vector
Current iterate (unscaled) for the design variables.
- nxint
Number of design variables or optimization variables.
- ncint
Number of constraints in the optimization problem.
- optionsmodopt.OptionsDictionary
Problem-specific options declared by the user in addition to the global problem options ‘jac_format’ and ‘hess_format’.
- objdict
Dictionary with objective names as keys and current (unscaled) objective function values as values. Note that only one objective is supported by modOpt currently.
- obj_scalerdict
Dictionary with objective names as keys and objective. scalers as values. Default value for objective scalers is 1.0.
- o_scaler: float
Objective scaler to use for single objective optimization.
- lagdict
Dictionary with the objective name as key and current Lagrangian function value as value.
- constrained: bool
True if the problem has constraints. False if unconstrained.
- declared_variables: list
List of problem variables declared by the user. It can at most be [‘dv’, ‘obj’, ‘grad’, ‘con’, ‘jac’, ‘jvp’, ‘vjp’, ‘obj_hess’, ‘obj_hvp’, ‘lag’, ‘lag_grad’, ‘lag_hess’, ‘lag_hvp’]
- x_lowernp.ndarray or NoneType
Vector of (scaled) lower bounds for the design variables. x_lower[k] = -np.inf if the variable at x[k] has no lower bound. x_lower = None if no variables have lower bounds.
- x_uppernp.ndarray or NoneType
Vector of (scaled) upper bounds for the design variables. x_upper[k] = np.inf if the variable at x[k] has no upper bound. x_upper = None if no variables have upper bounds.
- c_lowernp.ndarray or NoneType
Vector of (scaled) lower bounds for the constraints. c_lower[k] = -np.inf if the constraint at c[k] has no lower bound. c_lower = None if unconstrained or no constraints have lower bounds.
- c_uppernp.ndarray or NoneType
Vector of (scaled) upper bounds for the constraints. c_upper[k] = np.inf if the constraint at c[k] has no upper bound. c_upper = None if unconstrained or no constraints have upper bounds.
- x_scalernp.ndarray or NoneType
Vector of scalers for the design variables. x_scaler[k] = 1.0 by default.
- c_scalernp.ndarray or NoneType
Vector of scalers for the constraints. c_scaler = None if unconstrained. c_scaler[k] = 1.0 by default.
- design_variables_dictarraymanager.VectorComponentsDict
Dictionary containing (unscaled) design variable vector metadata.
- constraints_dictarraymanager.VectorComponentsDict
Dictionary containing (unscaled) constraint vector metadata.
- pC_px_dictarraymanager.MatrixComponentsDict
Dictionary containing (unscaled) constraint Jacobian matrix metadata.
- p2F_pxx_dictarraymanager.MatrixComponentsDict
Dictionary containing (unscaled) objective Hessian matrix metadata.
- p2L_pxx_dictarraymanager.MatrixComponentsDict
Dictionary containing Lagrangian Hessian matrix metadata.
- pF_pxarray_manager.Vector
Abstract vector containing (unscaled) objective gradients.
- pL_pxarray_manager.Vector
Abstract vector containing Lagrangian gradients.
- conarray_manager.Vector
Abstract vector containing (unscaled) constraints.
- jvparray_manager.Vector
Abstract vector containing constraint Jacobian-vector products (JVPs).
- vjparray_manager.Vector
Abstract vector containing constraint vector-Jacobian products (VJPs).
- obj_hvparray_manager.Vector
Abstract vector containing objective Hessian-vector products (HVPs).
- lag_hvparray_manager.Vector
Abstract vector containing Lagrangian Hessian-vector products (HVPs).
- pC_pxarraymanager.Matrix
Abstract matrix containing (unscaled) constraint Jacobian components.
- p2F_pxxarraymanager.Matrix
Abstract matrix containing (unscaled) objective Hessian components.
- p2L_pxxarraymanager.Matrix
Abstract matrix containing Lagrangian Hessian components.
- jac(array_manager.DenseMatrix, array_manager.COOMatrix, array_manager.CSRMatrix, array_manager.CSCMatrix)
Standard array_manager matrix object in the format self.options[‘jac_format’] provided by the user. This object provides standard numpy dense or scipy sparse matrices. The output format for matrices is useful to meet the requirements for the chosen optimizer.
- obj_hess(array_manager.DenseMatrix, array_manager.COOMatrix, array_manager.CSRMatrix, array_manager.CSCMatrix)
Standard array_manager matrix object in the format self.options[‘hess_format’] provided by the user. This object provides standard numpy dense or scipy sparse (unscaled) objective Hessian matrices. The output format for matrices is useful to meet the requirements for the chosen optimizer.
- lag_hess(array_manager.DenseMatrix, array_manager.COOMatrix, array_manager.CSRMatrix, array_manager.CSCMatrix)
Standard array_manager matrix object in the format self.options[‘hess_format’] provided by the user. This object provides standard numpy dense or scipy sparse matrices. The output format for matrices is useful to meet the requirements for the chosen optimizer.
Methods
add_constraints([name, shape, scaler, ...])User calls this method within Problem.setup() method to add constraints for the problem.
add_design_variables([name, shape, scaler, ...])User calls this method within Problem.setup() method to add design variable vectors for the problem.
add_objective([name, scaler])User calls this method within Problem.setup() method to add an objective with a name and a scaler.
compute_constraint_jacobian(dvs, jac)Compute the constraint Jacobian with respect to the design variable vector.
compute_constraint_jvp(dvs, vec, jvp)Compute the constraint Jacobian-vector product (JVP) for the given design variable vector and multiplying vector.
compute_constraint_vjp(dvs, vec, vjp)Compute the constraint vector-Jacobian product (VJP) for the given design variable vector and multiplying vector.
compute_constraints(dvs, con)Compute the constraint vector given the design variable vector.
compute_lagrangian(dvs, lag_mult, lag)Compute the Lagrangian given the design variable and Lagrange multiplier vectors.
compute_lagrangian_gradient(dvs, lag_mult, ...)Compute the Lagrangian gradient given the design variable and Lagrange multiplier vectors.
compute_lagrangian_hessian(dvs, lag_mult, ...)Compute the Lagrangian Hessian given the design variable and Lagrange multiplier vectors.
compute_lagrangian_hvp(dvs, lag_mult, vec, ...)Compute the Lagrangian Hessian-vector product (HVP) for a given design variable vector, Lagrange multiplier vector, and multiplying vector.
compute_objective(dvs, obj)Compute the objective function given the design variable vector.
compute_objective_gradient(dvs, grad)Compute the objective function gradient given the design variable vector.
compute_objective_hessian(dvs, obj_hess)Compute the objective Hessian given the design variable vector.
compute_objective_hvp(dvs, vec, obj_hvp)Compute the objective Hessian-vector product (HVP) for a given design variable vector and a multiplying vector.
declare_constraint_jacobian(of, wrt[, ...])User calls this method within Problem.setup_derivatives() method to declare nonzero constraint Jacobians.
declare_constraint_jvp(of[, vals])User calls this method within Problem.setup_derivatives() method to declare constraint Jacobian-vector product (JVP).
declare_constraint_vjp(wrt[, vals])User calls this method within Problem.setup_derivatives() method to declare constraint vector-Jacobian product (VJP).
declare_lagrangian([name])User calls this method within Problem.setup() method to add the Lagrangian dict with the objective name as key and default value 1.0.
declare_lagrangian_gradient(wrt[, vals])User calls this method within Problem.setup_derivatives() method to declare nonzero Lagrangian gradients.
declare_lagrangian_hessian(of, wrt[, shape, ...])User calls this method within Problem.setup_derivatives() method to declare nonzero Lagrangian Hessian components L_{xy} = d^2L/dydx.
declare_lagrangian_hvp(wrt[, vals])User calls this method within Problem.setup_derivatives() method to declare Lagrangian Hessian-vector product (HVP).
declare_objective_gradient(wrt[, vals])User calls this method within Problem.setup_derivatives() method to declare nonzero objective gradients.
declare_objective_hessian(of, wrt[, shape, ...])User calls this method within Problem.setup_derivatives() method to declare nonzero objective Hessian components F_{xy} = d^2F/dydx.
declare_objective_hvp(wrt[, vals])User calls this method within Problem.setup_derivatives() method to declare objective Hessian-vector product (HVP).
Set problem name and any problem-specific options.
setup()Call add_design_variables(), add_objective(), add_constraints() and declare_lagrangian().
Call declare_objective_gradient(), declare_objective_hessian(), declare_objective_hvp(), declare_constraint_jacobian(), declare_constraint_jvp(), declare_constraint_vjp(), declare_lagrangian_gradient(), declare_lagrangian_hessian(), and declare_lagrangian_hvp().
use_finite_differencing(derivative[, step])User calls this method within compute methods to approximate derivatives.
- __init__(**kwargs)[source]
Initialize the Problem() object. Calls user-specified initialize() method, and the _setup() method.
- _compute_constraint_jacobian(x)[source]
Wrapper for user-defined compute_constraint_jacobian(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- Returns
- np.ndarray
2-dimensional constraint Jacobian matrix.
- _compute_constraint_jvp(x, v)[source]
Wrapper for user-defined compute_constraint_jvp(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- vnp.ndarray
Vector to right-multiply Jacobian with.
- Returns
- np.ndarray
1-dimensional constraint JVP vector.
- _compute_constraint_vjp(x, v)[source]
Wrapper for user-defined compute_constraint_vjp(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- vnp.ndarray
Vector to left-multiply Jacobian with.
- Returns
- np.ndarray
1-dimensional constraint VJP vector.
- _compute_constraints(x)[source]
Wrapper for user-defined compute_constraints(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- Returns
- np.ndarray
1-dimensional constraint vector.
- _compute_lagrangian(x, z)[source]
Wrapper for user-defined compute_lagrangian(). Arguments here are numpy arrays as opposed to array_manager.Vector. Performs problem- and optimizer-independent scaling before passing Lagrangian to optimizers in modOpt.
- Parameters
- xnp.ndarray
Design variable vector.
- znp.ndarray
Lagrange multiplier vector.
- Returns
- float
Lagrangian function value.
- _compute_lagrangian_gradient(x, z)[source]
Wrapper for user-defined compute_lagrangian_gradient(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- znp.ndarray
Lagrange multiplier vector.
- Returns
- np.ndarray
1-dimensional Lagrangian gradient vector.
- _compute_lagrangian_hessian(x, z)[source]
Wrapper for user-defined compute_lagrangian_hessian(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- znp.ndarray
Lagrange multiplier vector.
- Returns
- np.ndarray
2-dimensional Lagrangian Hessian matrix (sparse or dense depending on self.options[‘hess_format’]).
- _compute_lagrangian_hvp(x, z, v)[source]
Wrapper for user-defined compute_lagrangian_hvp(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- znp.ndarray
Lagrange multiplier vector.
- vnp.ndarray
Vector to right-multiply Hessian with.
- Returns
- np.ndarray
1-dimensional Lagrangian HVP vector.
- _compute_objective(x)[source]
Wrapper for user-defined compute_objective(). Argument here is a numpy array as opposed to array_manager.Vector. Performs problem- and optimizer-independent scaling before passing objective to optimizers in modOpt.
- Parameters
- xnp.ndarray
Design variable vector.
- Returns
- float
Objective function value.
- _compute_objective_gradient(x)[source]
Wrapper for user-defined compute_objective_gradient(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- Returns
- np.ndarray
1-dimensional objective gradient vector.
- _compute_objective_hessian(x)[source]
Wrapper for user-defined compute_objective_hessian(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- Returns
- np.ndarray
2-dimensional objective Hessian matrix (sparse or dense depending on self.options[‘hess_format’]).
- _compute_objective_hvp(x, v)[source]
Wrapper for user-defined compute_objective_hvp(). Arguments are numpy arrays, performs problem- and optimizer-independent scaling.
- Parameters
- xnp.ndarray
Design variable vector.
- vnp.ndarray
Vector to right-multiply Hessian with.
- Returns
- np.ndarray
1-dimensional objective HVP vector.
- add_constraints(name=None, shape=(1,), scaler=None, lower=None, upper=None, equals=None)[source]
User calls this method within Problem.setup() method to add constraints for the problem.
- Parameters
- namestr
Constraint name assigned by the user.
- shapetuple, default=(1,)
Constraint shape. (1,) by default.
- scalerfloat or np.ndarray, optional
Constraint scaling factor. It can be a single scaler for all constraints in the vector, or an array of scalers with the same shape as the constraint.
- lowerfloat or np.ndarray, optional
Constraint lower bound. It can be a float in which case the given lower bound applies to all constraints in the constraint vector. An array of lower bounds with the same shape as the constraint is also acceptable.
- upper: float or np.ndarray, optional
Constraint upper bound. It can be a float in which case the given upper bound applies to all constraints in the constraint vector. An array of upper bounds with the same shape as the constraint is also acceptable.
- equals: float or np.ndarray, optional
Used for defining an equality constraint. It can be a float in which case the given constant applies to all constraints in the constraint vector. An array of floats with the same shape as the constraint is also acceptable. It is used when the right-hand side constants for the equality constraints are different.
- add_design_variables(name=None, shape=(1,), scaler=None, lower=None, upper=None, equals=None, vals=None)[source]
User calls this method within Problem.setup() method to add design variable vectors for the problem.
- Parameters
- namestr
Design variable name assigned by the user.
- shapetuple, default=(1,)
Design variable shape. (1,) by default.
- scalerfloat or np.ndarray, optional
Design variable scaling factor. It can be a single scaler for all variables in the vector, or an array of scalers with the same shape as the design variable.
- lowerfloat or np.ndarray, optional
Design variable lower bound. It can be a float in which case the given lower bound applies to all variables in the design variable vector. An array of lower bounds with the same shape as the design variable is also acceptable.
- upper: float or np.ndarray, optional
Design variable upper bound. It can be a float in which case the given upper bound applies to all variables in the design variable vector. An array of upper bounds with the same shape as the design variable is also acceptable.
- equals: float or np.ndarray, optional
Employing this makes the design variable a fixed constant. This must be used only for debugging purposes.
- vals: float or np.ndarray, optional
Initial values for the design variables. It can be a single value for all variables in the vector, or an array of initial values with the same shape as the design variable. If nothing is provided, 0. will be taken as the initial guess.
- add_objective(name='obj', scaler=1.0)[source]
User calls this method within Problem.setup() method to add an objective with a name and a scaler.
- Parameters
- namestr, default=’obj’
Objective name assigned by the user.
- scalerfloat, default=1.
Objective scaling factor.
- compute_constraint_jacobian(dvs, jac)[source]
Compute the constraint Jacobian with respect to the design variable vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- jacarray_manager.Matrix
Jacobian matrix of the constraints with respect to the design variable vector. This abstract matrix has dictionary-type views for component sub-Jacobians with keys (of,wrt) where ‘of’ is the constraint name and ‘wrt’ the design variable name.
- compute_constraint_jvp(dvs, vec, jvp)[source]
Compute the constraint Jacobian-vector product (JVP) for the given design variable vector and multiplying vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- vecarray_manager.Vector
Vector to multiply with the Jacobian. This abstract vector has dictionary-type views corresponding to component design variable vectors.
- jvparray_manager.Vector
Constraint Jacobian-vector product. This abstract vector has dictionary-type views corresponding to component constraint vectors.
- compute_constraint_vjp(dvs, vec, vjp)[source]
Compute the constraint vector-Jacobian product (VJP) for the given design variable vector and multiplying vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- vecarray_manager.Vector
Vector to multiply with the Jacobian. This abstract vector has dictionary-type views corresponding to component constraint vectors.
- vjparray_manager.Vector
Constraint vector-Jacobian product. This abstract vector has dictionary-type views corresponding to component design variable vectors.
- compute_constraints(dvs, con)[source]
Compute the constraint vector given the design variable vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- conarray_manager.Vector
Vector of constraints. This abstract vector has dictionary-type views for component constraint vectors.
- compute_lagrangian(dvs, lag_mult, lag)[source]
Compute the Lagrangian given the design variable and Lagrange multiplier vectors.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- lag_multarray_manager.Vector
Vector of Lagrange multipliers. This abstract vector has dictionary-type views for component Lagrange multiplier vectors corresponding to component constraints.
- lagdict
Objective function name and value.
- compute_lagrangian_gradient(dvs, lag_mult, lag_grad)[source]
Compute the Lagrangian gradient given the design variable and Lagrange multiplier vectors.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- lag_multarray_manager.Vector
Vector of Lagrange multipliers. This abstract vector has dictionary-type views for component Lagrange multiplier vectors corresponding to component constraints.
- lag_gradarray_manager.Vector
Gradient vector of the Lagrangian with respect to the design variable vector. This abstract vector has dictionary-type views for component gradient vectors corresponding to component design variable vectors.
- compute_lagrangian_hessian(dvs, lag_mult, lag_hess)[source]
Compute the Lagrangian Hessian given the design variable and Lagrange multiplier vectors.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- lag_multarray_manager.Vector
Vector of Lagrange multipliers. This abstract vector has dictionary-type views for component Lagrange multiplier vectors corresponding to component constraints.
- lag_hessarray_manager.Matrix
Hessian matrix of the Lagrangian with respect to the design variable vector. This abstract matrix has dictionary-type views for component sub-Hessians L_xy = d2L/dydx with keys (of,wrt) where ‘of’ is the x design variable name and ‘wrt’ is the y design variable name.
- compute_lagrangian_hvp(dvs, lag_mult, vec, lag_hvp)[source]
Compute the Lagrangian Hessian-vector product (HVP) for a given design variable vector, Lagrange multiplier vector, and multiplying vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- lag_multarray_manager.Vector
Vector of Lagrange multipliers. This abstract vector has dictionary-type views for component Lagrange multiplier vectors corresponding to component constraints.
- vecarray_manager.Vector
Vector to multiply with the Lagrangian Hessian. This abstract vector has dictionary-type views corresponding to component design variable vectors.
- lag_hvparray_manager.Vector
Lagrangian Hessian-vector product. This abstract vector has dictionary-type views corresponding to component design variable vectors.
- compute_objective(dvs, obj)[source]
Compute the objective function given the design variable vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- objdict
Objective function name and value.
- compute_objective_gradient(dvs, grad)[source]
Compute the objective function gradient given the design variable vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- gradarray_manager.Vector
Gradient vector of the objective function with respect to the design variable vector. This abstract vector has dictionary-type views for component gradient vectors corresponding to component design variable vectors.
- compute_objective_hessian(dvs, obj_hess)[source]
Compute the objective Hessian given the design variable vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- obj_hessarray_manager.Matrix
Hessian matrix of the objective function with respect to the design variable vector. This abstract matrix has dictionary-type views for component sub-Hessians F_xy = d2F/dydx with keys (of,wrt) where ‘of’ is the x design variable name and ‘wrt’ is the y design variable name.
- compute_objective_hvp(dvs, vec, obj_hvp)[source]
Compute the objective Hessian-vector product (HVP) for a given design variable vector and a multiplying vector.
- Parameters
- dvsarray_manager.Vector
Design variable vector. This abstract vector has dictionary-type views for component design variable vectors.
- vecarray_manager.Vector
Vector to multiply with the Hessian. This abstract vector has dictionary-type views corresponding to component design variable vectors.
- obj_hvparray_manager.Vector
Objective Hessian-vector product. This abstract vector has dictionary-type views corresponding to component design variable vectors.
- declare_constraint_jacobian(of, wrt, shape=None, vals=None, rows=None, cols=None, ind_ptr=None)[source]
User calls this method within Problem.setup_derivatives() method to declare nonzero constraint Jacobians. Jacobian components that are undeclared are assumed to be zeros. If the Jacobian is provided later (in compute_constraint_jacobian() method) in one of the sparse formats coo, csr, or csc, declare the sparsity by calling this method with kwargs (rows, cols), (rows, ind_ptr), or (cols, ind_ptr), respectively.
- Parameters
- ofstr
Name of the constraint for which the Jacobian needs to be declared.
- wrtstr
Name of the variable w.r.t. which the Jacobian needs to be declared.
- rowsnp.ndarray, optional
Row indices corresponding to vals. Needs to be declared if the format for the declared Jacobian is coo or csr.
- colsnp.ndarray, optional
Column indices corresponding to vals. Needs to be declared if the format for the declared Jacobian is coo or csc.
- ind_ptrnp.ndarray, optional
Index pointer array for compressed index formats. Needs to be declared if the format for the declared Jacobian is csr or csc.
- shapetuple, optional
Shape in which ‘vals’ are going to be provided later by the user (for dense or sparse formats). Note that this is not the shape of the declared Jacobian.
- valsfloat or np.ndarray, optional
Values for the constraint Jacobian. Useful if the constraint is independent of or linearly-dependent on the declared “wrt” design variables. ‘vals’ are nonzero entries corresponding to ‘rows’ or ‘cols’ if the declared Jacobian is in sparse format.
- declare_constraint_jvp(of, vals=None)[source]
User calls this method within Problem.setup_derivatives() method to declare constraint Jacobian-vector product (JVP).
- Parameters
- ofstr
Name of the constraint for which the JVP needs to be declared.
- valsfloat or np.ndarray, optional
Values for the constraint JVP. Useful if the “of” constraint is only linearly-dependent on all of the design variables.
- declare_constraint_vjp(wrt, vals=None)[source]
User calls this method within Problem.setup_derivatives() method to declare constraint vector-Jacobian product (VJP).
- Parameters
- wrtstr
Name of the variable w.r.t. which the VJP needs to be declared.
- valsfloat or np.ndarray, optional
Values for the constraint VJP. Useful if all the constraints are independent of or linearly-dependent on the “wrt” design variables.
- declare_lagrangian(name='obj')[source]
User calls this method within Problem.setup() method to add the Lagrangian dict with the objective name as key and default value 1.0.
- Parameters
- namestr, default=’obj’
Objective name corresponding to the Lagrangian.
- declare_lagrangian_gradient(wrt, vals=None)[source]
User calls this method within Problem.setup_derivatives() method to declare nonzero Lagrangian gradients. Gradients that are undeclared are assumed to be zeros.
- Parameters
- wrtstr
Variable w.r.t. which the Lagrangian gradient needs to be declared.
- valsfloat or np.ndarray, optional
Values for constant gradients. Useful if the Lagrangian is only linearly-dependent on the declared “wrt” design variables.
- declare_lagrangian_hessian(of, wrt, shape=None, vals=None, rows=None, cols=None, ind_ptr=None)[source]
User calls this method within Problem.setup_derivatives() method to declare nonzero Lagrangian Hessian components L_{xy} = d^2L/dydx. Hessian components that are undeclared are assumed to be zeros. If the Hessian component is provided later (in compute_lagrangian_hessian() method) in one of the sparse formats coo, csr, or csc, declare the Hessian sparsity by calling this method with kwargs (rows, cols), (rows, ind_ptr), or (cols, ind_ptr), respectively.
- Parameters
- ofstr
Name of the variable x in F_{xy}. Note that the declared Hessian is the derivative of the Lagrangian gradient “dL/dx” with respect to y, hence the keyword “of”.
- wrtstr
Name of the variable y in F_{xy}. Note that the declared Hessian is the derivative of the Lagrangian gradient dL/dx with respect to “y”, hence the keyword “wrt”.
- rowsnp.ndarray, optional
Row indices corresponding to vals. Needs to be declared if the format for the declared Hessian is coo or csr.
- colsnp.ndarray, optional
Column indices corresponding to vals. Needs to be declared if the format for the declared Hessian is coo or csc.
- ind_ptrnp.ndarray, optional
Index pointer array for compressed index formats. Needs to be declared if the format for the declared Hessian is csr or csc.
- shapetuple, optional
Shape in which ‘vals’ are going to be provided later by the user (for dense or sparse formats).
- valsfloat or np.ndarray, optional
Values for the Lagrangian Hessian. Useful if the Lagrangian gradient wrt “of” design variable is independent of or linearly-dependent on the “wrt” design variables. ‘vals’ are nonzero entries corresponding to ‘rows’ or ‘cols’ if the declared Hessian is in sparse format.
- declare_lagrangian_hvp(wrt, vals=None)[source]
User calls this method within Problem.setup_derivatives() method to declare Lagrangian Hessian-vector product (HVP).
- Parameters
- wrtstr
Name of the variables w.r.t. which the HVP needs to be declared.
- valsfloat or np.ndarray, optional
Values for the Lagrangian HVP. Useful if the HVP is constant w.r.t. the declared “wrt” design variables.
- declare_objective_gradient(wrt, vals=None)[source]
User calls this method within Problem.setup_derivatives() method to declare nonzero objective gradients. Gradients that are undeclared are assumed to be zeros.
- Parameters
- wrtstr
Variable w.r.t. which the objective gradient needs to be declared.
- valsfloat or np.ndarray, optional
Values for constant gradients. Useful if the objective is independent of, or linearly-dependent on the declared “wrt” design variables.
- declare_objective_hessian(of, wrt, shape=None, vals=None, rows=None, cols=None, ind_ptr=None)[source]
User calls this method within Problem.setup_derivatives() method to declare nonzero objective Hessian components F_{xy} = d^2F/dydx. Hessian components that are undeclared are assumed to be zeros. If the Hessian component is provided later (in compute_objective_hessian() method) in one of the sparse formats coo, csr, or csc, declare the Hessian sparsity by calling this method with kwargs (rows, cols), (rows, ind_ptr), or (cols, ind_ptr), respectively.
- Parameters
- ofstr
Name of the variable x in F_{xy}. Note that the declared Hessian is the derivative of the gradient “dF/dx” with respect to y, hence the keyword “of”.
- wrtstr
Name of the variable y in F_{xy}. Note that the declared Hessian is the derivative of the gradient dF/dx with respect to “y”, hence the keyword “wrt”.
- rowsnp.ndarray, optional
Row indices corresponding to vals. Needs to be declared if the format for the declared Hessian is coo or csr.
- colsnp.ndarray, optional
Column indices corresponding to vals. Needs to be declared if the format for the declared Hessian is coo or csc.
- ind_ptrnp.ndarray, optional
Index pointer array for compressed index formats. Needs to be declared if the format for the declared Hessian is csr or csc.
- shapetuple, optional
Shape in which ‘vals’ are going to be provided later by the user (for dense or sparse formats).
- valsfloat or np.ndarray, optional
Values for the Hessian. Useful if the objective gradient wrt “of” design variable is independent of or linearly-dependent on the “wrt” design variables. ‘vals’ are nonzero entries corresponding to ‘rows’ or ‘cols’ if the declared Hessian is in sparse format.
- declare_objective_hvp(wrt, vals=None)[source]
User calls this method within Problem.setup_derivatives() method to declare objective Hessian-vector product (HVP).
- Parameters
- wrtstr
Name of the variables w.r.t. which the HVP needs to be declared.
- valsfloat or np.ndarray, optional
Values for the objective HVP. Useful if the HVP is constant w.r.t. the declared “wrt” design variables.
- abstract setup()[source]
Call add_design_variables(), add_objective(), add_constraints() and declare_lagrangian().
- abstract setup_derivatives()[source]
Call declare_objective_gradient(), declare_objective_hessian(), declare_objective_hvp(), declare_constraint_jacobian(), declare_constraint_jvp(), declare_constraint_vjp(), declare_lagrangian_gradient(), declare_lagrangian_hessian(), and declare_lagrangian_hvp().
- use_finite_differencing(derivative, step=1e-06)[source]
User calls this method within compute methods to approximate derivatives.
- Parameters
- derivativestr
Derivative to approximate. Available derivatives are ‘objective_gradient’, ‘objective_hessian’, ‘constraint_jacobian’, ‘objective_hvp’, ‘constraint_jvp’.
- stepfloat or np.ndarray, default=1e-6
Finite difference step size.