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

Add `compatible` function checking sites against MPS, MPO

Open emstoudenmire opened this issue 4 years ago • 4 comments

Define a function compatible(sites::Vector{<:Index},psi::MPS) which checks that sites and psi are the same length and that sites==siteinds(psi) essentially. (Perhaps that could be the whole definition.)

emstoudenmire avatar Sep 19 '21 18:09 emstoudenmire

The main corner case with defining it as sites==siteinds(psi) is the case when there are multiple site indices per tensor. A more general definition would be something like all(s -> hassameinds(s[1], s[2]), zip(sites, siteinds(psi))).

Also I would prefer something a bit more descriptive, like compatible_inds. Another question would be, does the MPO version compare only to the unprimed indices, or all of the indices?

mtfishman avatar Sep 20 '21 14:09 mtfishman

These are good considerations. I agree about the function name.

For the MPO case, my vote would be that if either set of MPO inds are an exact match (including prime level) then it returns true, otherwise false. So the meaning would be “an MPS with these inds can be multiplied by this MPO without any index adjustments”.

emstoudenmire avatar Sep 20 '21 15:09 emstoudenmire

There's already a function like that used for checking index compatibility at the beginning of DMRG: https://github.com/ITensor/ITensors.jl/blob/v0.2.6/src/mps/dmrg.jl#L41

mtfishman avatar Sep 20 '21 15:09 mtfishman

There is a lot of similar functionality floating around as internal functions so I think it is a matter of choosing a good interface and exposing it externally.

I've been trying to go for a consistency between the ITensor level index functions and the MPS/MPO index functions, so something like hascommoninds could work here.

mtfishman avatar Sep 20 '21 15:09 mtfishman