Esempio n. 1
0
def HOTRGVerticalContractFTN():
    FTN = FiniteTensorNetwork(tensorNames=['u', 'd', 'l', 'r'])
    FTN.addLink('u', 'l', 'l', 'u')
    FTN.addLink('u', 'r', 'r', 'u')
    FTN.addLink('d', 'l', 'l', 'd')
    FTN.addLink('d', 'r', 'r', 'd')

    FTN.addLink('l', 'r', 'r', 'l')

    FTN.addPostNameChange('u', 'o', 'u')
    FTN.addPostNameChange('d', 'o', 'd')

    return FTN
Esempio n. 2
0
def CTMRGCornerExtendFTN():
    FTN = FiniteTensorNetwork(tensorNames=['c', 'ph', 'pv', 'w'])

    FTN.addLink('c', 'u', 'pv', 'd')
    FTN.addLink('c', 'r', 'ph', 'l')
    FTN.addLink('pv', 'r', 'w', 'l')
    FTN.addLink('ph', 'u', 'w', 'd')

    FTN.addPostOutProduct(['pv-u', 'w-u'], 'u')
    FTN.addPostOutProduct(['ph-r', 'w-r'], 'r')

    return FTN
Esempio n. 3
0
def triangleContractFTN():
    """
    Make a finite tensor network for triangle tensor contraction.

    Returns
    -------
    FTN : FiniteTensorNetwork
        A FiniteTensorNetwork that, takes three tensors(in form of makeTriangleTensorDict), legs of which are named as ["1", "2", "3"], contract them.
    
    """
    FTN = FiniteTensorNetwork(tensorNames=['u', 'l', 'r'])
    FTN.addLink('u', '2', 'l', '3')
    FTN.addLink('u', '3', 'r', '2')
    FTN.addLink('l', '2', 'r', '3')

    FTN.addPostNameChange('u', '1', '1')
    FTN.addPostNameChange('l', '1', '2')
    FTN.addPostNameChange('r', '1', '3')

    return FTN
Esempio n. 4
0
def squareContractFTN():
    """
    Make a finite tensor network for square tensor contraction.

    Returns
    -------
    FTN : FiniteTensorNetwork
        A FiniteTensorNetwork that, takes 4 tensors(in form of makeSquareTensorDict), legs of which are named as ['u', 'd', 'l', 'r'], contract them.
    
    """
    FTN = FiniteTensorNetwork(tensorNames=['ul', 'ur', 'dr', 'dl'])
    FTN.addLink('ul', 'd', 'dl', 'u')
    FTN.addLink('ul', 'r', 'ur', 'l')
    FTN.addLink('ur', 'd', 'dr', 'u')
    FTN.addLink('dl', 'r', 'dr', 'l')

    FTN.addPostOutProduct(['ul-u', 'ur-u'], 'u')
    FTN.addPostOutProduct(['ul-l', 'dl-l'], 'l')
    FTN.addPostOutProduct(['dl-d', 'dr-d'], 'd')
    FTN.addPostOutProduct(['ur-r', 'dr-r'], 'r')

    return FTN
Esempio n. 5
0
def CTMRGEvenZFTN():
    FTN = FiniteTensorNetwork(tensorNames=['alu', 'ald', 'aru', 'ard'])
    FTN.addLink('alu', 'u', 'ald', 'u')
    FTN.addLink('aru', 'u', 'ard', 'u')
    FTN.addLink('alu', 'r', 'aru', 'r')
    FTN.addLink('ald', 'r', 'ard', 'r')

    return FTN
Esempio n. 6
0
def CTMRGVEdgeBuildFTN():
    FTN = FiniteTensorNetwork(tensorNames=['p', 'au', 'ad'])
    # our a[u, d] is only for down part; for up part of a, we need to still point "u" to p
    FTN.addLink('ad', 'u', 'p', 'd')
    FTN.addLink('au', 'u', 'p', 'u')

    FTN.addPostNameChange('au', 'd', 'u')
    return FTN
Esempio n. 7
0
def CTMRGHEdgeBuildFTN():
    FTN = FiniteTensorNetwork(tensorNames=['p', 'al', 'ar'])
    # our a[l, r] is only for left part; for right part of a, we need to still point "r" to p
    FTN.addLink('al', 'r', 'p', 'l')
    FTN.addLink('ar', 'r', 'p', 'r')

    FTN.addPostNameChange('ar', 'l', 'r')
    return FTN
Esempio n. 8
0
def squareContractOutFTN():
    """
    Make a finite tensor network for square tensor contraction, where tensors are having inner legs and outer legs named "o".

    Returns
    -------
    FTN : FiniteTensorNetwork
        A FiniteTensorNetwork that, takes 4 tensors(in form of makeSquareTensorDict), legs of which are named as ['u'/'d', 'l'/'r', 'o'], contract them.
    
    """
    FTN = FiniteTensorNetwork(tensorNames=['ul', 'ur', 'dr', 'dl'])

    FTN.addLink('ul', 'd', 'dl', 'u')
    FTN.addLink('ul', 'r', 'ur', 'l')
    FTN.addLink('ur', 'd', 'dr', 'u')
    FTN.addLink('dl', 'r', 'dr', 'l')

    FTN.addPostNameChange('ul', 'o', 'u')
    FTN.addPostNameChange('ur', 'o', 'r')
    FTN.addPostNameChange('dl', 'o', 'l')
    FTN.addPostNameChange('dr', 'o', 'd')

    return FTN
Esempio n. 9
0
def CTMRGVEdgeExtendFTN():
    FTN = FiniteTensorNetwork(tensorNames=['p', 'w'])

    FTN.addLink('p', 'r', 'w', 'l')

    FTN.addPostOutProduct(['p-u', 'w-u'], 'u')
    FTN.addPostOutProduct(['p-d', 'w-d'], 'd')
    # FTN.addPostNameChange('p', 'u', 'ul')
    # FTN.addPostNameChange('p', 'd', 'dl')
    # FTN.addPostNameChange('w', 'u', 'ur')
    # FTN.addPostNameChange('w', 'd', 'dr')

    return FTN
Esempio n. 10
0
def CTMRGHEdgeExtendFTN():
    FTN = FiniteTensorNetwork(tensorNames=['p', 'w'])

    FTN.addLink('p', 'u', 'w', 'd')

    FTN.addPostOutProduct(['p-l', 'w-l'], 'l')
    FTN.addPostOutProduct(['p-r', 'w-r'], 'r')
    # FTN.addPostNameChange('p', 'l', 'ld')
    # FTN.addPostNameChange('p', 'r', 'rd')
    # FTN.addPostNameChange('w', 'l', 'lu')
    # FTN.addPostNameChange('w', 'r', 'ru')

    return FTN
Esempio n. 11
0
def EvenblyTNRQEnvFTN():
    FTN = FiniteTensorNetwork(
        tensorNames=['uul', 'uur', 'udl', 'udr', 'dul', 'dur', 'ddl', 'ddr'])

    FTN.addLink('udl', 'r', 'dul', 'r')
    FTN.addLink('udl', 'd', 'dul', 'd')
    FTN.addLink('udr', 'r', 'dur', 'r')
    FTN.addLink('udr', 'd', 'dur', 'd')

    FTN.addLink('udl', 'l', 'udr', 'l')
    FTN.addLink('dul', 'l', 'dur', 'l')
    FTN.addLink('uur', 'l', 'ddr', 'l')
    FTN.addLink('uur', 'u', 'ddr', 'u')

    FTN.addLink('udr', 'u', 'uur', 'd')
    FTN.addLink('dur', 'u', 'ddr', 'd')
    FTN.addLink('uul', 'r', 'uur', 'r')
    FTN.addLink('uul', 'd', 'udl', 'u')
    FTN.addLink('ddl', 'r', 'ddr', 'r')
    FTN.addLink('ddl', 'd', 'dul', 'u')

    FTN.addPostOutProduct(['uul-l', 'uul-u'], '1')
    FTN.addPostOutProduct(['ddl-l', 'ddl-u'], '2')

    return FTN
Esempio n. 12
0
def squareVerticalContractFTN(d):
    funcs.assertInSet(d, ['u', 'd'], 'vertical direction')
    opd = funcs.oppositeSingleDirection(d)
    FTN = FiniteTensorNetwork(tensorNames=['ul', 'ur', 'dr', 'dl'])

    FTN.addLink('ul', opd, 'dl', opd)
    FTN.addLink('ul', 'r', 'ur', 'l')
    FTN.addLink('ur', opd, 'dr', opd)
    FTN.addLink('dl', 'r', 'dr', 'l')

    FTN.addLink('ul', 'l', 'dl', 'l')
    FTN.addLink('ur', 'r', 'dr', 'r')

    FTN.addPostOutProduct([d + 'l-' + d, d + 'r-' + d], d)
    FTN.addPostOutProduct([opd + 'l-' + d, opd + 'r-' + d], opd)
    return FTN
Esempio n. 13
0
def squareHorizontalContractFTN(d):
    # TODO: add docstrings for following functions
    funcs.assertInSet(d, ['l', 'r'], 'horizontal direction')
    opd = funcs.oppositeSingleDirection(d)
    FTN = FiniteTensorNetwork(tensorNames=['ul', 'ur', 'dr', 'dl'])

    FTN.addLink('ul', 'd', 'dl', 'u')
    FTN.addLink('ul', opd, 'ur', opd)
    FTN.addLink('ur', 'd', 'dr', 'u')
    FTN.addLink('dl', opd, 'dr', opd)

    FTN.addLink('ul', 'u', 'ur', 'u')
    FTN.addLink('dl', 'd', 'dr', 'd')

    FTN.addPostOutProduct(['u' + d + '-' + d, 'd' + d + '-' + d], d)
    FTN.addPostOutProduct(['u' + opd + '-' + d, 'd' + opd + '-' + d], opd)
    return FTN
Esempio n. 14
0
    def test_FreeBondFTN(self):
        shapeA = (300, 4, 5)
        shapeB = (300, 6)
        shapeC = (4, 6, 5)
        a = Tensor(shape=shapeA,
                   labels=['a300', 'b4', 'c5'],
                   data=np.ones(shapeA))
        b = Tensor(shape=shapeB, labels=['a300', 'd6'], data=np.ones(shapeB))
        c = Tensor(shape=shapeC,
                   labels=['e4', 'd6', 'c5'],
                   data=np.ones(shapeC))

        tensorDict = TensorDict()
        tensorDict.setTensor('a', a)
        tensorDict.setTensor('b', b)
        tensorDict.setTensor('c', c)

        FTN = FiniteTensorNetwork(['a', 'b'], realCost=True)
        FTN.addTensor('c')

        FTN.addLink('a', 'a300', 'b', 'a300')
        FTN.addLink('a', 'c5', 'c', 'c5')
        FTN.addLink('b', 'd6', 'c', 'd6')

        result = FTN.contract(tensorDict, removeTensorTag=False)
        self.assertTrue(funcs.compareLists(result.labels, ['a-b4', 'c-e4']))
        self.assertEqual(int(result.a[0][1]), 9000)

        result = FTN.contract(tensorDict, removeTensorTag=True)
        self.assertTrue(funcs.compareLists(result.labels, ['b4', 'e4']))
        self.assertEqual(int(result.a[0][1]), 9000)

        FTN.unlock()
        FTN.addPostNameChange('c', 'e4', 'e4FromC')
        FTN.addPreNameChange('a', 'b4', 'b4FromA')
        FTN.addPreNameChange('a', 'a300', 'a3')
        FTN.removePreNameChange('a', 'a300', 'a3')
        FTN.addPostNameChange('a', 'd6', 'foo')
        FTN.removePostNameChange('a', 'd6', 'foo')

        result = FTN.contract(tensorDict, removeTensorTag=True)
        # print(result.labels)
        self.assertTrue(
            funcs.compareLists(result.labels, ['b4FromA', 'e4FromC']))
        self.assertEqual(int(result.a[0][1]), 9000)

        FTN.unlock()
        FTN.removePostNameChange('c', 'e4', 'e4FromC')
        FTN.addPreNameChange('c', 'e4', 'e4FromC')
        FTN.addPostOutProduct([('a', 'b4FromA'), ('c', 'e4FromC')], 'out')
        result = FTN.contract(tensorDict, removeTensorTag=True)

        self.assertListEqual(result.labels, ['out'])
        self.assertEqual(result.shape[0], 16)
Esempio n. 15
0
def CTMRGOddFTN():
    FTN = FiniteTensorNetwork(
        tensorNames=['alu', 'ald', 'aru', 'ard', 'pu', 'pd', 'pl', 'pr', 'w'])

    FTN.addLink('pu', 'l', 'alu', 'r')
    FTN.addLink('pu', 'r', 'aru', 'r')
    FTN.addLink('pd', 'l', 'ald', 'r')
    FTN.addLink('pd', 'r', 'ard', 'r')

    FTN.addLink('pl', 'u', 'alu', 'u')
    FTN.addLink('pl', 'd', 'ald', 'u')
    FTN.addLink('pr', 'u', 'aru', 'u')
    FTN.addLink('pr', 'd', 'ard', 'u')

    FTN.addLink('pl', 'r', 'w', 'l')
    FTN.addLink('pr', 'r', 'w', 'r')
    FTN.addLink('pd', 'u', 'w', 'd')
    FTN.addLink('pu', 'u', 'w', 'u')

    return FTN
Esempio n. 16
0
def HOTRGGiltTN():
    ATensorNames = ["aul", "aur", "adl", "adr"]
    QTensorNames = [
        'qbll', 'qbrl', 'qall', 'qarl', 'qblr', 'qbrr', 'qalr', 'qarr', 'qbu',
        'qbd', 'qau', 'qad'
    ]  # i(circle), o(line)
    wTensorNames = ['wll', 'wlr', 'wrl', 'wrr']  # u, d, o
    vTensorNames = ['vu', 'vd']  # l, r, o

    tensorNames = ATensorNames + QTensorNames + wTensorNames + vTensorNames

    FTN = FiniteTensorNetwork(tensorNames=tensorNames)

    # FTN.addLink('aul', 'adl', 'd', 'u')
    # FTN.addLink('aur', 'adr', 'd', 'u')

    # up / down bonds
    FTN.addLink('vu', 'l', 'qbu', 'o')
    FTN.addLink('vu', 'r', 'qau', 'o')
    FTN.addLink('vd', 'l', 'qbd', 'o')
    FTN.addLink('vd', 'r', 'qad', 'o')

    # left / right bonds
    FTN.addLink('wll', 'u', 'qbll', 'o')
    FTN.addLink('wll', 'd', 'qall', 'o')
    FTN.addLink('wrr', 'u', 'qbrr', 'o')
    FTN.addLink('wrr', 'd', 'qarr', 'o')

    # A left bonds
    FTN.addLink('aul', 'u', 'qbu', 'i')
    FTN.addLink('adl', 'd', 'qbd', 'i')
    FTN.addLink('aul', 'd', 'adl', 'u')
    FTN.addLink('aul', 'l', 'qbll', 'i')
    FTN.addLink('adl', 'l', 'qall', 'i')
    FTN.addLink('aul', 'r', 'qbrl', 'i')
    FTN.addLink('adl', 'r', 'qarl', 'i')

    # A right bonds
    FTN.addLink('aur', 'u', 'qau', 'i')
    FTN.addLink('adr', 'd', 'qad', 'i')
    FTN.addLink('aur', 'd', 'adr', 'u')
    FTN.addLink('aur', 'l', 'qblr', 'i')
    FTN.addLink('adr', 'l', 'qalr', 'i')
    FTN.addLink('aur', 'r', 'qbrr', 'i')
    FTN.addLink('adr', 'r', 'qarr', 'i')

    # center w bonds
    FTN.addLink('wlr', 'u', 'qbrl', 'o')
    FTN.addLink('wlr', 'd', 'qarl', 'o')
    FTN.addLink('wrl', 'u', 'qblr', 'o')
    FTN.addLink('wrl', 'd', 'qalr', 'o')
    FTN.addLink('wlr', 'o', 'wrl', 'o')

    tensorDict = TensorDict()
    chi = 10
    for ATensorName in ATensorNames:
        tensorDict.setTensor(
            ATensorName,
            Tensor(data=np.random.randn(chi, chi, chi, chi),
                   labels=['u', 'l', 'd', 'r']))
    for QTensorName in QTensorNames:
        tensorDict.setTensor(
            QTensorName,
            Tensor(data=np.random.randn(chi, chi), labels=['i', 'o']))
    for wTensorName in wTensorNames:
        tensorDict.setTensor(
            wTensorName,
            Tensor(data=np.random.randn(chi, chi, chi), labels=['u', 'd',
                                                                'o']))
    for vTensorName in vTensorNames:
        tensorDict.setTensor(
            vTensorName,
            Tensor(data=np.random.randn(chi, chi, chi), labels=['l', 'r',
                                                                'o']))

    res = FTN.contract(tensorDict)
    print(res)
Esempio n. 17
0
    def test_FTN(self):
        shapeA = (300, 4, 5)
        shapeB = (300, 6)
        shapeC = (4, 6, 5)
        a = Tensor(shape=shapeA,
                   labels=['a300', 'b4', 'c5'],
                   data=np.ones(shapeA))
        b = Tensor(shape=shapeB, labels=['a300', 'd6'], data=np.ones(shapeB))
        c = Tensor(shape=shapeC,
                   labels=['b4', 'd6', 'c5'],
                   data=np.ones(shapeC))

        tensorDict = TensorDict()
        tensorDict.setTensor('a', a)
        tensorDict.setTensor('b', b)
        tensorDict.setTensor('c', c)

        FTN = FiniteTensorNetwork(['a', 'b'], realCost=True)
        FTN.addTensor('c')

        FTN.addLink('a', 'a300', 'b', 'a300')
        FTN.addLink('a', 'b4', 'c', 'b4')
        FTN.addLink('a', 'c5', 'c', 'c5')
        FTN.addLink('b', 'd6', 'c', 'd6')

        result = FTN.contract(tensorDict)
        self.assertEqual(int(result.a), 36000)
        self.assertListEqual(FTN.optimalSeq, [(0, 1), (2, 0)])

        result2 = FTN.contract(tensorDict)
        self.assertEqual(int(result2.a), 36000)
        self.assertListEqual(FTN.optimalSeq, [(0, 1), (2, 0)])

        newShapeA = (3, 4, 5)
        newShapeB = (3, 6)

        newA = Tensor(shape=newShapeA,
                      labels=['a300', 'b4', 'c5'],
                      data=np.ones(newShapeA))
        newB = Tensor(shape=newShapeB,
                      labels=['a300', 'd6'],
                      data=np.ones(newShapeB))

        tensorDict.setTensor('a', newA)
        tensorDict.setTensor('b', newB)

        result3 = FTN.contract(tensorDict)
        self.assertEqual(int(result3.a), 360)
        self.assertListEqual(FTN.optimalSeq, [(0, 2), (1, 0)])
        self.assertEqual(FTN.bondDims['a-a300'], 3)
        self.assertEqual(FTN.tensorCount, 3)