modopt.ConvexQPSolvers

class modopt.ConvexQPSolvers(problem, recording=False, out_dir=None, hot_start_from=None, hot_start_atol=0.0, hot_start_rtol=0.0, visualize=[], keep_viz_open=False, turn_off_outputs=False, **kwargs)[source]

Class that interfaces modOpt with the qpsolvers package which provides a unified interface to various convex Quadratic Programming (QP) solvers available in Python. By default, the solver used is ‘quadprog’. Make sure to install ‘qpsolvers’ using pip install qpsolvers[wheels_only] quadprog osqp to install interfaced open-source QP solvers with pre-compiled binaries.

Parameters
problemProblem or ProblemLite

Object containing the convex QP problem to be solved.

turn_off_outputsbool, default=False

If True, prevents modOpt from generating any output files.

solver_optionsdict

Dictionary containing the solver name and its options. Available global options are: 'solver' and 'verbose'. Solver-specific options can also be passed. Make sure the ‘solver’ specified is installed on your machine.

Attributes
solver_namestr

The name of the solver to be used.

available_solverslist

The list of available solvers in qpsolvers. A subset of all the suppported solvers that are installed.

supported_solverslist

The list of supported solvers in qpsolvers.

Pnp.ndarray

The symmetric cost matrix. Always positive semi-definite for convex QP. Some solvers also require it to be positive definite.

qnp.ndarray

The cost vector.

Gnp.ndarray

The linear inequality constraint matrix.

hnp.ndarray

The linear inequality constraint vector.

Anp.ndarray

The linear equality constraint matrix.

bnp.ndarray

The linear equality constraint vector.

lbnp.ndarray

The lower bounds for the variables.

ubnp.ndarray

The upper bounds for the variables.

resultsdict

The results of the optimization.

qp_problem: qpsolvers.Problem

The QP problem to be solved.

Attributes of qpsolvers.Problem:

Pnp.ndarray

The symmetric cost matrix. Always positive semi-definite for convex QP. Some solvers also require it to be positive definite.

qnp.ndarray

The cost vector.

Gnp.ndarray

The linear inequality constraint matrix.

hnp.ndarray

The linear inequality constraint vector.

Anp.ndarray

The linear equality constraint matrix.

bnp.ndarray

The linear equality constraint vector.

lbnp.ndarray

The lower bounds for the variables.

ubnp.ndarray

The upper bounds for the variables.

has_sparsebool

Check whether the problem has sparse matrices.

is_unconstrainedbool

Check whether the problem has constraints.

Methods of qpsolvers.Problem:

check_constraints()

Check if the problem constraints are correctly defined.

cond(active_set: qpsolvers.ActiveSet)

Compute the condition number of the symmetric problem matrix representing hte problem data.

save(filename: str)

Save the problem data to a file. The “.npz” extension will be appended to the filename if it is not already there.

load(filename: str)

Load the problem data from a file.

unpack()

Unpack the problem data into a tuple of numpy arrays (P, q, G, h, A, b, lb, ub) and return it.

get_cute_classification(interest: str)

Get the CUTE classification string of the problem. interest can be ‘A’, ‘M’, or ‘R’, depending on whether your problem is academic, part of a modeling exercise, or has real-world applications.

Methods

check_first_derivatives([x, step, formulation])

Check the first derivatives of the optimization problem using finite differences.

print_results([optimal_variables, ...])

Print the results of the optimization problem to the console.

solve()

Solve the QP problem by calling qpsolvers with the requested solver and its options.

check_first_derivatives(x=None, step=1e-06, formulation='rs')

Check the first derivatives of the optimization problem using finite differences.

Parameters
xnp.ndarray, optional

The design variables at which the derivatives are to be checked. If not provided, the initial design variables are used.

stepfloat, default=1e-6

The step size for the finite differences.

print_results(optimal_variables=False, optimal_constraints=False, optimal_dual_variables=False, extras=False, all=False)[source]

Print the results of the optimization problem to the console.

Parameters
optimal_variablesbool, default=False

If True, print the optimal variables.

optimal_constraintsbool, default=False

If True, print the optimal constraints.

optimal_dual_variablesbool, default=False

If True, print the optimal dual variables.

extrasbool, default=False

If True, print the solver-specific extra information returned.

allbool, default=False

If True, print all available information.

solve()[source]

Solve the QP problem by calling qpsolvers with the requested solver and its options.