def test_quad_form(self, hbar): """Test it has the correct form using quadrature operators""" H, _ = squeezing(2, mode=1) H = normal_ordered(get_quad_operator(H, hbar=hbar), hbar=hbar) expected = QuadOperator('q1 p1', -1) expected += QuadOperator('', 1j) assert H == expected
def test_squeezing(self): """Test squeezing gives correct means and cov""" self.eng.reset() q = self.eng.register x = 0.2 p = 0.3 r = 0.42 phi = 0.123 H, t = squeezing(r, phi, hbar=self.hbar) with self.eng: Xgate(x) | q[0] Zgate(p) | q[0] GaussianPropagation(H, t) | q[0] state = self.eng.run('gaussian') # test the covariance matrix res = state.cov() S = rot(phi / 2) @ np.diag(np.exp([-r, r])) @ rot(phi / 2).T V = S @ S.T * self.hbar / 2 self.assertTrue(np.allclose(res, V)) # test the vector of means res = state.means() exp = S @ np.array([x, p]) self.assertTrue(np.allclose(res, exp))
def test_squeezing(self, hbar): """Test squeezing gives correct means and cov""" prog = sf.Program(1) eng = sf.Engine("gaussian") x = 0.2 p = 0.3 r = 0.42 phi = 0.123 H, t = squeezing(r, phi, hbar=hbar) with prog.context as q: Xgate(x) | q[0] Zgate(p) | q[0] GaussianPropagation(H, t) | q[0] state = eng.run(prog).state # test the covariance matrix res = state.cov() S = rot(phi / 2) @ np.diag(np.exp([-r, r])) @ rot(phi / 2).T V = S @ S.T * hbar / 2 assert np.allclose(res, V) # test the vector of means res = state.means() exp = S @ np.array([x, p]) assert np.allclose(res, exp)
def test_squeeze_coeff(self, hbar): """Test quadratic coefficients for Sgate""" # one mode # pylint: disable=invalid-unary-operand-type H, _ = squeezing(0.23, hbar=hbar) res, d = quadratic_coefficients(get_quad_operator(H, hbar)) expected = -np.array([[0, 1], [1, 0]]) assert np.allclose(res, expected) assert np.allclose(d, np.zeros([2])) # two modes H, _ = squeezing(0.23, mode=1, hbar=hbar) res, d = quadratic_coefficients(get_quad_operator(H, hbar)) expected = np.zeros([4, 4]) expected[1, 3] = -1 expected[3, 1] = -1 assert np.allclose(res, expected) assert np.allclose(d, np.zeros([4]))
def test_quad_form(self): """Test it has the correct form using quadrature operators""" self.logTestName() H, _ = squeezing(2, mode=1) H = normal_ordered(get_quad_operator(H, hbar=self.hbar), hbar=self.hbar) expected = QuadOperator('q1 p1', -1) expected += QuadOperator('', 1j) self.assertEqual(H, expected)
def test_identity(self): """Test alpha=0 gives identity""" self.logTestName() _, t = squeezing(0) self.assertEqual(t, 0)
def setUp(self): """Parameters""" self.hbar = 2 self.r = 0.242 self.phi = 0.452 self.H, self.t = squeezing(self.r, self.phi, hbar=self.hbar)
def test_time(self, hbar): """Test time parameter is correct""" _, t = squeezing(self.r, self.phi, hbar=hbar) assert t == self.r
def test_gaussian(self, hbar): """Test output is gaussian""" H, _ = squeezing(self.r, self.phi, hbar=hbar) res = get_quad_operator(H).is_gaussian() assert res
def test_hermitian(self, hbar): """Test output is hermitian""" H, _ = squeezing(self.r, 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 = squeezing(0) assert t == 0