Пример #1
0
    def test_williamson_BM_random_circuit_pure(self):
        self.logTestName()
        for k in range(nsamples):
            n = 3
            U2 = haar_measure(n)
            state = gaussiancircuit.GaussianModes(n, hbar=2)
            for i in range(n):
                state.squeeze(np.log(0.2 * i + 2), 0, i)
            state.apply_u(U2)

            V = state.scovmatxp()

            D, S = dec.williamson(V)
            omega = dec.sympmat(n)

            self.assertAlmostEqual(np.linalg.norm(S @ omega @ S.T - omega), 0)
            self.assertAlmostEqual(np.linalg.norm(S @ D @ S.T - V), 0)

            O, s, Oo = dec.bloch_messiah(S)
            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(O) @ omega @ O - omega), 0)
            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(O) @ O - np.identity(2 * n)), 0)

            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(Oo) @ omega @ Oo - omega), 0)
            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(Oo) @ Oo - np.identity(2 * n)), 0)
            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(s) @ omega @ s - omega), 0)
            self.assertAlmostEqual(np.linalg.norm(O @ s @ Oo - S), 0)
Пример #2
0
    def test_BM_random_degen_symplectic(self):
        self.logTestName()
        for k in range(nsamples):
            n = 20
            S = random_degen_symplectic(n)
            O, s, Oo = dec.bloch_messiah(S)
            omega = dec.sympmat(n)

            self.assertAlmostEqual(np.linalg.norm(S @ omega @ S.T - omega), 0)

            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(O) @ omega @ O - omega), 0)
            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(O) @ O - np.identity(2 * n)), 0)

            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(Oo) @ omega @ Oo - omega), 0)
            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(Oo) @ Oo - np.identity(2 * n)), 0)
            self.assertAlmostEqual(
                np.linalg.norm(np.transpose(s) @ omega @ s - omega), 0)
            self.assertAlmostEqual(np.linalg.norm(O @ s @ Oo - S), 0)