dimod.QuadraticModel.spin_to_binary#

QuadraticModel.spin_to_binary(inplace: bool = False) QuadraticModel[source]#

Convert any spin-valued variables to binary-valued.

Parameters:

inplace – If set to False, returns a new quadratic model with spin-valued variables converted to binary-valued variables.

Examples

>>> from dimod import QuadraticModel
>>> qm = QuadraticModel()
>>> qm.add_variables_from('SPIN', ['s1', 's2'])
>>> qm.add_variable('BINARY', 'b')
'b'
>>> qm_b = qm.spin_to_binary(inplace=False)
>>> qm_b.vartype('s1')
<Vartype.BINARY: frozenset({0, 1})>