diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index d67c9abf636..05abd31e808 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -45,17 +45,6 @@ Pending deprecations - Deprecated in v0.39 - Will be removed in v0.40 -* The ``decomp_depth`` argument in ``qml.device`` is deprecated. - - - Deprecated in v0.38 - - Will be removed in v0.39 - -* The ``simplify`` argument in ``qml.Hamiltonian`` and ``qml.ops.LinearCombination`` is deprecated. - Instead, ``qml.simplify()`` can be called on the constructed operator. - - - Deprecated in v0.37 - - Will be removed in v0.39 - * The ``QubitStateVector`` template is deprecated. Instead, use ``StatePrep``. @@ -106,6 +95,17 @@ Other deprecations Completed deprecation cycles ---------------------------- +* The ``simplify`` argument in ``qml.Hamiltonian`` and ``qml.ops.LinearCombination`` has been removed. + Instead, ``qml.simplify()`` can be called on the constructed operator. + + - Deprecated in v0.37 + - Removed in v0.39 + +* The ``decomp_depth`` argument in ``qml.device`` is removed. + + - Deprecated in v0.38 + - Removed in v0.39 + * The functions ``qml.qinfo.classical_fisher`` and ``qml.qinfo.quantum_fisher`` have been removed and migrated to the ``qml.gradients`` module. Therefore, ``qml.gradients.classical_fisher`` and ``qml.gradients.quantum_fisher`` should be used instead. diff --git a/doc/news/new_opmath.rst b/doc/news/new_opmath.rst index 59a1c54aa0b..c90df6d8978 100644 --- a/doc/news/new_opmath.rst +++ b/doc/news/new_opmath.rst @@ -245,10 +245,10 @@ To help identify a fix, select the option below that describes your situation. >>> qml.Hamiltonian([0.5], [X(0) @ X(1)]) 0.5 * (X(0) @ X(1)) - The API of :class:`~.ops.op_math.LinearCombination` is identical to that of :class:`~.Hamiltonian`. We can group observables or simplify upon initialization. + The API of :class:`~.ops.op_math.LinearCombination` is identical to that of :class:`~.Hamiltonian`. We can group observables upon initialization. - >>> H1 = qml.Hamiltonian([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc", simplify=True) - >>> H2 = qml.ops.LinearCombination([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc", simplify=True) + >>> H1 = qml.Hamiltonian([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc") + >>> H2 = qml.ops.LinearCombination([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc") >>> H1 == H2 True diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index cc20267978a..59f69b22dd9 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -66,6 +66,10 @@

Breaking changes 💔

+* The `simplify` argument in `qml.Hamiltonian` and `qml.ops.LinearCombination` has been removed. + Instead, `qml.simplify()` can be called on the constructed operator. + [(#6279)](https://github.com/PennyLaneAI/pennylane/pull/6279) + * The functions `qml.qinfo.classical_fisher` and `qml.qinfo.quantum_fisher` have been removed and migrated to the `qml.gradients` module. Therefore, `qml.gradients.classical_fisher` and `qml.gradients.quantum_fisher` should be used instead. [(#5911)](https://github.com/PennyLaneAI/pennylane/pull/5911) @@ -94,6 +98,9 @@ Please use `qml.transforms.split_non_commuting` instead. [(#6204)](https://github.com/PennyLaneAI/pennylane/pull/6204) +* The `decomp_depth` keyword argument to `qml.device` is removed. + [(#6234)](https://github.com/PennyLaneAI/pennylane/pull/6234) + * `Operator.expand` is now removed. Use `qml.tape.QuantumScript(op.deocomposition())` instead. [(#6227)](https://github.com/PennyLaneAI/pennylane/pull/6227) diff --git a/pennylane/_version.py b/pennylane/_version.py index 0c39c922ce2..a37a637f72b 100644 --- a/pennylane/_version.py +++ b/pennylane/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.39.0-dev16" +__version__ = "0.39.0-dev17" diff --git a/pennylane/devices/device_constructor.py b/pennylane/devices/device_constructor.py index 00ad188d1d1..1fc4df2acff 100644 --- a/pennylane/devices/device_constructor.py +++ b/pennylane/devices/device_constructor.py @@ -14,7 +14,6 @@ """ This module contains code for the main device construction delegation logic. """ -import warnings from importlib import metadata from sys import version_info @@ -57,8 +56,7 @@ def refresh_devices(): # pylint: disable=protected-access def device(name, *args, **kwargs): - r""" - Load a device and return the instance. + r"""Load a device and return the instance. This function is used to load a particular quantum device, which can then be used to construct QNodes. @@ -105,12 +103,6 @@ def device(name, *args, **kwargs): that contains global and/or device specific configurations. custom_decomps (Dict[Union(str, Operator), Callable]): Custom decompositions to be applied by the device at runtime. - decomp_depth (int): For when custom decompositions are specified, - the maximum expansion depth used by the expansion function. - - .. warning:: - - The ``decomp_depth`` argument is deprecated and will be removed in version 0.39. All devices must be loaded by specifying their **short-name** as listed above, followed by the **wires** (subsystems) you wish to initialize. The ``wires`` @@ -122,10 +114,10 @@ def device(name, *args, **kwargs): dev = qml.device('default.qubit', wires=5) def circuit(): - qml.Hadamard(wires=1) - qml.Hadamard(wires=[0]) - qml.CNOT(wires=[3, 4]) - ... + qml.Hadamard(wires=1) + qml.Hadamard(wires=[0]) + qml.CNOT(wires=[3, 4]) + ... The ``wires`` argument can also be a sequence of unique numbers or strings, specifying custom wire labels that the user employs to address the wires: @@ -135,10 +127,10 @@ def circuit(): dev = qml.device('default.qubit', wires=['ancilla', 'q11', 'q12', -1, 1]) def circuit(): - qml.Hadamard(wires='q11') - qml.Hadamard(wires=['ancilla']) - qml.CNOT(wires=['q12', -1]) - ... + qml.Hadamard(wires='q11') + qml.Hadamard(wires=['ancilla']) + qml.CNOT(wires=['q12', -1]) + ... On some newer devices, such as ``default.qubit``, the ``wires`` argument can be omitted altogether, and instead the wires will be computed when executing a circuit depending on its contents. @@ -157,8 +149,8 @@ def circuit(): @qml.qnode(dev) def circuit(a): - qml.RX(a, wires=0) - return qml.sample(qml.Z(0)) + qml.RX(a, wires=0) + return qml.sample(qml.Z(0)) >>> circuit(0.8) # 10 samples are returned array([ 1, 1, 1, 1, -1, 1, 1, -1, 1, 1]) @@ -243,15 +235,6 @@ def run_cnot(): # Pop the custom decomposition keyword argument; we will use it here # only and not pass it to the device. custom_decomps = kwargs.pop("custom_decomps", None) - decomp_depth = kwargs.pop("decomp_depth", None) - - if decomp_depth is not None: - warnings.warn( - "The decomp_depth argument is deprecated and will be removed in version 0.39. ", - qml.PennyLaneDeprecationWarning, - ) - else: - decomp_depth = 10 kwargs.pop("config", None) options.update(kwargs) @@ -284,12 +267,12 @@ def _safe_specifier_set(version_str): if custom_decomps is not None: if isinstance(dev, qml.devices.LegacyDevice): custom_decomp_expand_fn = qml.transforms.create_decomp_expand_fn( - custom_decomps, dev, decomp_depth=decomp_depth + custom_decomps, dev, decomp_depth=10 ) dev.custom_expand(custom_decomp_expand_fn) else: custom_decomp_preprocess = qml.transforms.tape_expand._create_decomp_preprocessing( - custom_decomps, dev, decomp_depth=decomp_depth + custom_decomps, dev, decomp_depth=10 ) dev.preprocess = custom_decomp_preprocess diff --git a/pennylane/ops/op_math/linear_combination.py b/pennylane/ops/op_math/linear_combination.py index 473a0253b60..c14975d1c3d 100644 --- a/pennylane/ops/op_math/linear_combination.py +++ b/pennylane/ops/op_math/linear_combination.py @@ -37,9 +37,6 @@ class LinearCombination(Sum): Args: coeffs (tensor_like): coefficients of the ``LinearCombination`` expression observables (Iterable[Observable]): observables in the ``LinearCombination`` expression, of same length as ``coeffs`` - simplify (bool): Specifies whether the ``LinearCombination`` is simplified upon initialization - (like-terms are combined). The default value is `False`. Note that ``coeffs`` cannot - be differentiated when using the ``'torch'`` interface and ``simplify=True``. Use of this argument is deprecated. grouping_type (str): If not ``None``, compute and store information on how to group commuting observables upon initialization. This information may be accessed when a :class:`~.QNode` containing this ``LinearCombination`` is executed on devices. The string refers to the type of binary relation between Pauli words. @@ -52,10 +49,6 @@ class LinearCombination(Sum): .. seealso:: `rustworkx.ColoringStrategy `_ for more information on the ``('lf', 'dsatur', 'gis')`` strategies. - .. warning:: - The ``simplify`` argument is deprecated and will be removed in a future release. - Instead, you can call ``qml.simplify`` on the constructed operator. - **Example:** A ``LinearCombination`` can be created by simply passing the list of coefficients @@ -124,7 +117,6 @@ def __init__( self, coeffs, observables: list[Operator], - simplify=False, grouping_type=None, method="lf", _grouping_indices=None, @@ -143,23 +135,6 @@ def __init__( if _pauli_rep is None: _pauli_rep = self._build_pauli_rep_static(coeffs, observables) - if simplify: - - warnings.warn( - "The simplify argument in qml.Hamiltonian and qml.ops.LinearCombination is deprecated. " - "Instead, you can call qml.simplify on the constructed operator.", - qml.PennyLaneDeprecationWarning, - ) - - # simplify upon initialization changes ops such that they wouldnt be removed in self.queue() anymore - if qml.QueuingManager.recording(): - for o in observables: - qml.QueuingManager.remove(o) - - coeffs, observables, _pauli_rep = self._simplify_coeffs_ops( - coeffs, observables, _pauli_rep - ) - self._coeffs = coeffs self._ops = [convert_to_opmath(op) for op in observables] diff --git a/pennylane/ops/qubit/hamiltonian.py b/pennylane/ops/qubit/hamiltonian.py index e369d5001e4..73e75bf76d8 100644 --- a/pennylane/ops/qubit/hamiltonian.py +++ b/pennylane/ops/qubit/hamiltonian.py @@ -81,8 +81,6 @@ class Hamiltonian(Observable): Args: coeffs (tensor_like): coefficients of the Hamiltonian expression observables (Iterable[Observable]): observables in the Hamiltonian expression, of same length as coeffs - simplify (bool): Specifies whether the Hamiltonian is simplified upon initialization - (like-terms are combined). The default value is `False`. Use of this argument is deprecated. grouping_type (str): If not None, compute and store information on how to group commuting observables upon initialization. This information may be accessed when QNodes containing this Hamiltonian are executed on devices. The string refers to the type of binary relation between Pauli words. @@ -91,10 +89,6 @@ class Hamiltonian(Observable): can be ``'lf'`` (Largest First) or ``'rlf'`` (Recursive Largest First). Ignored if ``grouping_type=None``. id (str): name to be assigned to this Hamiltonian instance - .. warning:: - The ``simplify`` argument is deprecated and will be removed in a future release. - Instead, you can call ``qml.simplify`` on the constructed operator. - **Example:** .. note:: @@ -254,7 +248,6 @@ def __init__( self, coeffs: TensorLike, observables: Iterable[Observable], - simplify: bool = False, grouping_type: Literal[None, "qwc", "commuting", "anticommuting"] = None, _grouping_indices: Optional[list[list[int]]] = None, method: Literal["lf", "rlf"] = "rlf", @@ -293,23 +286,6 @@ def __init__( # commuting observables, since recomputation is costly self._grouping_indices = _grouping_indices - if simplify: - - warn( - "The simplify argument in qml.Hamiltonian and qml.ops.LinearCombination is deprecated. " - "Instead, you can call qml.simplify on the constructed operator.", - qml.PennyLaneDeprecationWarning, - ) - - # simplify upon initialization changes ops such that they wouldnt be - # removed in self.queue() anymore, removing them here manually. - if qml.QueuingManager.recording(): - for o in observables: - qml.QueuingManager.remove(o) - - with qml.QueuingManager.stop_recording(): - self.simplify() - if grouping_type is not None: with qml.QueuingManager.stop_recording(): self._grouping_indices = _compute_grouping_indices( diff --git a/tests/devices/test_legacy_device.py b/tests/devices/test_legacy_device.py index c08d9411dca..10594bd62e0 100644 --- a/tests/devices/test_legacy_device.py +++ b/tests/devices/test_legacy_device.py @@ -1074,15 +1074,6 @@ def test_shot_vector_property(self): assert dev.shots.total_shots == 22 - def test_decomp_depth_is_deprecated(self): - """Test that a warning is raised when using the deprecated decomp_depth argument""" - - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="The decomp_depth argument is deprecated", - ): - qml.device("default.qubit", decomp_depth=1) - class TestBatchExecution: """Tests for the batch_execute method.""" diff --git a/tests/ops/op_math/test_linear_combination.py b/tests/ops/op_math/test_linear_combination.py index 553427ce799..748f2bfb48a 100644 --- a/tests/ops/op_math/test_linear_combination.py +++ b/tests/ops/op_math/test_linear_combination.py @@ -580,14 +580,6 @@ def circuit2(param): class TestLinearCombination: """Test the LinearCombination class""" - def test_deprecation_simplify_argument(self): - """Test that a deprecation warning is raised if the simplify argument is True.""" - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - _ = qml.ops.LinearCombination([1.0], [qml.X(0)], simplify=True) - def test_error_if_observables_operator(self): """Test thatt an error is raised if an operator is provided to observables.""" @@ -613,13 +605,9 @@ def test_error_if_observables_operator(self): def test_pauli_rep(self, coeffs, ops, true_pauli, simplify): """Test the pauli rep is correctly constructed""" if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - H = qml.ops.LinearCombination(coeffs, ops, simplify=simplify) + H = qml.ops.LinearCombination(coeffs, ops).simplify() else: - H = qml.ops.LinearCombination(coeffs, ops, simplify=simplify) + H = qml.ops.LinearCombination(coeffs, ops) pr = H.pauli_rep if simplify: pr.simplify() @@ -1659,31 +1647,13 @@ def test_simplify_reduces_tape_parameters(self): @qml.qnode(device) def circuit(): qml.RY(0.1, wires=0) - return qml.expval(qml.ops.LinearCombination([1.0, 2.0], [X(1), X(1)], simplify=True)) + return qml.expval(qml.simplify(qml.ops.LinearCombination([1.0, 2.0], [X(1), X(1)]))) - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - circuit() + circuit() pars = circuit.qtape.get_parameters(trainable_only=False) # simplify worked and added 1. and 2. assert pars == [0.1, 3.0] - @pytest.mark.usefixtures("use_legacy_and_new_opmath") - def test_queuing_behaviour(self): - """Tests that the base observables are correctly dequeued with simplify=True""" - - with qml.queuing.AnnotatedQueue() as q: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - obs = qml.Hamiltonian([1, 1, 1], [qml.X(0), qml.X(0), qml.Z(0)], simplify=True) - - assert len(q) == 1 - assert q.queue[0] == obs - class TestLinearCombinationDifferentiation: """Test that the LinearCombination coefficients are differentiable""" @@ -1702,23 +1672,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.ops.LinearCombination( - coeffs, - [X(0), Z(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group)) + if simplify + else qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group) ) grad_fn = qml.grad(circuit) - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - grad = grad_fn(coeffs, param) - else: - grad = grad_fn(coeffs, param) + grad = grad_fn(coeffs, param) # differentiating a cost that combines circuits with # measurements expval(Pauli) @@ -1783,23 +1743,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.ops.LinearCombination( - coeffs, - [X(0), Z(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group)) + if simplify + else qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group) ) grad_fn = qml.grad(circuit) - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - grad = grad_fn(coeffs, param) - else: - grad = grad_fn(coeffs, param) + grad = grad_fn(coeffs, param) # differentiating a cost that combines circuits with # measurements expval(Pauli) @@ -1860,24 +1810,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.ops.LinearCombination( - coeffs, - [X(0), Z(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group)) + if simplify + else qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group) ) grad_fn = jax.grad(circuit) - - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - grad = grad_fn(coeffs, param) - else: - grad = grad_fn(coeffs, param) + grad = grad_fn(coeffs, param) # differentiating a cost that combines circuits with # measurements expval(Pauli) @@ -1938,22 +1877,12 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.ops.LinearCombination( - coeffs, - [X(0), Z(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group)) + if simplify + else qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group) ) - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - res = circuit(coeffs, param) - else: - res = circuit(coeffs, param) + res = circuit(coeffs, param) res.backward() # pylint:disable=no-member grad = (coeffs.grad, param.grad) @@ -2032,23 +1961,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.ops.LinearCombination( - coeffs, - [X(0), Z(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group)) + if simplify + else qml.ops.LinearCombination(coeffs, [X(0), Z(0)], grouping_type=group) ) with tf.GradientTape() as tape: - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - res = circuit(coeffs, param) - else: - res = circuit(coeffs, param) + res = circuit(coeffs, param) grad = tape.gradient(res, [coeffs, param]) # differentiating a cost that combines circuits with diff --git a/tests/ops/qubit/test_hamiltonian.py b/tests/ops/qubit/test_hamiltonian.py index 169988f8c80..77639be562c 100644 --- a/tests/ops/qubit/test_hamiltonian.py +++ b/tests/ops/qubit/test_hamiltonian.py @@ -703,15 +703,6 @@ def test_deprecation_with_new_opmath(recwarn): assert len(recwarn) == 0 -def test_deprecation_simplify_argument(): - """Test that a deprecation warning is raised if the simplify argument is True.""" - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - _ = qml.ops.Hamiltonian([1.0], [qml.X(0)], simplify=True) - - @pytest.mark.usefixtures("use_legacy_opmath") class TestHamiltonian: """Test the Hamiltonian class""" @@ -1750,14 +1741,10 @@ def test_simplify_reduces_tape_parameters(self): def circuit(): qml.RY(0.1, wires=0) return qml.expval( - qml.Hamiltonian([1.0, 2.0], [qml.PauliX(1), qml.PauliX(1)], simplify=True) + qml.simplify(qml.Hamiltonian([1.0, 2.0], [qml.PauliX(1), qml.PauliX(1)])) ) - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - circuit() + circuit() pars = circuit.qtape.get_parameters(trainable_only=False) # simplify worked and added 1. and 2. assert pars == [0.1, 3.0] @@ -1781,24 +1768,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.Hamiltonian( - coeffs, - [qml.PauliX(0), qml.PauliZ(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group)) + if simplify + else qml.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group) ) grad_fn = qml.grad(circuit) - - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - grad = grad_fn(coeffs, param) - else: - grad = grad_fn(coeffs, param) + grad = grad_fn(coeffs, param) # differentiating a cost that combines circuits with # measurements expval(Pauli) @@ -1863,24 +1839,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.Hamiltonian( - coeffs, - [qml.PauliX(0), qml.PauliZ(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group)) + if simplify + else qml.ops.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group) ) grad_fn = qml.grad(circuit) - - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - grad = grad_fn(coeffs, param) - else: - grad = grad_fn(coeffs, param) + grad = grad_fn(coeffs, param) # differentiating a cost that combines circuits with # measurements expval(Pauli) @@ -1941,23 +1906,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.Hamiltonian( - coeffs, - [qml.PauliX(0), qml.PauliZ(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group)) + if simplify + else qml.ops.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group) ) grad_fn = jax.grad(circuit) - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - grad = grad_fn(coeffs, param) - else: - grad = grad_fn(coeffs, param) + grad = grad_fn(coeffs, param) # differentiating a cost that combines circuits with # measurements expval(Pauli) @@ -2017,23 +1972,12 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.Hamiltonian( - coeffs, - [qml.PauliX(0), qml.PauliZ(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group)) + if simplify + else qml.ops.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group) ) - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - res = circuit(coeffs, param) - else: - res = circuit(coeffs, param) - + res = circuit(coeffs, param) res.backward() # pylint:disable=no-member grad = (coeffs.grad, param.grad) @@ -2112,23 +2056,13 @@ def circuit(coeffs, param): qml.RX(param, wires=0) qml.RY(param, wires=0) return qml.expval( - qml.Hamiltonian( - coeffs, - [qml.PauliX(0), qml.PauliZ(0)], - simplify=simplify, - grouping_type=group, - ) + qml.simplify(qml.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group)) + if simplify + else qml.ops.Hamiltonian(coeffs, [qml.X(0), qml.Z(0)], grouping_type=group) ) with tf.GradientTape() as tape: - if simplify: - with pytest.warns( - qml.PennyLaneDeprecationWarning, - match="deprecated", - ): - res = circuit(coeffs, param) - else: - res = circuit(coeffs, param) + res = circuit(coeffs, param) grad = tape.gradient(res, [coeffs, param]) diff --git a/tests/transforms/test_tape_expand.py b/tests/transforms/test_tape_expand.py index db7472df086..25c7e35b20a 100644 --- a/tests/transforms/test_tape_expand.py +++ b/tests/transforms/test_tape_expand.py @@ -539,30 +539,6 @@ def circuit(): assert decomp_ops[2].name == "CNOT" - @pytest.mark.parametrize("device_name", ["default.qubit", "default.qubit.legacy"]) - def test_no_decomp_with_depth_zero(self, device_name): - """Test that specifying a single custom decomposition works as expected.""" - - custom_decomps = {"Hadamard": custom_hadamard, "CNOT": custom_cnot} - with pytest.warns( - qml.PennyLaneDeprecationWarning, match="The decomp_depth argument is deprecated" - ): - decomp_dev = qml.device( - device_name, wires=2, custom_decomps=custom_decomps, decomp_depth=0 - ) - - @qml.qnode(decomp_dev) - def circuit(): - qml.Hadamard(wires=0) - qml.CNOT(wires=[0, 1]) - return qml.expval(qml.PauliZ(0)) - - decomp_ops = qml.workflow.construct_batch(circuit, level=None)()[0][0].operations - - assert len(decomp_ops) == 2 - assert decomp_ops[0].name == "Hadamard" - assert decomp_ops[1].name == "CNOT" - @pytest.mark.parametrize("device_name", ["default.qubit", "default.qubit.legacy"]) def test_one_custom_decomp_gradient(self, device_name): """Test that gradients are still correctly computed after a decomposition @@ -713,52 +689,6 @@ def circuit(): assert decomp_ops[4].name == "CNOT" assert decomp_ops[4].wires == Wires([0, 1]) - @pytest.mark.parametrize("device_name", ["default.qubit", "default.qubit.legacy"]) - def test_custom_decomp_different_depth(self, device_name): - """Test that alternative expansion depths can be specified.""" - - # BasicEntanglerLayers custom decomposition involves AngleEmbedding. If - # expansion depth is 2, the AngleEmbedding will still be decomposed into - # RX (since it's not a supported operation on the device), but the RX will - # not be further decomposed even though the custom decomposition is specified. - custom_decomps = {"BasicEntanglerLayers": custom_basic_entangler_layers, "RX": custom_rx} - - with pytest.warns( - qml.PennyLaneDeprecationWarning, match="The decomp_depth argument is deprecated" - ): - decomp_dev_2 = qml.device( - device_name, wires=2, custom_decomps=custom_decomps, decomp_depth=2 - ) - - decomp_dev_3 = qml.device( - device_name, wires=2, custom_decomps=custom_decomps, decomp_depth=3 - ) - - def circuit(): - qml.BasicEntanglerLayers([[0.1, 0.2]], wires=[0, 1]) - return qml.expval(qml.PauliZ(0)) - - circuit2 = qml.QNode(circuit, decomp_dev_2) - circuit3 = qml.QNode(circuit, decomp_dev_3) - - decomp_ops = qml.workflow.construct_batch(circuit2, level=None)()[0][0].operations - - assert len(decomp_ops) == 3 - - assert decomp_ops[0].name == "RX" - assert np.isclose(decomp_ops[0].parameters[0], 0.1) - assert decomp_ops[0].wires == Wires(0) - - assert decomp_ops[1].name == "RX" - assert np.isclose(decomp_ops[1].parameters[0], 0.2) - assert decomp_ops[1].wires == Wires(1) - - assert decomp_ops[2].name == "CNOT" - assert decomp_ops[2].wires == Wires([0, 1]) - - decomp_ops = qml.workflow.construct_batch(circuit3, level=None)()[0][0].operations - assert len(decomp_ops) == 5 - @pytest.mark.parametrize("device_name", ["default.qubit", "default.qubit.legacy"]) def test_custom_decomp_with_adjoint(self, device_name): """Test that applying an adjoint in the circuit results in the adjoint