# Entanglement entropies are unstable in DMRG calculations

**URL:** https://itensor.discourse.group/t/entanglement-entropies-are-unstable-in-dmrg-calculations/1975
**Category:** ITensor Julia Questions
**Created:** [September 10, 2024, 2:40am UTC](https://itensor.discourse.group/t/entanglement-entropies-are-unstable-in-dmrg-calculations/1975 "2024-09-10T02:40:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![phy](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@phy](https://itensor.discourse.group/u/phy)
#### Post date: [September 10, 2024, 2:40am UTC](https://itensor.discourse.group/t/entanglement-entropies-are-unstable-in-dmrg-calculations/1975/1 "2024-09-10T02:40:08Z")

</div>

Hi, everyone  
I run the following code in order to calculate the entropy of 16-sites toric code:

using ITensors  
using CSV

Ny = 4  
Nx = 4  
N = Nx\*Ny  
J=1.0 # parameter

f = open(“Nx4\_Ny4\_svn.dat”,“w”)

sites = siteinds(“S=1/2”, N)

ampo = OpSum()

ampo +=-16_J, “Sx”,1,“Sx”,2,“Sx”,3,“Sx”,4  
ampo +=-16_J, “Sz”,2,“Sz”,11,“Sz”,12,“Sz”,3  
ampo +=-16_J, “Sx”,3,“Sx”,12,“Sx”,13,“Sx”,14  
ampo +=-16_J, “Sz”,4,“Sz”,3,“Sz”,14,“Sz”,15  
ampo +=-16_J, “Sx”,5,“Sx”,4,“Sx”,15,“Sx”,16  
ampo +=-16_J, “Sz”,6,“Sz”,1,“Sz”,4,“Sz”,5  
ampo +=-16_J, “Sx”,7,“Sx”,8,“Sx”,1,“Sx”,6  
ampo +=-16_J, “Sz”,8,“Sz”,9,“Sz”,2,“Sz”,1  
ampo +=-16\*J, “Sx”,9,“Sx”,10,“Sx”,11,“Sx”,2

println(“$ampo”)

H= MPO(ampo, sites)  
#println(“$H”)

nsweeps = 10  
maxdim = [100, 200, 400, 800, 1600]  
cutoff = [1E-4,1E-5,1E-7,1E-9,1E-12]  
noise = [1E-5, 1E-7, 1E-10, 0.0]

# Initialize wavefunction to be bond dimension 10 random MPS with number of particles the same as state

psi0 = randomMPS(sites,10)

# Start DMRG calculation:

energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff, noise, outputlevel=1)

function entropyvonneumann(psi::MPS, N::Int)  
s = siteinds(psi)  
SvN = fill(0.0, N)  
for b in 2:N-1  
orthogonalize!(psi, b)  
\_,S = svd(psi[b], (linkind(psi, b-1), s[b]))  
for n in 1:dim(S, 1)  
p = S[n,n]^2  
SvN[b] -= p \* log(p)  
end  
println(“J=$J, b=b, svn=(SvN[b]), $energy”)  
write(f,“J=$J b (SvN[b]) $energy\n”)  
end  
return SvN  
end

SvN = entropyvonneumann(psi, N)

close(f)

The label of site are as follows

 ![cbf8dc06fad5df7ad476430ac89a3055](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/4d2e512e25a7a775577e07bc30520ad021a49a2e.jpeg)

I can get the entangment entropy as a funtion of the cutsite after running, but these results are unstable and will get the different data for each running. The data of entropy are the same when b \<5 and become different when b \>=5, we give three examples ( running results of 3 times using the complete same code) as follows  
Data (1)  
J=1.0, b=2, svn=1.3862943611198908, -9.000000000000004  
J=1.0, b=3, svn=2.0794415416798357, -9.000000000000004  
J=1.0, b=4, svn=2.079441541679836, -9.000000000000004  
J=1.0, b=5, svn=2.7725887222397816, -9.000000000000004  
J=1.0, b=6, svn=2.5424747758731376, -9.000000000000004  
J=1.0, b=7, svn=2.289308475916981, -9.000000000000004  
J=1.0, b=8, svn=2.2063608166324324, -9.000000000000004  
J=1.0, b=9, svn=1.9187730461528667, -9.000000000000004  
J=1.0, b=10, svn=2.040892313013744, -9.000000000000004  
J=1.0, b=11, svn=1.7026450235254373, -9.000000000000004  
J=1.0, b=12, svn=1.4736111530772424, -9.000000000000004  
J=1.0, b=13, svn=1.2736661289966225, -9.000000000000004  
J=1.0, b=14, svn=0.9797397339989812, -9.000000000000004  
J=1.0, b=15, svn=0.42231391439364097, -9.000000000000004

Data (2)  
J=1.0, b=2, svn=1.3862943611198908, -9.000000000000002  
J=1.0, b=3, svn=2.079441541679836, -9.000000000000002  
J=1.0, b=4, svn=2.0794415416798366, -9.000000000000002  
J=1.0, b=5, svn=2.772588722239783, -9.000000000000002  
J=1.0, b=6, svn=2.7574566244084022, -9.000000000000002  
J=1.0, b=7, svn=2.924867596066312, -9.000000000000002  
J=1.0, b=8, svn=2.269382809994537, -9.000000000000002  
J=1.0, b=9, svn=2.0257138838402566, -9.000000000000002  
J=1.0, b=10, svn=1.406780861617313, -9.000000000000002  
J=1.0, b=11, svn=1.386294361119891, -9.000000000000002  
J=1.0, b=12, svn=1.2329113062192134, -9.000000000000002  
J=1.0, b=13, svn=1.1856753610512647, -9.000000000000002  
J=1.0, b=14, svn=0.7042871251731921, -9.000000000000002  
J=1.0, b=15, svn=0.5003747635562024, -9.000000000000002

Data (3)  
J=1.0, b=2, svn=1.3862943611198908, -9.0  
J=1.0, b=3, svn=2.0794415416798353, -9.0  
J=1.0, b=4, svn=2.0794415416798353, -9.0  
J=1.0, b=5, svn=2.7725887222397794, -9.0  
J=1.0, b=6, svn=2.397125842206675, -9.0  
J=1.0, b=7, svn=2.685365628634381, -9.0  
J=1.0, b=8, svn=2.1019174442000783, -9.0  
J=1.0, b=9, svn=1.622085351687482, -9.0  
J=1.0, b=10, svn=1.7410553559106263, -9.0  
J=1.0, b=11, svn=1.3985082756156524, -9.0  
J=1.0, b=12, svn=1.389196525102433, -9.0  
J=1.0, b=13, svn=1.5357069195188937, -9.0  
J=1.0, b=14, svn=1.3394491212850217, -9.0  
J=1.0, b=15, svn=0.6930155646252019, -9.0

How to understand this unstablility of entanglement entropy and how to fix it ?
