def test_quad_form(self, hbar): """Test it has the correct form using quadrature operators""" H, _ = beamsplitter(np.pi / 4, np.pi / 2, mode1=1, mode2=3, hbar=hbar) H = normal_ordered(get_quad_operator(H, hbar=hbar), hbar=hbar) expected = QuadOperator('q1 q3', -1) expected += QuadOperator('p1 p3', -1) assert H == expected
def test_quad_form(self): """Test it has the correct form using quadrature operators""" self.logTestName() H, _ = beamsplitter(np.pi / 4, np.pi / 2, mode1=1, mode2=3, hbar=self.hbar) H = normal_ordered(get_quad_operator(H, hbar=self.hbar), hbar=self.hbar) expected = QuadOperator('q1 q3', -1) expected += QuadOperator('p1 p3', -1) self.assertEqual(H, expected)
def test_beamsplitter(self, hbar): """Test beamsplitter produces correct cov and means""" H, t = beamsplitter(self.th, self.phi, hbar=hbar) resD, resV = self.H_circuit(H, t) gate = BSgate(self.th, self.phi) expD, expV = self.ref_circuit(gate) # test the covariance matrix assert np.allclose(resV, expV) # test the vector of means assert np.allclose(resD, expD)
def test_beamsplitter_coeff(self, hbar): """Test quadratic coefficients for BSgate""" # arbitrary beamsplitter theta = 0.5423 phi = 0.3242 H, _ = beamsplitter(theta, phi, hbar=hbar) res, d = quadratic_coefficients(get_quad_operator(H, hbar=hbar)) expected = np.zeros([4, 4]) expected[0, 3] = expected[3, 0] = -np.cos(np.pi - phi) expected[1, 2] = expected[2, 1] = np.cos(np.pi - phi) expected[0, 1] = expected[1, 0] = -np.sin(np.pi - phi) expected[2, 3] = expected[3, 2] = -np.sin(np.pi - phi) assert np.allclose(res, expected) assert np.allclose(d, np.zeros([4]))
def test_beamsplitter(self): """Test beamsplitter produces correct cov and means""" self.eng.reset() H, t = beamsplitter(self.th, self.phi, hbar=self.hbar) resD, resV = self.H_circuit(H, t) gate = BSgate(self.th, self.phi) expD, expV = self.ref_circuit(gate) # test the covariance matrix self.assertTrue(np.allclose(resV, expV)) # test the vector of means self.assertTrue(np.allclose(resD, expD))
def test_identity(self): """Test alpha=0 gives identity""" self.logTestName() _, t = beamsplitter(0, 0) self.assertEqual(t, 0)
def setUp(self): """Parameters""" self.hbar = 2 self.theta = 0.242 self.phi = 0.452 self.H, self.t = beamsplitter(self.theta, self.phi, hbar=self.hbar)
def test_time(self, hbar): """Test time parameter is correct""" _, t = beamsplitter(self.theta, self.phi, hbar=hbar) assert t == self.theta
def test_gaussian(self, hbar): """Test output is gaussian""" H, _ = beamsplitter(self.theta, self.phi, hbar=hbar) res = get_quad_operator(H).is_gaussian() assert res
def test_hermitian(self, hbar): """Test output is hermitian""" H, _ = beamsplitter(self.theta, self.phi, hbar=hbar) assert is_hermitian(H) assert is_hermitian(get_quad_operator(H))
def test_identity(self): """Test alpha=0 gives identity""" _, t = beamsplitter(0, 0) assert t == 0