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
Esempio n. 2
0
    def test_CNOT_hadamard_identity(self):
        C = qc.CNOT()
        H = qc.Hadamard()

        C1 = (H * H)(C(H * H, qubit_indices=[1, 0]))

        self.assertLess(max_absolute_difference(C, C1), epsilon)
Esempio n. 3
0
    def test_CNOT_swap_identity(self):
        C = qc.CNOT()
        Sw = qc.Swap()

        Sw1 = C(C(C, qubit_indices=[1, 0]))
        self.assertLess(
            max_absolute_difference(
                Sw, Sw1), epsilon)
Esempio n. 4
0
def bell_state(x, y):
    H = qc.Hadamard()
    CNOT = qc.CNOT()

    phi = qc.bitstring(x, y)
    phi = H(phi, qubit_indices=[0])

    return CNOT(phi)
Esempio n. 5
0
    def test_squared_equals_I(self):
        for Op_type in self.squared_equals_I_list:
            I = qc.Identity()
            U = Op_type()

            diff = max_absolute_difference(U(U), I)
            self.assertLess(diff, epsilon)

        I = qc.Identity(2)
        C = qc.CNOT()
        self.assertLess(max_absolute_difference(C(C), I), epsilon)
Esempio n. 6
0
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