Skip to content

Commit 0cd911c

Browse files
authored
Merge branch 'master' into no-grad-on-diff-method-none
2 parents 9c785ce + d90d539 commit 0cd911c

File tree

9 files changed

+25
-133
lines changed

9 files changed

+25
-133
lines changed

doc/development/deprecations.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ deprecations are listed below.
99
Pending deprecations
1010
--------------------
1111

12-
* The ``tape`` and ``qtape`` properties of ``QNode`` have been deprecated.
13-
Instead, use the ``qml.workflow.construct_tape`` function.
14-
15-
- Deprecated in v0.40
16-
- Will be removed in v0.41
17-
1812
* The ``max_expansion`` argument in :func:`~pennylane.devices.preprocess.decompose` is deprecated.
1913

2014
- Deprecated in v0.40
@@ -25,11 +19,6 @@ Pending deprecations
2519
- Deprecated in v0.40
2620
- Will be removed in v0.41
2721

28-
* The ``gradient_fn`` keyword argument to ``qml.execute`` has been renamed ``diff_method``.
29-
30-
- Deprecated in v0.40
31-
- Will be removed in v0.41
32-
3322
* ``op.ops`` and ``op.coeffs`` for ``Sum`` and ``Prod`` will be removed in the future. Use
3423
:meth:`~.Operator.terms` instead.
3524

@@ -73,6 +62,17 @@ for details on how to port your legacy code to the new system. The following fun
7362
Completed deprecation cycles
7463
----------------------------
7564

65+
* The ``tape`` and ``qtape`` properties of ``QNode`` have been removed.
66+
Instead, use the ``qml.workflow.construct_tape`` function.
67+
68+
- Deprecated in v0.40
69+
- Removed in v0.41
70+
71+
* The ``gradient_fn`` keyword argument to ``qml.execute`` has been removed. Instead, it has been replaced with ``diff_method``.
72+
73+
- Deprecated in v0.40
74+
- Removed in v0.41
75+
7676
* The ``QNode.get_best_method`` and ``QNode.best_method_str`` methods have been removed.
7777
Instead, use the ``qml.workflow.get_best_diff_method`` function.
7878

doc/releases/changelog-dev.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121
<h3>Breaking changes 💔</h3>
2222

23+
* The ``tape`` and ``qtape`` properties of ``QNode`` have been removed.
24+
Instead, use the ``qml.workflow.construct_tape`` function.
25+
[(#6825)](https://github.com/PennyLaneAI/pennylane/pull/6825)
26+
27+
* The ``gradient_fn`` keyword argument to ``qml.execute`` has been removed. Instead, it has been replaced with ``diff_method``.
28+
[(#6830)](https://github.com/PennyLaneAI/pennylane/pull/6830)
29+
2330
* The ``QNode.get_best_method`` and ``QNode.best_method_str`` methods have been removed.
2431
Instead, use the ``qml.workflow.get_best_diff_method`` function.
2532
[(#6823)](https://github.com/PennyLaneAI/pennylane/pull/6823)
@@ -46,3 +53,4 @@ This release contains contributions from (in alphabetical order):
4653
Yushao Chen,
4754
Diksha Dhawan,
4855
Christina Lee,
56+
Andrija Paurevic

pennylane/workflow/execution.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from collections.abc import Callable
2222
from dataclasses import replace
2323
from typing import Optional, Union
24-
from warnings import warn
2524

2625
from cachetools import Cache
2726

@@ -55,7 +54,6 @@ def execute(
5554
max_diff=1,
5655
device_vjp=False,
5756
mcm_config=None,
58-
gradient_fn="unset",
5957
) -> ResultBatch:
6058
"""A function for executing a batch of tapes on a device with compatibility for auto-differentiation.
6159
@@ -85,16 +83,14 @@ def execute(
8583
cache (None, bool, dict, Cache): Whether to cache evaluations. This can result in
8684
a significant reduction in quantum evaluations during gradient computations.
8785
cachesize (int): the size of the cache.
88-
max_diff (int): If ``gradient_fn`` is a gradient transform, this option specifies
86+
max_diff (int): If ``diff_method`` is a gradient transform, this option specifies
8987
the maximum number of derivatives to support. Increasing this value allows
9088
for higher-order derivatives to be extracted, at the cost of additional
9189
(classical) computational overhead during the backward pass.
9290
device_vjp=False (Optional[bool]): whether or not to use the device-provided Jacobian
9391
product if it is available.
9492
mcm_config (dict): Dictionary containing configuration options for handling
9593
mid-circuit measurements.
96-
gradient_fn="unset": **DEPRECATED**. This keyword argument has been renamed
97-
``diff_method`` and will be removed in v0.41.
9894
9995
Returns:
10096
list[tensor_like[float]]: A nested list of tape results. Each element in
@@ -158,13 +154,6 @@ def cost_fn(params, x):
158154
if not isinstance(device, qml.devices.Device):
159155
device = qml.devices.LegacyDeviceFacade(device)
160156

161-
if gradient_fn != "unset":
162-
warn(
163-
"gradient_fn has been renamed to diff_method in qml.execute",
164-
qml.PennyLaneDeprecationWarning,
165-
)
166-
diff_method = gradient_fn
167-
168157
if logger.isEnabledFor(logging.DEBUG):
169158
logger.debug(
170159
(

pennylane/workflow/qnode.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from pennylane.logging import debug_logger
3030
from pennylane.math import Interface, SupportedInterfaceUserInput, get_canonical_interface_name
3131
from pennylane.measurements import MidMeasureMP
32-
from pennylane.tape import QuantumScript, QuantumTape
32+
from pennylane.tape import QuantumScript
3333
from pennylane.transforms.core import TransformContainer, TransformDispatcher, TransformProgram
3434

3535
from ._capture_qnode import capture_qnode
@@ -693,25 +693,6 @@ def get_gradient_fn(
693693
f"options are {tuple(get_args(SupportedDiffMethods))}."
694694
)
695695

696-
@property
697-
def tape(self) -> QuantumTape:
698-
"""The quantum tape
699-
700-
.. warning::
701-
702-
This property is deprecated in v0.40 and will be removed in v0.41.
703-
Instead, use the :func:`qml.workflow.construct_tape <.workflow.construct_tape>` function.
704-
"""
705-
706-
warnings.warn(
707-
"The tape/qtape property is deprecated and will be removed in v0.41. "
708-
"Instead, use the qml.workflow.construct_tape function.",
709-
qml.PennyLaneDeprecationWarning,
710-
)
711-
return self._tape
712-
713-
qtape = tape # for backwards compatibility
714-
715696
@debug_logger
716697
def construct(self, args, kwargs) -> qml.tape.QuantumScript:
717698
"""Call the quantum function with a tape context, ensuring the operations get queued."""

tests/devices/test_default_clifford.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ def circuit_fn():
599599
return qml.expval(qml.PauliZ(0))
600600

601601
qnode_clfrd = qml.QNode(circuit_fn, dev_c)
602-
qnode_clfrd()
602+
tape = qml.workflow.construct_tape(qnode_clfrd)()
603603

604-
conf_c, tape_c = dev_c.setup_execution_config(), qnode_clfrd.tape
604+
conf_c, tape_c = dev_c.setup_execution_config(), tape
605605

606606
with pytest.raises(
607607
NotImplementedError,

tests/ops/functions/test_map_wires.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def qfunc():
198198
assert isinstance(m_ops[1], Prod)
199199
qml.assert_equal(m_ops[0], mapped_op)
200200
qml.assert_equal(m_ops[1], mapped_op_2)
201-
assert m_qnode.tape.observables[0].wires == Wires(wire_map[0])
202-
assert m_qnode.tape.observables[1].wires == Wires(wire_map[1])
201+
assert m_tape.observables[0].wires == Wires(wire_map[0])
202+
assert m_tape.observables[1].wires == Wires(wire_map[1])
203203

204204
@pytest.mark.jax
205205
def test_jitting_simplified_qfunc(self):

tests/test_qnode.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@
3131
from pennylane.typing import PostprocessingFn
3232

3333

34-
def test_tape_property_is_deprecated():
35-
"""Test that the tape property is deprecated."""
36-
dev = qml.device("default.qubit")
37-
38-
@qml.qnode(dev)
39-
def circuit(x):
40-
qml.RX(x, wires=0)
41-
return qml.PauliY(0)
42-
43-
with pytest.warns(
44-
qml.PennyLaneDeprecationWarning, match="The tape/qtape property is deprecated"
45-
):
46-
_ = circuit.tape
47-
48-
4934
def dummyfunc():
5035
"""dummy func."""
5136
return None
@@ -482,47 +467,6 @@ def circuit():
482467
class TestTapeConstruction:
483468
"""Tests for the tape construction"""
484469

485-
def test_basic_tape_construction(self, tol):
486-
"""Test that a quantum tape is properly constructed"""
487-
dev = qml.device("default.qubit", wires=2)
488-
489-
def func(x, y):
490-
qml.RX(x, wires=0)
491-
qml.RY(y, wires=1)
492-
qml.CNOT(wires=[0, 1])
493-
return qml.expval(qml.PauliZ(0))
494-
495-
qn = QNode(func, dev)
496-
497-
x = pnp.array(0.12, requires_grad=True)
498-
y = pnp.array(0.54, requires_grad=True)
499-
500-
res = qn(x, y)
501-
with pytest.warns(
502-
qml.PennyLaneDeprecationWarning, match="tape/qtape property is deprecated"
503-
):
504-
tape = qn.tape
505-
506-
assert isinstance(tape, QuantumScript)
507-
assert len(tape.operations) == 3
508-
assert len(tape.observables) == 1
509-
assert tape.num_params == 2
510-
assert tape.shots.total_shots is None
511-
512-
expected = qml.execute([tape], dev, None)
513-
assert np.allclose(res, expected, atol=tol, rtol=0)
514-
515-
# when called, a new quantum tape is constructed
516-
old_tape = tape
517-
res2 = qn(x, y)
518-
with pytest.warns(
519-
qml.PennyLaneDeprecationWarning, match="tape/qtape property is deprecated"
520-
):
521-
new_tape = qn.tape
522-
523-
assert np.allclose(res, res2, atol=tol, rtol=0)
524-
assert new_tape is not old_tape
525-
526470
def test_returning_non_measurements(self):
527471
"""Test that an exception is raised if a non-measurement
528472
is returned from the QNode."""

tests/test_qnode_legacy.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,6 @@
3232
from pennylane.typing import PostprocessingFn
3333

3434

35-
def test_legacy_qtape_property_is_deprecated():
36-
"""Test that the legacy qtape property is deprecated."""
37-
dev = qml.device("default.qubit")
38-
39-
@qml.qnode(dev)
40-
def circuit(x):
41-
qml.RX(x, wires=0)
42-
return qml.PauliY(0)
43-
44-
with pytest.warns(
45-
qml.PennyLaneDeprecationWarning, match="The tape/qtape property is deprecated"
46-
):
47-
_ = circuit.qtape
48-
49-
5035
def dummyfunc():
5136
"""dummy func."""
5237
return None

tests/workflow/interfaces/execute/test_execute.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@ def test_execute_legacy_device():
5757
assert qml.math.allclose(res[0], np.cos(0.1))
5858

5959

60-
def test_gradient_fn_deprecation():
61-
"""Test that gradient_fn has been renamed to diff_method."""
62-
63-
tape = qml.tape.QuantumScript([qml.RX(qml.numpy.array(1.0), 0)], [qml.expval(qml.Z(0))])
64-
dev = qml.device("default.qubit")
65-
66-
with dev.tracker:
67-
with pytest.warns(
68-
qml.PennyLaneDeprecationWarning, match=r"gradient_fn has been renamed to diff_method"
69-
):
70-
qml.execute((tape,), dev, gradient_fn="adjoint")
71-
72-
assert dev.tracker.totals["execute_and_derivative_batches"] == 1 # uses adjoint diff
73-
74-
7560
def test_execution_with_empty_batch():
7661
"""Test that qml.execute can be used with an empty batch."""
7762

0 commit comments

Comments
 (0)