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

Environments #145

Closed JoeyT1994 closed 3 months ago

JoeyT1994 commented 3 months ago

This PR adds the functionality environment(tn::AbstractITensorNetwork, verbs::Vector) to the codebase with returns the environment (related to the derivative) of an ITensorNetwork with respect to some subset of its vertices.

Algorithms are defined for getting the environments/derivates which currently include either exact contraction or belief propagation. This new functionality has been hooked to interface environment(f::AbstractFormNetwork, state_vertices::Vector).

Testing it added for this within test/test_forms.jl

mtfishman commented 3 months ago

My thinking on derivative(f::AbstractFormNetwork, state_vertices::Vector) is that for a form, you can only take the derivative with respect to the state vertices, so a separate function derivative_state wouldn't be necessary.

JoeyT1994 commented 3 months ago

@mtfishman In terms of derivative(f::AbstractFormNetwork, state_vertices::Vector) instead of derivative_state(f::AbstractFormNetwork, state_vertices::Vector), the issue is that it conflicts with derivative(itn::AbstractITensorNetwork, vertices::Vector) in src/derivative.jl which I want derivative_state to forward to. We have the hierarchy FormNetwork <: AbstractITensorNetwork and so currently that would just create a circular loop.

I was originally defining derivative(itn::AbstractITensorNetwork, vertices::Vector) and having derivative(f::AbstractFormNetwork, state_vertices::Vector) pass to that by calling derivative(itensornetwork(f), vertices(f, state_vertices)) but the logic for building the bp_cache (if it is not defined) is in derivative(itn::AbstractITensorNetwork, vertices::Vector) and I want the default cache (default partitioning) to be different for an AbstractFormNetwork vs an AbstractITensorNetwork`. I.e I have:

default_partitioning(ψ::AbstractITensorNetwork) = group(v -> v, vertices(ψ))
default_partitioning(f::AbstractFormNetwork) = group(v -> state_vertex(f,v), vertices(f))

at the moment so a standard ψ::AbstractITensorNetwork just has simple BP done on it with no partitioning but a f::AbstractFormNetwork will partition itself by the state_vertices by default.

codecov-commenter commented 3 months ago

Codecov Report

Attention: Patch coverage is 88.00000% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 73.87%. Comparing base (5df202a) to head (9bb5c7a). Report is 3 commits behind head on main.

Files Patch % Lines
src/caches/beliefpropagationcache.jl 80.00% 3 Missing :warning:
src/formnetworks/abstractformnetwork.jl 83.33% 3 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #145 +/- ## ========================================== + Coverage 73.61% 73.87% +0.25% ========================================== Files 71 75 +4 Lines 4146 4256 +110 ========================================== + Hits 3052 3144 +92 - Misses 1094 1112 +18 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mtfishman commented 3 months ago

Can't you specify a different default partitioning in derivative(f::AbstractFormNetwork, state_vertices::Vector)? That issue seems like something we can circumvent without having to define a new function derivative_state.

JoeyT1994 commented 3 months ago

Yeah good point: I can make the choice partitioning a kwarg of derivative(Alg::"BP", ...) and have derivative(f::AbstractForm, ...) define that and pass it on

mtfishman commented 3 months ago

Looks good, thanks! One more step towards BP-based DMRG/TDVP...