qiskit_addon_opt_mapper.converters.BinaryToSpin

class BinaryToSpin[source]

Bases: OptimizationProblemConverter

Convert all binary variables in the problem to spin variables.

The conversion is done by the relation b_i = (1 - s_i)/2 where b_i is a binary variable and s_i is a spin variable.

Initialize converter.

__init__()[source]

Initialize converter.

Return type:

None

Methods

__init__()

Initialize converter.

convert(problem)

Convert all binary variables in the problem to spin variables.

interpret(x)

Convert a solution of the converted problem back to a solution of the original problem.

convert(problem)[source]

Convert all binary variables in the problem to spin variables.

Parameters:

problem (OptimizationProblem)

Return type:

OptimizationProblem

interpret(x)[source]

Convert a solution of the converted problem back to a solution of the original problem.

For binaries that became spins, we use b = (1 - s)/2.

Parameters:

x (ndarray | list[float])

Return type:

ndarray