Exemple #1
0
 def setUp(self):
     self.subsystems = random.randint(2, 5, size=random.randint(4))
     self.dim = numpy.prod(self.subsystems)
     self.sqmatrix = random.randn(self.dim, self.dim) + 1.0j * random.randn(self.dim, self.dim)
     self.hmatrix = numpy.dot(self.sqmatrix.conjugate().transpose(), self.sqmatrix)
     self.test = hoperator(self.hmatrix, self.subsystems)
     self.pttest = hoperator([[1, 2, 3, 4], [2, 5, 6, 7], [3, 6, 8, 9], [4, 7, 9, 10]], [2, 2])
Exemple #2
0
    def test_hoperator(self):
        for i in range(1000):
            # make sure operator is passed to class
            self.assertListEqual([i for i in chain(*self.hmatrix)], [i for i in chain(*self.test.matrix)])
            # should raise an exception for non Hermitian matrix
            with self.assertRaises(TypeError):
                hoperator(self.sqmatrix, self.subsystems)

            self.sqmatrix = random.randn(self.dim, self.dim) + 1.0j * random.randn(self.dim, self.dim)
            self.hmatrix = numpy.dot(self.sqmatrix.conjugate().transpose(), self.sqmatrix)
            self.test = hoperator(self.hmatrix, self.subsystems)

            # should raise an exception for non square matrix
        with self.assertRaises(TypeError):
            hoperator(self.hmatrix[:-1, :], self.subsystems)
            # should raise an exception if dimensions of matrix do not fit product of dimensions of subsystems
        with self.assertRaises(TypeError):
            hoperator(self.hmatrix[:-1, :-1], self.subsystems)
            # make sure operator is properly transposed
        self.assertListEqual(
            [i for i in chain(*self.pttest.ptranspose([1]))], [i for i in chain(*self.pttest.ptranspose([0]))]
        )
        self.assertListEqual(
            [1, 2, 3, 6, 2, 5, 4, 7, 3, 4, 8, 9, 6, 7, 9, 10], [i for i in chain(*self.pttest.ptranspose([0]))]
        )
        self.assertListEqual(
            [1, 2, 3, 4, 2, 5, 6, 7, 3, 6, 8, 9, 4, 7, 9, 10], [i for i in chain(*self.pttest.ptranspose([0, 1]))]
        )