dimod.BinaryQuadraticModel.change_vartype

BinaryQuadraticModel.change_vartype(**kwargs)[source]

Create a binary quadratic model with the specified vartype.

Parameters:
  • vartype (Vartype/str/set, optional) –

    Variable type for the changed model. Accepted input values:

    • Vartype.SPIN, 'SPIN', {-1, 1}
    • Vartype.BINARY, 'BINARY', {0, 1}
  • inplace (bool, optional, default=True) – If True, the binary quadratic model is updated in-place; otherwise, a new binary quadratic model is returned.
Returns:

BinaryQuadraticModel. A new binary quadratic model with vartype matching input ‘vartype’.

Examples

This example creates an Ising model and then creates a QUBO from it.

>>> import dimod
...
>>> bqm_spin = dimod.BinaryQuadraticModel({1: 1, 2: 2}, {(1, 2): 0.5}, 0.5, dimod.SPIN)
>>> bqm_qubo = bqm_spin.change_vartype('BINARY', inplace=False)
>>> bqm_spin.offset, bqm_spin.vartype
(0.5, <Vartype.SPIN: frozenset({1, -1})>)
>>> bqm_qubo.offset, bqm_qubo.vartype
(-2.0, <Vartype.BINARY: frozenset({0, 1})>)