Exemplo n.º 1
0
class TestControlledAddition:
    """Tests for controlled addition function"""
    s = 0.242
    H, t = controlled_addition(s)

    def test_identity(self):
        """Test alpha=0 gives identity"""
        _, t = controlled_addition(0)
        assert t == 0

    def test_hermitian(self, hbar):
        """Test output is hermitian"""
        assert is_hermitian(self.H)
        assert is_hermitian(get_boson_operator(self.H, hbar=hbar))

    def test_gaussian(self):
        """Test output is gaussian"""
        res = self.H.is_gaussian()
        assert res

    def test_time(self):
        """Test time parameter is correct"""
        assert self.t == self.s

    def test_boson_form(self, hbar):
        """Test bosonic form is correct"""
        H = normal_ordered(get_boson_operator(self.H, hbar=hbar))
        expected = BosonOperator('0 1', -1j)
        expected += BosonOperator('0 1^', 1j)
        expected += BosonOperator('0^ 1', -1j)
        expected += BosonOperator('0^ 1^', 1j)
        assert H == expected
Exemplo n.º 2
0
 def test_controlled_addition(self):
     """Test quadratic coefficients for CXgate"""
     H, _ = controlled_addition(0.23)
     res, d = quadratic_coefficients(H)
     expected = np.fliplr(np.diag([1, 0, 0, 1]))
     assert np.allclose(res, expected)
     assert np.allclose(d, np.zeros([4]))
Exemplo n.º 3
0
    def test_controlled_addition(self):
        """Test CXgate produces correct cov and means"""
        H, t = controlled_addition(self.r)
        resD, resV = self.H_circuit(H, t)

        gate = CXgate(self.r)
        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)
Exemplo n.º 4
0
    def test_controlled_addition(self):
        """Test CXgate produces correct cov and means"""
        self.logTestName()
        self.eng.reset()

        H, t = controlled_addition(self.r)
        resD, resV = self.H_circuit(H, t)

        gate = CXgate(self.r)
        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))
Exemplo n.º 5
0
 def test_identity(self):
     """Test alpha=0 gives identity"""
     self.logTestName()
     _, t = controlled_addition(0)
     self.assertEqual(t, 0)
Exemplo n.º 6
0
 def setUp(self):
     """Parameters"""
     self.hbar = 2
     self.s = 0.242
     self.H, self.t = controlled_addition(self.s)
Exemplo n.º 7
0
 def test_identity(self):
     """Test alpha=0 gives identity"""
     _, t = controlled_addition(0)
     assert t == 0