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

Make test for 3rd party imports meaningful again #2270

Merged
merged 2 commits into from
Apr 8, 2024
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
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ jobs:
with:
python-version: "3.11"
- name: Install Mitiq
# Since requirements.txt includes cirq, which in turn has pyquil as dependency,
# we explicitly remove pyquil from the installed packages after installing mitiq
run: |
python -m pip install --upgrade pip
pip install .
pip uninstall -y pyquil

- name: Test without 3rd party packages
run: |
Expand Down Expand Up @@ -113,6 +116,7 @@ jobs:
- name: Submit coverage report to Codecov
# Only submit to Codecov once.
if: ${{ matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'}}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
3 changes: 1 addition & 2 deletions mitiq/benchmarks/randomized_benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# module.
# Original authors: Cirq developers: Xiao Mi, Dave Bacon, Craig Gidney,
# Ping Yeh, Matthew Neely.
# Code URL = ('https://github.com/quantumlib/Cirq/blob/main/cirq-core/cirq/
# experiments/qubit_characterizations.py').
# Code URL = ('https://github.com/quantumlib/Cirq/blob/main/cirq-core/cirq/experiments/qubit_characterizations.py').
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to the PR's scope; it just annoyed me that I couldn't Ctrl+Click on that link from my IDE 😄

#
# This source code is licensed under the GPL license (v3) found in the
# LICENSE file in the root directory of this source tree.
Expand Down
10 changes: 6 additions & 4 deletions mitiq/tests/test_without_third_party_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
interfaces with Mitiq (see mitiq.SUPPORTED_PROGRAM_TYPES).
"""

from abc import ABCMeta
from typing import Union, get_origin

from cirq import Circuit


def test_import():
Expand All @@ -20,14 +22,14 @@ def test_import():
"""
import mitiq

if isinstance(mitiq.QPROGRAM, ABCMeta):
pass # If only Cirq is installed, QPROGRAM is not a typing.Union.
else:
if get_origin(mitiq.QPROGRAM) is Union:
Comment on lines -23 to +25
Copy link
Member

Choose a reason for hiding this comment

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

Nice, this is an easier way to understand that the type of something is a Union!

assert (
1 # cirq.Circuit is always supported.
<= len(mitiq.QPROGRAM.__args__) # All installed types.
<= len(mitiq.SUPPORTED_PROGRAM_TYPES.keys()) # All types.
)
else:
assert mitiq.QPROGRAM is Circuit


# TODO: More tests wanted!
Loading