Skip to content

Commit

Permalink
do_contraction: debug IndexError for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Dec 5, 2023
1 parent 795300c commit f6260d5
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions cotengra/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,32 +706,39 @@ def do_contraction(

contractions = tqdm.tqdm(contractions, total=N - 1)

for p, l, r, tdot, arg, perm in contractions:
if (l is None) and (r is None):
# single term simplification, perform inplace with einsum
temps[p] = _einsum(arg, temps[p])
continue

# get input arrays for this contraction
l_array = temps.pop(l)
r_array = temps.pop(r)

if tdot:
p_array = _tensordot(l_array, r_array, arg)
if perm:
p_array = do("transpose", p_array, perm, like=backend)
else:
p_array = _einsum(arg, l_array, r_array)

if exponent is not None:
factor = do("max", do("abs", p_array, like=backend), like=backend)
if check_zero and float(factor) == 0.0:
return 0.0, 0.0
exponent = exponent + do("log10", factor, like=backend)
p_array = p_array / factor

# insert the new intermediate array
temps[p] = p_array
try:
for p, l, r, tdot, arg, perm in contractions:
if (l is None) and (r is None):
# single term simplification, perform inplace with einsum
temps[p] = _einsum(arg, temps[p])
continue

# get input arrays for this contraction
l_array = temps.pop(l)
r_array = temps.pop(r)

if tdot:
p_array = _tensordot(l_array, r_array, arg)
if perm:
p_array = do("transpose", p_array, perm, like=backend)
else:
p_array = _einsum(arg, l_array, r_array)

if exponent is not None:
factor = do("max", do("abs", p_array, like=backend), like=backend)
if check_zero and float(factor) == 0.0:
return 0.0, 0.0
exponent = exponent + do("log10", factor, like=backend)
p_array = p_array / factor

# insert the new intermediate array
temps[p] = p_array
except IndexError as e:
raise IndexError(
f"Original error: {e}\n",
f"Contractions: {contractions}\n",
f"Array shapes: {[shape(x) for x in arrays]}\n",
)

if exponent is not None:
return p_array, exponent
Expand Down

0 comments on commit f6260d5

Please sign in to comment.