def test_decomposition(self, U, tol):
        """This test checks the function :func:`dec.rectangular_symmetric` for
        various unitary matrices.

        A given unitary (identity or random draw from Haar measure) is
        decomposed using the function :func:`dec.rectangular_symmetric`
        and the resulting beamsplitters are multiplied together.

        Test passes if the product matches identity.
        """
        nmax, mmax = U.shape
        assert nmax == mmax
        tlist, diags = dec.rectangular_symmetric(U)
        qrec = np.identity(nmax)
        for i in tlist:
            qrec = dec.mach_zehnder(*i) @ qrec
        qrec = np.diag(diags) @ qrec
        assert np.allclose(U, qrec, atol=tol, rtol=0)
 def test_unitary_validation(self):
     """Test that an exception is raised if not unitary"""
     A = np.random.random([5, 5]) + 1j * np.random.random([5, 5])
     with pytest.raises(ValueError, match="matrix is not unitary"):
         dec.rectangular_symmetric(A)