picos.solvers

Optimization solver interfaces.

This package contains the interfaces to the optimization solvers that PICOS uses as its backend. You do not need to instanciate any of the solver classes directly; if you want to select a particular solver, it is most convenient to supply it to Problem.solve via the solver keyword argument.

Outline

Classes

CPLEXSolver

Interface to the CPLEX solver via its official Python interface.

CVXOPTSolver

Interface to the CVXOPT solver.

ECOSSolver

Interface to the ECOS solver via its official Python interface.

GLPKSolver

Interface to the GLPK solver via swiglpk.

GurobiSolver

Interface to the Gurobi solver via its official Python interface.

MOSEKFusionSolver

Interface to the MOSEK solver via its high level Fusion API.

MOSEKSolver

Interface to the MOSEK solver via its low level Optimizer API.

SCIPSolver

Interface to the SCIP solver via the PySCIPOpt Python interface.

SMCPSolver

Interface to the SMCP solver.

Solver

Base class for an interface to an optimization solver.

Functions

all_solvers

Return a dictionary mapping solver names to implementation classes.

available_solvers

Return a sorted list of names of available solvers.

get_solver

Return the implementation class of the solver with the given name.

get_solver_name

Return the registry name of a solver instance.

Exceptions

ConflictingOptionsError

Two solver options are in conflict.

DependentOptionError

A solver option is invalid due to another option not being set.

OptionError

Base class for solver option related errors.

OptionValueError

A solver option has an invalid value.

ProblemUpdateError

Changes to the problem could not be forward to the solver.

SolverError

Base class for solver-specific exceptions.

UnsupportedOptionError

The solver does not support an option.

Submodules

picos.solvers.solver

Backend for solver interface implementations.

picos.solvers.solver_cplex

Implementation of CPLEXSolver.

picos.solvers.solver_cvxopt

Implementation of CVXOPTSolver.

picos.solvers.solver_ecos

Implementation of ECOSSolver.

picos.solvers.solver_glpk

Implementation of GLPKSolver.

picos.solvers.solver_gurobi

Implementation of GurobiSolver.

picos.solvers.solver_mosek

Implementation of MOSEKSolver.

picos.solvers.solver_mskfsn

Implementation of MOSEKFusionSolver.

picos.solvers.solver_scip

Implementation of SCIPSolver.

picos.solvers.solver_smcp

Implementation of SMCPSolver.

Classes

CPLEXSolver

class picos.solvers.CPLEXSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the CPLEX solver via its official Python interface.

Note

Names are used instead of indices for identifying both variables and constraints since indices can change if the CPLEX instance is modified.

class CplexRSOCC(LHSVars, RHSVars, LHSCons, RHSCons, quadCon)

Bases: tuple

static __new__(_cls, LHSVars, RHSVars, LHSCons, RHSCons, quadCon)

Create new instance of CplexRSOCC(LHSVars, RHSVars, LHSCons, RHSCons, quadCon)

LHSCons

Alias for field number 2

LHSVars

Alias for field number 0

RHSCons

Alias for field number 3

RHSVars

Alias for field number 1

quadCon

Alias for field number 4

class CplexSOCC(LHSVars, RHSVar, LHSCons, RHSCon, quadCon)

Bases: tuple

static __new__(_cls, LHSVars, RHSVar, LHSCons, RHSCon, quadCon)

Create new instance of CplexSOCC(LHSVars, RHSVar, LHSCons, RHSCon, quadCon)

LHSCons

Alias for field number 2

LHSVars

Alias for field number 0

RHSCon

Alias for field number 3

RHSVar

Alias for field number 1

quadCon

Alias for field number 4

__init__(problem)[source]

Initialize a CPLEX solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression, QuadraticExpression subject to AffineConstraint, SOCConstraint, RSOCConstraint, ConvexQuadraticConstraint using any variables and any options.>
nextConstraintID = None

Used to create unique names for constraints.

CVXOPTSolver

class picos.solvers.CVXOPTSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the CVXOPT solver.

Also used as an interface to the SMCP solver.

__init__(problem)[source]

Initialize a CVXOPT solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression, LogSumExp subject to AffineConstraint, SOCConstraint, RSOCConstraint, LMIConstraint, LogSumExpConstraint using RealVariable, ComplexVariable, SymmetricVariable, SkewSymmetricVariable, HermitianVariable, LowerTriangularVariable, UpperTriangularVariable and any options.>
property is_smcp

Whether to implement SMCP instead of CVXOPT.

ECOSSolver

class picos.solvers.ECOSSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the ECOS solver via its official Python interface.

__init__(problem)[source]

Initialize an ECOS solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

stack(*args)[source]

Stack vectors or matrices, the latter vertically.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

zeros(shape)[source]

Create a zero array or a zero matrix, depending on shape.

SUPPORTED = <Specification: Optimize AffineExpression subject to AffineConstraint, SOCConstraint, RSOCConstraint, ExpConeConstraint using any variables and any options.>
property array

ECOS’ array type.

property ecos

Return the ECOS core module ecos.py.

The module is obtained by import ecos up to ECOS 2.0.6 and by import ecos.ecos starting with ECOS 2.0.7.

property matrix

ECOS’ matrix type.

GLPKSolver

class picos.solvers.GLPKSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the GLPK solver via swiglpk.

__init__(problem)[source]

Initialize a GLPK solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression subject to AffineConstraint using any variables and any options.>

GurobiSolver

class picos.solvers.GurobiSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the Gurobi solver via its official Python interface.

class GurobiRSOCC(LHSVars, RHSVars, LHSCons, RHSCons, quadCon)

Bases: tuple

static __new__(_cls, LHSVars, RHSVars, LHSCons, RHSCons, quadCon)

Create new instance of GurobiRSOCC(LHSVars, RHSVars, LHSCons, RHSCons, quadCon)

LHSCons

Alias for field number 2

LHSVars

Alias for field number 0

RHSCons

Alias for field number 3

RHSVars

Alias for field number 1

quadCon

Alias for field number 4

class GurobiSOCC(LHSVars, RHSVar, LHSCons, RHSCon, quadCon)

Bases: tuple

static __new__(_cls, LHSVars, RHSVar, LHSCons, RHSCon, quadCon)

Create new instance of GurobiSOCC(LHSVars, RHSVar, LHSCons, RHSCon, quadCon)

LHSCons

Alias for field number 2

LHSVars

Alias for field number 0

RHSCon

Alias for field number 3

RHSVar

Alias for field number 1

quadCon

Alias for field number 4

__init__(problem)[source]

Initialize a Gurobi solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression, QuadraticExpression subject to AffineConstraint, SOCConstraint, RSOCConstraint, ConvexQuadraticConstraint using any variables and any options.>

MOSEKFusionSolver

class picos.solvers.MOSEKFusionSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the MOSEK solver via its high level Fusion API.

Supports both MOSEK 8 and 9.

The Fusion API is currently much slower than MOSEK’s low level Python API. If this changes in the future, the Fusion API would be the prefered interface.

__init__(problem)[source]

Initialize a MOSEK (Fusion) solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression subject to AffineConstraint, SOCConstraint, RSOCConstraint, LMIConstraint using any variables and any options.>
property ver

The major version of the available MOSEK library.

MOSEKSolver

class picos.solvers.MOSEKSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the MOSEK solver via its low level Optimizer API.

Supports both MOSEK 8 and 9.

The low level API is tedious to interface, but is currently much faster than the high level Fusion API, which would be the prefered interface otherwise.

__init__(problem)[source]

Initialize a MOSEK (Optimizer) solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression, QuadraticExpression subject to AffineConstraint, SOCConstraint, RSOCConstraint, ConvexQuadraticConstraint, LMIConstraint using any variables and any options.>
property env

This references a MOSEK environment, which is shared among all MOSEKSolver instances. (The MOSEK documentation states that “[a]ll tasks in the program should share the same environment.”)

property ver

The major version of the available MOSEK library.

SCIPSolver

class picos.solvers.SCIPSolver(problem)[source]

Bases: picos.solvers.solver.Solver

Interface to the SCIP solver via the PySCIPOpt Python interface.

__init__(problem)[source]

Initialize a SCIP solver interface.

Parameters

problem (Problem) – The problem to be solved.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

reset_problem()[source]

Implement reset_problem.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression subject to AffineConstraint, SOCConstraint, RSOCConstraint, ConvexQuadraticConstraint, NonconvexQuadraticConstraint using any variables and any options.>

SMCPSolver

class picos.solvers.SMCPSolver(problem)[source]

Bases: picos.solvers.solver_cvxopt.CVXOPTSolver

Interface to the SMCP solver.

Most of the logic is implemented in the CVXOPTSolver base class.

classmethod default_penalty()[source]

Implement default_penalty.

classmethod names()[source]

Implement names.

classmethod supports(footprint)[source]

Implement supports.

classmethod test_availability()[source]

Implement test_availability.

SUPPORTED = <Specification: Optimize AffineExpression subject to AffineConstraint, LMIConstraint using RealVariable, ComplexVariable, SymmetricVariable, SkewSymmetricVariable, HermitianVariable, LowerTriangularVariable, UpperTriangularVariable and any options.>
property is_smcp

Whether to implement SMCP instead of CVXOPT.

Solver

class picos.solvers.Solver(problem)[source]

Bases: abc.ABC

Base class for an interface to an optimization solver.

__init__(problem)[source]

Instanciate a solver interface with an optimization problem.

An exception is raised when the solver is not available on the user’s platform. No exception is raised when the problem type is not supported as the problem is first imported when the user calls solve.

Solver implementations are supposed to also implement __init__, but with problem as its only positional argument, and using super to provide fixed values for this method’s additional parameters.

Parameters

problem (Problem) – A PICOS optimization problem.

classmethod available(verbose=False)[source]

Whether the solver is properly installed on the system.

abstract classmethod default_penalty()[source]

Report the default penalty for the solver.

See Options for the scale.

execute()[source]

Solve the problem and return the solution.

Returns picos.Solution or list(picos.Solution)

A solution object or list thereof.

external_problem()[source]

Return the external (PICOS) problem represenation.

internal_problem()[source]

Return the solver’s internal problem represenation.

abstract classmethod names()[source]

Returns a triple (name, display_name, long_display_name).

classmethod penalty(options)[source]

Report solver penalty given an Options object.

classmethod predict(footprint)[source]

Return the solver class.

This mimics the behavior of Reformulation.predict so that solvers can be the last pipeline node in a reformulation strategy.

reset()[source]

A shorthand for reset_problem.

This is defined for consistency with Reformulation.reset.

abstract reset_problem()[source]

Reset the solver’s internal problem representation and related data.

Method implementations are supposed to

  • set int to None (after performing any garbage collection), and

  • reset all additional problem metadata to the state it had after __init__, in particular the data stored for _update_problem.

Solver implementations should not call reset_problem directly, except from within __init__ if this is convenient.

The user may call this method at any time if they wish to solve the problem from scratch.

abstract classmethod supports(footprint)[source]

Whether a type of problem, given by footprint, is supported.

The default implementation ensures that all reformulations required by user’s choice have been performed before the problem is handed to the solver. Solver implementations are thus required to incorporate it.

abstract classmethod test_availability()[source]

Raise an exception if the solver is not installed on the system.

Checks whether the solver is installed on the system, and raises an appropriate exception (usually ModuleNotFoundError or ImportError) if not. Does not return anything.

verbosity()[source]

Return the problem’s current verbosity level.

property display_name

Short display name of the solver.

property ext

The “external” (input) problem.

property long_display_name

Long display name of the solver.

property name

Keyword string of the solver.

Functions

all_solvers

picos.solvers.all_solvers()[source]

Return a dictionary mapping solver names to implementation classes.

available_solvers

picos.solvers.available_solvers(problem=None)[source]

Return a sorted list of names of available solvers.

Parameters

problem – DEPRECATED

get_solver

picos.solvers.get_solver(name)[source]

Return the implementation class of the solver with the given name.

get_solver_name

picos.solvers.get_solver_name(solver)[source]

Return the registry name of a solver instance.

Exceptions

ConflictingOptionsError

exception picos.solvers.ConflictingOptionsError[source]

Bases: picos.solvers.solver.OptionError

Two solver options are in conflict.

Raised by implementations of _solve to signal to the user that two options they specified cannot be used in conjunction.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__new__()

Create and return a new object. See help(type) for accurate signature.

DependentOptionError

exception picos.solvers.DependentOptionError[source]

Bases: picos.solvers.solver.OptionError

A solver option is invalid due to another option not being set.

Raised by implementations of _solve to signal to the user that an option they specified needs another option to also be set.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__new__()

Create and return a new object. See help(type) for accurate signature.

OptionError

exception picos.solvers.OptionError[source]

Bases: picos.solvers.solver.SolverError

Base class for solver option related errors.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__new__()

Create and return a new object. See help(type) for accurate signature.

OptionValueError

exception picos.solvers.OptionValueError[source]

Bases: picos.solvers.solver.OptionError, ValueError

A solver option has an invalid value.

Raised by implementations of _solve to signal to the user that they have set an option to an invalid value.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__new__()

Create and return a new object. See help(type) for accurate signature.

ProblemUpdateError

exception picos.solvers.ProblemUpdateError[source]

Bases: picos.solvers.solver.SolverError

Changes to the problem could not be forward to the solver.

Raised by implementations of _update_problem to signal to the method _load_problem that the problem needs to be re-imported.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__new__()

Create and return a new object. See help(type) for accurate signature.

SolverError

exception picos.solvers.SolverError[source]

Bases: Exception

Base class for solver-specific exceptions.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__new__()

Create and return a new object. See help(type) for accurate signature.

UnsupportedOptionError

exception picos.solvers.UnsupportedOptionError[source]

Bases: picos.solvers.solver.OptionError

The solver does not support an option.

Raised by implementations of _solve to signal to the user that an option they specified is not supported by the solver or the requested sub-solver, or in conjunction with the given problem type or with another option. If the option is valid but not supported by PICOS, then NotImplementedError should be raised instead. The exception is only raised if the strictOptions option is set, otherwise a warning is printed.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__new__()

Create and return a new object. See help(type) for accurate signature.