Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensors] [BUG] random_mps(sites, ψ) with quantum number conservation errors #1540

Closed
christopherdavidwhite2 opened this issue Oct 10, 2024 · 3 comments
Labels
bug Something isn't working ITensors Issues or pull requests related to the `ITensors` package.

Comments

@christopherdavidwhite2
Copy link

Description of bug

I'm trying to make a random MPS with quantum number conservation; random_mps(sites, ψ) results in an error buried pretty far down.

Minimal code demonstrating the bug or unexpected behavior

Minimal runnable code

using ITensors
using Pkg
Pkg.status("ITensors")

Nsites = 2
sites = siteinds("Electron", Nsites; conserve_qns = true)
ψ0 = MPS(sites,["UpDn", "Emp"])
random_mps(sites, ψ0)

Expected output or behavior

I expect a random MPS

Actual output or behavior

Output of minimal runnable code

[9136182c] ITensors v0.6.19
ERROR: LoadError: MethodError: no method matching state(::Index{Vector{Pair{QN, Int64}}}, ::ITensor)

Closest candidates are:
  state(::Index, !Matched::AbstractString; kwargs...)
   @ ITensors ~/.julia/packages/ITensors/FpnkY/src/lib/SiteTypes/src/sitetype.jl:595
  state(::Index, !Matched::Integer)
   @ ITensors ~/.julia/packages/ITensors/FpnkY/src/lib/SiteTypes/src/sitetype.jl:636

Stacktrace:
 [1] (::ITensors.ITensorMPS.var"#398#400"{Vector{Index{Vector{Pair{QN, Int64}}}}, MPS})(j::Int64)
   @ ITensors.ITensorMPS ./essentials.jl:0
 [2] iterate
   @ ./generator.jl:47 [inlined]
 [3] collect
   @ ./array.jl:834 [inlined]
 [4] MPS(eltype::Type{Float64}, sites::Vector{Index{Vector{Pair{QN, Int64}}}}, states_::MPS)
   @ ITensors.ITensorMPS ~/.julia/packages/ITensors/FpnkY/src/lib/ITensorMPS/src/mps.jl:421
 [5] random_mps(rng::Random.TaskLocalRNG, eltype::Type{Float64}, sites::Vector{Index{Vector{Pair{QN, Int64}}}}, state::MPS; linkdims::Int64)
   @ ITensors.ITensorMPS ~/.julia/packages/ITensors/FpnkY/src/lib/ITensorMPS/src/mps.jl:311
 [6] random_mps(rng::Random.TaskLocalRNG, sites::Vector{Index{Vector{Pair{QN, Int64}}}}, state::MPS; linkdims::Int64)
   @ ITensors.ITensorMPS ~/.julia/packages/ITensors/FpnkY/src/lib/ITensorMPS/src/mps.jl:292
 [7] random_mps(sites::Vector{Index{Vector{Pair{QN, Int64}}}}, state::MPS; linkdims::Int64)
   @ ITensors.ITensorMPS ~/.julia/packages/ITensors/FpnkY/src/lib/ITensorMPS/src/mps.jl:283
 [8] random_mps(sites::Vector{Index{Vector{Pair{QN, Int64}}}}, state::MPS)
   @ ITensors.ITensorMPS ~/.julia/packages/ITensors/FpnkY/src/lib/ITensorMPS/src/mps.jl:280
 [9] top-level scope
   @ ~/bugreport.jl:8
in expression starting at /Users/white/bugreport.jl:8

Version information

  • Output from versioninfo():
julia> versioninfo()
versioninfo()
Julia Version 1.10.5
Commit 6f3fdf7b362 (2024-08-27 14:19 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M3
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
Status `~/.julia/environments/v1.10/Project.toml`
  [9136182c] ITensors v0.6.19
@christopherdavidwhite2 christopherdavidwhite2 added bug Something isn't working ITensors Issues or pull requests related to the `ITensors` package. labels Oct 10, 2024
@mtfishman
Copy link
Member

mtfishman commented Oct 10, 2024

I don't think we ever purposefully supported passing an MPS as the second argument of random_mps (if that works for non-QN tensors, that is most likely just an accident), you should use random_mps(sites, ["UpDn", "Emp"]).

@christopherdavidwhite2
Copy link
Author

yep, this works. (Could've sworn (1) I tried this, and (2) the MPS is what I recall from the past, but you'd know better than I do.)

In any case thanks for the help, and sorry for the bother.

@mtfishman
Copy link
Member

No worries! Probably we should try to catch that MPS case, if it accidentally works in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ITensors Issues or pull requests related to the `ITensors` package.
Projects
None yet
Development

No branches or pull requests

2 participants