def controlled_x(self, q, rnd): Gates.Z(q, 0) if Measurement.rr_measurement(q, [PauliZ(), PauliX()], [0, 1], rnd) == -1: Gates.Z(q, 1) Gates.H(q, 1) Gates.Z(q, 0)
def all_bell_states(self, q, ix): Gates.H(q, 0) if ix >= 2: Gates.X(q, 1) Gates.CNOT(q, 0, 1) if ix % 2 == 1: Gates.Z(q, 0)
def bell_state(self, q, index): assert q.length == 2 Gates.H(q, 0) Gates.CNOT(q, 0, 1) if index % 2 == 1: Gates.Z(q, 1) if index >= 2: Gates.X(q, 1)
def controlled_x_general(self, q): # Gates.CNOT(q, 0, 1) items = [0.1, 0.9] r1, r2, r3 = choice(items), choice(items), choice(items) bad = [[0.1, 0.9, 0.9], [0.9, 0.9, 0.1]] if [r1, r2, r3] in bad: r1, r2, r3 = [0.1, 0.1, 0.1] print r1, r2, r3 q.add_qubit() #print "before measurement", q p1 = self.copy_qubit(q, 1, 0, r1) #print "after measurement", q Gates.H(q, 0) Gates.H(q, 2) p2 = Measurement.rr_measurement(q, [PauliZ(), PauliZ()], [0, 2], r2) Gates.H(q, 0) Gates.H(q, 2) if p2 == -1: Gates.Z(q, 1) if p1 != Measurement.rr_measurement(q, [PauliZ()], [0], r3): Gates.X(q, 2) #print "after CNOT", q q.remove_qubit()
def check_a_b(self, q, alpha): Gates.Z(q, 0) Gates.RY(q, -2 * alpha, 0) return not self.single_qubit(q)
def superposition_basis(self, q): self.superposition(q) Gates.Z(q, 0) Gates.R1(q, pi, 1)
def sign_flip(self, q): Gates.Z(q, 0)
print q Gates.CNOT(q, iy, ix) print q m = Measurement.measure(q, ix) print m, q Gates.CNOT(q, iy, ix) print m, q Gates.H(q, iy) print m, q Gates.H(q, ix) print m, q def mZX(q, ix, iy): Gates.H(q, iy) Gates.CNOT(q, iy, ix) m = Measurement.measure(q, ix) Gates.CNOT(q, iy, ix) Gates.H(q, iy) print m, q q = Qubits(2) Gates.H(q, 0) Gates.H(q, 1) Gates.CY(q, 1, 0) Gates.CZ(q, 0, 1) Gates.Z(q, 0) Gates.Z(q, 1) print(q)