ITensor / ITensorMPS.jl

MPS and MPO methods based on ITensor (ITensors.jl)
Apache License 2.0
23 stars 4 forks source link

Add `reverse(::MPS/MPO)` #57

Open mtfishman opened 3 years ago

mtfishman commented 3 years ago

Define reverse(::MPS/MPO) by reversing the tensor order as well as the orthogonality limits.

julia> using ITensors

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

julia> psi = MPS(s);

julia> reverse(psi)
ERROR: MethodError: no method matching reverse(::MPS)
Closest candidates are:
  reverse(::Tuple) at tuple.jl:466
  reverse(::Pair{A, B}) where {A, B} at pair.jl:61
  reverse(::Union{SubString{String}, String}) at strings/substring.jl:166
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1
sr33dhar commented 1 year ago

Hi, is this feature available? If not, is this a good first issue to be working on? Thanks!

emstoudenmire commented 1 year ago

I think this would be a good first-time issue, yes. We may ultimately want to have a single, generic code that would do reverse on any linear tensor network (either MPS, MPO, or something like them with any number of site indices) but having just the MPS and MPO versions initially would be helpful.

@mtfishman I would imagine this function would also re-index all of the sites, correct?

mtfishman commented 1 year ago

I was picturing this would result in an MPS/MPO such that:

psi_rev = reverse(psi)
n = length(psi)
psi[1] == psi_rev[n]
psi[2] == psi_rev[n-1]
# etc.

just like how it acts on a Vector:

julia> reverse([1, 2, 3])
3-element Vector{Int64}:
 3
 2
 1
mtfishman commented 1 year ago

However, @sr33dhar please note that the next generation of MPS code is being developed in https://github.com/mtfishman/ITensorNetworks.jl so we would prefer to add new features to that code.

sr33dhar commented 1 year ago

Ah, thanks! For now, the idea of psi[k] == psi_rev[n-k+1] would work for me @mtfishman.

I was trying to implement the TEBD using MPS on an all to all connected Ising Hamiltonian using a SWAP network when I needed this. After half the network, the tensors all go into reverse order, and it would be wasteful to keep swapping until they regain the original order.

Meanwhile, I'll checkout https://github.com/mtfishman/ITensorNetworks.jl Please do let me know if there is anything I can do to help.