Skip to content

[ITensors] [BUG] correlation_matrix() chokes on Pauli matrices X, Y (complex expectation value) #1609

@christopherdavidwhite2

Description

@christopherdavidwhite2

Description of bug

When I attempt to take the correlation matrix of the two Paulis X and Y, I get an InexactError

Minimal code demonstrating the bug

Minimal runnable code

L = 4
ss = ITensorMPS.siteinds("S=1/2",L)
ψ = MPS([state("Up", s) for s in ss])
correlation_matrix(ψ, "Y", "Z")

Curiously the same thing happens if I do ψ *= im to force the eltype of ψ's tensors to be complex.

Expected output or behavior

I expect im on the diagonal

Actual output or behavior

InexactError: Float64(0.0 + 1.0im)

Output of minimal runnable code

InexactError: Float64(0.0 + 1.0im)

Stacktrace:
  [1] Real
    @ ./complex.jl:44 [inlined]
  [2] convert
    @ ./number.jl:7 [inlined]
  [3] setindex!
    @ ./genericmemory.jl:243 [inlined]
  [4] unsafe_copyto!(dest::Memory{Float64}, doffs::Int64, src::Memory{ComplexF64}, soffs::Int64, n::Int64)
    @ Base ./genericmemory.jl:153
  [5] unsafe_copyto!
    @ ./genericmemory.jl:133 [inlined]
  [6] _copyto_impl!
    @ ./array.jl:308 [inlined]
  [7] copyto!
    @ ./array.jl:294 [inlined]
  [8] copyto!
    @ ./array.jl:319 [inlined]
  [9] copyto_axcheck!
    @ ./abstractarray.jl:1167 [inlined]
 [10] Array
    @ ./array.jl:626 [inlined]
 [11] Array
    @ ./boot.jl:606 [inlined]
...
    @ ITensorMPS ~/.julia/packages/ITensorMPS/jyjxG/src/mps.jl:907
 [23] correlation_matrix(psi::MPS, _Op1::String, _Op2::String)
    @ ITensorMPS ~/.julia/packages/ITensorMPS/jyjxG/src/mps.jl:739
 [24] top-level scope
    @ ~/work/2024-11-SHADOW/src/MatrixProductShadows/jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_W3sZmlsZQ==.jl:7

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 8 × Apple M3
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m2)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
  JULIA_NUM_THREADS = 
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
[9136182c] ITensors v0.7.11
julia> using Pkg; Pkg.status("ITensorMPS")
[0d1a4710] ITensorMPS v0.3.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    ITensorsIssues or pull requests related to the `ITensors` package.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions