modopt.ProblemLite
- class modopt.ProblemLite(x0, name='unnamed_problem', obj=None, con=None, grad=None, jac=None, obj_hess=None, lag_hess=None, fd_step=1e-06, vp_fd_step=1e-06, xl=None, xu=None, cl=None, cu=None, x_scaler=1.0, o_scaler=1.0, c_scaler=1.0, jvp=None, vjp=None, obj_hvp=None, lag_hvp=None, lag=None, lag_grad=None, grad_free=False)[source]
Lightweight base class for defining optimization problems in modOpt. Performs basic setup for optimization problems, without using
array_manager. This class is useful for defining simple optimization problems with initial design variables, objective, constraints and their derivative functions. TheProblemLite()object can be used when the user wants to call the optimizer directly with x0, obj, con, grad, jac, obj_hess, etc. functions.- Major differences from
Problem()class: No
array_managerobjects are used so no setup of matrices, vectors, etc.No declarations of design variables, objectives, constraints, etc.
No
setup()orsetup_derivatives()method is called.Functions and derivatives are directly called from the user-provided functions (thin wrapper).
Only single objective problems are supported.
Only a single design variable vector and single constraint vector function are supported.
Every STORED VARIABLE in this class is SCALED by the user-provided scaling factors.
Objective and constraint functions are always called together in
_funcs(x)method.Gradient and Jacobian functions are always called together in
_derivs(x)method.Caches the function and first derivative values for the same input
xto avoid redundant, consecutive evaluations.Keeps track of the number of function and gradient evaluations and time taken for each.
- Still supports:
Feasibility problems and unconstrained optimization problems.
Finite differencing by default for unavailable derivatives.
Matrix-vector products vjp, jvp, obj_hvp, lag_hvp.
Caching of function and derivative values (although scaled) for the same input
x.Scaling of design variables, objectives, and constraints.
Bounds on design variables and constraints.
Lagrangian functions and derivatives for constrained problems.
Sparse or dense matrix formats for Jacobian and Hessian in user-provided functions, if supported by the optimizer used.
- __init__(x0, name='unnamed_problem', obj=None, con=None, grad=None, jac=None, obj_hess=None, lag_hess=None, fd_step=1e-06, vp_fd_step=1e-06, xl=None, xu=None, cl=None, cu=None, x_scaler=1.0, o_scaler=1.0, c_scaler=1.0, jvp=None, vjp=None, obj_hvp=None, lag_hvp=None, lag=None, lag_grad=None, grad_free=False)[source]
Initialize the optimization problem with the given design variables, objective, constraints, and their derivatives.
- Attributes
- namestr, default=’unnamed_problem’
Problem name assigned by the user.
- x0np.ndarray
Initial guess for design variables.
- objcallable
Objective function. Signature: obj(x: np.ndarray) -> float
- concallable
Constraints function. Signature: con(x: np.ndarray) -> np.ndarray
- gradcallable
Gradient of the objective function. Signature: grad(x: np.ndarray) -> np.ndarray
- jaccallable
Jacobian of the constraints function. Signature: jac(x: np.ndarray) -> np.ndarray
- obj_hesscallable
Hessian of the objective function. Signature: obj_hess(x: np.ndarray) -> np.ndarray
- lag_hesscallable
Hessian of the Lagrangian function. Signature: lag_hess(x: np.ndarray, mu: np.ndarray) -> np.ndarray
- fd_stepfloat or np.ndarray, default=1e-6
Finite difference step size for gradient, Jacobian, and Hessian computations.
- vp_fd_stepfloat, default=1e-6
Finite difference step size for computing vector products, if not provided by the user. USed in JVP, OBJ_HVP, LAG_HVP computations. Must always be a scalar.
- xlfloat or np.ndarray
Lower bounds on design variables.
- xufloat or np.ndarray
Upper bounds on design variables.
- clfloat or np.ndarray
Lower bounds on constraints.
- cufloat or np.ndarray
Upper bounds on constraints.
- x_scalerfloat or np.ndarray
Scaling factor for design variables.
- o_scalerfloat
Scaling factor for the objective function.
- c_scalerfloat or np.ndarray
Scaling factor for constraints.
- jvpcallable
Jacobian-vector product function. Signature: jvp(x: np.ndarray, v: np.ndarray) -> np.ndarray
- vjpcallable
Vector-Jacobian product function. Signature: vjp(x: np.ndarray, v: np.ndarray) -> np.ndarray
- obj_hvpcallable
Hessian-vector product function for the objective. Signature: obj_hvp(x: np.ndarray, v: np.ndarray) -> np.ndarray
- lag_hvpcallable
Hessian-vector product function for the Lagrangian. Signature: lag_hvp(x: np.ndarray, mu: np.ndarray, v: np.ndarray) -> np.ndarray
- lagcallable
Lagrangian function. Signature: lag(x: np.ndarray, mu: np.ndarray) -> float
- lag_gradcallable
Gradient of the Lagrangian function. Signature: lag_grad(x: np.ndarray, mu: np.ndarray) -> np.ndarray
- grad_freebool, default=False
If
True, ProblemLite will not use/generate any derivative information.
- Major differences from