Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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