Skip to content

Commit

Permalink
Keep up with quimb-1.5.0 (#6087)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pavoljuhas committed May 6, 2023
1 parent 6d3f27e commit dc23f87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cirq-core/cirq/contrib/quimb/state_vector.py
Expand Up @@ -177,6 +177,8 @@ def tensor_expectation_value(
if ram_gb > max_ram_gb:
raise MemoryError(f"We estimate that this contraction will take too much RAM! {ram_gb} GB")
e_val = tn.contract(inplace=True)
if isinstance(e_val, qtn.TensorNetwork):
e_val = e_val.item()
assert e_val.imag < tol
assert cast(complex, pauli_string.coefficient).imag < tol
return e_val.real * pauli_string.coefficient
3 changes: 3 additions & 0 deletions dev_tools/notebooks/isolated_notebook_test.py
Expand Up @@ -62,6 +62,9 @@
# By default all notebooks should be tested, however, this list contains exceptions to the rule
# please always add a reason for skipping.
SKIP_NOTEBOOKS = [
# TODO(#6088) - enable notebooks below
'cirq-core/cirq/contrib/quimb/Contract-a-Grid-Circuit.ipynb',
# End of TODO(#6088)
# skipping vendor notebooks as we don't have auth sorted out
"**/aqt/*.ipynb",
"**/azure-quantum/*.ipynb",
Expand Down
8 changes: 6 additions & 2 deletions dev_tools/notebooks/notebook_test.py
Expand Up @@ -73,8 +73,12 @@ def require_packages_not_changed():
def env_with_temporary_pip_target():
"""Setup system environment that tells pip to install packages to a temporary directory."""
with tempfile.TemporaryDirectory(suffix='-notebook-site-packages') as tmpdirname:
# Note: We need to append tmpdirname to the PYTHONPATH, because PYTHONPATH may
# already point to the development sources of Cirq (as happens with check/pytest).
# Should some notebook pip-install a stable version of Cirq to tmpdirname,
# it would appear in PYTHONPATH after the development Cirq.
pythonpath = (
f'{tmpdirname}{os.pathsep}{os.environ["PYTHONPATH"]}'
f'{os.environ["PYTHONPATH"]}{os.pathsep}{tmpdirname}'
if 'PYTHONPATH' in os.environ
else tmpdirname
)
Expand All @@ -84,7 +88,7 @@ def env_with_temporary_pip_target():

@pytest.mark.slow
@pytest.mark.parametrize("notebook_path", filter_notebooks(list_all_notebooks(), SKIP_NOTEBOOKS))
def test_notebooks_against_released_cirq(
def test_notebooks_against_cirq_head(
notebook_path, require_packages_not_changed, env_with_temporary_pip_target
):
"""Test that jupyter notebooks execute.
Expand Down

0 comments on commit dc23f87

Please sign in to comment.