picos.solvers.solver¶
Backend for solver interface implementations.
Exceptions
- exception picos.solvers.solver.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.
- exception picos.solvers.solver.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.
- exception picos.solvers.solver.OptionError[source]¶
Bases:
picos.solvers.solver.SolverError
Base class for solver option related errors.
- exception picos.solvers.solver.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.
- exception picos.solvers.solver.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.
- exception picos.solvers.solver.SolverError[source]¶
Bases:
Exception
Base class for solver-specific exceptions.
- exception picos.solvers.solver.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.
Classes
- class picos.solvers.solver.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.
- static check_import(importName)[source]¶
Asserts that a module is available without actually importing it.
- Raises
ModuleNotFoundError – If the module could not be found.
- 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.
- classmethod get_via_name(interface_in_parenthesis=False)[source]¶
Return the name of the solver with the Python interface used.
- 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.
- abstract classmethod names()[source]¶
Return a name sequence
(internal, short, long, interface)
.The internal name is a lowercase keyword used for solver selection.
The short name is a properly capitalized official solver shortand.
The long name is the full official name of the solver.
The interface name is a properly capitalized short name of the Python interface used, or
None
if the solver is Python-native or includes a unique Python interface.
- 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, explain=False)[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 ext¶
The “external” (input) problem.
- property long_name¶
Long name of the solver.
- property name¶
Keyword string of the solver.
- property short_name¶
Short name of the solver.
- property via_name¶
The short names of the solver and Python interface used.