dimod.QuadraticModel.change_vartype#

QuadraticModel.change_vartype(vartype: Vartype | str | frozenset, v: Hashable) QuadraticModel[source]#

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

Parameters:
  • vartype

    Variable type. One of:

  • 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