Skip to content

Commit bfba965

Browse files
authored
Avoid DivisionByZero error when TensorNetwork simplifies to a scalar (#6586)
Problem: Python 3.12 requires quimb-1.8.0, but quimb-1.8.0 cannot evaluate path-info for TensorNetwork consisting of a scalar Tensor. Solution: Skip path-info evaluation for scalar TensorNetwork. Path-info is used for RAM estimation only which is not a problem for scalar TensorNetwork-s. This fixes unit test failure for cirq-core/cirq/contrib/quimb/grid_circuits_test.py::test_tensor_expectation_value Ref: jcmgray/quimb#231
1 parent 69e3de1 commit bfba965

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cirq-core/cirq/contrib/quimb/state_vector.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ def tensor_expectation_value(
170170
)
171171
else:
172172
tn.rank_simplify(inplace=True)
173-
path_info = tn.contract(get='path-info')
174-
ram_gb = path_info.largest_intermediate * 128 / 8 / 1024 / 1024 / 1024
173+
# TODO(#6586): revert when our minimum quimb version has bugfix for quimb#231
174+
# Skip path-info evaluation when TensorNetwork consists of scalar Tensors.
175+
# Avoid bug in quimb-1.8.0.
176+
# Ref: https://github.com/jcmgray/quimb/issues/231
177+
if tn.ind_map:
178+
path_info = tn.contract(get='path-info')
179+
ram_gb = path_info.largest_intermediate * 128 / 8 / 1024 / 1024 / 1024
180+
else:
181+
ram_gb = 0
175182
if ram_gb > max_ram_gb:
176183
raise MemoryError(f"We estimate that this contraction will take too much RAM! {ram_gb} GB")
177184
e_val = tn.contract(inplace=True)

0 commit comments

Comments
 (0)