+1 vote
asked by (1.1k points)

Hi,

My code has an error after updating the new ITensors.jl. The sample code is as follows,

s = Index([QN(("N",i,3))=>1 for i = 0:(2)];dir = ITensors.Arrow(1))
l = setdir(addtags(s,"left"),ITensors.Arrow(-1))
r = addtags(s,"right")
A = emptyITensor(l,r)
A[l(1),r(1)] = 1.0

It throws an error saying "no method matching ValLength(::Index{Array{Pair{QN,Int64},1}})". What is changed for the new version? Thanks.

Jin

1 Answer

0 votes
answered by (9.8k points)
edited by

Hi Jin,

This works as expected for me with the latest version of ITensors.jl:

pkg> st ITensors
Status [...]
  [9136182c] ITensors v0.1.30

julia> using ITensors

julia> s = Index([QN(("N",i,3))=>1 for i = 0:(2)];dir = ITensors.Arrow(1))
(dim=3|id=859) <Out>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1

julia> l = setdir(addtags(s,"left"),ITensors.Arrow(-1))
(dim=3|id=859|"left") <In>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1

julia> r = addtags(s,"right")
(dim=3|id=859|"right") <Out>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1

julia> A = emptyITensor(l,r)
ITensor ord=2
(dim=3|id=859|"left") <In>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1
(dim=3|id=859|"right") <Out>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1
NDTensors.Empty{Float64,NDTensors.BlockSparse{Float64,Array{Float64,1},2}}

julia> A[l(1),r(1)] = 1.0
1.0

julia> @show A;
A = ITensor ord=2
Dim 1: (dim=3|id=859|"left") <In>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1
Dim 2: (dim=3|id=859|"right") <Out>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1
NDTensors.BlockSparse{Float64,Array{Float64,1},2}
 3×3
Block: Block{2}((0x0000000000000001, 0x0000000000000001), 0xa03b74afc6984a6a)
 [1:1, 1:1]
 1.0

We've been making quite a few changes to indexing and block sparse operations in recent versions, so possibly something broke in one of the versions before v0.1.30.

Also note that the Index direction is out by default, and you can make a new Index with the arrow direction reversed with dag:

julia> s = Index([QN("N",i,3)=>1 for i = 0:2])
(dim=3|id=917) <Out>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1

julia> l = dag(addtags(s,"left"))
(dim=3|id=917|"left") <In>
 1: QN("N",0,3) => 1
 2: QN("N",1,3) => 1
 3: QN("N",2,3) => 1

-Matt

commented by (9.8k points)
Ah I see, indeed when I go back to v0.1.29 of ITensors.jl I see the same error as you. Please update to v0.1.30 with:

    julia> using Pkg; Pkg.update()

or equivalently:

    julia> ] up
commented by (9.8k points)
It appears that the issue is particular to having v0.1.29 of ITensors.jl and v0.1.19 of NDTensors.jl, I can make it more strict in the future about which versions are compatible with which. So an alternative is to set ITensors.jl to v0.1.29 and NDTensors.jl to v0.1.18 (in case someone is having trouble with the latest versions).
commented by (1.1k points)
Thanks Matt, very helpful.
Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...