dimod.generators.xor_gate#

xor_gate(in0: Hashable, in1: Hashable, out: Hashable, aux: Hashable, *, strength: float = 1.0) BinaryQuadraticModel[source]#

Generate a binary quadratic model with ground states corresponding to an XOR gate.

Note that it is not possible to construct a binary quadratic model with only three variables for an XOR gate.

Parameters:
  • in0 – Variable label for one of the inputs.

  • in1 – Variable label for one of the inputs.

  • out – Variable label for the output.

  • aux – Variable label for an auxiliary variable.

  • strength – Energy of the lowest-energy infeasible state.

Returns:

A binary quadratic model with ground states corresponding to an XOR gate. The model has four variables and six interactions.

Examples

>>> bqm = dimod.generators.xor_gate('x1', 'x2', 'z', 'a')
>>> print(dimod.ExactSolver().sample(bqm).lowest())
   a x1 x2  z energy num_oc.
0  0  0  0  0    0.0       1
1  0  0  1  1    0.0       1
2  0  1  0  1    0.0       1
3  1  1  1  0    0.0       1
['BINARY', 4 rows, 4 samples, 4 variables]