def test_equality(self): xor1 = XorConst(Binary("a"), Binary("b"), Binary("c"), label="xor") xor2 = XorConst(Binary("a"), Binary("b"), Binary("c"), label="xor") xor3 = XorConst(Binary("b"), Binary("c"), Binary("a"), label="xor") or1 = OrConst(Binary("a"), Binary("b"), Binary("c"), label="xor") self.assertTrue(xor1 + 1 == xor2 + 1) self.assertTrue(xor1 == xor2) self.assertFalse(xor1 == or1) self.assertFalse(xor1 == xor3)
def test_xor(self): a, b, c = Qbit("a"), Qbit("b"), Qbit("c") exp = XorConst(a, b, c, label="xor") model = exp.compile() self.assertTrue(model.energy({"a": 1, "b": 1, "c": 0, "aux_xor": 1}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 1, "b": 0, "c": 1, "aux_xor": 0}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 0, "b": 1, "c": 1, "aux_xor": 0}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 1, "b": 1, "c": 0, "aux_xor": 1}, vartype="BINARY") == 0) self.assertTrue(model.energy({"a": 0, "b": 0, "c": 1, "aux_xor": 1}, vartype="BINARY") > 0) self.assertTrue(model.energy({"a": 1, "b": 1, "c": 1, "aux_xor": 1}, vartype="BINARY") > 0)