def quantum_teleportation(alice_state):
    # Get operators we will need
    CNOT = qc.CNOT()
    H = qc.Hadamard()
    X = qc.PauliX()
    Z = qc.PauliZ()

    # The prepared, shared Bell state
    bell = qc.bell_state(0, 0)
    # The whole state vector
    state = alice_state * bell

    # Apply CNOT and Hadamard gate
    state = CNOT(state, qubit_indices=[0, 1])
    state = H(state, qubit_indices=[0])

    # Measure the first two bits
    # The only uncollapsed part of the state vector is Bob's
    M1, M2 = state.measure(qubit_indices=[0, 1], remove=True)

    # Apply X and/or Z gates to third qubit depending on measurements
    if M2:
        state = X(state)
    if M1:
        state = Z(state)

    return state
Beispiel #2
0
    def test_hadamard_pauli_identities(self):
        X = qc.PauliX()
        Y = qc.PauliY()
        Z = qc.PauliZ()
        H = qc.Hadamard()

        self.assertLess(max_absolute_difference(H(X(H)), Z), epsilon)
        self.assertLess(max_absolute_difference(H(Z(H)), X), epsilon)
        self.assertLess(max_absolute_difference(H(Y(H)), -Y), epsilon)
        self.assertLess(max_absolute_difference(X(Y(X)), -Y), epsilon)
Beispiel #3
0
    def test_rotations_equal_pauli(self):
        X = qc.PauliX()
        Y = qc.PauliY()
        Z = qc.PauliZ()
        Rx = qc.RotationX(np.pi)
        Ry = qc.RotationY(np.pi)
        Rz = qc.RotationZ(np.pi)

        self.assertLess(max_absolute_difference(1j * Rx, X), epsilon)
        self.assertLess(max_absolute_difference(1j * Ry, Y), epsilon)
        self.assertLess(max_absolute_difference(1j * Rz, Z), epsilon)
Beispiel #4
0
    def test_pauli_identities(self):
        X = qc.PauliX()
        Y = qc.PauliY()
        Z = qc.PauliZ()

        self.assertLess(max_absolute_difference(X(Y), 1j * Z), epsilon)
        self.assertLess(max_absolute_difference(Y(X), -1j * Z), epsilon)
        self.assertLess(max_absolute_difference(Y(Z), 1j * X), epsilon)
        self.assertLess(max_absolute_difference(Z(Y), -1j * X), epsilon)
        self.assertLess(max_absolute_difference(Z(X), 1j * Y), epsilon)
        self.assertLess(max_absolute_difference(X(Z), -1j * Y), epsilon)
Beispiel #5
0
    def test_hadamard(self):
        """
        H = (X + Y)/sqrt(2)
        """
        H = qc.Hadamard()
        X = qc.PauliX()
        Z = qc.PauliZ()
        H1 = (X + Z) / np.sqrt(2)
        max_diff = max_absolute_difference(H, H1)
        self.assertLess(max_diff, epsilon)
        H2 = (X + Z) * (1 / np.sqrt(2))
        max_diff = max_absolute_difference(H, H2)
        self.assertLess(max_diff, epsilon)
        H3 = 1 / np.sqrt(2) * (Z + X)
        max_diff = max_absolute_difference(H, H3)
        self.assertLess(max_diff, epsilon)

        self.assertLess(max_absolute_difference(np.sqrt(2) * H - Z, X),
                        epsilon)
def superdense_coding(bit_1, bit_2):
    # Get operators we will need
    CNOT = qc.CNOT()
    H = qc.Hadamard()
    X = qc.PauliX()
    Z = qc.PauliZ()

    # The prepared, shared Bell state
    # Initially, half is in Alice's possession, and half in Bob's
    phi = qc.bell_state(0, 0)

    # Alice manipulates her qubit
    if bit_2:
        phi = X(phi, qubit_indices=[0])
    if bit_1:
        phi = Z(phi, qubit_indices=[0])

    # Bob decodes the two bits
    phi = CNOT(phi)
    phi = H(phi, qubit_indices=[0])
    measurements = phi.measure()
    return measurements
Beispiel #7
0
 def test_sqrtnot_squared_equals_X(self):
     R1 = qc.SqrtNot()(qc.SqrtNot())
     R2 = qc.PauliX()
     diff = max_absolute_difference(R1, R2)
     self.assertLess(diff, epsilon)