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

Issue running Trotter-Suzuki example #90

Open
nikita-astronaut opened this issue Oct 29, 2024 · 2 comments
Open

Issue running Trotter-Suzuki example #90

nikita-astronaut opened this issue Oct 29, 2024 · 2 comments

Comments

@nikita-astronaut
Copy link

Dear ITensors developers, I hope you are doing well!

I ran into an issue with one of the examples trotter_suzuki_decomposition.py.

$ julia trotter_suzuki_decomposition.jl 
ERROR: LoadError: You are trying to add an ITensor with indices:

((dim=2|id=657|"S=1/2,Site,n=2")', (dim=2|id=657|"S=1/2,Site,n=2"), (dim=2|id=902|"S=1/2,Site,n=3")', (dim=2|id=902|"S=1/2,Site,n=3"))

into an ITensor with indices:

((dim=2|id=640|"S=1/2,Site,n=1")', (dim=2|id=640|"S=1/2,Site,n=1"), (dim=2|id=657|"S=1/2,Site,n=2")', (dim=2|id=657|"S=1/2,Site,n=2"))

but the indices are not permutations of each other.

Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] _map!!(f::Function, R::NDTensors.DenseTensor{Float64, 4, NTuple{4, Index{Int64}}, NDTensors.Dense{Float64, Vector{Float64}}}, T1::NDTensors.DenseTensor{Float64, 4, NTuple{4, Index{Int64}}, NDTensors.Dense{Float64, Vector{Float64}}}, T2::NDTensors.DenseTensor{Float64, 4, NTuple{4, Index{Int64}}, NDTensors.Dense{Float64, Vector{Float64}}})
    @ ITensors ~/.julia/packages/ITensors/GkEpm/src/itensor.jl:1884
  [3] map!(f::Function, R::ITensor, T1::ITensor, T2::ITensor)
    @ ITensors ~/.julia/packages/ITensors/GkEpm/src/itensor.jl:1910
  [4] copyto!
    @ ~/.julia/packages/ITensors/GkEpm/src/broadcast.jl:310 [inlined]
  [5] materialize!
    @ ./broadcast.jl:878 [inlined]
  [6] materialize!
    @ ./broadcast.jl:875 [inlined]
  [7] _add(A::NDTensors.DenseTensor{Float64, 4, NTuple{4, Index{Int64}}, NDTensors.Dense{Float64, Vector{Float64}}}, B::NDTensors.DenseTensor{Float64, 4, NTuple{4, Index{Int64}}, NDTensors.Dense{Float64, Vector{Float64}}})
    @ ITensors ~/.julia/packages/ITensors/GkEpm/src/itensor.jl:1806
  [8] +(A::ITensor, B::ITensor)
    @ ITensors ~/.julia/packages/ITensors/GkEpm/src/itensor.jl:1814
  [9] ITensor(o::Sum{Scaled{Float64, Prod{Op}}}, s::Vector{Index{Int64}})
    @ ITensors.ITensorsOpsExt ~/.julia/packages/ITensors/GkEpm/src/lib/ITensorsOpsExt/src/ITensorsOpsExt.jl:41
 [10] main(N::Int64; nsteps::Int64, order::Int64)
    @ Main ~/trotter_suzuki_decomposition.jl:20
 [11] macro expansion
    @ show.jl:1229 [inlined]
 [12] top-level scope
    @ ~/trotter_suzuki_decomposition.jl:27
in expression starting at /home/nktastr_google_com/trotter_suzuki_decomposition.jl:27

Do you have an idea what could have gone wrong? Using the CUDA.jl backend. Thank you very much!

@mtfishman
Copy link
Member

mtfishman commented Oct 29, 2024

Very strange, thanks for the report. If I downgrade to Julia 1.6 and ITensors.jl v0.2.11 (before the existence of ITensorMPS.jl) that example code works, I guess something happened between then and now that broke that code.

EDIT: It looks like it was already broken back in ITensors.jl v0.3.68 (with the same error message).

@mtfishman mtfishman changed the title Issue running an example Issue running Trotter-Suzuki example Oct 29, 2024
@mtfishman
Copy link
Member

It looks like this PR broke that code: ITensor/ITensors.jl#919.

The issue is that this line is converting the OpSum of the Hamiltonian into an ITensor, which requires inserting identity operators when terms are not overlapping. We were doing that properly before ITensor/ITensors.jl#919, but I guess that was causing some trouble for automatic differentiation libraries so I simplified that conversion code, but I simplified it too much and it no longer inserts identities properly.

Anyway, that code is pretty experimental so shouldn't really be relied on, I would recommend this tutorial: https://itensor.github.io/ITensors.jl/dev/tutorials/MPSTimeEvolution.html for a more reliable (but more manual) approach.

I'm going to delete that example for now to not cause confusion and keep this issue open as a reminder to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants