qiskit_addon_opt_mapper.converters.InequalityToEquality

class InequalityToEquality(mode='auto')[source]

Bases: OptimizationProblemConverter

Convert inequality constraints into equality constraints by introducing slack variables.

Examples

>>> from qiskit_addon_opt_mapper.problems import OptimizationProblem
>>> from qiskit_addon_opt_mapper.converters import InequalityToEquality
>>> problem = OptimizationProblem()
>>> # define a problem
>>> conv = InequalityToEquality()
>>> problem2 = conv.convert(problem)

Init method.

Parameters:

mode (str) –

To choose the type of slack variables. There are 3 options for mode.

  • ’integer’: All slack variables will be integer variables.

  • ’continuous’: All slack variables will be continuous variables.

  • ’auto’: Use integer variables if possible, otherwise use continuous variables.

__init__(mode='auto')[source]

Init method.

Parameters:

mode (str) –

To choose the type of slack variables. There are 3 options for mode.

  • ’integer’: All slack variables will be integer variables.

  • ’continuous’: All slack variables will be continuous variables.

  • ’auto’: Use integer variables if possible, otherwise use continuous variables.

Return type:

None

Methods

__init__([mode])

Init method.

convert(problem)

Convert a problem with inequality constraints into one with only equality constraints.

interpret(x)

Convert a result of a converted problem into that of the original problem.

Attributes

mode

Returns the mode of the converter.

convert(problem)[source]

Convert a problem with inequality constraints into one with only equality constraints.

Parameters:

problem (OptimizationProblem) – The problem to be solved, that may contain inequality constraints.

Returns:

The converted problem, that contain only equality constraints.

Raises:
  • OptimizationError – If a variable type is not supported.

  • OptimizationError – If an unsupported mode is selected.

  • OptimizationError – If an unsupported sense is specified.

Return type:

OptimizationProblem

interpret(x)[source]

Convert a result of a converted problem into that of the original problem.

Parameters:

x (ndarray | list[float]) – The result of the converted problem or the given result in case of FAILURE.

Returns:

The result of the original problem.

Return type:

ndarray

property mode: str

Returns the mode of the converter.

Returns:

The mode of the converter used for additional slack variables