ITensors.jl
ITensors.jl copied to clipboard
Add `compatible` function checking sites against MPS, MPO
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.)
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?
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”.
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
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.