Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep up with quimb-1.5.0 #6087

Merged
merged 7 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cirq-core/cirq/contrib/quimb/state_vector.py
Original file line number Diff line number Diff line change
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, the contraction above will always produce a scalar, so why not call item unconditionally?

e_val = tn.contract(inplace=True).item()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With quimb-1.4.2 tn.contract() may return a standard float which does not have the item method.
We could do e_val = np.asarray(tn.contract(...)).item(), but that is IMO harder to parse for humans than above. :)

We could also require quimb==1.5, but I feel that is a bit imposing on anyone installing cirq.

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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