Ejemplo n.º 1
0
    def test_GetTotalQnums(self):
        bd_sym_1 = tor10.Bond(3,
                              tor10.BD_KET,
                              qnums=[[0, 2, 1, 0], [1, 1, -1, 1],
                                     [2, -1, 1, 0]])
        bd_sym_2 = tor10.Bond(4,
                              tor10.BD_KET,
                              qnums=[[-1, 0, -1, 3], [0, 0, -1, 2],
                                     [1, 0, 1, 0], [2, -2, -1, 1]])
        bd_sym_3 = tor10.Bond(2,
                              tor10.BD_BRA,
                              qnums=[[-4, 3, 0, -1], [1, 1, -2, 3]])

        sym_T = tor10.UniTensor(bonds=[bd_sym_1, bd_sym_2, bd_sym_3],
                                rowrank=2,
                                labels=[1, 2, 3])

        tqin, tqout = sym_T.GetTotalQnums()

        qin = tor10.Bond(12,
                         tor10.BD_KET,
                         qnums=[[+4, -3, +0, +1], [+3, -1, +2, +0],
                                [+2, -1, +0, +2], [+1, -1, +0, +3],
                                [+3, -1, -2, +2], [+2, +1, +0, +1],
                                [+1, +1, -2, +3], [+0, +1, -2, +4],
                                [+2, +0, +0, +1], [+1, +2, +2, +0],
                                [+0, +2, +0, +2], [-1, +2, +0, +3]])
        # Output of qnums in Bond.assign is sorted, while it is not sorted in UniTensor.GetTotalQnums
        y = np.lexsort(tqin.qnums.T[::-1])[::-1]
        qnums = tqin.qnums[y, :]

        for i in range(qnums.shape[0]):
            self.assertListEqual(list(qnums[i]), list(qin.qnums[i]))
Ejemplo n.º 2
0
    def test_CombineBonds(self):
        bds_x = [tor10.Bond(5), tor10.Bond(5), tor10.Bond(3)]
        x = tor10.UniTensor(bonds=bds_x, rowrank=2, labels=[4, 3, 5])
        x.CombineBonds([5, 3])
        self.assertListEqual(list(x.shape), [5, 15])
        self.assertListEqual(list(x.labels), [4, 5])

        y = tor10.UniTensor(bonds=bds_x, rowrank=2, labels=[4, 3, 5])
        y.CombineBonds([3, 5])
        self.assertListEqual(list(y.shape), [15, 5])
        self.assertListEqual(list(y.labels), [3, 4])

        z = tor10.UniTensor(bonds=bds_x * 2,
                            rowrank=3,
                            labels=[4, 3, 5, 6, 7, 8])
        z.CombineBonds([4, 5, 6])
        self.assertListEqual(list(z.shape), [75, 5, 5, 3])
        self.assertListEqual(list(z.labels), [4, 3, 7, 8])
        self.assertEqual(z.rowrank, 1)

        z2 = tor10.UniTensor(bonds=bds_x * 2,
                             rowrank=3,
                             labels=[4, 3, 5, 6, 7, 8])
        z2.CombineBonds([4, 5, 6], permute_back=True)
        self.assertListEqual(list(z2.shape), [75, 5, 5, 3])
        self.assertListEqual(list(z2.labels), [4, 3, 7, 8])
        self.assertEqual(z2.rowrank, 2)
Ejemplo n.º 3
0
    def test_Permute(self):
        bds_x = [
            tor10.Bond(6),
            tor10.Bond(5),
            tor10.Bond(4),
            tor10.Bond(3),
            tor10.Bond(2)
        ]
        x = tor10.UniTensor(bonds=bds_x, rowrank=3, labels=[1, 3, 5, 7, 8])
        x.Permute([0, 2, 1, 4, 3])
        self.assertListEqual(list(x.labels), [1, 5, 3, 8, 7])
        self.assertEqual(x.rowrank, 3)
        self.assertListEqual(list(x.shape), [6, 4, 5, 2, 3])
        self.assertFalse(x.is_contiguous())

        y = tor10.UniTensor(bonds=bds_x, rowrank=3, labels=[1, 3, 5, 7, 8])
        y.Permute([3, 1, 5, 7, 8], by_label=True)
        self.assertListEqual(list(y.labels), [3, 1, 5, 7, 8])
        self.assertEqual(y.rowrank, 3)
        self.assertListEqual(list(y.shape), [5, 6, 4, 3, 2])
        self.assertFalse(y.is_contiguous())

        z = tor10.UniTensor(bonds=bds_x, rowrank=3, labels=[1, 3, 5, 7, 8])
        z.Permute([3, 1, 5, 7, 8], rowrank=2, by_label=True)
        self.assertListEqual(list(z.labels), [3, 1, 5, 7, 8])
        self.assertEqual(z.rowrank, 2)
        self.assertListEqual(list(z.shape), [5, 6, 4, 3, 2])
        self.assertFalse(z.is_contiguous())
Ejemplo n.º 4
0
 def test_GetValidQnums(self):
     bd_sym_1 = tor10.Bond(3, tor10.BD_KET, qnums=[[0], [1], [2]])
     bd_sym_2 = tor10.Bond(4, tor10.BD_KET, qnums=[[-1], [2], [0], [2]])
     bd_sym_3 = tor10.Bond(5, tor10.BD_BRA, qnums=[[4], [2], [2], [5], [1]])
     sym_T = tor10.UniTensor(bonds=[bd_sym_1, bd_sym_2, bd_sym_3],
                             rowrank=2,
                             labels=[10, 11, 12])
     qnums = sym_T.GetValidQnums()
     self.assertListEqual(list(qnums.flatten()), [1, 2, 4])
Ejemplo n.º 5
0
    def setUp(self):
        # Bond:
        # =======================================

        # Non-symmetry:
        self.bd_x = tor10.Bond(3)
        self.bd_y = tor10.Bond(4)
        self.bd_z = tor10.Bond(3)

        # > U1
        self.bd_sym_U1 = tor10.Bond(3, qnums=[[-1], [0], [1]])

        # > Z2
        self.bd_sym_Z2 = tor10.Bond(3,
                                    qnums=[[0], [1], [0]],
                                    sym_types=[tor10.Symmetry.Zn(2)])

        # > Z4
        self.bd_sym_Z4 = tor10.Bond(3,
                                    qnums=[[0], [2], [3]],
                                    sym_types=[tor10.Symmetry.Zn(4)])

        # > Multiple U1
        self.bd_sym_multU1 = tor10.Bond(3,
                                        qnums=[[-2, -1, 0, -1], [1, -4, 0, 0],
                                               [-8, -3, 1, 5]])

        # > Multiple mix symmetry: U1 x Z2 x Z4
        self.bd_sym_mix = tor10.Bond(3,
                                     qnums=[[-2, 0, 0], [-1, 1, 3], [1, 0, 2]],
                                     sym_types=[
                                         tor10.Symmetry.U1(),
                                         tor10.Symmetry.Zn(2),
                                         tor10.Symmetry.Zn(4)
                                     ])
Ejemplo n.º 6
0
    def test_combine(self):

        a = tor10.Bond(3)
        b = tor10.Bond(4)
        c = tor10.Bond(2, qnums=[[0, 1, -1], [1, 1, 0]])
        d = tor10.Bond(2, qnums=[[1, 0, -1], [1, 0, 0]])
        e = tor10.Bond(2,
                       qnums=[[1, 0], [1, 0]],
                       sym_types=[tor10.Symmetry.U1(),
                                  tor10.Symmetry.Zn(4)])

        a.combine(b)
        self.assertEqual(a.dim, 12)

        c.combine(d)
        self.assertListEqual(list(d.qnums[0]), [1, 0, -1])
Ejemplo n.º 7
0
    def test_assign(self):
        bond1 = tor10.Bond(3)
        bond1.assign(5)
        self.assertEqual(bond1.dim, 5)
        bond1.assign(3, qnums=[[1], [2], [3]])
        self.assertListEqual(list(bond1.qnums), [[1], [2], [3]])

        bond1.assign(3,
                     qnums=[[1], [2], [3]],
                     sym_types=[tor10.Symmetry.Zn(4)])
        self.assertEqual(bond1.sym_types, [tor10.Symmetry.Zn(4)])
Ejemplo n.º 8
0
    def test_PutGetBlock(self):
        bd_sym_1 = tor10.Bond(3, tor10.BD_KET, qnums=[[0], [1], [2]])
        bd_sym_2 = tor10.Bond(4, tor10.BD_KET, qnums=[[-1], [2], [0], [2]])
        bd_sym_3 = tor10.Bond(5, tor10.BD_BRA, qnums=[[4], [2], [2], [5], [1]])

        sym_T = tor10.UniTensor(bonds=[bd_sym_1, bd_sym_2, bd_sym_3],
                                rowrank=2,
                                labels=[10, 11, 12])
        BN = sym_T.GetBlock(2)
        self.assertListEqual(list(BN.Storage.flatten()),
                             [0., 0., 0., 0., 0., 0.])
        self.assertListEqual(list(BN.shape), [3, 2])

        BN.SetElem([float(i) for i in range(6)])
        sym_T.PutBlock(BN, 2)

        BN = sym_T.GetBlock(2)
        self.assertListEqual(list(BN.Storage.flatten()),
                             [0., 1., 2., 3., 4., 5.])
        self.assertListEqual(list(BN.shape), [3, 2])
Ejemplo n.º 9
0
 def test_change(self):
     bond1 = tor10.Bond(3)
     bond1.change(tor10.BD_REGULAR)
     self.assertEqual(bond1.bondType, tor10.BD_REGULAR)
Ejemplo n.º 10
0
 def test_Reshape_(self):
     bds_x = [tor10.Bond(6), tor10.Bond(5), tor10.Bond(3)]
     x = tor10.UniTensor(bonds=bds_x, rowrank=1, labels=[4, 3, 5])
     x.Reshape_([2, 3, 5, 3], new_labels=[1, 2, 3, -1], rowrank=2)
     self.assertListEqual(list(x.labels), [1, 2, 3, -1])
Ejemplo n.º 11
0
 def test_SetLabels(self):
     bds_x = [tor10.Bond(5), tor10.Bond(5), tor10.Bond(3)]
     x = tor10.UniTensor(bonds=bds_x, rowrank=1, labels=[4, 3, 5])
     x.SetLabels([3, 2, 1])
     self.assertListEqual(list(x.labels), [3, 2, 1])
Ejemplo n.º 12
0
 def test_SetLabel(self):
     bds_x = [tor10.Bond(5), tor10.Bond(5), tor10.Bond(3)]
     x = tor10.UniTensor(bonds=bds_x, rowrank=1, labels=[4, 3, 5])
     x.SetLabel(-1, 2)
     self.assertEqual(x.labels[2], -1)