Skip to content

Commit

Permalink
Remove qtape/tape property from QNode (#6825)
Browse files Browse the repository at this point in the history
Completing the deprecation cycle.

No idea why those tests didn't complain in CI before when it was first
deprecated ... weird!

[sc-82149]
  • Loading branch information
andrijapau authored Jan 15, 2025
1 parent ff7ba81 commit d90d539
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 101 deletions.
12 changes: 6 additions & 6 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ deprecations are listed below.
Pending deprecations
--------------------

* 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
Expand Down Expand Up @@ -68,6 +62,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 ``gradient_fn`` keyword argument to ``qml.execute`` has been removed. Instead, it has been replaced with ``diff_method``.

- Deprecated in v0.40
Expand Down
5 changes: 5 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

<h3>Breaking changes 💔</h3>

* 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)

* The ``gradient_fn`` keyword argument to ``qml.execute`` has been removed. Instead, it has been replaced with ``diff_method``.
[(#6830)](https://github.com/PennyLaneAI/pennylane/pull/6830)

Expand Down Expand Up @@ -46,3 +50,4 @@ This release contains contributions from (in alphabetical order):
Yushao Chen,
Diksha Dhawan,
Christina Lee,
Andrija Paurevic
21 changes: 1 addition & 20 deletions pennylane/workflow/qnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -695,25 +695,6 @@ def get_gradient_fn(
f"options are {tuple(get_args(SupportedDiffMethods))}."
)

@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."""
Expand Down
4 changes: 2 additions & 2 deletions tests/devices/test_default_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/ops/functions/test_map_wires.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +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)
assert m_qnode.tape.observables[0].wires == Wires(wire_map[0])
assert m_qnode.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):
Expand Down
56 changes: 0 additions & 56 deletions tests/test_qnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -482,47 +467,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."""
Expand Down
15 changes: 0 additions & 15 deletions tests/test_qnode_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d90d539

Please sign in to comment.