ITensor / ITensorNetworks.jl

A package with general tools for working with higher-dimensional tensor networks based on ITensor.
MIT License
51 stars 12 forks source link

Add support for building operators without a link space #171

Closed JoeyT1994 closed 1 month ago

JoeyT1994 commented 1 month ago

This PR allows one to pass the kwarg link_space = nothing into the ITensorNetwork(f::Function, s::IndsNetwork; ...) constructor so that it doesn't add any link indices when constructing the ITensorNetwork. The change is made at the level of insert_linkinds(s::IndsNetwork; link_space = trivial_space(s). The default of link indices of dimension 1 is unchanged.

One can now do ITensorNetwork(Op("I), s; link_space = nothing) to build the identity operator without any link indices. The default for the BiLinearForm(psi, phi; ...) constructor is done based on whether psi does or doesn't have site indices.

@mtfishman I'm adding this so that when one builds the formnetwork <psi|I|psi> and does BP the message tensors don't end up with additional trivial indices which can lead to complications when you want to square root them and gauge the local state etc.

Let me know if you can think of a better way to support this functionality or if you are okay with as is.

mtfishman commented 1 month ago

This sounds reasonable. Handling the corner case of having no link indices vs. trivial link indices is definitely tricky and part of this package that I found most difficult to design, we may have to step back and assess it more systematically at some point.