Skip to content

Commit 2c0c481

Browse files
authored
Fix quimb version checking (#3378)
Making quimb version check more robust. In some systems the version might not be parseable as (int,int), e.g `0+unknown`. This PR fixes these scenarios. Fixes #3263.
1 parent ddb4071 commit 2c0c481

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cirq/contrib/quimb/state_vector.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@
77

88
import cirq
99

10-
QUIMB_VERSION = tuple(int(x) for x in quimb.__version__.split('.'))
10+
11+
# coverage: ignore
12+
def _get_quimb_version():
13+
"""Returns the quimb version and parsed (major,minor) numbers if possible.
14+
Returns:
15+
a tuple of ((major, minor), version string)
16+
"""
17+
version = quimb.__version__
18+
try:
19+
return tuple(int(x) for x in version.split('.')), version
20+
except:
21+
return (0, 0), version
22+
23+
24+
QUIMB_VERSION = _get_quimb_version()
1125

1226

1327
def circuit_to_tensors(circuit: cirq.Circuit,
@@ -150,9 +164,10 @@ def tensor_expectation_value(circuit: cirq.Circuit,
150164
tags={'Q0', 'bra0'}) for q in qubits
151165
]
152166
tn = qtn.TensorNetwork(tensors + end_bras)
153-
if QUIMB_VERSION < (1, 3):
167+
if QUIMB_VERSION[0] < (1, 3):
154168
# coverage: ignore
155-
warnings.warn('Please use quimb>=1.3 for optimal performance in '
169+
warnings.warn(f'quimb version {QUIMB_VERSION[1]} detected. Please use '
170+
f'quimb>=1.3 for optimal performance in '
156171
'`tensor_expectation_value`. '
157172
'See https://github.com/quantumlib/Cirq/issues/3263')
158173
else:

0 commit comments

Comments
 (0)