dimod.binary.BinaryQuadraticModel.spin#

property BinaryQuadraticModel.spin: BinaryQuadraticModel[source]#

Spin-valued version of the binary quadratic model.

If the binary quadratic model is spin-valued, this references itself, otherwise it references a view.

Examples

This example exploits the simplicity of the Ising representation of a Boolean NOT gate, \(s_1s_2\), relative to its QUBO counterpart, \(2x_1x_2−x_1−x_2+1\), to change a QUBO representation of an AND gate, derived in the Ocean documentation’s AND example, to represent a NAND gate.

>>> Q = [[0, 1, -2], [0, 0, -2], [0, 0, 3]]
>>> x = dimod.BinaryArray(["in1", "in2", "out_and"])
>>> bqm = x.dot(Q).dot(x)               # bqm represents an AND gate
>>> bqm.spin.add_quadratic("out_and", "out_nand", 1)    # adds a NOT
>>> bqm.vartype is dimod.Vartype.BINARY
True
>>> print(dimod.ExactSolver().sample(bqm).lowest())
  in1 in2 out_and out_nand energy num_oc.
0   1   1       1        0   -1.0       1
1   0   1       0        1   -1.0       1
2   1   0       0        1   -1.0       1
3   0   0       0        1   -1.0       1
['BINARY', 4 rows, 4 samples, 4 variables]