DMRG code example error

Hi, I am working on Julia 1.8.2 and trying to run the code example on the webpage DMRG Examples · ITensors.jl

using ITensors

let
  N = 100
  sites = siteinds("S=1",N)

  os = OpSum()
  for j=1:N-1
    os += 0.5,"S+",j,"S-",j+1
    os += 0.5,"S-",j,"S+",j+1
    os += "Sz",j,"Sz",j+1
  end
  H = MPO(os,sites)

  nsweeps = 5 # number of sweeps is 5
  maxdim = [10,20,100,100,200] # gradually increase states kept
  cutoff = [1E-10] # desired truncation error

  psi0 = randomMPS(sites,2)

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

  return
end

But it gives an error saying that

ERROR: MethodError: no method matching sort(::Tuple{Index{Int64}, Index{Int64}}; by::typeof(plev))

And the Stacktrace is

Stacktrace:
 [1] permute(M::MPO, #unused#::Tuple{typeof(linkind), typeof(siteinds), typeof(linkind)})
   @ ITensors F:\Julia-1.8.2\packages\packages\ITensors\hLDmL\src\mps\dmrg.jl:13
 [2] #dmrg#1051
   @ F:\Julia-1.8.2\packages\packages\ITensors\hLDmL\src\mps\dmrg.jl:25 [inlined]
 [3] dmrg
   @ F:\Julia-1.8.2\packages\packages\ITensors\hLDmL\src\mps\dmrg.jl:20 [inlined]
 [4] #dmrg#1057
   @ F:\Julia-1.8.2\packages\packages\ITensors\hLDmL\src\mps\dmrg.jl:375 [inlined]
 [5] top-level scope
   @ .\Untitled-1:21

I succeeded in running this piece of code previously but it doesn’t work today. Updating Julia to latest version doesn’t help. How may I solve this problem?

Thanks!

That looks like an error that occurred in an older version of ITensors.jl. Could you try updating all of your packages and also share the output of using Pkg; Pkg.status()?

Below is updating all the packages and the output of Pkg.status():

(entanglement_code) pkg> update
┌ Warning: attempting to remove probably stale pidfile
│   path = "F:\\Julia-1.8.2\\packages\\registries\\.pid"
└ @ FileWatching.Pidfile F:\Julia-1.9.2\share\julia\stdlib\v1.9\FileWatching\src\pidfile.jl:244
    Updating registry at `F:\Julia-1.8.2\packages\registries\General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
  No Changes to `D:\entanglement_code\Project.toml`
  No Changes to `D:\entanglement_code\Manifest.toml`

julia> using Pkg

julia> Pkg.status()
Status `D:\entanglement_code\Project.toml`
  [336ed68f] CSV v0.10.14   
  [5a033b19] CurveFit v0.6.0
  [28b8d3ca] GR v0.73.3     
  [d2c73de3] GR_jll v0.73.3+0

Maybe I’m missing something but I don’t see ITensors listed there. Also it seems like there is something wrong with your package registry, maybe you should try removing the registry (7. Registries · Pkg.jl) and then reinstall your packages.

2 Likes

It works now! Thanks!