Skip to content

Commit

Permalink
Fix quimb version checking (#3378)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
balopat authored Oct 1, 2020
1 parent ddb4071 commit 2c0c481
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cirq/contrib/quimb/state_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@

import cirq

QUIMB_VERSION = tuple(int(x) for x in quimb.__version__.split('.'))

# coverage: ignore
def _get_quimb_version():
"""Returns the quimb version and parsed (major,minor) numbers if possible.
Returns:
a tuple of ((major, minor), version string)
"""
version = quimb.__version__
try:
return tuple(int(x) for x in version.split('.')), version
except:
return (0, 0), version


QUIMB_VERSION = _get_quimb_version()


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

0 comments on commit 2c0c481

Please sign in to comment.