示例#1
0
文件: test_xplib.py 项目: CaoRX/CTL
 def test_xplib(self):
     # pass
     # self.assertEqual(funcs.tupleProduct((2, 3)), 6)
     CTL.setXP(None)
     with self.assertRaises(AttributeError) as context:
         simplestExample()
     CTL.setXP(np)
     res = simplestExample()
     print('res = {}'.format(res))
示例#2
0
文件: test_cupy.py 项目: CaoRX/CTL
 def test_cupy(self):
     # pass
     # self.assertEqual(funcs.tupleProduct((2, 3)), 6)
     try:
         import cupy as cp
     except:
         return
     CTL.setXP(cp)
     res = simplestExample()
     print('res = {}'.format(res))
示例#3
0
parentdir = os.path.dirname(currentdir)
sys.path.append(os.path.join(parentdir, 'src'))

from CTL.tensor.tensor import Tensor
from CTL.tensor.contract.link import makeLink
from CTL.tensor.contract.optimalContract import contractAndCostWithSequence
from CTL.examples.MPS import contractWithMPS

from CTL.models.Ising import IsingSiteTensor, IsingEdgeMatrix, IsingTNFromUndirectedGraph, exactZFromGraphIsing
from CTL.funcs.graphFuncs import squareLatticeFBC, squareLatticeFBC

import numpy as np
import cupy as cp
import CTL

CTL.setXP(cp)


def contractHandmadeTN():
    print('contractHandmadeTN():')
    a = Tensor(shape=(3, 5, 7), labels=['a3', 'a5', 'a7'])
    b = Tensor(shape=(2, 4, 5), labels=['b2', 'b4', 'b5'])
    c = Tensor(shape=(2, 7, 7, 7), labels=['c2', 'c71', 'c72', 'c73'])
    d = Tensor(shape=(7, 7, 3, 4), labels=['d71', 'd72', 'd3', 'd4'])
    e = Tensor(shape=(3, 3, 5), labels=['e31', 'e32', 'e5'])
    f = Tensor(shape=(2, 2, 5), labels=['f21', 'f22', 'f5'])
    g = Tensor(shape=(4, 4, 3, 3), labels=['g41', 'g42', 'g31', 'g32'])
    makeLink('a3', 'e31', a, e)
    makeLink('a5', 'b5', a, b)
    makeLink('a7', 'c72', a, c)
示例#4
0
def HOTRGImpurityExample(beta=0.5):
    print('test magnet for Ising model, beta = {}'.format(beta))
    # beta = 0.6

    symmetryBroken = 1e-5
    a = squareIsingTensor(beta=beta, symmetryBroken=symmetryBroken)
    hotrg = HOTRG(a, chiH=16)
    for _ in range(20):
        hotrg.iterate()

    mTensor = squareIsingTensor(beta=beta,
                                obs="M",
                                symmetryBroken=symmetryBroken)
    impurityTN = ImpurityTensorNetwork([a, mTensor], 2)
    impurityTN.setRG(hotrg)

    for _ in range(20):
        impurityTN.iterate()
    M = impurityTN.measureObservables()
    M = [x[1] for x in M]
    exactM = infiniteIsingExactM(1.0 / beta)
    print('magnet = {}'.format(M[-1] * 0.5))
    print('exact magnet = {}'.format(exactM))


if __name__ == '__main__':
    CTL.setXP(None)
    CTL.setXP(np)
    simplestExample()
    HOTRGImpurityExample(beta=0.6)
    twoTensorsContraction()