dimod.QuadraticModel.change_vartype#
- QuadraticModel.change_vartype(vartype: Literal[Vartype.SPIN, 'SPIN', Vartype.BINARY, 'BINARY', Vartype.INTEGER, 'INTEGER', Vartype.REAL, 'REAL'], v: Hashable) QuadraticModel [source]#
Change the variable type of the given variable, updating the biases.
- Parameters:
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