dimod.QuadraticModel.flip_variable#

QuadraticModel.flip_variable(v: Hashable)[source]#

Flip the specified binary-valued variable.

Parameters:

v – Binary-valued (\(\{0, 1\}\) or \(\{-1, 1\}\)) variable in the quadratic model.

Raises:

Examples

In this example we flip the value of a binary variable x. That is we substitute (1 - x) which always takes the opposite value.

>>> x = dimod.Binary('x')
>>> s = dimod.Spin('s')
>>> qm = x + 2*s + 3*x*s
>>> qm.flip_variable('x')
>>> qm.is_equal((1-x) + 2*s + 3*(1-x)*s)
True

In this example we flip the value of a spin variable s. That is we substitute -s which always takes the opposite value.

>>> x = dimod.Binary('x')
>>> s = dimod.Spin('s')
>>> qm = x + 2*s + 3*x*s
>>> qm.flip_variable('s')
>>> qm.is_equal(x + 2*-s + 3*x*-s)
True