qiskit_addon_opt_mapper.converters.SpinToBinary

class SpinToBinary[source]

Bases: OptimizationProblemConverter

Convert all spin variables in the problem to binary variables.

The conversion is done by the relation:

s_i = 1 - 2 b_i

where s_i is a spin variable (in {-1, +1}) and b_i is a binary variable (in {0, 1}).

Class initializer.

__init__()[source]

Class initializer.

Return type:

None

Methods

__init__()

Class initializer.

convert(problem)

Convert all spin variables in the problem to binary variables.

interpret(x)

Convert a solution of the converted (binary) problem back to the original (spin) space.

convert(problem)[source]

Convert all spin variables in the problem to binary variables.

Parameters:

problem (OptimizationProblem)

Return type:

OptimizationProblem

interpret(x)[source]

Convert a solution of the converted (binary) problem back to the original (spin) space.

For spins we use s = 1 - 2 b.

Parameters:

x (ndarray | list[float])

Return type:

ndarray