def test_teleportation_fidelity(setup_eng, pure): """Test that teleportation of a coherent state has high fidelity""" eng, prog = setup_eng(3) s = np.sqrt(2) z = 2 BS = BSgate(np.pi / 4, 0) alpha = 0.5 + 0.2j with prog.context as q: # TODO: at some point, use the blackbird parser to # read in the following directly from the examples folder Coherent(alpha) | q[0] Squeezed(-z) | q[1] Squeezed(z) | q[2] BS | (q[1], q[2]) BS | (q[0], q[1]) MeasureHomodyne(0, select=0.07) | q[0] MeasureHomodyne(np.pi / 2, select=0.1) | q[1] Xgate(scale(q[0], s)) | q[2] Zgate(scale(q[1], s)) | q[2] state = eng.run(prog).state fidelity = state.fidelity_coherent([0, 0, alpha]) assert np.allclose(fidelity, 1, atol=0.02, rtol=0)
def test_average_fidelity(self): self.logTestName() q = self.eng.register with self.eng: Coherent(self.a) | q[0] BSgate() | (q[0], q[1]) BSgate() | (q[1], q[2]) MeasureX | q[1] MeasureP | q[2] Xgate(scale(q[1], sqrt(2))) | q[0] Zgate(scale(q[2], sqrt(2))) | q[0] BSgate() | (q[0], q[3]) # check outputs are identical clones state = self.eng.run(modes=[0, 3]) coh = np.array([state.is_coherent(i) for i in range(2)]) disp = state.displacement() self.assertAllTrue(coh) self.assertAllAlmostEqual(*disp, delta=self.tol) f = np.empty([self.shots]) a = np.empty([self.shots], dtype=np.complex128) for i in range(self.shots): self.eng.reset(keep_history=True) state = self.eng.run(modes=[0]) f[i] = state.fidelity_coherent([0.7 + 1.2j]) a[i] = state.displacement() self.assertAlmostEqual(np.mean(f), 2. / 3., delta=0.1) self.assertAlmostEqual(np.mean(a), self.a, delta=0.1) self.assertAllAlmostEqual(np.cov([a.real, a.imag]), 0.25 * np.identity(2), delta=0.1)
def gaussian_cloning_circuit(q): # TODO: at some point, use the blackbird parser to # read in the following directly from the examples folder BSgate() | (q[0], q[1]) BSgate() | (q[1], q[2]) MeasureX | q[1] MeasureP | q[2] Xgate(scale(q[1], np.sqrt(2))) | q[0] Zgate(scale(q[2], np.sqrt(2))) | q[0] BSgate() | (q[0], q[3])
def test_scale(self, rr): """Test that the neg function creates a regref transform that negates""" a = 0.574 x = -0.6543 rrt = utils.scale(rr, a) assert isinstance(rrt, RegRefTransform) assert rrt.func(x) == a * x
def test_scale(self): """Test that the neg function creates a regref transform that negates""" a = 0.574 x = -0.6543 eng, q = sf.Engine(1) rrt = utils.scale(q[0], a) assert isinstance(rrt, sf.engine.RegRefTransform) assert rrt.func(x) == a * x
eng = sf.Engine(backend="gaussian") gaussian_cloning = sf.Program(4) with gaussian_cloning.context as q: # state to be cloned Coherent(0.7+1.2j) | q[0] # 50-50 beamsplitter BS = BSgate(pi/4, 0) # symmetric Gaussian cloning scheme BS | (q[0], q[1]) BS | (q[1], q[2]) MeasureX | q[1] MeasureP | q[2] Xgate(scale(q[1], sqrt(2))) | q[0] Zgate(scale(q[2], sqrt(2))) | q[0] # after the final beamsplitter, modes q[0] and q[3] # will contain identical approximate clones of the # initial state Coherent(0.1+0j) BS | (q[0], q[3]) # end circuit # run the engine results = eng.run(gaussian_cloning, modes=[0, 3]) # return the cloning fidelity fidelity = sqrt(results.state.fidelity_coherent([0.7+1.2j, 0.7+1.2j])) # return the cloned displacement alpha = results.state.displacement()
psi, alice, bob = q[0], q[1], q[2] # state to be teleported: Coherent(1+0.5j) | psi # 50-50 beamsplitter BS = BSgate(pi/4, 0) # maximally entangled states Squeezed(-2) | alice Squeezed(2) | bob BS | (alice, bob) # Alice performs the joint measurement # in the maximally entangled basis BS | (psi, alice) MeasureX | psi MeasureP | alice # Bob conditionally displaces his mode # based on Alice's measurement result Xgate(scale(psi, sqrt(2))) | bob Zgate(scale(alice, sqrt(2))) | bob # end circuit results = eng.run(teleportation) # view Bob's output state and fidelity print(q[0].val, q[1].val) print(results.state.displacement([2])) print(results.state.fidelity_coherent([0, 0, 1+0.5j]))