ITensor / ITensor/ITensorMPS.jl

[ITensors] [BUG] Add check for flux when adding ITensors and MPS

Open
#71 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
85
Forks
27
Avg merge
22m
Merged PRs (30d)
1

Description

Description of bug

Currently you are allowed to add two ITensors or MPS which have different flux, which is not well defined. It should throw an error.

See https://itensor.discourse.group/t/how-to-deal-with-entangled-state-of-different-quantum-number/94.

Minimal code demonstrating the bug or unexpected behavior

Minimal runnable code

julia> using ITensors

julia> s = siteinds("S=1/2", 3; conserve_qns=true);

julia> A1 = randomITensor(QN(), s[1]', dag(s[1]));

julia> A2 = randomITensor(QN("Sz", 2), s[1]', dag(s[1]));

julia> @show A1;
A1 = ITensor ord=2
Dim 1: (dim=2|id=12|"S=1/2,Site,n=1")' <Out>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1
Dim 2: (dim=2|id=12|"S=1/2,Site,n=1") <In>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1
NDTensors.BlockSparse{Float64, Vector{Float64}, 2}
 2×2
Block(1, 1)
 [1:1, 1:1]
 -0.7467320137298004

Block(2, 2)
 [2:2, 2:2]
 -0.2159039892715488

julia> @show A2;
A2 = ITensor ord=2
Dim 1: (dim=2|id=12|"S=1/2,Site,n=1")' <Out>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1
Dim 2: (dim=2|id=12|"S=1/2,Site,n=1") <In>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1
NDTensors.BlockSparse{Float64, Vector{Float64}, 2}
 2×2
Block(1, 2)
 [1:1, 2:2]
 -0.5224630234648842

julia> @show A1 + A2;
A1 + A2 = ITensor ord=2
Dim 1: (dim=2|id=12|"S=1/2,Site,n=1")' <Out>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1
Dim 2: (dim=2|id=12|"S=1/2,Site,n=1") <In>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1
NDTensors.BlockSparse{Float64, Vector{Float64}, 2}
 2×2
Block(1, 1)
 [1:1, 1:1]
 -0.7467320137298004

Block(2, 2)
 [2:2, 2:2]
 -0.2159039892715488

Block(1, 2)
 [1:1, 2:2]
 -0.5224630234648842

julia> psi1 = MPS(s, ["Dn", "Dn", "Dn"]);

julia> psi2 = MPS(s, ["Up", "Dn", "Dn"]);

julia> psi1 + psi2
MPS
[1] ((dim=2|id=12|"S=1/2,Site,n=1") <Out>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1, (dim=1|id=84|"Link,l=1") <Out>
 1: QN("Sz",-2) => 1)
[2] ((dim=2|id=494|"S=1/2,Site,n=2") <Out>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1, (dim=1|id=155|"Link,l=2") <Out>
 1: QN("Sz",-1) => 1, (dim=1|id=84|"Link,l=1") <In>
 1: QN("Sz",-2) => 1)
[3] ((dim=2|id=221|"S=1/2,Site,n=3") <Out>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1, (dim=1|id=155|"Link,l=2") <In>
 1: QN("Sz",-1) => 1)

julia> flux(psi1)
QN("Sz",-3)

julia> flux(psi2)
QN("Sz",-1)

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) E-2176M  CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = vim
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
      Status `~/.julia/environments/v1.7/Project.toml`
  [9136182c] ITensors v0.3.10

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the ITensor and MPS addition paths shown by the minimal Julia example, then inspect how flux is obtained for each operand. Reproduce additions with mismatched and matching flux values; done when mismatched ITensors and MPS throw an error while valid additions remain supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.