Exemplo n.º 1
0
    def test_crz_decomposition_correctness(self, phi, tol):
        """Test that the decomposition of the controlled Z
        qubit rotation is correct"""

        expected = CRotz(phi)

        obtained = CNOT @ np.kron(I, Rphi(-phi / 2)) @ CNOT @ np.kron(
            I, Rphi(phi / 2))
        assert np.allclose(expected, obtained, atol=tol, rtol=0)
Exemplo n.º 2
0
    def test_phase_shift(self, tol):
        """Test phase shift is correct"""

        # test identity for theta=0
        assert np.allclose(Rphi(0), np.identity(2), atol=tol, rtol=0)

        # test arbitrary phase shift
        phi = 0.5432
        expected = np.array([[1, 0], [0, np.exp(1j * phi)]])
        assert np.allclose(Rphi(phi), expected, atol=tol, rtol=0)
Exemplo n.º 3
0
    def test_phase_shift(self):
        """Test phase shift is correct"""
        self.logTestName()

        # test identity for theta=0
        self.assertAllAlmostEqual(Rphi(0), np.identity(2), delta=self.tol)

        # test arbitrary phase shift
        phi = 0.5432
        expected = np.array([[1, 0], [0, np.exp(1j * phi)]])
        self.assertAllAlmostEqual(Rphi(phi), expected, delta=self.tol)
Exemplo n.º 4
0
def U3(theta, phi, lam):
    return Rphi(phi) @ Rphi(lam) @ Rot3(lam, theta, -lam)