Optimizing dmrg results for expected values of observables

Hi Shovan, Yes the modern julia version is quite different. Here is a julia version for S2 and S=1/2 sites:

using ITensors

function makeS2(sites)
    N = length(sites)
    S2 = MPO(sites)
    qns=[QN("Sz",0)=>3,QN("Sz",-2)=>1,QN("Sz",2)=>1]
    col= Index(qns,"Link,l=0")
    for n in 1:N
        row = dag(col)
        col = Index(qns,"Link,l=$n")
        s=sites[n]
     
        W = ITensor(row,col,dag(s),prime(s))
       
        W += op(s,"Id") * onehot(row=>1,col=>1)
        W += op(s,"Id") * onehot(row=>2,col=>2)

        W += op(s,"S2") * onehot(row=>2,col=>1) 

        W += 2*op(s,"Sz") *onehot(row=>2,col=>3) 
        W += op(s,"Id") * onehot(row=>3,col=>3) 
        W += op(s,"Sz") * onehot(row=>3,col=>1)

        W += op(s,"S+") * onehot(row=>2,col=>4) 
        W += op(s,"Id") * onehot(row=>4,col=>4) 
        W += op(s,"S-") * onehot(row=>4,col=>1) 

        W += op(s,"S-") * onehot(row=>2,col=>5) 
        W += op(s,"Id") * onehot(row=>5,col=>5) 
        W += op(s,"S+") * onehot(row=>5,col=>1)

        #
        #  Terminate the MPO by effectively capping with l/r vectors.
        #
        if n==1
            W*=onehot(dag(row)=>5)
        end
        if n==N
            W*=onehot(dag(col)=>1)
        end

        S2[n] = W
    end

    return S2
end

sites = siteinds("S=1/2", 5,conserve_qns=true)
S2=makeS2(sites)

Next time please start a new topic. The discourse system is telling me the topic is solved and I should not be replying :slight_smile:

Anyway I hope this helps.

2 Likes