def test_measure_order(self): """Order of measurement must not make a difference.""" b00 = bell.bell_state(0, 0) _, b00 = ops.Measure(b00, 0, tostate=0) _, b00 = ops.Measure(b00, 1, tostate=0) self.assertTrue(math.isclose(b00.prob(0, 0), 1.0)) self.assertTrue(math.isclose(b00.prob(1, 1), 0.0)) b00 = bell.bell_state(0, 0) _, b00 = ops.Measure(b00, 1, tostate=0) _, b00 = ops.Measure(b00, 0, tostate=0) self.assertTrue(math.isclose(b00.prob(0, 0), 1.0)) self.assertTrue(math.isclose(b00.prob(1, 1), 0.0))
def main(argv): if len(argv) > 1: raise app.UsageError('Too many command-line arguments.') # Step 1: Alice and Bob share an entangled pair, and separate. psi = bell.bell_state(0, 0) # Step 2: Alice wants to teleport a qubit |x> to Bob, # which is in the state: # |x> = a|0> + b|1> (with a^2 + b^2 == 1) a = 0.6 b = math.sqrt(1.0 - a * a) x = state.qubit(a, b) print('Quantum Teleportation') print('Start with EPR Pair a={:.2f}, b={:.2f}'.format(a, b)) # Produce combined state. alice = x * psi # Alice lets the 1st qubit interact with the 2nd qubit, which is her # part of the entangle state with Bob. alice = ops.Cnot(0, 1)(alice) # Now she applies a Hadamard to qubit 0. Bob still owns qubit 2. alice = ops.Hadamard()(alice, idx=0) # Alices measures and communicates the result (|00>, |01>, ...) to Bob. alice_measures(alice, a, b, 0, 0) alice_measures(alice, a, b, 0, 1) alice_measures(alice, a, b, 1, 0) alice_measures(alice, a, b, 1, 1)
def test_bell_and_pauli(self): b00 = bell.bell_state(0, 0) bell_xz = ops.PauliX()(b00) bell_xz = ops.PauliZ()(bell_xz) bell_iy = (1j * ops.PauliY())(b00) self.assertTrue(np.allclose(bell_xz, bell_iy))
def test_not_pure(self): """Bell states are pure states.""" for a in [0, 1]: for b in [0, 1]: b = bell.bell_state(a, b) self.assertTrue(b.density().is_pure()) self.assertTrue( math.isclose(np.real(np.trace(b.density())), 1.0, abs_tol=1e-6))
def test_bell(self): """Check successful entanglement by computing the schmidt_number.""" b00 = bell.bell_state(0, 0) self.assertGreater(b00.schmidt_number([1]), 1.0) self.assertTrue( b00.is_close((state.zeros(2) + state.ones(2)) / math.sqrt(2))) # Note the order is reversed from pictorials. op_exp = (ops.Cnot(0, 1) @ (ops.Hadamard() * ops.Identity())) b00_exp = op_exp(state.zeros(2)) self.assertTrue(b00.is_close(b00_exp)) b01 = bell.bell_state(0, 1) self.assertGreater(b01.schmidt_number([1]), 1.0) b10 = bell.bell_state(1, 0) self.assertGreater(b10.schmidt_number([1]), 1.0) b11 = bell.bell_state(1, 1) self.assertGreater(b11.schmidt_number([1]), 1.0)
def test_measure(self): b00 = bell.bell_state(0, 1) self.assertTrue(math.isclose(b00.prob(0, 1), 0.5, abs_tol=1e-6)) self.assertTrue(math.isclose(b00.prob(1, 0), 0.5, abs_tol=1e-6)) _, b00 = ops.Measure(b00, 0, tostate=0) self.assertTrue(math.isclose(b00.prob(0, 1), 1.0, abs_tol=1e-6)) self.assertTrue(math.isclose(b00.prob(1, 0), 0.0, abs_tol=1e-6)) # This state can't be measured, all zeros. _, b00 = ops.Measure(b00, 1, tostate=1) self.assertTrue(math.isclose(b00.prob(1, 0), 0.0, abs_tol=1e-6)) b00 = bell.bell_state(0, 1) self.assertTrue(math.isclose(b00.prob(0, 1), 0.5, abs_tol=1e-6)) self.assertTrue(math.isclose(b00.prob(1, 0), 0.5, abs_tol=1e-6)) _, b00 = ops.Measure(b00, 0, tostate=1) self.assertTrue(math.isclose(b00.prob(0, 1), 0.0, abs_tol=1e-6)) self.assertTrue(math.isclose(b00.prob(1, 0), 1.0, abs_tol=1e-6)) # This state can't be measured, all zeros. p, _ = ops.Measure(b00, 1, tostate=1, collapse=False) self.assertEqual(p, 0.0)
def main(argv): if len(argv) > 1: raise app.UsageError('Too many command-line arguments.') # Step 1: Alice and Bob share an entangled pair, and separate. psi = bell.bell_state(0, 0) # Alices manipulates her qubit and sends her 1 qubit back to Bob, # who measures. In the Hadamard basis he would get b00, b01, etc. # but we're measuring in the computational basis by reverse # applying Hadamard and Cnot. for bit0 in range(2): for bit1 in range(2): psi_alice = alice_manipulates(psi, bit0, bit1) bob_measures(psi_alice, bit0, bit1)
def test_partial(self): """Test partial trace.""" psi = bell.bell_state(0, 0) reduced = ops.TraceOut(psi.density(), [0]) self.assertTrue( math.isclose(np.real(np.trace(reduced)), 1.0, abs_tol=1e-6)) self.assertTrue(math.isclose(np.real(reduced[0, 0]), 0.5, abs_tol=1e-6)) self.assertTrue(math.isclose(np.real(reduced[1, 1]), 0.5, abs_tol=1e-6)) q0 = state.qubit(alpha=0.5) q1 = state.qubit(alpha=0.8660254) psi = q0 * q1 reduced = ops.TraceOut(psi.density(), [0]) self.assertTrue(math.isclose(np.real(np.trace(reduced)), 1.0)) self.assertTrue( math.isclose(np.real(reduced[0, 0]), 0.75, abs_tol=1e-6)) self.assertTrue( math.isclose(np.real(reduced[1, 1]), 0.25, abs_tol=1e-6)) reduced = ops.TraceOut(psi.density(), [1]) self.assertTrue(math.isclose(np.real(np.trace(reduced)), 1.0)) self.assertTrue( math.isclose(np.real(reduced[0, 0]), 0.25, abs_tol=1e-6)) self.assertTrue( math.isclose(np.real(reduced[1, 1]), 0.75, abs_tol=1e-6)) psi = q1 * q0 * state.qubit(alpha=(0.8660254)) reduced = ops.TraceOut(psi.density(), [2]) reduced = ops.TraceOut(reduced, [0]) self.assertTrue(math.isclose(np.real(np.trace(reduced)), 1.0)) self.assertTrue(math.isclose(np.real(reduced[0, 0]), 0.25)) self.assertTrue(math.isclose(np.real(reduced[1, 1]), 0.75)) psi = q1 * q0 * state.qubit(alpha=(0.8660254)) reduced = ops.TraceOut(psi.density(), [0, 2]) self.assertTrue(math.isclose(np.real(np.trace(reduced)), 1.0)) self.assertTrue(math.isclose(np.real(reduced[0, 0]), 0.25)) self.assertTrue(math.isclose(np.real(reduced[1, 1]), 0.75))