dimod.QuadraticModel.change_vartype

QuadraticModel.change_vartype(vartype: Union[dimod.vartypes.Vartype, str, frozenset], v: Hashable) dimod.quadratic.quadratic_model.QuadraticModel[source]

Change the variable type of the given variable, updating the biases.

Parameters
  • vartype

    Variable type. One of:

    • Vartype.SPIN, 'SPIN', {-1, 1}

    • Vartype.BINARY, 'BINARY', {0, 1}

    • Vartype.INTEGER, 'INTEGER'

  • v – Variable to change to the specified vartype.

Example

>>> qm = dimod.QuadraticModel()
>>> a = qm.add_variable('SPIN', 'a')
>>> qm.set_linear(a, 1.5)
>>> qm.energy({a: +1})
1.5
>>> qm.energy({a: -1})
-1.5
>>> qm.change_vartype('BINARY', a)
QuadraticModel({'a': 3.0}, {}, -1.5, {'a': 'BINARY'}, dtype='float64')
>>> qm.energy({a: 1})
1.5
>>> qm.energy({a: 0})
-1.5