Ejemplo n.º 1
0
def getBMPSRowOps(GammaC, LambdaC, GammaD, LambdaD, AEnv, BEnv, steps):
    convergence = []
    envOpAB = bops.permute(bops.multiContraction(AEnv, BEnv, '1', '3'),
                           [0, 3, 2, 4, 1, 5])
    envOpBA = bops.permute(bops.multiContraction(BEnv, AEnv, '1', '3'),
                           [0, 3, 2, 4, 1, 5])
    op = envOpBA
    for i in range(steps):
        oldGammaC, oldLambdaC, oldGammaD, oldLambdaD = GammaC, LambdaC, GammaD, LambdaD
        GammaC, LambdaC, GammaD, LambdaD = bmpsRowStep(GammaC, LambdaC, GammaD,
                                                       LambdaD, op)
        GammaD, LambdaD, GammaC, LambdaC = bmpsRowStep(GammaD, LambdaD, GammaC,
                                                       LambdaC, op)
        # if i > 0:
        #     convergence.append(
        #         checkConvergence(oldGammaC, oldLambdaC, oldGammaD, oldLambdaD, GammaC, LambdaC, GammaD, LambdaD, 2))
        bops.removeState([oldGammaC, oldLambdaC, oldGammaD, oldLambdaD])

    # cUp = bops.multiContraction(GammaC, LambdaC, '2', '0', isDiag2=True)
    # dUp = bops.multiContraction(GammaD, LambdaD, '2', '0', isDiag2=True)
    # GammaC, LambdaC, GammaD, LambdaD = bmpsRowStep(GammaC, LambdaC, GammaD, LambdaD, op)
    # cDown = bops.multiContraction(GammaC, LambdaC, '2', '0', isDiag2=True)
    # dDown = bops.multiContraction(GammaD, LambdaD, '2', '0', isDiag2=True)
    bops.removeState([
        GammaC, LambdaC, GammaD, LambdaD, oldGammaC, oldLambdaC, oldGammaD,
        oldLambdaD
    ])
    return GammaC, LambdaC, GammaD, LambdaD
Ejemplo n.º 2
0
def applyHToM(HL, HR, H, M, k):
    k1 = k
    k2 = k + 1

    # Add HL.opSum x h.identity(k1) x h.identity(k2) x I(Right)
    # and I(Left) x h.identity(k1) x h.identity(k2) x HR.opSum
    Hv = bops.multiContraction(HL.opSum, M, '0', '0')
    Hv = bops.addNodes(Hv, bops.multiContraction(M, HR.opSum, '3', '0'))

    # Add I(Left) x h.single(k1) x h.identity(k2) x I(Right)
    # And I(Left) x h.identity(k1) x h.single(k2) x I(Right)
    Hv = bops.addNodes(Hv, \
                       bops.permute(bops.multiContraction(M, H.singles[k1], '1', '0'), [0, 3, 1, 2]))
    Hv = bops.addNodes(Hv, \
                       bops.permute(bops.multiContraction(M, H.singles[k2], '2', '0'), [0, 1, 3, 2]))

    # Add HL.openOp x h.r2l(k1) x h.identity(k2) x I(Right)
    # And I(Left) x h.identity(k1) x h.l2r(k2) x HR.openOp
    HK1R2L = bops.permute(bops.multiContraction(M, H.r2l[k1], '1', '0'), [0, 4, 3, 1, 2])
    Hv = bops.addNodes(Hv, \
                       bops.multiContraction(HL.openOp, HK1R2L, '02', '01'))
    HK2L2R = bops.permute(bops.multiContraction(M, H.l2r[k2], '2', '0'), [0, 1, 3, 4, 2])
    Hv = bops.addNodes(Hv, \
                       bops.multiContraction(HK2L2R, HR.openOp, '43', '02'))

    # Add I(Left) x h.l2r(k1) x h.r2l(k2) x I(Right)
    HK1K2 = bops.multiContraction(M, H.l2r[k1], '1', '0')
    HK1K2 = bops.multiContraction(HK1K2, H.r2l[k2], '14', '02')
    HK1K2 = bops.permute(HK1K2, [0, 2, 3, 1])
    Hv = bops.addNodes(Hv, HK1K2)

    return Hv
Ejemplo n.º 3
0
def expectationValue(currSites, op):
    left = leftRow
    for i in range(l):
        left = bops.multiContraction(left, cUp, '3', '0', cleanOr1=True)
        leftUp = toricCode.applyOpTosite(currSites[0][i * 2], op)
        leftDown = toricCode.applyOpTosite(currSites[1][i * 2], op)
        left = bops.multiContraction(left, leftUp, '23', '30', cleanOr1=True)
        left = bops.multiContraction(left, leftDown, '14', '30', cleanOr1=True)
        left = bops.permute(
            bops.multiContraction(left, dDown, '04', '21', cleanOr1=True),
            [3, 2, 1, 0])

        left = bops.multiContraction(left, dUp, '3', '0', cleanOr1=True)
        rightUp = toricCode.applyOpTosite(currSites[0][i * 2 + 1], op)
        rightDown = toricCode.applyOpTosite(currSites[1][i * 2 + 1], op)
        left = bops.multiContraction(left, rightUp, '23', '30', cleanOr1=True)
        left = bops.multiContraction(left,
                                     rightDown,
                                     '14',
                                     '30',
                                     cleanOr1=True)
        left = bops.permute(
            bops.multiContraction(left, cDown, '04', '21', cleanOr1=True),
            [3, 2, 1, 0])

        bops.removeState([leftUp, leftDown, rightDown, rightUp])
    return bops.multiContraction(left, rightRow, '0123', '3210').tensor * 1
Ejemplo n.º 4
0
def XXVar(statesDir: str, outDir: str, NA, theta, phi):
    maxBondDim = 100
    res = np.zeros(2, dtype=complex)
    U = tn.Node(
        np.matmul(ru.getUPhi(np.pi * phi / 2, 2),
                  ru.getUTheta(np.pi * theta / 2, 2)))
    with open(statesDir + 'psiXX_NA_' + str(NA) + '_NB_' + str(NA), 'rb') as f:
        psi = pickle.load(f)
    psiCopy = bops.relaxState(psi, 64)
    res[0] = bops.getOverlap(psi, psiCopy)
    bops.removeState(psi)
    for i in range(NA):
        psiCopy[i] = bops.permute(
            bops.multiContraction(psiCopy[i], U, '1', '0'), [0, 2, 1])
    doublePsi = [None for j in range(len(psiCopy))]
    for j in range(len(psiCopy)):
        doublePsi[j] = doubleMPSSite(psiCopy[j])
    doubleCopy = bops.copyState(doublePsi)
    for j in range(NA):
        doublePsi[j] = bops.permute(
            bops.multiContraction(doublePsi[j], E, '1', '0', cleanOr1=True),
            [0, 2, 1])
    res[1] = bops.getOverlap(doublePsi, doubleCopy)

    with open(
            outDir + 'XXVar_NA_' + str(NA) + '_t_' + str(theta) + '_p_' +
            str(phi), 'wb') as f:
        pickle.dump(res, f)
    print(res)
Ejemplo n.º 5
0
def applyLocalOperators(cUp, dUp, cDown, dDown, leftRow, rightRow, A, B, l,
                        ops):
    left = leftRow
    for i in range(l):
        left = bops.multiContraction(left, cUp, '3', '0', cleanOr1=True)
        leftUp = applyOpTosite(B, ops[i * 4])
        leftDown = applyOpTosite(A, ops[i * 4 + 1])
        left = bops.multiContraction(left, leftUp, '23', '30', cleanOr1=True)
        left = bops.multiContraction(left, leftDown, '14', '30', cleanOr1=True)
        left = bops.permute(
            bops.multiContraction(left, dDown, '04', '21', cleanOr1=True),
            [3, 2, 1, 0])

        left = bops.multiContraction(left, dUp, '3', '0', cleanOr1=True)
        rightUp = applyOpTosite(A, ops[i * 4 + 2])
        rightDown = applyOpTosite(B, ops[i * 4 + 3])
        left = bops.multiContraction(left, rightUp, '23', '30', cleanOr1=True)
        left = bops.multiContraction(left,
                                     rightDown,
                                     '14',
                                     '30',
                                     cleanOr1=True)
        left = bops.permute(
            bops.multiContraction(left, cDown, '04', '21', cleanOr1=True),
            [3, 2, 1, 0])

        bops.removeState([leftUp, leftDown, rightDown, rightUp])

    return bops.multiContraction(left, rightRow, '0123', '3210').tensor * 1
Ejemplo n.º 6
0
def projectS(psi, AEnd):
    projector0Tensor = np.zeros((2, 2))
    projector0Tensor[0, 0] = 1
    projector0 = tn.Node(projector0Tensor, backend=None)
    projector1Tensor = np.zeros((2, 2))
    projector1Tensor[1, 1] = 1
    projector1 = tn.Node(projector1Tensor, backend=None)
    for i in range(AEnd + 1):
        if i % 2 == 0:
            psi[i] = bops.permute(bops.multiContraction(psi[i], projector0, [1], [0]), [0, 2, 1])
        else:
            psi[i] = bops.permute(bops.multiContraction(psi[i], projector1, [1], [0]), [0, 2, 1])
Ejemplo n.º 7
0
def horizontalPair(leftSite, rightSite, cleanLeft=True, cleanRight=True):
    pair = bops.multiContraction(leftSite,
                                 rightSite,
                                 '1',
                                 '3',
                                 cleanOr1=cleanLeft,
                                 cleanOr2=cleanRight)
    pair = bops.multiContraction(pair, ru.getPairUnitary(d), '37', '01')
    [left, right, te] = bops.svdTruncation(pair, [0, 1, 2, 6], [3, 4, 5, 7],
                                           '>>',
                                           maxBondDim=16)
    return bops.permute(left,
                        [0, 4, 1, 2, 3]), bops.permute(right, [1, 2, 3, 0, 4])
Ejemplo n.º 8
0
def stateEnergy(psi: List[tn.Node], H: HOp):
    E = 0
    for i in range(len(psi)):
        psiCopy = bops.copyState(psi)
        single_i = bops.copyState([H.singles[i]])[0]
        psiCopy[i] = bops.permute(tn.contract(psiCopy[i][1] ^ single_i[0], name=('site' + str(i))), [0, 2, 1])
        E += bops.getOverlap(psiCopy, psi)
        bops.removeState(psiCopy)
        tn.remove_node(single_i)
    for i in range(len(psi) - 1):
        psiCopy = bops.copyState(psi)
        r2l = bops.copyState([H.r2l[i+1]])[0]
        l2r = bops.copyState([H.l2r[i]])[0]
        psiCopy[i][2] ^ psiCopy[i+1][0]
        psiCopy[i][1] ^ l2r[0]
        r2l[0] ^ psiCopy[i+1][1]
        l2r[2] ^ r2l[2]
        M = tn.contract_between(psiCopy[i], \
                                tn.contract_between(l2r, tn.contract_between(r2l, psiCopy[i+1])))
        if bops.multiContraction(M, M, '0123', '0123*').tensor != 0:
            [psiCopy, te] = bops.assignNewSiteTensors(psiCopy, i, M, '>>')
            E += bops.getOverlap(psiCopy, psi)
        bops.removeState(psiCopy)
        tn.remove_node(r2l)
        tn.remove_node(l2r)
    return E
Ejemplo n.º 9
0
def expectationValues(psi: List[tn.Node], vs: List[List[np.array]]):
    vs = np.round(vs, 10)
    n = len(vs)
    NA = len(vs[0])
    result = 1
    # result = np.eye(2, dtype=complex)
    for copy in range(n):
        psiCopy = bops.copyState(psi)
        for alpha in range(NA - 1, -1, -1):
            overlap = np.matmul(vs[copy][alpha],
                                np.conj(vs[np.mod(copy + 1, n)][alpha]))
            toEstimate = np.outer(vs[copy][alpha],
                                  np.conj(vs[np.mod(copy + 1, n)][alpha]))
            if np.abs(np.round(overlap, 8)) == 2:
                toMeasure = toEstimate
            else:
                hermitianComponent = np.random.randint(2)
                if hermitianComponent:
                    toMeasure = (toEstimate +
                                 np.conj(np.transpose(toEstimate)))
                else:
                    toMeasure = (toEstimate -
                                 np.conj(np.transpose(toEstimate)))
            psiCopy[alpha] = bops.permute(bops.multiContraction(psiCopy[alpha], tn.Node(toMeasure), \
                                                   '1', '1'), [0, 2, 1])
            psiCopy = bops.shiftWorkingSite(psiCopy, alpha, '<<')
        result *= bops.getOverlap(psiCopy, psi)
        # result = np.matmul(result, toMeasure)
        bops.removeState(psiCopy)
    return result
Ejemplo n.º 10
0
def estimateOp(xRight, xLeft, upRow, downRow, A, ops):
    N = len(ops)
    curr = xLeft
    for i in range(int(N / 2)):
        closedA = tn.Node(
            np.trace(bops.multiContraction(ops[i * 2], A, '1', '0').tensor,
                     axis1=0,
                     axis2=5))
        closedB = tn.Node(
            np.trace(bops.multiContraction(ops[i * 2 + 1], A, '1', '0').tensor,
                     axis1=0,
                     axis2=5))
        closed = bops.permute(
            bops.multiContraction(closedA, closedB, '1', '3'),
            [0, 3, 2, 4, 1, 5])
        curr = bops.multiContraction(bops.multiContraction(
            bops.multiContraction(curr, upRow, '0', '0'),
            closed,
            '023',
            '201',
            cleanOr1=True),
                                     downRow,
                                     '034',
                                     '012',
                                     cleanOr1=True)
    return bops.multiContraction(curr, xRight, '012', '012').tensor
Ejemplo n.º 11
0
def toEnvOperator(op):
    result = bops.unifyLegs(
        bops.unifyLegs(
            bops.unifyLegs(
                bops.unifyLegs(bops.permute(op, [0, 4, 1, 5, 2, 6, 3, 7]), 6,
                               7), 4, 5), 2, 3), 0, 1)
    tn.remove_node(op)
    return result
Ejemplo n.º 12
0
def bmpsDensityMatrix(cUp, dUp, cDown, dDown, AEnv, BEnv, A, B, steps):
    rightRow = bmpsCols(cUp, dUp, cDown, dDown, AEnv, BEnv, steps, 'right')
    leftRow = bmpsCols(cUp, dUp, cDown, dDown, AEnv, BEnv, steps, 'left')
    upRow = bops.multiContraction(cUp, dUp, '2', '0')
    downRow = bops.multiContraction(cDown, dDown, '2', '0')
    circle = bops.multiContraction(
        bops.multiContraction(bops.multiContraction(leftRow, upRow, '3', '0'),
                              rightRow, '5', '0'), downRow, '07', '03')

    parityTensor = np.eye(4, dtype=complex)
    parityTensor[1, 1] = -1
    parityTensor[3, 3] = -1
    parity = tn.Node(parityTensor)
    if A[0].dimension == 4:
        parityA = tn.Node(
            np.trace(bops.multiContraction(parity, A, '1', '0').tensor,
                     axis1=0,
                     axis2=5))
        ABNet = bops.permute(
            bops.multiContraction(
                bops.multiContraction(parityA, parityA, '1', '3'),
                bops.multiContraction(parityA, parityA, '1', '3'),
                '15',
                '03',
                cleanOr1=True,
                cleanOr2=True), [5, 1, 0, 2, 3, 6, 4, 7])
        p2 = bops.multiContraction(circle, ABNet, '01234567', '01234567')
        b = 1

    ABNet = bops.permute(
        bops.multiContraction(bops.multiContraction(B, A, '2', '4'),
                              bops.multiContraction(A, B, '2', '4'),
                              '28',
                              '16',
                              cleanOr1=True,
                              cleanOr2=True),
        [2, 10, 9, 13, 14, 5, 1, 6, 0, 4, 8, 12, 3, 7, 11, 15])
    dm = bops.multiContraction(circle,
                               ABNet,
                               '23140567',
                               '01234567',
                               cleanOr1=True,
                               cleanOr2=True)
    ordered = np.round(np.reshape(dm.tensor, [16, 16]), 13)
    ordered = ordered / np.trace(ordered)
    return dm
Ejemplo n.º 13
0
def trotterSweep(trotterGates, psi, startSite, endSite, maxBondDim=1024):
    psiCopy = bops.copyState(psi)
    truncErr = 0
    N = len(psi)
    for k in [endSite - i for i in range(startSite, endSite)]:
        M = bops.multiContraction(psiCopy[k - 1], psiCopy[k], [2], [0])
        M = bops.permute(
            bops.multiContraction(M, trotterGates[k - 1], [1, 2], [0, 1]),
            [0, 2, 3, 1])
        [l, r, currTruncErr] = bops.svdTruncation(M,
                                                  M[:2],
                                                  M[2:],
                                                  '<<',
                                                  maxBondDim,
                                                  leftName='site' + str(k - 1),
                                                  rightName='site' + str(k),
                                                  edgeName='v' + str(k))
        if currTruncErr > truncErr:
            truncErr = currTruncErr
        psiCopy[k] = r
        psiCopy[k - 1] = l
        bops.multiContraction(r, r, [1, 2], [1, 2, '*'])
    for k in range(startSite, endSite):
        M = bops.multiContraction(psiCopy[k], psiCopy[k + 1], [2], [0])
        M = bops.permute(
            bops.multiContraction(M, trotterGates[k], [1, 2], [0, 1]),
            [0, 2, 3, 1])
        [l, r,
         currTruncErr] = bops.svdTruncation(M,
                                            M[:2],
                                            M[2:],
                                            '>>',
                                            maxBondDim,
                                            leftName='site' + str(k),
                                            rightName='site' + str(k + 1),
                                            edgeName='v' + str(k + 1))
        if currTruncErr > truncErr:
            truncErr = currTruncErr
        psiCopy[k] = l
        psiCopy[k + 1] = r
    # For imaginary time propagation, renormalize state.
    norm = bops.getOverlap(psiCopy, psiCopy)
    psiCopy[N - 1].tensor = psiCopy[N - 1].tensor / math.sqrt(abs(norm))
    return psiCopy, truncErr
Ejemplo n.º 14
0
def exactPurity(l, xRight, xLeft, upRow, downRow, A, filename, d=2):
    curr = xLeft
    pair = bops.permute(bops.multiContraction(A, A, '2', '4'),
                        [1, 6, 3, 7, 2, 8, 0, 5, 4, 9])
    for i in range(int(l / 2)):
        curr = bops.multiContraction(
            bops.multiContraction(curr, upRow, '0', '0'), downRow, '1', '0')
        curr = bops.multiContraction(
            curr, pair, [0, i * 4 + 1, i * 4 + 2, i * 4 + 4, i * 4 + 5],
            '20145')
        curr = bops.permute(curr, [i * 4, i * 4 + 2, i * 4 + 1] +
                            list(range(i * 2)) + [i * 4 + 3, i * 4 + 4] +
                            list(range(i * 2, i * 4)) + [i * 4 + 5, i * 4 + 6])
    dm = bops.multiContraction(curr, xRight, '012', '012')
    ordered = np.reshape(dm.tensor, [d**l, d**l]) / np.trace(
        np.reshape(dm.tensor, [d**l, d**l]))
    purity = sum(np.linalg.eigvalsh(np.matmul(ordered, ordered)))
    with open(filename + '_l_' + str(l), 'wb') as f:
        pickle.dump(purity, f)
    return purity
Ejemplo n.º 15
0
def applyH(psi: List[tn.Node], H: HOp):
    psiCopy = bops.copyState(psi)
    single_0 = bops.copyState([H.singles[0]])[0]
    psiCopy[0] = bops.permute(tn.contract(psiCopy[0][1] ^ single_0[0], name=('site' + str(0))), [0, 2, 1])
    result = psiCopy
    for i in range(1, len(psi)):
        psiCopy = bops.copyState(psi)
        single_i = bops.copyState([H.singles[i]])[0]
        psiCopy[i] = bops.permute(tn.contract(psiCopy[i][1] ^ single_i[0], name=('site' + str(i))), [0, 2, 1])
        result = bops.addStates(result, psiCopy)
    for i in range(len(psi) - 1):
        psiCopy = bops.copyState(psi)
        r2l = bops.copyState([H.r2l[i+1]])[0]
        l2r = bops.copyState([H.l2r[i]])[0]
        psiCopy[i][2] ^ psiCopy[i+1][0]
        psiCopy[i][1] ^ l2r[0]
        r2l[0] ^ psiCopy[i+1][1]
        l2r[2] ^ r2l[2]
        M = tn.contract_between(psiCopy[i], \
                                tn.contract_between(l2r, tn.contract_between(r2l, psiCopy[i+1])))
        [psiCopy, te] = bops.assignNewSiteTensors(psiCopy, i, M, '>>')
        result = bops.addStates(result, psiCopy)
    return result
Ejemplo n.º 16
0
def makeMeasurement(psi, site, toProject):
    localDM = bops.multiContraction(psi[site], psi[site], '02', '02*').tensor
    projectionProbability = np.trace(np.matmul(localDM,
                                               toProject)) / np.trace(localDM)
    # Project to the measured vector
    if np.random.uniform(0, 1) < projectionProbability:
        psi[site] = bops.permute(
            bops.multiContraction(psi[site],
                                  tn.Node(toProject),
                                  '1',
                                  '1',
                                  cleanOr1=True,
                                  cleanOr2=True), [0, 2, 1])
        res = 1
    else:
        psi[site] = bops.permute(
            bops.multiContraction(psi[site],
                                  tn.Node(np.eye(d) - toProject),
                                  '1',
                                  '1',
                                  cleanOr1=True,
                                  cleanOr2=True), [0, 2, 1])
        res = 0
    return res
Ejemplo n.º 17
0
def bmpsCols(upRow: tn.Node,
             downRow: tn.Node,
             AEnv: tn.Node,
             BEnv: tn.Node,
             steps,
             option='right',
             X=None):
    envOpAB = bops.permute(bops.multiContraction(AEnv, BEnv, '1', '3'),
                           [0, 3, 2, 4, 1, 5])
    envOpBA = bops.permute(bops.multiContraction(BEnv, AEnv, '1', '3'),
                           [0, 3, 2, 4, 1, 5])
    if X is None:
        if option == 'right':
            X = tn.Node(
                np.ones((upRow[3].dimension, envOpBA[3].dimension,
                         envOpAB[3].dimension, downRow[0].dimension),
                        dtype=complex))
        else:
            X = tn.Node(
                np.ones((downRow[0].dimension, envOpAB[2].dimension,
                         envOpBA[2].dimension, upRow[0].dimension),
                        dtype=complex))
    for i in range(steps):
        if option == 'right':
            X = bops.multiContraction(upRow, X, '3', '0')
            X = bops.multiContraction(X, envOpBA, '123', '013', cleanOr1=True)
            X = bops.multiContraction(X, envOpAB, '451', '013', cleanOr1=True)
            X = bops.multiContraction(X, downRow, '154', '012', cleanOr1=True)
        else:
            X = bops.multiContraction(downRow, X, '3', '0')
            X = bops.multiContraction(X, envOpAB, '321', '245', cleanOr1=True)
            X = bops.multiContraction(X, envOpBA, '134', '245', cleanOr1=True)
            X = bops.multiContraction(X, upRow, '134', '012', cleanOr1=True)
        norm = np.sqrt(bops.multiContraction(X, X, '0123', '0123*').tensor)
        X = bops.multNode(X, 1 / norm)
    return X
Ejemplo n.º 18
0
def get2ByNExplicit(l: int):
    with open('results/toricBoundaries', 'rb') as f:
        [upRow, downRow, leftRow, rightRow, openA, openB, A,
         B] = pickle.load(f)
    left = bops.multiContraction(
        downRow, bops.multiContraction(leftRow, upRow, '3', '0'), '3', '0')
    for i in range(1, l):
        left = bops.multiContraction(
            downRow,
            bops.multiContraction(left, upRow, [3 + 4 * i], '0',
                                  cleanOr1=True), '3', '0')
    circle = bops.multiContraction(left, downRow, [3 + 4 * l, 0], '03')
    openA = tn.Node(
        np.transpose(
            np.reshape(np.kron(A.tensor, A.tensor),
                       [d**2, d**2, d**2, d**2, d, d]), [4, 0, 1, 2, 3, 5]))
    openB = tn.Node(
        np.transpose(
            np.reshape(np.kron(B.tensor, B.tensor),
                       [d**2, d**2, d**2, d**2, d, d]), [4, 0, 1, 2, 3, 5]))
    ABNet = bops.permute(
        bops.multiContraction(bops.multiContraction(openB, openA, '2', '4'),
                              bops.multiContraction(openA, openB, '2', '4'),
                              '28',
                              '16',
                              cleanOr1=True,
                              cleanOr2=True),
        [1, 5, 6, 13, 14, 9, 10, 2, 0, 4, 8, 12, 3, 7, 11, 15])
    if l == 2:
        curr = bops.multiContraction(circle, ABNet, '234567', '456701')
        res = bops.permute(
            bops.multiContraction(curr, ABNet, '23450176', '01234567'),
            [0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15])
        rdm = np.reshape(res.tensor, [2**8, 2**8])
        rdm = rdm / np.trace(rdm)
    return rdm
Ejemplo n.º 19
0
def twoCopiesEntanglement(circle, A, B):
    doubleCircle = tn.Node(np.kron(circle.tensor, circle.tensor))
    doubleA = tn.Node(np.kron(A.tensor, A.tensor))
    doubleB = tn.Node(np.kron(B.tensor, B.tensor))

    AEnv = tn.Node(np.trace(A.get_tensor(), axis1=0, axis2=5))
    BEnv = tn.Node(np.trace(B.get_tensor(), axis1=0, axis2=5))
    ABNet = bops.permute(
        bops.multiContraction(bops.multiContraction(BEnv, AEnv, '1', '3'),
                              bops.multiContraction(AEnv, BEnv, '1', '3'),
                              '15', '03'), [5, 1, 0, 2, 3, 6, 4, 7])
    n = bops.multiContraction(circle, ABNet, '01234567', '01234567').tensor

    p2 = bops.multiContraction(doubleCircle, ABNet, '01234567',
                               '01234567').tensor
    return p2
Ejemplo n.º 20
0
def verticalPair(topSite, bottomSite, cleanTop=True, cleanBottom=True):
    pair = bops.multiContraction(topSite,
                                 bottomSite,
                                 '2',
                                 '0',
                                 cleanOr1=cleanTop,
                                 cleanOr2=cleanBottom)
    pair = bops.multiContraction(pair,
                                 ru.getPairUnitary(d),
                                 '37',
                                 '01',
                                 cleanOr1=True,
                                 cleanOr2=True)
    [top, bottom, te] = bops.svdTruncation(pair, [0, 1, 2, 6], [3, 4, 5, 7],
                                           '>>',
                                           maxBondDim=16)
    return bops.permute(top, [0, 1, 4, 2, 3]), bottom
Ejemplo n.º 21
0
def bmpsSides(cUp: tn.Node,
              dUp: tn.Node,
              cDown: tn.Node,
              dDown: tn.Node,
              AEnv: tn.Node,
              BEnv: tn.Node,
              steps,
              option='right'):
    envOpAB = bops.permute(bops.multiContraction(AEnv, BEnv, '1', '3'),
                           [0, 3, 2, 4, 1, 5])
    upRow = bops.multiContraction(cUp, dUp, '2', '0')
    downRow = bops.multiContraction(cDown, dDown, '2', '0')
    if option == 'right':
        X = tn.Node(
            np.ones((upRow[3].dimension, envOpAB[3].dimension,
                     downRow[3].dimension),
                    dtype=complex))
    else:
        X = tn.Node(
            np.ones((upRow[0].dimension, envOpAB[2].dimension,
                     downRow[0].dimension),
                    dtype=complex))
    for i in range(steps):
        if option == 'right':
            X = bops.multiContraction(
                bops.multiContraction(bops.multiContraction(
                    X, upRow, '0', '3'),
                                      envOpAB,
                                      '340',
                                      '013',
                                      cleanOr1=True), downRow, '034', '312')
        else:
            X = bops.multiContraction(bops.multiContraction(
                bops.multiContraction(X, upRow, '0', '0'),
                envOpAB,
                '023',
                '201',
                cleanOr1=True),
                                      downRow,
                                      '034',
                                      '012',
                                      cleanOr1=True)
        norm = np.sqrt(bops.multiContraction(X, X, '012', '012*').tensor)
        X = bops.multNode(X, 1 / norm)
    return X
Ejemplo n.º 22
0
def getDMRGH(N, onsiteTerms, neighborTerms, d=2):
    hSingles = [None] * N
    for i in range(N):
        hSingles[i] = tn.Node(onsiteTerms[i], name=('single' + str(i)), axis_names=['s' + str(i) + '*', 's' + str(i)])
    hr2l = [None] * (N)
    hl2r = [None] * (N)
    for i in range(N-1):
        if d == 2:
            neighborTerm = np.reshape(neighborTerms[i], (2, 2, 2, 2))
        elif d == 3:
            neighborTerm = np.reshape(neighborTerms[i], (3, 3, 3, 3))
        pairOp = tn.Node(neighborTerm, \
                         axis_names=['s' + str(i) + '*', 's' + str(i+1) + '*', 's' + str(i), 's' + str(i+1)])
        splitted = tn.split_node(pairOp, [pairOp[0], pairOp[2]], [pairOp[1], pairOp[3]], \
                                          left_name=('l2r' + str(i)), right_name=('r2l' + str(i) + '*'), edge_name='m')
        hr2l[i+1] = bops.permute(splitted[1], [1, 2, 0])
        hl2r[i] = splitted[0]
    return HOp(hSingles, hr2l, hl2r)
Ejemplo n.º 23
0
def localVecsEstimate(psi: List[tn.Node],
                      vs: List[List[np.array]],
                      half='left'):
    vs = np.round(vs, 10)
    n = len(vs)
    result = 1
    for copy in range(n):
        if half == 'left':
            NA = len(vs[0])
            curr = bops.multiContraction(psi[NA], psi[NA], '12', '12*')
            sites = range(NA - 1, -1, -1)
        elif half == 'right':
            NA = len(psi) - len(vs[0])
            curr = bops.multiContraction(psi[len(psi) - NA - 1],
                                         psi[len(psi) - NA - 1], '01', '01*')
            sites = range(NA, len(psi))
        psiCopy = bops.copyState(psi)
        for alpha in sites:
            toEstimate = np.outer(vs[copy][alpha - NA],
                                  np.conj(vs[np.mod(copy + 1, n)][alpha - NA]))
            psiCopy[alpha] = bops.permute(bops.multiContraction(psiCopy[alpha], tn.Node(toEstimate), \
                                                   '1', '1'), [0, 2, 1])
            if half == 'left':
                curr = bops.multiContraction(bops.multiContraction(
                    psiCopy[alpha], curr, '2', '0', cleanOr2=True),
                                             psi[alpha],
                                             '12',
                                             '12*',
                                             cleanOr1=True)
            elif half == 'right':
                curr = bops.multiContraction(bops.multiContraction(
                    curr, psiCopy[alpha], '0', '0', cleanOr2=True),
                                             psi[alpha],
                                             '01',
                                             '01*',
                                             cleanOr1=True)
            # psiCopy = bops.shiftWorkingSite(psiCopy, alpha, '<<')
        result *= np.trace(curr.tensor)
        tn.remove_node(curr)
        bops.removeState(psiCopy)
    return result
Ejemplo n.º 24
0
def singleHaarEstimation(psi: List[tn.Node], us: List[tn.Node], n: int,
                         NA: int):
    psiCopy = bops.copyState(psi)
    projector0 = np.zeros((2, 2))
    projector0[0, 0] = 1
    projector1 = np.zeros((2, 2))
    projector1[1, 1] = 1
    measurementResults = np.array(NA)
    estimation = 1
    for i in range(NA):
        psiCopy[i] = bops.permute(
            bops.multiContraction(psiCopy[i], us[i], '1', '1', cleanOr1=True),
            [0, 2, 1])
        measurementResults[i] = makeMeasurement(psiCopy, i, projector0)
        if measurementResults:
            resultProjector = projector0
        else:
            resultProjector = projector1
        localEstimation = np.matmul(np.matmul(np.conj(np.transpose(us[i].tensor)), resultProjector), us[i].tensor) \
            - np.eye(2)
        estimation *= np.trace(localEstimation**4)
        psiCopy = bops.shiftWorkingSite(psiCopy, i, '<<')
    return estimation
Ejemplo n.º 25
0
def getExplicit2by2(g=0):
    if g == 0:
        with open('results/toricBoundaries', 'rb') as f:
            [upRow, downRow, leftRow, rightRow, openA, openB, A,
             B] = pickle.load(f)
    else:
        with open('results/toricBoundaries_g_' + str(g), 'rb') as f:
            [upRow, downRow, leftRow, rightRow, openA, openB, A,
             B] = pickle.load(f)
    circle = bops.multiContraction(
        bops.multiContraction(bops.multiContraction(upRow, rightRow, '3', '0'),
                              downRow, '5', '0'), leftRow, '70', '03')
    ABNet = bops.permute(
        bops.multiContraction(bops.multiContraction(openB, openA, '2', '4'),
                              bops.multiContraction(openA, openB, '2', '4'),
                              '28',
                              '16',
                              cleanOr1=True,
                              cleanOr2=True),
        [1, 5, 6, 13, 14, 9, 10, 2, 0, 4, 8, 12, 3, 7, 11, 15])
    dm = bops.multiContraction(circle, ABNet, '01234567', '01234567')
    ordered = np.round(np.reshape(dm.tensor, [16, 16]), 14)
    ordered /= np.trace(ordered)
    return ordered
Ejemplo n.º 26
0
                                                '3',
                                                '0',
                                                cleanOr1=True),
                          base,
                          '4',
                          '0',
                          cleanOr1=True)
AEnv = tn.Node(np.trace(A.get_tensor(), axis1=0, axis2=5))

GammaATensor = np.zeros((d, d, d), dtype=complex)
GammaATensor[1, 1, 1] = 1
GammaATensor[0, 0, 0] = 1
GammaBTensor = np.zeros((d, d, d), dtype=complex)
GammaBTensor[1, 1, 1] = 1
GammaBTensor[1, 1, 0] = -1
GammaBTensor[0, 0, 1] = 1
GammaBTensor[0, 0, 0] = 1
LambdaTensor = np.ones(d, dtype=complex)
cUp, dUp, cDown, dDown = peps.getBMPSRowOps(tn.Node(GammaATensor),
                                            tn.Node(LambdaTensor),
                                            tn.Node(GammaBTensor),
                                            tn.Node(LambdaTensor), AEnv, AEnv,
                                            100)
xRight = peps.bmpsSides(cUp, dUp, cUp, dUp, AEnv, AEnv, 100, option='right')
xLeft = peps.bmpsSides(cUp, dUp, cUp, dUp, AEnv, AEnv, 100, option='left')

pair = bops.permute(bops.multiContraction(A, A, '2', '4'),
                    [1, 6, 3, 7, 2, 8, 0, 5, 4, 9])
upRow = bops.multiContraction(cUp, dUp, '2', '0')
downRow = bops.multiContraction(cDown, dDown, '2', '0')
Ejemplo n.º 27
0
# origSizes = [T.tensor.shape[0], T.tensor.shape[1]]
# tMatrix = np.round(np.reshape(T.tensor, [origSizes[0] * origSizes[1], origSizes[0] * origSizes[1]]), 14)
# vals, vecs = scipy.sparse.linalg.eigs(tMatrix, k=1)
# # vals = np.round(vals, 6)
# # uVec = vecs[:, list(vals).index(1)]
# uVec = vecs[:, 0]
# uMatrix = np.reshape(uVec, origSizes)
# uMatrix /= np.sqrt(np.trace(np.matmul(uMatrix, np.conj(np.transpose(uMatrix)))) / len(uMatrix))
# print(np.trace(np.matmul(uMatrix, np.conj(uMatrix))) / len(uMatrix))
# U = tn.Node(uMatrix, backend=None)


psiP = bops.copyState(psi, conj=True)
for i in A1 + A2:
    currU = trUnitary(i)
    psiP[i] = bops.permute(bops.multiContraction(psiP[i], currU, [1], [0]), [0, 2, 1])
psiConj = bops.copyState(psi, conj=True)
curr = bops.multiContraction(psiP[A1[0]], psiConj[A1[0]], [0, 1], [0, 1])
for i in range(A1[1], A2[-1]-1):
    curr = bops.multiContraction(bops.multiContraction(curr, psiP[i], [0], [0]), psiConj[i], [0, 1], [0, 1])
curr = bops.multiContraction(bops.multiContraction(curr, psiP[A2[-1]], [0], [0]), psiConj[A2[-1]], [0, 1, 2], [0, 1, 2])
# pt = getPartiallyTransposed(psi, A1[0], A1[-1], A2[0], A2[-1])
# reg = getStraightDM(psiP, A1[0], A1[-1], A2[0], A2[-1])
b=1
""" This does not give the same result as Poleman-Turner's paper! """

def applySwap(psi, psiP, startInd, endInd):
    psiDagger = bops.copyState(psi, conj=True)
    psiPDagger = bops.copyState(psi, conj=True)
    curr = bops.multiContraction(psi[startInd], psiDagger[startInd], [0], [0])
    currP = bops.multiContraction(psiP[startInd], psiPDagger[startInd], [0], [0])
Ejemplo n.º 28
0
with open(
        homedir + '/expected_MPS_NA_' + str(NA) + '_NB_' + str(NB) + '_n_' +
        str(n) + '_' + half, 'wb') as f:
    pickle.dump(Sn, f)
mySum = 0
M = 1000
if half == 'left':
    steps = int(2**(NA * n))
    for k in range(len(psi) - 1, NA - 1, -1):
        psi = bops.shiftWorkingSite(psi, k, '<<')
    sites = range(NA)
else:
    steps = int(2**(NB * n))
    sites = range(NA, len(psi))
for site in sites:
    psi[site] = bops.permute(bops.multiContraction(psi[site], U, '1', '0'),
                             [0, 2, 1])
for m in range(M * steps):
    if half == 'left':
        vs = [[np.array([np.exp(1j * np.pi * np.random.randint(4) / 2), np.exp(1j * np.pi * np.random.randint(4) / 2)]) \
               for alpha in range(NA)] for copy in range(n)]
    else:
        vs = [[np.array([np.exp(1j * np.pi * np.random.randint(4) / 2), np.exp(1j * np.pi * np.random.randint(4) / 2)]) \
               for alpha in range(NB)] for copy in range(n)]
    u = np.matmul(ru.getUTheta(theta, d=2), ru.getUPhi(phi, d=2))
    for i in range(len(vs)):
        for j in range(len(vs[0])):
            vs[i][j] = np.matmul(u, vs[i][j])
    currEstimation = localVecsEstimate(psi, vs, half=half)
    mySum += currEstimation
    if m % M == M - 1:
        with open(
Ejemplo n.º 29
0
                                   '1', '0')
    u1 = tn.Node(randomUs.haar_measure(d))
    openA1 = bops.multiContraction(u1,
                                   bops.multiContraction(openA, u1, '5', '1*'),
                                   '1', '0')
    u2 = tn.Node(randomUs.haar_measure(d))
    openA2 = bops.multiContraction(u2,
                                   bops.multiContraction(openA, u2, '5', '1*'),
                                   '1', '0')
    u3 = tn.Node(randomUs.haar_measure(d))
    openB3 = bops.multiContraction(u3,
                                   bops.multiContraction(openB, u3, '5', '1*'),
                                   '1', '0')
    env123 = bops.multiContraction(circle, BEnv, '12', '03')
    env23 = bops.multiContraction(env123, AEnv, '126', '013')
    env3 = bops.permute(bops.multiContraction(env23, AEnv, '430', '023'),
                        [2, 0, 1, 3])

    us[m] = [u0.tensor, u1.tensor, u2.tensor, u3.tensor]

    rho3 = bops.multiContraction(env3, openB3, '0123', '1234')
    ks[m][3] = randomMeas(rho3.tensor / np.trace(rho3.tensor))
    if ks[m][3] == 0:
        B3 = tn.Node(openB3.tensor[0, :, :, :, :, 0])
    else:
        B3 = tn.Node(openB3.tensor[1, :, :, :, :, 1])
    env2 = bops.permute(bops.multiContraction(env23, B3, '512', '012'),
                        [2, 3, 1, 0])
    rho2 = bops.multiContraction(env2, openA2, '0123', '1234')
    ks[m][2] = randomMeas(rho2.tensor / np.trace(rho2.tensor))
    if ks[m][2] == 0:
        A2 = tn.Node(openA2.tensor[0, :, :, :, :, 0])
Ejemplo n.º 30
0
AEnv = toEnvOperator(bops.multiContraction(A, A, '4', '4*'))
BEnv = toEnvOperator(bops.multiContraction(B, B, '4', '4*'))
chi = 32
nonPhysicalLegs = 1
GammaTensor = np.ones((nonPhysicalLegs, d**2, nonPhysicalLegs), dtype=complex)
GammaC = tn.Node(GammaTensor, name='GammaC', backend=None)
LambdaC = tn.Node(np.eye(nonPhysicalLegs) / np.sqrt(nonPhysicalLegs),
                  backend=None)
GammaD = tn.Node(GammaTensor, name='GammaD', backend=None)
LambdaD = tn.Node(np.eye(nonPhysicalLegs) / np.sqrt(nonPhysicalLegs),
                  backend=None)

steps = 50

envOpAB = bops.permute(bops.multiContraction(AEnv, BEnv, '1', '3'),
                       [0, 3, 2, 4, 1, 5])
envOpBA = bops.permute(bops.multiContraction(BEnv, AEnv, '1', '3'),
                       [0, 3, 2, 4, 1, 5])
#
# curr = bops.permute(bops.multiContraction(envOpBA, envOpAB, '45', '01'), [0, 2, 4, 6, 1, 3, 5, 7])
#
# for i in range(50):
#     [C, D, te] = bops.svdTruncation(curr, [0, 1, 2, 3], [4, 5, 6, 7], '>>', normalize=True)
#     curr = bops.permute(bops.multiContraction(D, C, '23', '12'), [1, 3, 0, 5, 2, 4])
#     curr = bops.permute(bops.multiContraction(curr, envOpAB, '45', '01'), [0, 2, 4, 6, 1, 3, 5, 7])
#
# currAB = curr
# [C, D, te] = bops.svdTruncation(curr, [0, 1, 2, 3], [4, 5, 6, 7], '>>', normalize=True)
# currBA = bops.permute(bops.multiContraction(D, C, '23', '12'), [1, 3, 0, 5, 2, 4])
# currBA = bops.permute(bops.multiContraction(currBA, envOpAB, '45', '01'), [0, 2, 4, 6, 1, 3, 5, 7])
#