def test_layeredCNOT(self): reg = Q.create_register(3) reg[0].X() # |1> Q.CNOT(reg[0], reg[1]) reg[2].X() # |1> Q.CNOT(reg[1], reg[2]) m = reg[2].M() self.assertTrue(not m)
def test_superdense(self): c = Q.Circuit() A, B = c.create_qubits(2) A.H() Q.CNOT(A, B) A.ZX() Q.CNOT(A, B) A.H() self.assertEqual(c.M_many(A, B), "11")
def test_H1CNOT(self): bit1, bit2 = Q.create_register(2) bit1.H() bit2.X() Q.CNOT(bit1, bit2) m1, m2 = bit1.M(), bit2.M() self.assertNotEqual(m1, m2)
def test_01CNOT(self): # bit1 = Q.Qubit(Q.State.zero()) # bit2 = Q.Qubit(Q.State.one()) bit1, bit2 = Q.create_register(2) bit2.X() Q.CNOT(bit1, bit2) m1, m2 = bit1.M(), bit2.M() self.assertTrue((not m1) and m2)
def add(self, other): n = max(other.l, self.l) circ = Q.Circuit() reg = circ.create_qubits((3 * n) + 1) a = reg[0:n] b = reg[n:(2 * n) + 1] c = reg[(2 * n) + 1:] cl = [0 for i in range(n + 1)] for idx, i in enumerate(self.register): if i == 1: a[self.l - (idx + 1)].X() for idx, i in enumerate(other.register): if i == 1: b[other.l - (idx + 1)].X() for i in range(n - 1): Q.CCNOT(a[i], b[i], c[i + 1]) Q.CNOT(a[i], b[i]) Q.CCNOT(c[i], b[i], c[i + 1]) Q.CCNOT(a[n - 1], b[n - 1], b[n]) Q.CNOT(a[n - 1], b[n - 1]) Q.CCNOT(c[n - 1], b[n - 1], b[n]) Q.CNOT(c[n - 1], b[n - 1]) for i in range(n - 1): Q.CCNOT(c[(n - 2) - i], b[(n - 2) - i], c[(n - 1) - i]) Q.CNOT(a[(n - 2) - i], b[(n - 2) - i]) Q.CCNOT(a[(n - 2) - i], b[(n - 2) - i], c[(n - 1) - i]) Q.CNOT(c[(n - 2) - i], b[(n - 2) - i]) Q.CNOT(a[(n - 2) - i], b[(n - 2) - i]) for i in range(n + 1): cl[n - i] = b[i].M(rtype=int) return QInteger(cl)
import quantum as Q c = Q.Circuit() A, B, C, D = c.create_qubits(4) B.H() Q.CNOT(A, B) Q.CNOT(C, D) Q.CNOT(B, C) pass