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¶
Interface to the CPLEX solver via its official Python interface. |
|
Interface to the CVXOPT solver. |
|
Interface to the ECOS solver via its official Python interface. |
|
Interface to the GLPK solver via swiglpk. |
|
Interface to the Gurobi solver via its official Python interface. |
|
Interface to the MOSEK solver via its high level Fusion API. |
|
Interface to the MOSEK solver via its low level Optimizer API. |
|
Interface to the SCIP solver via the PySCIPOpt Python interface. |
|
Interface to the SMCP solver. |
|
Base class for an interface to an optimization solver. |
Functions¶
Return a dictionary mapping solver names to implementation classes. |
|
Return a sorted list of names of available solvers. |
|
Return the implementation class of the solver with the given name. |
|
Return the registry name of a solver instance. |
Exceptions¶
Two solver options are in conflict. |
|
A solver option is invalid due to another option not being set. |
|
Base class for solver option related errors. |
|
A solver option has an invalid value. |
|
Changes to the problem could not be forward to the solver. |
|
Base class for solver-specific exceptions. |
|
The solver does not support an option. |
Submodules¶
Backend for solver interface implementations. |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
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
-
static
-
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
-
static
-
__init__
(problem)[source]¶ Initialize a CPLEX solver interface.
- Parameters
problem (Problem) – The problem to be solved.
-
classmethod
default_penalty
()[source]¶ Implement
default_penalty
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression, QuadraticExpression subject to DummyConstraint, AffineConstraint, SOCConstraint, RSOCConstraint, ConvexQuadraticConstraint using any variables and any options.>¶
-
nextConstraintID
¶ Used to create unique names for constraints.
-
class
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
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression, LogSumExp subject to DummyConstraint, 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
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression subject to DummyConstraint, 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 byimport 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
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression subject to DummyConstraint, 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
-
static
-
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
-
static
-
__init__
(problem)[source]¶ Initialize a Gurobi solver interface.
- Parameters
problem (Problem) – The problem to be solved.
-
classmethod
default_penalty
()[source]¶ Implement
default_penalty
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression, QuadraticExpression subject to DummyConstraint, AffineConstraint, SOCConstraint, RSOCConstraint, ConvexQuadraticConstraint using any variables and any options.>¶
-
class
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
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression subject to DummyConstraint, 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
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression, QuadraticExpression subject to DummyConstraint, 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
.
-
reset_problem
()[source]¶ Implement
reset_problem
.
-
classmethod
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression subject to DummyConstraint, 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
test_availability
()[source]¶ Implement
test_availability
.
-
SUPPORTED
= <Specification: Optimize AffineExpression subject to DummyConstraint, AffineConstraint, LMIConstraint using RealVariable, ComplexVariable, SymmetricVariable, SkewSymmetricVariable, HermitianVariable, LowerTriangularVariable, UpperTriangularVariable and any options.>¶
-
property
is_smcp
¶ Whether to implement SMCP instead of CVXOPT.
-
classmethod
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 a solution is requested.
Solver implementations are supposed to also implement
__init__
, but withproblem
as its only positional argument, and usingsuper
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.
-
abstract classmethod
is_free
()[source]¶ Report whether the solver is free software.
This allows users to prevent PICOS from using non-free solvers at all, including for internal use, via the
NONFREE_SOLVERS
setting.
-
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), andreset 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
orImportError
) if not. Does not return anything.
-
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.
-
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__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__new__
(**kwargs)¶ 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__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__new__
(**kwargs)¶ 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__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__new__
(**kwargs)¶ 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__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__new__
(**kwargs)¶ 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__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-
SolverError¶
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 thestrictOptions
option is set, otherwise a warning is printed.-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-