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

Improve test suite speed: pytest-xdist; qcut and qchem markers; update reconstruct tests #2504

Merged
merged 17 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
53 changes: 47 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci.txt
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
pip install wheel pytest pytest-cov pytest-mock pytest-xdist flaky --upgrade

- name: Conditionally install openfermionpyscf
if: contains(' 3.9', matrix.config.python-version)
Expand All @@ -65,9 +65,6 @@ jobs:
if: contains(matrix.config.interfaces, 'jax')
run: pip3 install jax jaxlib

- name: Install KaHyPar
run: pip3 install kahypar==1.1.7

- name: Install PennyLane
run: |
pip install -r requirements-ci.txt
Expand All @@ -78,7 +75,7 @@ jobs:
run: python -m pip install -i https://test.pypi.org/simple/ PennyLane-Lightning --pre --upgrade

- name: Run tests
run: python -m pytest tests --cov=pennylane $COVERAGE_FLAGS
run: python -m pytest tests --cov=pennylane $COVERAGE_FLAGS -n auto

- name: Adjust coverage file for Codecov
run: bash <(sed -i 's/filename=\"/filename=\"pennylane\//g' coverage.xml)
Expand All @@ -88,6 +85,50 @@ jobs:
with:
file: ./coverage.xml

qcut-kahypar:
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci.txt
pip install wheel pytest pytest-cov pytest-mock pytest-xdist flaky --upgrade

- name: Install KaHyPar
run: pip3 install kahypar==1.1.7

- name: Install PennyLane
run: |
pip install -r requirements-ci.txt
python setup.py bdist_wheel
pip install dist/PennyLane*.whl

- name: Run tests
run: |
python -m pytest tests/ -m kahypar -n auto

- name: Adjust coverage file for Codecov
run: bash <(sed -i 's/filename=\"/filename=\"pennylane\//g' coverage.xml)

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
antalszava marked this conversation as resolved.
Show resolved Hide resolved

device-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -153,4 +194,4 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
file: ./coverage.xml
4 changes: 3 additions & 1 deletion tests/devices/test_default_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ def test_sample_error_multi_wire(self, gaussian_device_2_wires):
with pytest.raises(ValueError, match="Only one mode can be measured in homodyne"):
sample = gaussian_device_2_wires.sample("P", [0, 1], [])

@pytest.mark.parametrize("observable", set(qml.ops.cv.obs) - set(["P", "X", "QuadOperator"]))
@pytest.mark.parametrize(
"observable", sorted(set(qml.ops.cv.obs) - set(["P", "X", "QuadOperator"]))
antalszava marked this conversation as resolved.
Show resolved Hide resolved
)
def test_sample_error_unsupported_observable(self, gaussian_device_2_wires, observable):
"""Test that the sample function raises an error if the given observable is not supported"""

Expand Down
6 changes: 3 additions & 3 deletions tests/fourier/test_reconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def circuit(x):
return circuit


def fun_close(fun1, fun2, zero=None, tol=1e-5, samples=100):
def fun_close(fun1, fun2, zero=None, tol=1e-5, samples=10):
antalszava marked this conversation as resolved.
Show resolved Hide resolved
X = np.linspace(-np.pi, np.pi, samples)
if zero is not None:
X = qml.math.convert_like(X, zero)
Expand Down Expand Up @@ -730,7 +730,7 @@ def qnode_2(X, y):


def qnode_3(X, Y):
for i in range(5):
for i in range(3):
antalszava marked this conversation as resolved.
Show resolved Hide resolved
qml.RX(X[i], wires=0)
qml.RY(Y[i], wires=0)
qml.RX(X[i], wires=0)
Expand Down Expand Up @@ -941,7 +941,7 @@ def test_differentiability_jax(
grad = jax.grad(rec)
assert np.isclose(grad(x0), exp_qnode_grad(*params)[inner_key])
assert np.isclose(grad(x0 + 0.1), exp_grad(x0 + 0.1))
assert fun_close(grad, exp_grad, 10)
assert fun_close(grad, exp_grad, samples=3)
antalszava marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.parametrize(
"qnode, params, ids, nums_frequency, spectra, shifts, exp_calls",
Expand Down
1 change: 1 addition & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[pytest]
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
kahypar: marks tests from the QCut that use the KaHyPar package (deselect with '-m "not kahypar"')
gpu: marks tests run on a GPU (deselect with '-m "not gpu"')
filterwarnings =
ignore::DeprecationWarning:autograd.numpy.numpy_wrapper
2 changes: 2 additions & 0 deletions tests/transforms/test_qcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -4188,6 +4188,7 @@ def make_weakly_connected_tape(
return tape


@pytest.mark.kahypar
class TestKaHyPar:
"""Tests for the KaHyPar cutting function and utilities."""

Expand Down Expand Up @@ -4495,6 +4496,7 @@ def test_find_and_place_cuts(self, local_measurement, with_manual_cut, cut_strat
)


@pytest.mark.kahypar
class TestAutoCutCircuit:
"""Integration tests for automatic-cutting-enabled `cut_circuit` transform.
Mostly borrowing tests cases from ``TestCutCircuitTransform``.
Expand Down