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_1H1CCNOT(self): reg = Q.create_register(3) reg[0].X() reg[1].H() reg[2].X() Q.CCNOT(*reg) m1, m2, m3 = Q.observe_all(*reg) self.assertTrue(m1 and (m2 != m3))
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 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 execute(self, env): if self.dtype == None: return env.overwrite( self.address, self.address + self.size, list(Q.create_register(self.size)) if self.dtype == "Q" else [0 for i in range(self.size)])