ITensors.jl icon indicating copy to clipboard operation
ITensors.jl copied to clipboard

Add `reverse(::MPS/MPO)`

Open mtfishman opened this issue 3 years ago • 5 comments

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

mtfishman avatar Jul 05 '21 20:07 mtfishman

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

sr33dhar avatar Jan 15 '23 13:01 sr33dhar

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?

emstoudenmire avatar Jan 16 '23 07:01 emstoudenmire

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 avatar Jan 17 '23 16:01 mtfishman

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.

mtfishman avatar Jan 17 '23 22:01 mtfishman

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.

sr33dhar avatar Jan 18 '23 14:01 sr33dhar