# How to use the tensornetwork.block_tensor.index.fuse_charge_pair function in tensornetwork

## To help you get started, we’ve selected a few tensornetwork examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

google / TensorNetwork / tensornetwork / block_tensor / block_tensor.py View on Github
# get unique charges and their degeneracies on the first leg.
# We are fusing from "left" to "right".
accumulated_charges, accumulated_degeneracies = np.unique(
charges[0], return_counts=True)
#multiply the flow into the charges of first leg
accumulated_charges *= flows[0]
for n in range(1, len(charges)):
#list of unique charges and list of their degeneracies
#on the next unfused leg of the tensor
leg_charges, leg_degeneracies = np.unique(charges[n], return_counts=True)

#fuse the unique charges
#Note: entries in fused_charges are not unique anymore.
#flow1 = 1 because the flow of leg 0 has already been
#mulitplied above
fused_charges = fuse_charge_pair(
q1=accumulated_charges, flow1=1, q2=leg_charges, flow2=flows[n])
#compute the degeneracies of fused_charges charges
#fused_degeneracies is a list of degeneracies such that
# fused_degeneracies[n] is the degeneracy of of
# charge c = fused_charges[n].
fused_degeneracies = fuse_degeneracies(accumulated_degeneracies,
leg_degeneracies)
#compute the new degeneracies resulting from fusing
#accumulated_charges and leg_charges_2
accumulated_charges = np.unique(fused_charges)
accumulated_degeneracies = np.empty(
len(accumulated_charges), dtype=np.int64)
for n in range(len(accumulated_charges)):
accumulated_degeneracies[n] = np.sum(
fused_degeneracies[fused_charges == accumulated_charges[n]])
return accumulated_charges, accumulated_degeneracies

## tensornetwork

A high level tensor network API for accelerated tensor network calculations.

Apache-2.0