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

Remove qtape/tape property from QNode #6825

Merged
merged 9 commits into from
Jan 15, 2025
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
12 changes: 6 additions & 6 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
6 changes: 5 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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)

<h3>Deprecations 👋</h3>

<h3>Documentation 📝</h3>
Expand All @@ -20,4 +24,4 @@
<h3>Contributors ✍️</h3>

This release contains contributions from (in alphabetical order):
Diksha Dhawan
Diksha Dhawan
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 @@ -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."""
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
5 changes: 3 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,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)()
andrijapau marked this conversation as resolved.
Show resolved Hide resolved
andrijapau marked this conversation as resolved.
Show resolved Hide resolved
assert tape.observables[0].wires == Wires(wire_map[0])
assert tape.observables[1].wires == Wires(wire_map[1])
andrijapau marked this conversation as resolved.
Show resolved Hide resolved

@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 @@ -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."""
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
Loading