basic codes not working all of a sudden

Hi,

I have been using ITensors (v0.3) on a very regular basis for the last ~4 months (in Jupyter with its IJulia kernel, and Julia v1.9.0) for my ongoing projects and everything had been working fine until yesterday. Today all of a sudden nothing is working and every code I have is throwing up the same sort of errors even though I had made no changes to their previously saved versions and was merely re-running them for more data collection and testing. I went back to the Heisenberg spin chain examples for both DMRG and TEBD given in the documentation to see if they were running as they should (and did, in my own early education), but here too I am seeing the same errors as I saw with my own projects’ codes. I am showing the errors I have for both DMRG and TEBD of 1d Heisenberg chain. It’s as if my whole ITensors has corrupted or source codes missing or something all of a sudden. The only thing I did between previous runs of my codes and today’s runs was installing PastaQ (if that’s relevant an info at all).

TEBD

using ITensors
using ITensors.Strided
using LinearAlgebra
using Printf
using Random

let
  N = 100
  cutoff = 1E-8
  tau = 0.1
  ttotal = 2.0

  # Make an array of 'site' indices
  s = siteinds("S=1/2", N; conserve_qns=true)

  # Make gates (1,2),(2,3),(3,4),...
  gates = ITensor[]
  for j in 1:(N - 1)
    s1 = s[j]
    s2 = s[j + 1]
        
    hj =
      op("Sz", s1) * op("Sz", s2) +
      1 / 2 * op("S+", s1) * op("S-", s2) +
      1 / 2 * op("S-", s1) * op("S+", s2)
    Gj = exp(-im * tau / 2 * hj)
    push!(gates, Gj)
  end
  # Include gates in reverse order too
  # (N,N-1),(N-1,N-2),...
  append!(gates, reverse(gates))

  # Initialize psi to be a product state (alternating up and down)
  psi = productMPS(s, n -> isodd(n) ? "Up" : "Dn")

  c = div(N, 2) # center site

  # Compute and print <Sz> at each time step
  # then apply the gates to go to the next time
  for t in 0.0:tau:ttotal
    Sz = expect(psi, "Sz"; sites=c)
    println("$t $Sz")

    t≈ttotal && break

    psi = apply(gates, psi; cutoff)
    normalize!(psi)
  end

  return
end

MethodError: no method matching sort(::Tuple{Int64, Int64})

Closest candidates are:
sort(::AbstractUnitRange)
@ Base range.jl:1384
sort(::AbstractRange)
@ Base range.jl:1387
sort(::Dictionaries.AbstractIndices{I}; kwargs…) where I
@ Dictionaries C:\Users\adity.julia\packages\Dictionaries\7aBxp\src\AbstractIndices.jl:376

Stacktrace:
[1] permutedims_combine_output(T::NDTensors.BlockSparseTensor{ComplexF64, 4, NTuple{4, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{ComplexF64, Vector{ComplexF64}, 4}}, is::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, perm::NTuple{4, Int64}, combdims::Tuple{Int64, Int64}, blockperm::Vector{Int64}, blockcomb::Vector{Int64})
@ NDTensors C:\Users\adity.julia\packages\NDTensors\kR4oQ\src\blocksparse\blocksparsetensor.jl:439
[2] permutedims_combine(T::NDTensors.BlockSparseTensor{ComplexF64, 4, NTuple{4, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{ComplexF64, Vector{ComplexF64}, 4}}, is::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, perm::NTuple{4, Int64}, combdims::Tuple{Int64, Int64}, blockperm::Vector{Int64}, blockcomb::Vector{Int64})
@ NDTensors C:\Users\adity.julia\packages\NDTensors\kR4oQ\src\blocksparse\blocksparsetensor.jl:467
[3] contract(tensor::NDTensors.BlockSparseTensor{ComplexF64, 4, NTuple{4, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{ComplexF64, Vector{ComplexF64}, 4}}, tensor_labels::NTuple{4, Int64}, combiner_tensor::NDTensors.Tensor{Number, 3, NDTensors.Combiner, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}}, combiner_tensor_labels::Tuple{Int64, Int64, Int64})
@ NDTensors C:\Users\adity.julia\packages\NDTensors\kR4oQ\src\blocksparse\combiner.jl:72
[4] _contract(A::NDTensors.BlockSparseTensor{ComplexF64, 4, NTuple{4, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{ComplexF64, Vector{ComplexF64}, 4}}, B::NDTensors.Tensor{Number, 3, NDTensors.Combiner, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}})
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\tensor_algebra.jl:3
[5] _contract(A::ITensor, B::ITensor)
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\tensor_algebra.jl:9
[6] contract(A::ITensor, B::ITensor)
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\tensor_algebra.jl:104
[7] *(A::ITensor, B::ITensor)
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\tensor_algebra.jl:91
[8] exp(A::ITensor, Linds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, Rinds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\matrix_algebra.jl:80
[9] exp(A::ITensor, Linds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, Rinds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}})
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\matrix_algebra.jl:39
[10] exp(A::ITensor; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\matrix_algebra.jl:88
[11] exp(A::ITensor)
@ ITensors C:\Users\adity.julia\packages\ITensors\hLDmL\src\tensor_operations\matrix_algebra.jl:85
[12] top-level scope
@ In[8]:20

The line “20” referred to in the last line above is the line of Gj in the gates construction loop.

Similarly in the DMRG code of the 1d Heisenberg -

using ITensors
using ITensors.Strided
using LinearAlgebra
using Printf
using Random

let
  N = 100

  sites = siteinds("S=1/2", N; conserve_qns=true)

  os = OpSum()
  for j in 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)

  state = [isodd(n) ? "Up" : "Dn" for n in 1:N]
  #psi0 = randomMPS(sites, state, 10)  
  psi0 = productMPS(sites, n -> isodd(n) ? "Up" : "Dn")

  # Plan to do 5 DMRG sweeps:
  nsweeps = 5
  # Set maximum MPS bond dimensions for each sweep
  maxdim = [10, 20, 100, 100, 200]
  # Set maximum truncation error allowed when adapting bond dimensions
  cutoff = [1E-11]

  # Run the DMRG algorithm, returning energy and optimized MPS
  energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff)
  @printf("Final energy = %.12f\n", energy)
end

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

Closest candidates are:
sort(::AbstractUnitRange) got unsupported keyword argument “by”
@ Base range.jl:1384
sort(::AbstractRange) got unsupported keyword argument “by”
@ Base range.jl:1387
sort(::Dictionaries.AbstractIndices{I}; kwargs…) where I
@ Dictionaries C:\Users\adity.julia\packages\Dictionaries\7aBxp\src\AbstractIndices.jl:376

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

The line “26” is the line that calls the dmrg function.

So my query and worry is am I correct in suspecting that somehow my ITensors has been corrupted ?

Update - Updating the whole package manager and the various packages including ITensors appears to have removed the issues. Last night I’d uninstalled PastaQ, and tried to update ITensors separately but that didn’t work, then had reinstalled PastaQ and tried to update ITensors but still nothing improved. But today after removing some redundant packages in Julia and updating all the other ones has sorted it. Weird. And this was scary :smiley:

I had to manually remove PyCall, PyPlot and SymPy before upgrading everything else (I believe these were installed with PastaQ ? I don’t remember seeing them in my package-list last I checked). This is not the first time PyCall and PyPlot caused an issue in my Julia. Only after removing them it seems the upgrades rooted out whatever the problem was.

1 Like

Glad to hear you got everything working. I have found it can be subtle to properly upgrade all packages. There are some advanced features of Julia’s package manager in the latest versions that can provide more info about why packages aren’t upgrading, so those features can be useful to read about. But I imagine the Python-dependent packages may add an extra level of complication.