Пример #1
0
 def test_Dgate_displacement(self, hbar):
     """Test displacement vector matches Dgate"""
     a = 0.23 - 0.432j
     H, t = displacement(a, hbar=hbar)
     _, d = quadratic_coefficients(get_quad_operator(H, hbar))
     expected = np.array([a.real, a.imag]) * np.sqrt(2 * hbar) / t
     assert np.allclose(d, expected)
     assert np.allclose(a, t * (d[0] + d[1] * 1j) / np.sqrt(2 * hbar))
Пример #2
0
 def test_Dgate_displacement(self):
     """Test displacement vector matches Dgate"""
     self.logTestName()
     a = 0.23-0.432j
     H, t = displacement(a, hbar=self.hbar)
     _, d = quadratic_coefficients(get_quad_operator(H, self.hbar))
     expected = np.array([a.real, a.imag])*np.sqrt(2*self.hbar)/t
     self.assertTrue(np.allclose(d, expected))
     self.assertTrue(np.allclose(a, t*(d[0]+d[1]*1j)/np.sqrt(2*self.hbar)))
Пример #3
0
    def test_coefficients(self, hbar):
        """Test coefficients are correct"""
        H, _ = displacement(self.alpha, hbar=hbar)
        phi = np.angle(self.alpha)

        for term, coeff in H.terms.items():
            assert len(term) == 1
            j = 1 - term[0][1]
            expected = (-1)**j * np.exp(1j * phi * (-1)**j) * hbar
            assert coeff == 1j * expected
Пример #4
0
    def test_coefficients(self):
        """Test coefficients are correct"""
        H, _ = displacement(self.alpha, hbar=self.hbar)
        phi = np.angle(self.alpha)

        for term, coeff in H.terms.items():
            self.assertEqual(len(term), 1)
            j = 1 - term[0][1]
            expected = (-1)**j * np.exp(1j * phi * (-1)**j) * self.hbar
            self.assertEqual(coeff, 1j * expected)
Пример #5
0
    def test_displacement(self):
        """Test displacement gives correct means and cov"""
        self.eng.reset()
        q = self.eng.register

        a = 0.2 + 0.3j
        H, t = displacement(a, hbar=self.hbar)

        with self.eng:
            GaussianPropagation(H, t) | q[0]

        state = self.eng.run('gaussian')

        # test the covariance matrix
        res = state.cov()
        expected = np.identity(2) * self.hbar / 2
        self.assertTrue(np.allclose(res, expected))

        # test the vector of means
        res = state.means()
        expected = np.array([a.real, a.imag]) * np.sqrt(2 * self.hbar)
        self.assertTrue(np.allclose(res, expected))
Пример #6
0
    def test_displacement(self, hbar):
        """Test displacement gives correct means and cov"""
        prog = sf.Program(1)
        eng = sf.Engine("gaussian")

        a = 0.2 + 0.3j
        H, t = displacement(a, hbar=hbar)

        with prog.context as q:
            GaussianPropagation(H, t) | q[0]

        state = eng.run(prog).state

        # test the covariance matrix
        res = state.cov()
        expected = np.identity(2) * hbar / 2
        assert np.allclose(res, expected)

        # test the vector of means
        res = state.means()
        expected = np.array([a.real, a.imag]) * np.sqrt(2 * hbar)
        assert np.allclose(res, expected)
Пример #7
0
 def test_time(self):
     """Test time parameter is correct"""
     self.logTestName()
     _, r = displacement(self.alpha)
     self.assertEqual(r, np.abs(self.alpha))
Пример #8
0
 def test_gaussian(self):
     """Test output is gaussian"""
     self.logTestName()
     H, _ = displacement(self.alpha, hbar=self.hbar)
     res = get_quad_operator(H, hbar=self.hbar).is_gaussian()
     self.assertTrue(res)
Пример #9
0
 def test_hermitian(self):
     """Test output is hermitian"""
     self.logTestName()
     H, _ = displacement(self.alpha, hbar=self.hbar)
     self.assertTrue(is_hermitian(H))
     self.assertTrue(is_hermitian(get_quad_operator(H)))
Пример #10
0
 def test_identity(self):
     """Test alpha=0 gives identity"""
     self.logTestName()
     H, r = displacement(0, hbar=self.hbar)
     self.assertEqual(H, BosonOperator.identity())
     self.assertEqual(r, 0)
Пример #11
0
 def test_time(self):
     """Test time parameter is correct"""
     _, r = displacement(self.alpha)
     assert r == np.abs(self.alpha)
Пример #12
0
 def test_gaussian(self, hbar):
     """Test output is gaussian"""
     H, _ = displacement(self.alpha, hbar=hbar)
     res = get_quad_operator(H, hbar=hbar).is_gaussian()
     assert res
Пример #13
0
 def test_hermitian(self, hbar):
     """Test output is hermitian"""
     H, _ = displacement(self.alpha, hbar=hbar)
     assert is_hermitian(H)
     assert is_hermitian(get_quad_operator(H))
Пример #14
0
 def test_identity(self, hbar):
     """Test alpha=0 gives identity"""
     H, r = displacement(0, hbar=hbar)
     assert H == BosonOperator.identity()
     assert r == 0