CVXPY Interface

CVXPY is an open source Python-embedded modeling language for convex optimization problems. It lets you express your problem in a natural way that follows the math, which is quite flexible and efficient. This chapter introduces how to use the Cardinal Optimizer (COPT) in CVXPY.

Installation guide

Before calling COPT in CVXPY to solve problem, users need to setup CVXPY and COPT correctly. CVXPY currently supports Python 3.7 and later versions of Python. Users can download Python from Anaconda distribution or Python official distribution . We recommend users install the Anaconda distribution, because it is more user-friendly and convenient for Python novices.

Install via conda

We recommend that users who have installed the Anaconda distribution of Python use its own conda tool to install CVXPY. Execute the following commands in Windows command prompt or terminal on Linux and MacOS:

conda install -c conda-forge cvxpy

Install via pip

Users can also install CVXPY through the standard pip tool, execute the following command in Windows command prompt or Linux and MacOS terminal:

pip install cvxpy

Setup CVXPY interface

CVXPY V1.3 and its above versions support calling COPT directly. users need to install and configure COPT in advance and then:

import cvxpy as cp

In CVXPY’s solving function solve, specify the parameter solver="COPT" to use the COPT solver to solve:


Introduction of features

The CVXPY interface of COPT supports Linear Programming (LP), Mixed Integer Programming (MIP), Convex Quadratic Programming (QP), Second-Order-Cone Programming (SOCP), Semi-definite Programming (SDP), Mixed Integer Convex Quadratic Programming (MIQP) and Mixed Integer Second-Order-Cone Programming (MISOCP), common used parameters are:

  • verbose

    CVXPY builtin parameter, which controls whether to display solving log to the screen. The default value is False, which means no log to be displayed.

  • params

    This option sets optimization parameters in the form of key=value. Please refer to the chapter Parameters for currently supported parameters.