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

Generalize `inner(::MPO, ::MPS, ::MPO, ::MPS)` for arbitrary tags

Open mtfishman opened this issue 4 years ago • 2 comments

This currently fails:

using ITensors
s = siteinds("S=1/2", 3)
A = MPO(s, "Id")
A = noprime(replacetags(A, "Site" => "X"; plev = 1))
ψ = randomMPS(s)
inner(A, ψ, A, ψ)

with an error:

ERROR: MethodError: no method matching prime(::Nothing, ::Int64)
Closest candidates are:
  prime(::Index, ::Int64) at /home/mfishman/.julia/dev/ITensors/src/index.jl:374
  prime(::IndexVal, ::Integer) at /home/mfishman/.julia/dev/ITensors/src/index.jl:535
  prime(::IndexSet, ::Integer, ::Any...; kwargs...) at /home/mfishman/.julia/dev/ITensors/src/indexset.jl:810
  ...
Stacktrace:
 [1] dot(::MPO, ::MPS, ::MPO, ::MPS; make_inds_match::Bool) at /home/mfishman/.julia/dev/ITensors/src/mps/mpo.jl:233
 [2] dot at /home/mfishman/.julia/dev/ITensors/src/mps/mpo.jl:217 [inlined]
 [3] inner(::MPO, ::MPS, ::MPO, ::MPS) at /home/mfishman/.julia/dev/ITensors/src/mps/mpo.jl:247
[...]

since inner(::MPO, ::MPS, ::MPO, ::MPS) currently assumes the MPO has pairs of primed and unprimed indices with "Site" tags. This would be very useful to generalize (for example, when using an LPDO representing an MPDO in the form X*X†).

mtfishman avatar Sep 22 '20 16:09 mtfishman

The issue with relying on the "Site" tags would be solved by replacing https://github.com/ITensor/ITensors.jl/blob/a5733fc4433e1accbca1a5ac0593d73e424442df/src/mps/mpo.jl#L430 with

ABcommon = uniqueind(siteinds(A, j), IndexSet(Axcommon))

I believe, which should then work for arbitrary tags. Is this all you meant, or were you implying that the assumptions on the prime structure of the MPOs should also be relaxed?

leburgel avatar Oct 04 '22 18:10 leburgel

In principle it shouldn't depend on any tag or prime conventions, it should just require that for inner(A, x, B, y):

  1. A and x share site indices.
  2. B and y share site indices.
  3. A * x and B * y share site indices.

mtfishman avatar Oct 04 '22 18:10 mtfishman