Backend for solver interface implementations.


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 the strictOptions option is set, otherwise a warning is printed.


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

Bases: abc.ABC

Base class for an interface to an optimization solver.


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 with problem as its only positional argument, and using super to provide fixed values for this method’s additional 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.


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.


Solve the problem and return the solution.

Returns picos.Solution or list(picos.Solution)

A solution object or list thereof.


Return the external (PICOS) problem represenation.

classmethod get_via_name(interface_in_parenthesis=False)[source]

Return the name of the solver with the Python interface used.


Return the solver’s internal problem represenation.

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).

  1. The internal name is a lowercase keyword used for solver selection.

  2. The short name is a properly capitalized official solver shortand.

  3. The long name is the full official name of the solver.

  4. 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 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.


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, 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.


explain (bool) – If True, then this returns a tuple where the first element is this method’s regular return value and where the second element is a string naming one reason why the footprint is not supported (None if it is).

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.


Return the problem’s current verbosity level.

property ext

The “external” (input) problem.

property interface_name

Short name of the Python interface used, or None.

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.