From 405b12cffad57b90afd6b76d3d29ea69c677c5e8 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Mon, 15 Apr 2024 16:14:52 -0400 Subject: [PATCH 1/4] Add prelim support for test-level markers --- tests/numpy/test_numpy_random.py | 2 ++ tests/numpy/test_numpy_wrapper.py | 9 +++++++++ tests/pytest.ini | 3 +++ 3 files changed, 14 insertions(+) diff --git a/tests/numpy/test_numpy_random.py b/tests/numpy/test_numpy_random.py index d8db4ff0e27..d39d27d6b1d 100644 --- a/tests/numpy/test_numpy_random.py +++ b/tests/numpy/test_numpy_random.py @@ -43,6 +43,7 @@ general_gen = random.default_rng() +@pytest.mark.unit_test class TestGeneratorDistributions: @pytest.mark.parametrize("distribution", distributions_no_extra_input) def test_generator_distributions(self, distribution): @@ -61,6 +62,7 @@ def test_generator_distributions(self, distribution): assert output.requires_grad is False +@pytest.mark.unit_test class Test_default_rng: def test_no_input(self): """Tests that np.random.default_rng() returns a generator object when diff --git a/tests/numpy/test_numpy_wrapper.py b/tests/numpy/test_numpy_wrapper.py index 09bb05aedf0..a85fd14ccc0 100644 --- a/tests/numpy/test_numpy_wrapper.py +++ b/tests/numpy/test_numpy_wrapper.py @@ -25,6 +25,7 @@ from pennylane.numpy.tensor import tensor_to_arraybox +@pytest.mark.unit_test class TestExtractTensors: """Tests for the extract_tensors function""" @@ -56,6 +57,7 @@ def test_iterable_with_unpatched_numpy_arrays(self): assert res[1] is arr2 +@pytest.mark.unit_test class TestTensor: """Tests for the Tensor(ndarray) subclass""" @@ -141,6 +143,7 @@ def test_numpy_to_arraybox(self): ] +@pytest.mark.unit_test class TestNumpyIntegration: """Test that the wrapped NumPy functionality integrates well with standard NumPy functions.""" @@ -428,6 +431,7 @@ def __call__(self, *args, **kwargs): assert len(res) == 2 +@pytest.mark.integration_test class TestAutogradIntegration: """Test autograd works with the new tensor subclass""" @@ -458,6 +462,7 @@ def cost(x): grad_fn(arr1) +@pytest.mark.unit_test class TestScalarHashing: """Test for the hashing capability of scalar arrays.""" @@ -505,6 +510,7 @@ def test_nonzero_dim_arrays_non_hashable(self): class TestNumpyConversion: """Tests for the tensor.unwrap() and tensor.numpy() methods""" + @pytest.mark.unit_test def test_convert_scalar_array(self): """Test that a scalar array converts to a python literal""" data = np.array(1.543) @@ -512,6 +518,7 @@ def test_convert_scalar_array(self): assert res == data.item() assert isinstance(res, float) + @pytest.mark.unit_test def test_convert_array(self): """Test that a numpy array successfully converts""" data = np.array([1, 2, 3]) @@ -522,6 +529,7 @@ def test_convert_array(self): assert isinstance(res, np.ndarray) assert not isinstance(res, np.tensor) + @pytest.mark.system_test def test_single_gate_parameter(self): """Test that when supplied a PennyLane tensor, a QNode passes an unwrapped tensor as the argument to a gate taking a single parameter""" @@ -545,6 +553,7 @@ def circuit(phi=None): assert op.name == "RX" assert op.parameters == [p] + @pytest.mark.system_test def test_multiple_gate_parameter(self): """Test that when supplied a PennyLane tensor, a QNode passes arguments as unwrapped tensors to a gate taking multiple parameters""" diff --git a/tests/pytest.ini b/tests/pytest.ini index 85bd26efbd6..4b313b4f825 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -1,5 +1,8 @@ [pytest] markers = + unit_test: marks tests as unit-level tests (select with '-m "unit_test"') + integration_test: marks tests as integration-level tests (select with '-m "integration_test"') + system_test: marks tests as system-level tests (select with '-m "system_test"') core: marks tests for core testing (select with '-m "core"') autograd: marks tests for autograd testing (select with '-m "autograd"') torch: marks tests for torch testing (select with '-m "core"') From 891ddca06fbfbdd22a6bcf0fc9d1caaff3033343 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 17 May 2024 10:17:49 -0400 Subject: [PATCH 2/4] Update changelog --- doc/releases/changelog-dev.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 04650804ade..be35265e8bb 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -6,6 +6,9 @@

Improvements 🛠

+* Add support for 3 new pytest markers: `unit_test`, `integration_test` and `system_test`. + [(#5517)][https://github.com/PennyLaneAI/pennylane/pull/5517] + * The sorting order of parameter-shift terms is now guaranteed to resolve ties in the absolute value with the sign of the shifts. [(#5582)](https://github.com/PennyLaneAI/pennylane/pull/5582) @@ -153,5 +156,6 @@ Soran Jahangiri, Korbinian Kottmann, Christina Lee, Vincent Michaud-Rioux, +Lee James O'Riordan, Kenya Sakka, David Wierichs. From 8b1d3fcb84123b17c061d768a1c2ea55a87b2968 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Tue, 21 May 2024 13:39:14 -0400 Subject: [PATCH 3/4] Follow review suggestions --- doc/releases/changelog-dev.md | 2 +- tests/numpy/test_numpy_random.py | 4 ++-- tests/numpy/test_numpy_wrapper.py | 18 +++++++++--------- tests/pytest.ini | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index be35265e8bb..219be5c76b2 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -6,7 +6,7 @@

Improvements 🛠

-* Add support for 3 new pytest markers: `unit_test`, `integration_test` and `system_test`. +* Add support for 3 new pytest markers: `unit`, `integration` and `system`. [(#5517)][https://github.com/PennyLaneAI/pennylane/pull/5517] * The sorting order of parameter-shift terms is now guaranteed to resolve ties in the absolute value with the sign of the shifts. diff --git a/tests/numpy/test_numpy_random.py b/tests/numpy/test_numpy_random.py index d39d27d6b1d..6cfd9e483a6 100644 --- a/tests/numpy/test_numpy_random.py +++ b/tests/numpy/test_numpy_random.py @@ -43,7 +43,7 @@ general_gen = random.default_rng() -@pytest.mark.unit_test +@pytest.mark.unit class TestGeneratorDistributions: @pytest.mark.parametrize("distribution", distributions_no_extra_input) def test_generator_distributions(self, distribution): @@ -62,7 +62,7 @@ def test_generator_distributions(self, distribution): assert output.requires_grad is False -@pytest.mark.unit_test +@pytest.mark.unit class Test_default_rng: def test_no_input(self): """Tests that np.random.default_rng() returns a generator object when diff --git a/tests/numpy/test_numpy_wrapper.py b/tests/numpy/test_numpy_wrapper.py index f7003102528..f89bc715b6e 100644 --- a/tests/numpy/test_numpy_wrapper.py +++ b/tests/numpy/test_numpy_wrapper.py @@ -25,7 +25,7 @@ from pennylane.numpy.tensor import tensor_to_arraybox -@pytest.mark.unit_test +@pytest.mark.unit class TestExtractTensors: """Tests for the extract_tensors function""" @@ -57,7 +57,7 @@ def test_iterable_with_unpatched_numpy_arrays(self): assert res[1] is arr2 -@pytest.mark.unit_test +@pytest.mark.unit class TestTensor: """Tests for the Tensor(ndarray) subclass""" @@ -143,7 +143,7 @@ def test_numpy_to_arraybox(self): ] -@pytest.mark.unit_test +@pytest.mark.unit class TestNumpyIntegration: """Test that the wrapped NumPy functionality integrates well with standard NumPy functions.""" @@ -431,7 +431,7 @@ def __call__(self, *args, **kwargs): assert len(res) == 2 -@pytest.mark.integration_test +@pytest.mark.integration class TestAutogradIntegration: """Test autograd works with the new tensor subclass""" @@ -462,7 +462,7 @@ def cost(x): grad_fn(arr1) -@pytest.mark.unit_test +@pytest.mark.unit class TestScalarHashing: """Test for the hashing capability of scalar arrays.""" @@ -510,7 +510,7 @@ def test_nonzero_dim_arrays_non_hashable(self): class TestNumpyConversion: """Tests for the tensor.unwrap() and tensor.numpy() methods""" - @pytest.mark.unit_test + @pytest.mark.unit def test_convert_scalar_array(self): """Test that a scalar array converts to a python literal""" data = np.array(1.543) @@ -518,7 +518,7 @@ def test_convert_scalar_array(self): assert res == data.item() assert isinstance(res, float) - @pytest.mark.unit_test + @pytest.mark.unit def test_convert_array(self): """Test that a numpy array successfully converts""" data = np.array([1, 2, 3]) @@ -529,7 +529,7 @@ def test_convert_array(self): assert isinstance(res, np.ndarray) assert not isinstance(res, np.tensor) - @pytest.mark.system_test + @pytest.mark.system def test_single_gate_parameter(self): """Test that when supplied a PennyLane tensor, a QNode passes an unwrapped tensor as the argument to a gate taking a single parameter""" @@ -553,7 +553,7 @@ def circuit(phi=None): assert op.name == "RX" assert op.parameters == [p] - @pytest.mark.system_test + @pytest.mark.system def test_multiple_gate_parameter(self): """Test that when supplied a PennyLane tensor, a QNode passes arguments as unwrapped tensors to a gate taking multiple parameters""" diff --git a/tests/pytest.ini b/tests/pytest.ini index 4b313b4f825..4c2812d4a75 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -1,8 +1,8 @@ [pytest] markers = - unit_test: marks tests as unit-level tests (select with '-m "unit_test"') - integration_test: marks tests as integration-level tests (select with '-m "integration_test"') - system_test: marks tests as system-level tests (select with '-m "system_test"') + unit: marks tests as unit-level tests (select with '-m "unit"') + integration: marks tests as integration-level tests (select with '-m "integration"') + system: marks tests as system-level tests (select with '-m "system"') core: marks tests for core testing (select with '-m "core"') autograd: marks tests for autograd testing (select with '-m "autograd"') torch: marks tests for torch testing (select with '-m "core"') From 372aab8458f1aebf04e2c453b4700f15416c4b33 Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Tue, 21 May 2024 13:39:33 -0400 Subject: [PATCH 4/4] Update doc/releases/changelog-dev.md Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com> --- doc/releases/changelog-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 219be5c76b2..83643f91f29 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -7,7 +7,7 @@

Improvements 🛠

* Add support for 3 new pytest markers: `unit`, `integration` and `system`. - [(#5517)][https://github.com/PennyLaneAI/pennylane/pull/5517] + [(#5517)](https://github.com/PennyLaneAI/pennylane/pull/5517) * The sorting order of parameter-shift terms is now guaranteed to resolve ties in the absolute value with the sign of the shifts. [(#5582)](https://github.com/PennyLaneAI/pennylane/pull/5582)