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

Account for BP edge case where network evaluates to 0 #178

Closed JoeyT1994 closed 1 month ago

JoeyT1994 commented 1 month ago

This PR fixed the bp edge case where the network contracts to the scalar 0 which would previously yield Nan.

This is achieved by:

  1. Updating the default_message_update function to only divide by the norm if its not zero -> avoiding the creating of message tensors with nan in them.
  2. Adding to logscalar(alg::Algorithm"bp", tn::AbstractITensorNetwork) a check if any of the denominators terms are zero. If this is the case then log(tn) should be -Inf. This is because, on a tree, if the product of message(pe) and message(reverse(pe) on any partitionedge is zero then the contraction of the tree must be zero (assuming the messages are converged).

A quick test is added.

@ryanlevy this should fix the issue with bp in ITensorNumericalAnalysis.jl