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
def test_schmidt_examples(self): self.assertEqual(qc.bell_state().schmidt_number(indices=[0]), 2) self.assertEqual( qc.positive_superposition(d=2).schmidt_number(indices=[0]), 1) x = (qc.bitstring(0, 0) + qc.bitstring(0, 1) + qc.bitstring(1, 0)) / np.sqrt(3) self.assertEqual(x.schmidt_number(indices=[0]), 2)
def test_bell_state_measurement2(self): state = qc.bell_state(0, 0) rho1 = qc.DensityOperator.from_ensemble([state]) idx = np.random.randint(2) m = rho1.measure(qubit_indices=[idx], remove=True)[0] state = qc.bitstring(m) rho2 = qc.DensityOperator.from_ensemble([state]) assert_allclose(rho1._t, rho2._t)
def test_unitarily_unchanged(self): num_tests = 10 for test_i in range(num_tests): x = qc.positive_superposition(d=2) U = random_unitary_operator(d=1) * random_unitary_operator(d=1) self.assertEqual(U(x).schmidt_number(indices=[0]), 1) x = qc.bell_state() U = random_unitary_operator(d=1) * random_unitary_operator(d=1) self.assertEqual(U(x).schmidt_number(indices=[0]), 2)
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
def test_bell_state_unit_length(self): for x, y in product([0, 1], repeat=2): state = qc.bell_state(x, y) diff = abs(state.probabilities.sum() - 1) self.assertLess(diff, epsilon)
def test_bell_state_example(self): for x, y in product([0, 1], repeat=2): state1 = qc.bell_state(x, y) state2 = produce_bell_states.bell_state(x, y) diff = max_absolute_difference(state1, state2) self.assertLess(diff, epsilon)