Skip to content

Commit dc23f87

Browse files
authored
Keep up with quimb-1.5.0 (#6087)
As of quimb-1.5.0 `TensorNetwork.contract(inplace=True)` returns TensorNetwork instead of scalar. Convert to scalar if needed. Also correct CI issues that showed for testing notebooks w/r to the cirq head here: * Fix misleading unit test name by renaming `test_notebooks_against_released_cirq` --> `test_notebooks_against_cirq_head`. Note: Notebooks are tested with released Cirq in isolated_notebook_test.py. * Append to PYTHONPATH when tested notebooks pip-install any packages. Prefer use of development Cirq sources in `test_notebooks_against_cirq_head`. * Disable isolated CI test of Contract-a-Grid-Circuit.ipynb Requires next cirq release.
1 parent 6d3f27e commit dc23f87

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Diff for: cirq-core/cirq/contrib/quimb/state_vector.py

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def tensor_expectation_value(
177177
if ram_gb > max_ram_gb:
178178
raise MemoryError(f"We estimate that this contraction will take too much RAM! {ram_gb} GB")
179179
e_val = tn.contract(inplace=True)
180+
if isinstance(e_val, qtn.TensorNetwork):
181+
e_val = e_val.item()
180182
assert e_val.imag < tol
181183
assert cast(complex, pauli_string.coefficient).imag < tol
182184
return e_val.real * pauli_string.coefficient

Diff for: dev_tools/notebooks/isolated_notebook_test.py

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
# By default all notebooks should be tested, however, this list contains exceptions to the rule
6363
# please always add a reason for skipping.
6464
SKIP_NOTEBOOKS = [
65+
# TODO(#6088) - enable notebooks below
66+
'cirq-core/cirq/contrib/quimb/Contract-a-Grid-Circuit.ipynb',
67+
# End of TODO(#6088)
6568
# skipping vendor notebooks as we don't have auth sorted out
6669
"**/aqt/*.ipynb",
6770
"**/azure-quantum/*.ipynb",

Diff for: dev_tools/notebooks/notebook_test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ def require_packages_not_changed():
7373
def env_with_temporary_pip_target():
7474
"""Setup system environment that tells pip to install packages to a temporary directory."""
7575
with tempfile.TemporaryDirectory(suffix='-notebook-site-packages') as tmpdirname:
76+
# Note: We need to append tmpdirname to the PYTHONPATH, because PYTHONPATH may
77+
# already point to the development sources of Cirq (as happens with check/pytest).
78+
# Should some notebook pip-install a stable version of Cirq to tmpdirname,
79+
# it would appear in PYTHONPATH after the development Cirq.
7680
pythonpath = (
77-
f'{tmpdirname}{os.pathsep}{os.environ["PYTHONPATH"]}'
81+
f'{os.environ["PYTHONPATH"]}{os.pathsep}{tmpdirname}'
7882
if 'PYTHONPATH' in os.environ
7983
else tmpdirname
8084
)
@@ -84,7 +88,7 @@ def env_with_temporary_pip_target():
8488

8589
@pytest.mark.slow
8690
@pytest.mark.parametrize("notebook_path", filter_notebooks(list_all_notebooks(), SKIP_NOTEBOOKS))
87-
def test_notebooks_against_released_cirq(
91+
def test_notebooks_against_cirq_head(
8892
notebook_path, require_packages_not_changed, env_with_temporary_pip_target
8993
):
9094
"""Test that jupyter notebooks execute.

0 commit comments

Comments
 (0)