From ebbbc7d12b6962fa51c74fd1d25ffb8860986d85 Mon Sep 17 00:00:00 2001 From: andrijapau Date: Tue, 14 Jan 2025 13:38:52 -0500 Subject: [PATCH 1/7] initial commit --- doc/development/deprecations.rst | 12 +++---- pennylane/workflow/qnode.py | 21 +----------- tests/test_qnode.py | 56 -------------------------------- tests/test_qnode_legacy.py | 15 --------- 4 files changed, 7 insertions(+), 97 deletions(-) diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index fd1c5051e25..1f4c5905f0b 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -15,12 +15,6 @@ Pending deprecations - Deprecated in v0.40 - Will be removed in v0.41 -* The ``tape`` and ``qtape`` properties of ``QNode`` have been deprecated. - Instead, use the ``qml.workflow.construct_tape`` function. - - - Deprecated in v0.40 - - Will be removed in v0.41 - * The ``max_expansion`` argument in :func:`~pennylane.devices.preprocess.decompose` is deprecated. - Deprecated in v0.40 @@ -90,6 +84,12 @@ for details on how to port your legacy code to the new system. The following fun Completed deprecation cycles ---------------------------- +* The ``tape`` and ``qtape`` properties of ``QNode`` have been removed. + Instead, use the ``qml.workflow.construct_tape`` function. + + - Deprecated in v0.40 + - Removed in v0.41 + * The ``qml.qinfo`` module has been removed. Please see the respective functions in the ``qml.math`` and ``qml.measurements`` modules instead. diff --git a/pennylane/workflow/qnode.py b/pennylane/workflow/qnode.py index 14f4f6fc9cc..d1f63358094 100644 --- a/pennylane/workflow/qnode.py +++ b/pennylane/workflow/qnode.py @@ -29,7 +29,7 @@ from pennylane.logging import debug_logger from pennylane.math import Interface, SupportedInterfaceUserInput, get_canonical_interface_name from pennylane.measurements import MidMeasureMP -from pennylane.tape import QuantumScript, QuantumTape +from pennylane.tape import QuantumScript from pennylane.transforms.core import TransformContainer, TransformDispatcher, TransformProgram from ._capture_qnode import capture_qnode @@ -817,25 +817,6 @@ def best_method_str(device: SupportedDeviceAPIs, interface: SupportedInterfaceUs # only other options at this point are "backprop" or "device" return transform - @property - def tape(self) -> QuantumTape: - """The quantum tape - - .. warning:: - - This property is deprecated in v0.40 and will be removed in v0.41. - Instead, use the :func:`qml.workflow.construct_tape <.workflow.construct_tape>` function. - """ - - warnings.warn( - "The tape/qtape property is deprecated and will be removed in v0.41. " - "Instead, use the qml.workflow.construct_tape function.", - qml.PennyLaneDeprecationWarning, - ) - return self._tape - - qtape = tape # for backwards compatibility - @debug_logger def construct(self, args, kwargs) -> qml.tape.QuantumScript: """Call the quantum function with a tape context, ensuring the operations get queued.""" diff --git a/tests/test_qnode.py b/tests/test_qnode.py index 5ac318333a3..c7dc96ac373 100644 --- a/tests/test_qnode.py +++ b/tests/test_qnode.py @@ -31,21 +31,6 @@ from pennylane.typing import PostprocessingFn -def test_tape_property_is_deprecated(): - """Test that the tape property is deprecated.""" - dev = qml.device("default.qubit") - - @qml.qnode(dev) - def circuit(x): - qml.RX(x, wires=0) - return qml.PauliY(0) - - with pytest.warns( - qml.PennyLaneDeprecationWarning, match="The tape/qtape property is deprecated" - ): - _ = circuit.tape - - def dummyfunc(): """dummy func.""" return None @@ -556,47 +541,6 @@ def circuit(): class TestTapeConstruction: """Tests for the tape construction""" - def test_basic_tape_construction(self, tol): - """Test that a quantum tape is properly constructed""" - dev = qml.device("default.qubit", wires=2) - - def func(x, y): - qml.RX(x, wires=0) - qml.RY(y, wires=1) - qml.CNOT(wires=[0, 1]) - return qml.expval(qml.PauliZ(0)) - - qn = QNode(func, dev) - - x = pnp.array(0.12, requires_grad=True) - y = pnp.array(0.54, requires_grad=True) - - res = qn(x, y) - with pytest.warns( - qml.PennyLaneDeprecationWarning, match="tape/qtape property is deprecated" - ): - tape = qn.tape - - assert isinstance(tape, QuantumScript) - assert len(tape.operations) == 3 - assert len(tape.observables) == 1 - assert tape.num_params == 2 - assert tape.shots.total_shots is None - - expected = qml.execute([tape], dev, None) - assert np.allclose(res, expected, atol=tol, rtol=0) - - # when called, a new quantum tape is constructed - old_tape = tape - res2 = qn(x, y) - with pytest.warns( - qml.PennyLaneDeprecationWarning, match="tape/qtape property is deprecated" - ): - new_tape = qn.tape - - assert np.allclose(res, res2, atol=tol, rtol=0) - assert new_tape is not old_tape - def test_returning_non_measurements(self): """Test that an exception is raised if a non-measurement is returned from the QNode.""" diff --git a/tests/test_qnode_legacy.py b/tests/test_qnode_legacy.py index 8ce5e8b1e00..249fa1ca41e 100644 --- a/tests/test_qnode_legacy.py +++ b/tests/test_qnode_legacy.py @@ -32,21 +32,6 @@ from pennylane.typing import PostprocessingFn -def test_legacy_qtape_property_is_deprecated(): - """Test that the legacy qtape property is deprecated.""" - dev = qml.device("default.qubit") - - @qml.qnode(dev) - def circuit(x): - qml.RX(x, wires=0) - return qml.PauliY(0) - - with pytest.warns( - qml.PennyLaneDeprecationWarning, match="The tape/qtape property is deprecated" - ): - _ = circuit.qtape - - def dummyfunc(): """dummy func.""" return None From 7f7c0f24eb8353ed42201b59df55572cdf80c8f4 Mon Sep 17 00:00:00 2001 From: andrijapau Date: Tue, 14 Jan 2025 13:50:47 -0500 Subject: [PATCH 2/7] fix: Update source code ... idk why? --- tests/devices/test_default_clifford.py | 4 ++-- tests/ops/functions/test_map_wires.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/devices/test_default_clifford.py b/tests/devices/test_default_clifford.py index ad420ee8120..7dc838d75de 100644 --- a/tests/devices/test_default_clifford.py +++ b/tests/devices/test_default_clifford.py @@ -599,9 +599,9 @@ def circuit_fn(): return qml.expval(qml.PauliZ(0)) qnode_clfrd = qml.QNode(circuit_fn, dev_c) - qnode_clfrd() + tape = qml.workflow.construct_tape(qnode_clfrd) - conf_c, tape_c = dev_c.setup_execution_config(), qnode_clfrd.tape + conf_c, tape_c = dev_c.setup_execution_config(), tape with pytest.raises( NotImplementedError, diff --git a/tests/ops/functions/test_map_wires.py b/tests/ops/functions/test_map_wires.py index 8f6abe2f02b..3fe9c879464 100644 --- a/tests/ops/functions/test_map_wires.py +++ b/tests/ops/functions/test_map_wires.py @@ -198,8 +198,9 @@ def qfunc(): assert isinstance(m_ops[1], Prod) qml.assert_equal(m_ops[0], mapped_op) qml.assert_equal(m_ops[1], mapped_op_2) - assert m_qnode.tape.observables[0].wires == Wires(wire_map[0]) - assert m_qnode.tape.observables[1].wires == Wires(wire_map[1]) + tape = qml.workflow.construct_tape(m_qnode)() + assert tape.observables[0].wires == Wires(wire_map[0]) + assert tape.observables[1].wires == Wires(wire_map[1]) @pytest.mark.jax def test_jitting_simplified_qfunc(self): From 3f216c4e40601d51b733ac0f4a6563669683c4c1 Mon Sep 17 00:00:00 2001 From: andrijapau Date: Tue, 14 Jan 2025 13:57:17 -0500 Subject: [PATCH 3/7] fix: Update way tape is constructed oopos --- tests/devices/test_default_clifford.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/devices/test_default_clifford.py b/tests/devices/test_default_clifford.py index 7dc838d75de..9a26846a261 100644 --- a/tests/devices/test_default_clifford.py +++ b/tests/devices/test_default_clifford.py @@ -599,7 +599,7 @@ def circuit_fn(): return qml.expval(qml.PauliZ(0)) qnode_clfrd = qml.QNode(circuit_fn, dev_c) - tape = qml.workflow.construct_tape(qnode_clfrd) + tape = qml.workflow.construct_tape(qnode_clfrd)() conf_c, tape_c = dev_c.setup_execution_config(), tape From 38eaec6997de527fcbd323eff55d19a4949ef418 Mon Sep 17 00:00:00 2001 From: andrijapau Date: Wed, 15 Jan 2025 10:07:25 -0500 Subject: [PATCH 4/7] doc: Update changelog-dev.md --- 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 0f9e46664b9..bbff315d954 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -10,6 +10,10 @@

Deprecations 👋

+* The ``tape`` and ``qtape`` properties of ``QNode`` have been removed. + Instead, use the ``qml.workflow.construct_tape`` function. + [(#6825)](https://github.com/PennyLaneAI/pennylane/pull/6825) +

Documentation 📝

* Updated documentation for vibrational Hamiltonians From c80ecbdaf15d1efdd4d99f02cec7a1b19524b37d Mon Sep 17 00:00:00 2001 From: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com> Date: Wed, 15 Jan 2025 10:14:38 -0500 Subject: [PATCH 5/7] Update changelog-dev.md --- doc/releases/changelog-dev.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index bbff315d954..7ff7bc9d3ed 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -8,11 +8,11 @@

Breaking changes 💔

-

Deprecations 👋

- * The ``tape`` and ``qtape`` properties of ``QNode`` have been removed. Instead, use the ``qml.workflow.construct_tape`` function. [(#6825)](https://github.com/PennyLaneAI/pennylane/pull/6825) + +

Deprecations 👋

Documentation 📝

@@ -24,4 +24,4 @@

Contributors ✍️

This release contains contributions from (in alphabetical order): -Diksha Dhawan \ No newline at end of file +Diksha Dhawan From 791a3204f97a7ebcfc2e3583dcd32552cebf8e71 Mon Sep 17 00:00:00 2001 From: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:46:32 -0500 Subject: [PATCH 6/7] Apply suggestions from code review --- tests/ops/functions/test_map_wires.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ops/functions/test_map_wires.py b/tests/ops/functions/test_map_wires.py index 3fe9c879464..aee65a01920 100644 --- a/tests/ops/functions/test_map_wires.py +++ b/tests/ops/functions/test_map_wires.py @@ -198,9 +198,8 @@ def qfunc(): assert isinstance(m_ops[1], Prod) qml.assert_equal(m_ops[0], mapped_op) qml.assert_equal(m_ops[1], mapped_op_2) - tape = qml.workflow.construct_tape(m_qnode)() - assert tape.observables[0].wires == Wires(wire_map[0]) - assert tape.observables[1].wires == Wires(wire_map[1]) + assert m_tape.observables[0].wires == Wires(wire_map[0]) + assert m_tape.observables[1].wires == Wires(wire_map[1]) @pytest.mark.jax def test_jitting_simplified_qfunc(self): From a591c7021679cb1993beab36df2265c3c3cd6cce Mon Sep 17 00:00:00 2001 From: andrijapau Date: Wed, 15 Jan 2025 16:51:16 -0500 Subject: [PATCH 7/7] doc: Update changelog-dev.md --- doc/releases/changelog-dev.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 24c527f69c5..4399efce503 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -46,6 +46,8 @@

Contributors ✍️

This release contains contributions from (in alphabetical order): + Yushao Chen, Diksha Dhawan, Christina Lee, +Andrija Paurevic