Repository: PennyLaneAI/pennylane
Pull request #5994 (2024-07-12 19:11:02)

Deprecate `Operator.expand` function
Deprecated since it is redundant bloat and can be done manually pretty easily.

[[sc-65069](https://app.shortcut.com/xanaduai/story/65069)]


github-actions[bot]: Hello. You may have forgotten to update the changelog!
Please edit [`doc/releases/changelog-dev.md`](/PennyLaneAI/pennylane/blob/master/doc/releases/changelog-dev.md) with:
* A one-to-two sentence description of the change. You may include a small working example for new features.
* A link back to this PR.
* Your name (or GitHub username) in the contributors section.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5994?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.66%. Comparing base [(`dbb26f2`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/dbb26f2c7ca54798d70756b685ce566da776bfad?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) to head [(`d409dc1`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/d409dc1fccd82f317e047c47ed0589e6ed835d37?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).
> Report is 5 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #5994      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files         425      426       +1     
  Lines       40926    40655     -271     
==========================================
- Hits        40793    40520     -273     
- Misses        133      135       +2     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5994?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).


Patch:
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 4a8e3327a..d906618d7 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -78,23 +78,27 @@
 
 <h3>Deprecations 👋</h3>
 
+* `Operator.expand` has been deprecated. Users should simply use `qml.tape.QuantumScript(op.decomposition())`
+  for equivalent behaviour.
+  [(#5994)](https://github.com/PennyLaneAI/pennylane/pull/5994)
+
 * `pennylane.transforms.sum_expand` and `pennylane.transforms.hamiltonian_expand` have been deprecated.
   Users should instead use `pennylane.transforms.split_non_commuting` for equivalent behaviour.
   [(#6003)](https://github.com/PennyLaneAI/pennylane/pull/6003)
 
-* The `expand_fn` argument in `qml.execute` has been deprecated. 
+* The `expand_fn` argument in `qml.execute` has been deprecated.
   Instead, please create a `qml.transforms.core.TransformProgram` with the desired preprocessing and pass it to the `transform_program` argument of `qml.execute`.
   [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
 
-* The `max_expansion` argument in `qml.execute` has been deprecated. 
+* The `max_expansion` argument in `qml.execute` has been deprecated.
   Instead, please use `qml.devices.preprocess.decompose` with the desired expansion level, add it to a `TransformProgram` and pass it to the `transform_program` argument of `qml.execute`.
   [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
 
-* The `override_shots` argument in `qml.execute` is deprecated. 
+* The `override_shots` argument in `qml.execute` is deprecated.
   Instead, please add the shots to the `QuantumTape`'s to be executed.
   [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
 
-* The `device_batch_transform` argument in `qml.execute` is deprecated. 
+* The `device_batch_transform` argument in `qml.execute` is deprecated.
   Instead, please create a `qml.transforms.core.TransformProgram` with the desired preprocessing and pass it to the `transform_program` argument of `qml.execute`.
   [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
 
diff --git a/pennylane/operation.py b/pennylane/operation.py
index 5b46976e0..687421931 100644
--- a/pennylane/operation.py
+++ b/pennylane/operation.py
@@ -1498,9 +1498,19 @@ class Operator(abc.ABC, metaclass=ABCCaptureMeta):
     def expand(self):
         """Returns a tape that contains the decomposition of the operator.
 
+        .. warning::
+            This function is deprecated and will be removed in version 0.39.
+            The same behaviour can be achieved simply through 'qml.tape.QuantumScript(self.decomposition())'.
+
         Returns:
             .QuantumTape: quantum tape
         """
+        warnings.warn(
+            "'Operator.expand' is deprecated and will be removed in version 0.39. "
+            "The same behaviour can be achieved simply through 'qml.tape.QuantumScript(self.decomposition())'.",
+            qml.PennyLaneDeprecationWarning,
+        )
+
         if not self.has_decomposition:
             raise DecompositionUndefinedError
 
diff --git a/pennylane/ops/functions/assert_valid.py b/pennylane/ops/functions/assert_valid.py
index 860ed3d16..bc92514a4 100644
--- a/pennylane/ops/functions/assert_valid.py
+++ b/pennylane/ops/functions/assert_valid.py
@@ -53,16 +53,13 @@ def _check_decomposition(op, skip_wire_mapping):
         with qml.queuing.AnnotatedQueue() as queued_decomp:
             op.decomposition()
         processed_queue = qml.tape.QuantumTape.from_queue(queued_decomp)
-        expand = op.expand()
 
         assert isinstance(decomp, list), "decomposition must be a list"
         assert isinstance(compute_decomp, list), "decomposition must be a list"
-        assert isinstance(expand, qml.tape.QuantumScript), "expand must return a QuantumScript"
 
-        for o1, o2, o3, o4 in zip(decomp, compute_decomp, processed_queue, expand):
+        for o1, o2, o3 in zip(decomp, compute_decomp, processed_queue):
             assert o1 == o2, "decomposition must match compute_decomposition"
             assert o1 == o3, "decomposition must match queued operations"
-            assert o1 == o4, "decomposition must match expansion"
             assert isinstance(o1, qml.operation.Operator), "decomposition must contain operators"
 
         if skip_wire_mapping:
@@ -83,9 +80,6 @@ def _check_decomposition(op, skip_wire_mapping):
             qml.operation.DecompositionUndefinedError,
             failure_comment=failure_comment,
         )()
-        _assert_error_raised(
-            op.expand, qml.operation.DecompositionUndefinedError, failure_comment=failure_comment
-        )()
         _assert_error_raised(
             op.compute_decomposition,
             qml.operation.DecompositionUndefinedError,
diff --git a/pennylane/ops/functions/eigvals.py b/pennylane/ops/functions/eigvals.py
index 6e64ccc3d..8ae2f8dbc 100644
--- a/pennylane/ops/functions/eigvals.py
+++ b/pennylane/ops/functions/eigvals.py
@@ -135,7 +135,7 @@ def eigvals(op: qml.operation.Operator, k=1, which="SA") -> TensorLike:
     try:
         return op.eigvals()
     except qml.operation.EigvalsUndefinedError:
-        return eigvals(op.expand(), k=k, which=which)
+        return eigvals(qml.tape.QuantumScript(op.decomposition()), k=k, which=which)
 
 
 @partial(transform, is_informative=True)
diff --git a/pennylane/ops/functions/matrix.py b/pennylane/ops/functions/matrix.py
index eafb8dc38..92b2e5e1d 100644
--- a/pennylane/ops/functions/matrix.py
+++ b/pennylane/ops/functions/matrix.py
@@ -227,7 +227,7 @@ def matrix(op: Union[Operator, PauliWord, PauliSentence], wire_order=None) -> Te
     try:
         return op.matrix(wire_order=wire_order)
     except:  # pylint: disable=bare-except
-        return matrix(op.expand(), wire_order=wire_order or op.wires)
+        return matrix(qml.tape.QuantumScript(op.decomposition()), wire_order=wire_order or op.wires)
 
 
 @partial(transform, is_informative=True)
diff --git a/pennylane/transforms/decompositions/clifford_t_transform.py b/pennylane/transforms/decompositions/clifford_t_transform.py
index 92698752e..9fc772aea 100644
--- a/pennylane/transforms/decompositions/clifford_t_transform.py
+++ b/pennylane/transforms/decompositions/clifford_t_transform.py
@@ -83,7 +83,7 @@ def _check_clifford_op(op, use_decomposition=False):
 
     # Check if matrix can be calculated for the operator
     if (not op.has_matrix and not use_decomposition) or (
-        use_decomposition and not op.expand().wires
+        use_decomposition and not qml.tape.QuantumScript(op.decomposition()).wires
     ):
         return False
 


Test patch:
diff --git a/tests/ops/functions/test_assert_valid.py b/tests/ops/functions/test_assert_valid.py
index 9cb87c0cf..b9a6cf453 100644
--- a/tests/ops/functions/test_assert_valid.py
+++ b/tests/ops/functions/test_assert_valid.py
@@ -52,34 +52,6 @@ class TestDecompositionErrors:
         with pytest.raises(AssertionError, match="decomposition must match queued operations"):
             assert_valid(BadDecomp(wires=0), skip_pickle=True)
 
-    def test_expand_must_be_qscript(self):
-        """Test that an error is raised if expand does not return a QuantumScript"""
-
-        class BadDecomp(Operator):
-            @staticmethod
-            def compute_decomposition(wires):
-                return [qml.RY(2.3, 0)]
-
-            def expand(self):
-                return [qml.S(0)]
-
-        with pytest.raises(AssertionError, match=r"expand must return a QuantumScript"):
-            assert_valid(BadDecomp(wires=0), skip_pickle=True)
-
-    def test_decomposition_must_match_expand(self):
-        """Test that decomposition and expand must match."""
-
-        class BadDecomp(Operator):
-            @staticmethod
-            def compute_decomposition(wires):
-                return [qml.RY(2.3, 0)]
-
-            def expand(self):
-                return qml.tape.QuantumScript([qml.S(0)])
-
-        with pytest.raises(AssertionError, match="decomposition must match expansion"):
-            assert_valid(BadDecomp(wires=0), skip_pickle=True)
-
     def test_decomposition_wires_must_be_mapped(self):
         """Test that the operators in decomposition have mapped wires after mapping the op."""
 
diff --git a/tests/ops/op_math/test_adjoint.py b/tests/ops/op_math/test_adjoint.py
index f1a3763bc..5819ab2d4 100644
--- a/tests/ops/op_math/test_adjoint.py
+++ b/tests/ops/op_math/test_adjoint.py
@@ -736,7 +736,7 @@ class TestDecompositionExpand:
     def test_expand_custom_adjoint_defined(self):
         """Test expansion method when a custom adjoint is defined."""
         base = qml.Hadamard(0)
-        tape = Adjoint(base).expand()
+        tape = qml.tape.QuantumScript(Adjoint(base).decomposition())
 
         assert len(tape) == 1
         assert isinstance(tape[0], qml.Hadamard)
@@ -756,8 +756,8 @@ class TestDecompositionExpand:
         """Test expansion when base has decomposition but no custom adjoint."""
 
         base = qml.SX(0)
-        base_tape = base.expand()
-        tape = Adjoint(base).expand()
+        base_tape = qml.tape.QuantumScript(base.decomposition())
+        tape = qml.tape.QuantumScript(Adjoint(base).decomposition())
 
         for base_op, adj_op in zip(reversed(base_tape), tape):
             assert isinstance(adj_op, Adjoint)
@@ -784,7 +784,7 @@ class TestDecompositionExpand:
 
         assert adj2.decomposition()[0] is base
 
-        tape = adj2.expand()
+        tape = qml.tape.QuantumScript(adj2.decomposition())
         assert tape.circuit[0] is base
 
 
diff --git a/tests/ops/op_math/test_controlled.py b/tests/ops/op_math/test_controlled.py
index dd9c24ca1..d73616a29 100644
--- a/tests/ops/op_math/test_controlled.py
+++ b/tests/ops/op_math/test_controlled.py
@@ -1086,7 +1086,7 @@ class TestDecomposition:
         custom_ctrl_op = custom_ctrl_cls(*params, active_wires)
 
         assert ctrl_op.decomposition() == expected
-        assert ctrl_op.expand().circuit == expected
+        assert qml.tape.QuantumScript(ctrl_op.decomposition()).circuit == expected
         assert custom_ctrl_op.decomposition() == expected
         assert custom_ctrl_cls.compute_decomposition(*params, active_wires) == expected
 
@@ -1130,7 +1130,7 @@ class TestDecomposition:
         ctrl_op = Controlled(base_op, control_wires=ctrl_wires, work_wires=Wires("aux"))
 
         assert ctrl_op.decomposition() == expected
-        assert ctrl_op.expand().circuit == expected
+        assert qml.tape.QuantumScript(ctrl_op.decomposition()).circuit == expected
 
     def test_decomposition_nested(self):
         """Tests decompositions of nested controlled operations"""
@@ -1143,7 +1143,7 @@ class TestDecomposition:
             qml.Toffoli(wires=[2, 1, 0]),
         ]
         assert ctrl_op.decomposition() == expected
-        assert ctrl_op.expand().circuit == expected
+        assert qml.tape.QuantumScript(ctrl_op.decomposition()).circuit == expected
 
     def test_decomposition_undefined(self):
         """Tests error raised when decomposition is undefined"""
@@ -1169,7 +1169,7 @@ class TestDecomposition:
         op = Controlled(base, control_wires, control_values)
 
         decomp1 = op.decomposition()
-        decomp2 = op.expand().circuit
+        decomp2 = qml.tape.QuantumScript(op.decomposition()).circuit
 
         for decomp in [decomp1, decomp2]:
             qml.assert_equal(decomp[0], qml.PauliX(1))
diff --git a/tests/ops/op_math/test_controlled_decompositions.py b/tests/ops/op_math/test_controlled_decompositions.py
index 810d2a9c2..c8cd1e4e3 100644
--- a/tests/ops/op_math/test_controlled_decompositions.py
+++ b/tests/ops/op_math/test_controlled_decompositions.py
@@ -313,7 +313,9 @@ class TestControlledDecompositionZYZ:
 
         assert op.has_decomposition
         decomp = (
-            op.expand().expand().circuit if test_expand else op.decomposition()[0].decomposition()
+            qml.tape.QuantumScript(op.decomposition()).expand().circuit
+            if test_expand
+            else op.decomposition()[0].decomposition()
         )
         expected = qml.ops.ctrl_decomp_zyz(base, (0,))  # pylint:disable=no-member
         assert equal_list(decomp, expected)
@@ -336,12 +338,20 @@ class TestControlledDecompositionZYZ:
         op = Controlled(base, (0,), control_values=[False])
 
         assert op.has_decomposition
-        decomp = op.expand().circuit if test_expand else op.decomposition()
+        decomp = (
+            qml.tape.QuantumScript(op.decomposition()).circuit
+            if test_expand
+            else op.decomposition()
+        )
         assert len(decomp) == 3
         qml.assert_equal(qml.PauliX(0), decomp[0])
         qml.assert_equal(qml.PauliX(0), decomp[-1])
         decomp = decomp[1]
-        decomp = decomp.expand().circuit if test_expand else decomp.decomposition()
+        decomp = (
+            qml.tape.QuantumScript(decomp.decomposition()).circuit
+            if test_expand
+            else decomp.decomposition()
+        )
         expected = qml.ops.ctrl_decomp_zyz(base, (0,))
         assert equal_list(decomp, expected)
 
diff --git a/tests/ops/op_math/test_exp.py b/tests/ops/op_math/test_exp.py
index cc8d5f8dd..9c42fcf87 100644
--- a/tests/ops/op_math/test_exp.py
+++ b/tests/ops/op_math/test_exp.py
@@ -594,7 +594,7 @@ class TestDecomposition:
         """Tests that the sequence of gates implemented in the trotter decomposition is correct"""
 
         op = qml.exp(hamiltonian, coeff=-1j * time, num_steps=steps)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         for expected_gate, gate in zip(expected_queue, queue):
             prep = [gate.parameters, gate.wires]
diff --git a/tests/ops/op_math/test_pow_op.py b/tests/ops/op_math/test_pow_op.py
index 9fbda5e74..15ad53f3c 100644
--- a/tests/ops/op_math/test_pow_op.py
+++ b/tests/ops/op_math/test_pow_op.py
@@ -948,7 +948,7 @@ class TestDecompositionExpand:
         """Test that the expand method uses a shortcut if it is defined for that exponent and base."""
         base = qml.PauliX(0)
         op = Pow(base, 0.5)
-        expansion_tape = op.expand()
+        expansion_tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(expansion_tape) == 1
         assert isinstance(expansion_tape[0], qml.SX)
@@ -972,7 +972,7 @@ class TestDecompositionExpand:
 
         base = qml.SX(0)
         op = Pow(base, 3)
-        expansion_tape = op.expand()
+        expansion_tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(expansion_tape) == 3
 
diff --git a/tests/ops/qubit/test_arithmetic_ops.py b/tests/ops/qubit/test_arithmetic_ops.py
index 98155e877..8b701b0fa 100644
--- a/tests/ops/qubit/test_arithmetic_ops.py
+++ b/tests/ops/qubit/test_arithmetic_ops.py
@@ -194,7 +194,7 @@ class TestQubitSum:
         if expand:
             ops = [
                 qml.StatePrep(input_state, wires=[0, 1, 2]),
-                *qml.QubitSum(wires=wires).expand(),
+                *qml.tape.QuantumScript(qml.QubitSum(wires=wires).decomposition()),
             ]
         else:
             ops = [qml.StatePrep(input_state, wires=[0, 1, 2]), qml.QubitSum(wires=wires)]
diff --git a/tests/templates/test_embeddings/test_amplitude.py b/tests/templates/test_embeddings/test_amplitude.py
index 5cf0f47c8..859feb114 100644
--- a/tests/templates/test_embeddings/test_amplitude.py
+++ b/tests/templates/test_embeddings/test_amplitude.py
@@ -59,7 +59,7 @@ class TestDecomposition:
         """Checks the queue for the default settings."""
 
         op = qml.AmplitudeEmbedding(features=FEATURES[0], wires=range(2))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(tape.operations) == 1
         assert tape.operations[0].name == "StatePrep"
@@ -70,7 +70,7 @@ class TestDecomposition:
 
         op = qml.AmplitudeEmbedding(features=BROADCASTED_FEATURES[0], wires=range(2))
         assert op.batch_size == 3
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(tape.operations) == 1
         assert tape.operations[0].name == "StatePrep"
diff --git a/tests/templates/test_embeddings/test_angle.py b/tests/templates/test_embeddings/test_angle.py
index 2d7bf5b0f..93cfdaccc 100644
--- a/tests/templates/test_embeddings/test_angle.py
+++ b/tests/templates/test_embeddings/test_angle.py
@@ -59,7 +59,7 @@ class TestDecomposition:
         """Checks the queue for the default settings."""
 
         op = qml.AngleEmbedding(features=features, wires=range(4))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(tape.operations) == len(features)
         for gate in tape.operations:
@@ -73,7 +73,7 @@ class TestDecomposition:
 
         op = qml.AngleEmbedding(features=features, wires=range(4))
         assert op.batch_size == 5
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(tape.operations) == 3
         for gate in tape.operations:
@@ -86,7 +86,7 @@ class TestDecomposition:
         """Checks the queue for the specified rotation settings."""
 
         op = qml.AngleEmbedding(features=[1, 1, 1], wires=range(4), rotation=rotation)
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for gate in tape.operations:
             assert gate.name == "R" + rotation
diff --git a/tests/templates/test_embeddings/test_basis.py b/tests/templates/test_embeddings/test_basis.py
index 81ea1b526..31bc736cf 100644
--- a/tests/templates/test_embeddings/test_basis.py
+++ b/tests/templates/test_embeddings/test_basis.py
@@ -54,7 +54,7 @@ class TestDecomposition:
         """Checks the queue."""
 
         op = qml.BasisEmbedding(features=features, wires=range(3))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(tape.operations) == features.count(1)
         for gate in tape.operations:
diff --git a/tests/templates/test_embeddings/test_displacement_emb.py b/tests/templates/test_embeddings/test_displacement_emb.py
index 2700df62e..9c9769ab4 100644
--- a/tests/templates/test_embeddings/test_displacement_emb.py
+++ b/tests/templates/test_embeddings/test_displacement_emb.py
@@ -54,7 +54,7 @@ class TestDecomposition:
         """Checks the queue for the default settings."""
 
         op = qml.DisplacementEmbedding(features=features, wires=range(3))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(tape.operations) == len(features)
         for idx, gate in enumerate(tape.operations):
diff --git a/tests/templates/test_embeddings/test_iqp_emb.py b/tests/templates/test_embeddings/test_iqp_emb.py
index c19731c77..274e9e3e7 100644
--- a/tests/templates/test_embeddings/test_iqp_emb.py
+++ b/tests/templates/test_embeddings/test_iqp_emb.py
@@ -49,7 +49,7 @@ class TestDecomposition:
         features = list(range(n_wires))
 
         op = qml.IQPEmbedding(features, wires=range(n_wires))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         j = 0
         for i, gate in enumerate(tape.operations):
@@ -67,7 +67,7 @@ class TestDecomposition:
 
         op = qml.IQPEmbedding(features, wires=range(n_wires))
         assert op.batch_size == 3
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         j = 0
         for i, gate in enumerate(tape.operations):
@@ -87,7 +87,7 @@ class TestDecomposition:
         expected_wires = self.QUEUES[2][2] + self.QUEUES[2][2]
 
         op = qml.IQPEmbedding(features, wires=range(3), n_repeats=2)
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for i, gate in enumerate(tape.operations):
             assert gate.name == expected_names[i]
@@ -112,7 +112,7 @@ class TestDecomposition:
         expected_wires = [[0], [0], [1], [1], [2], [2], *pattern]
 
         op = qml.IQPEmbedding(features, wires=range(3), pattern=pattern)
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for i, gate in enumerate(tape.operations):
             assert gate.name == expected_names[i]
diff --git a/tests/templates/test_embeddings/test_qaoa_emb.py b/tests/templates/test_embeddings/test_qaoa_emb.py
index 92909c35f..4a56f14b1 100644
--- a/tests/templates/test_embeddings/test_qaoa_emb.py
+++ b/tests/templates/test_embeddings/test_qaoa_emb.py
@@ -76,7 +76,7 @@ class TestDecomposition:
         weights = np.zeros(shape=weight_shape)
 
         op = qml.QAOAEmbedding(features, weights, wires=range(n_wires))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for i, gate in enumerate(tape.operations):
             assert gate.name == expected_names[i]
@@ -94,7 +94,7 @@ class TestDecomposition:
         # Only broadcast features
         op = qml.QAOAEmbedding(broadcasted_features, weights, wires=range(n_wires))
         assert op.batch_size == n_broadcast
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for i, gate in enumerate(tape.operations):
             assert gate.name == expected_names[i]
@@ -106,7 +106,7 @@ class TestDecomposition:
         # Only broadcast weights
         op = qml.QAOAEmbedding(features, broadcasted_weights, wires=range(n_wires))
         assert op.batch_size == n_broadcast
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for i, gate in enumerate(tape.operations):
             assert gate.name == expected_names[i]
@@ -118,7 +118,7 @@ class TestDecomposition:
         # Broadcast weights and features
         op = qml.QAOAEmbedding(broadcasted_features, broadcasted_weights, wires=range(n_wires))
         assert op.batch_size == n_broadcast
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for i, gate in enumerate(tape.operations):
             assert gate.name == expected_names[i]
@@ -134,7 +134,7 @@ class TestDecomposition:
         weights = np.zeros(shape=(1, 3))
 
         op = qml.QAOAEmbedding(features, weights, wires=range(2), local_field=local_field)
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
         gate_names = [gate.name for gate in tape.operations]
 
         assert gate_names[3] == get_name[local_field]
diff --git a/tests/templates/test_embeddings/test_squeezing_emb.py b/tests/templates/test_embeddings/test_squeezing_emb.py
index 4486ee7cd..198905e66 100644
--- a/tests/templates/test_embeddings/test_squeezing_emb.py
+++ b/tests/templates/test_embeddings/test_squeezing_emb.py
@@ -54,7 +54,7 @@ class TestDecomposition:
         """Checks the queue for the default settings."""
 
         op = qml.SqueezingEmbedding(features=features, wires=range(3))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         assert len(tape.operations) == len(features)
         for idx, gate in enumerate(tape.operations):
diff --git a/tests/templates/test_layers/test_basic_entangler.py b/tests/templates/test_layers/test_basic_entangler.py
index 4bce90322..3f672917b 100644
--- a/tests/templates/test_layers/test_basic_entangler.py
+++ b/tests/templates/test_layers/test_basic_entangler.py
@@ -54,7 +54,7 @@ class TestDecomposition:
         weights = np.random.random(size=weight_shape)
 
         op = qml.BasicEntanglerLayers(weights, wires=range(n_wires))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         for i, gate in enumerate(tape.operations):
             assert gate.name == expected_names[i]
@@ -67,7 +67,7 @@ class TestDecomposition:
         weights = np.zeros(shape=(1, 2))
 
         op = qml.BasicEntanglerLayers(weights, wires=range(2), rotation=rotation)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert rotation in [type(gate) for gate in queue]
 
diff --git a/tests/templates/test_layers/test_cv_neural_net.py b/tests/templates/test_layers/test_cv_neural_net.py
index ddb4c35a2..d9946cf67 100644
--- a/tests/templates/test_layers/test_cv_neural_net.py
+++ b/tests/templates/test_layers/test_cv_neural_net.py
@@ -76,7 +76,7 @@ class TestDecomposition:
         weights = [np.random.random(shape) for shape in shapes]
 
         op = qml.CVNeuralNetLayers(*weights, wires=range(n_wires))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         i = 0
         for gate in tape.operations:
@@ -85,7 +85,7 @@ class TestDecomposition:
                 assert gate.wires.labels == tuple(expected_wires[i])
                 i = i + 1
             else:
-                for gate_inter in gate.expand().operations:
+                for gate_inter in gate.decomposition():
                     assert gate_inter.name == expected_names[i]
                     assert gate_inter.wires.labels == tuple(expected_wires[i])
                     i = i + 1
diff --git a/tests/templates/test_layers/test_gate_fabric.py b/tests/templates/test_layers/test_gate_fabric.py
index ae14dc173..a69a8fe42 100644
--- a/tests/templates/test_layers/test_gate_fabric.py
+++ b/tests/templates/test_layers/test_gate_fabric.py
@@ -72,7 +72,7 @@ class TestDecomposition:
         op = qml.GateFabric(
             weights, wires=range(qubits), init_state=init_state, include_pi=include_pi
         )
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         # number of gates
         assert len(queue) == n_gates
diff --git a/tests/templates/test_layers/test_particle_conserving_u1.py b/tests/templates/test_layers/test_particle_conserving_u1.py
index 0f9c23cdc..7e46abe87 100644
--- a/tests/templates/test_layers/test_particle_conserving_u1.py
+++ b/tests/templates/test_layers/test_particle_conserving_u1.py
@@ -90,7 +90,7 @@ class TestDecomposition:
         nm_wires += [wires[l : l + 2] for l in range(1, qubits - 1, 2)]
 
         op = qml.ParticleConservingU1(weights, wires, init_state=np.array([1, 1, 0, 0]))
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert gate_count == len(queue)
 
diff --git a/tests/templates/test_layers/test_particle_conserving_u2.py b/tests/templates/test_layers/test_particle_conserving_u2.py
index 54e92914a..c6c88bbfe 100644
--- a/tests/templates/test_layers/test_particle_conserving_u2.py
+++ b/tests/templates/test_layers/test_particle_conserving_u2.py
@@ -57,7 +57,7 @@ class TestDecomposition:
         ) * layers
 
         op = qml.ParticleConservingU2(weights, wires=range(qubits), init_state=init_state)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         # number of gates
         assert len(queue) == n_gates
diff --git a/tests/templates/test_layers/test_random.py b/tests/templates/test_layers/test_random.py
index 42a7accc3..9d9763074 100644
--- a/tests/templates/test_layers/test_random.py
+++ b/tests/templates/test_layers/test_random.py
@@ -83,11 +83,11 @@ class TestDecomposition:
         op2 = qml.RandomLayers(weights, wires=range(2), seed=42)
         op3 = qml.RandomLayers(weights, wires=range(2), seed=42)
 
-        queue1 = op1.expand().operations
+        queue1 = op1.decomposition()
         decomp1 = op1.compute_decomposition(*op1.parameters, wires=op1.wires, **op1.hyperparameters)
-        queue2 = op2.expand().operations
+        queue2 = op2.decomposition()
         decomp2 = op2.compute_decomposition(*op2.parameters, wires=op2.wires, **op2.hyperparameters)
-        queue3 = op3.expand().operations
+        queue3 = op3.decomposition()
         decomp3 = op3.compute_decomposition(*op3.parameters, wires=op3.wires, **op3.hyperparameters)
 
         assert not all(g1.name == g2.name for g1, g2 in zip(queue1, queue2))
@@ -106,7 +106,7 @@ class TestDecomposition:
         weights = np.random.randn(n_layers, n_rots)
 
         op = qml.RandomLayers(weights, wires=range(2))
-        ops = op.expand().operations
+        ops = op.decomposition()
 
         gate_names = [g.name for g in ops]
         assert len(gate_names) - gate_names.count("CNOT") == n_layers * n_rots
@@ -131,7 +131,7 @@ class TestDecomposition:
         weights = np.random.random(size=(2, n_rots))
 
         op = qml.RandomLayers(weights, wires=range(3))
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         gate_wires = [gate.wires.labels for gate in queue]
         wires_flat = [item for w in gate_wires for item in w]
diff --git a/tests/templates/test_layers/test_simplified_twodesign.py b/tests/templates/test_layers/test_simplified_twodesign.py
index abe9ca025..1580fb42a 100644
--- a/tests/templates/test_layers/test_simplified_twodesign.py
+++ b/tests/templates/test_layers/test_simplified_twodesign.py
@@ -64,7 +64,7 @@ class TestDecomposition:
         initial_layer = np.random.randn(n_wires)
 
         op = qml.SimplifiedTwoDesign(initial_layer, weights, wires=range(n_wires))
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         for i, gate in enumerate(queue):
             assert gate.name == expected_names[i]
@@ -81,7 +81,7 @@ class TestDecomposition:
         weights = np.random.randn(*shape_weights)
 
         op = qml.SimplifiedTwoDesign(initial_layer, weights, wires=range(n_wires))
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         # test the device parameters
         for _ in range(n_layers):
diff --git a/tests/templates/test_layers/test_strongly_entangling.py b/tests/templates/test_layers/test_strongly_entangling.py
index ed9839b84..393786b3d 100644
--- a/tests/templates/test_layers/test_strongly_entangling.py
+++ b/tests/templates/test_layers/test_strongly_entangling.py
@@ -67,7 +67,7 @@ class TestDecomposition:
         weights = np.random.random(size=weight_shape)
 
         op = qml.StronglyEntanglingLayers(weights, wires=range(n_wires))
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         if batch_dim is None:
             param_sets = iter(weights.reshape((-1, 3)))
@@ -93,7 +93,7 @@ class TestDecomposition:
         weights = np.random.randn(*shape)
 
         op = qml.StronglyEntanglingLayers(weights=weights, wires=range(n_wires), imprimitive=qml.CZ)
-        ops = op.expand().operations
+        ops = op.decomposition()
 
         gate_names = [gate.name for gate in ops]
         assert gate_names.count("CZ") == n_wires * n_layers
@@ -134,7 +134,7 @@ class TestDecomposition:
         weights = np.random.randn(*shape)
 
         op = qml.StronglyEntanglingLayers(weights=weights, wires=range(n_wires), ranges=ranges)
-        ops = op.expand().operations
+        ops = op.decomposition()
 
         gate_wires = [gate.wires.labels for gate in ops]
         range_idx = 0
diff --git a/tests/templates/test_state_preparations/test_arbitrary_state_prep.py b/tests/templates/test_state_preparations/test_arbitrary_state_prep.py
index 8191dbc5f..e12f1dc5f 100644
--- a/tests/templates/test_state_preparations/test_arbitrary_state_prep.py
+++ b/tests/templates/test_state_preparations/test_arbitrary_state_prep.py
@@ -79,7 +79,7 @@ class TestDecomposition:
         weights = np.array([0, 1], dtype=float)
 
         op = qml.ArbitraryStatePreparation(weights, wires=[0])
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert queue[0].name == "PauliRot"
 
@@ -97,7 +97,7 @@ class TestDecomposition:
         weights = np.array([0, 1, 2, 3, 4, 5], dtype=float)
 
         op = qml.ArbitraryStatePreparation(weights, wires=[0, 1])
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert queue[0].name == "PauliRot"
 
diff --git a/tests/templates/test_state_preparations/test_basis_state_prep.py b/tests/templates/test_state_preparations/test_basis_state_prep.py
index f7dcd2a2e..90b88463a 100644
--- a/tests/templates/test_state_preparations/test_basis_state_prep.py
+++ b/tests/templates/test_state_preparations/test_basis_state_prep.py
@@ -55,7 +55,7 @@ class TestDecomposition:
         """Tests queue for simple cases."""
 
         op = qml.BasisStatePreparation(basis_state, wires)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         for id, gate in enumerate(queue):
             assert gate.name == "PauliX"
diff --git a/tests/templates/test_state_preparations/test_cosine_window.py b/tests/templates/test_state_preparations/test_cosine_window.py
index 2941d9f6b..a9bfa87fc 100644
--- a/tests/templates/test_state_preparations/test_cosine_window.py
+++ b/tests/templates/test_state_preparations/test_cosine_window.py
@@ -38,7 +38,7 @@ class TestDecomposition:
         """Test that the correct gates are applied."""
 
         op = qml.CosineWindow(wires=[0])
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert queue[0].name == "Hadamard"
         assert queue[1].name == "RZ"
diff --git a/tests/templates/test_state_preparations/test_qutrit_basis_state_prep.py b/tests/templates/test_state_preparations/test_qutrit_basis_state_prep.py
index c52d5d334..987550795 100644
--- a/tests/templates/test_state_preparations/test_qutrit_basis_state_prep.py
+++ b/tests/templates/test_state_preparations/test_qutrit_basis_state_prep.py
@@ -58,7 +58,7 @@ class TestDecomposition:
         """Tests queue for simple cases."""
 
         op = qml.QutritBasisStatePreparation(basis_state, wires)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         for id, gate in enumerate(queue):
             assert gate.name == "TShift"
diff --git a/tests/templates/test_subroutines/test_all_singles_doubles.py b/tests/templates/test_subroutines/test_all_singles_doubles.py
index b303beab5..7d2086313 100644
--- a/tests/templates/test_subroutines/test_all_singles_doubles.py
+++ b/tests/templates/test_subroutines/test_all_singles_doubles.py
@@ -99,7 +99,7 @@ class TestDecomposition:
         hf_state = np.array([1, 1, 0, 0, 0, 0])
 
         op = qml.AllSinglesDoubles(weights, wires, hf_state, singles=singles, doubles=doubles)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert len(queue) == len(singles) + len(doubles) + 1
 
diff --git a/tests/templates/test_subroutines/test_approx_time_evolution.py b/tests/templates/test_subroutines/test_approx_time_evolution.py
index 80f6b962b..426233126 100644
--- a/tests/templates/test_subroutines/test_approx_time_evolution.py
+++ b/tests/templates/test_subroutines/test_approx_time_evolution.py
@@ -116,7 +116,7 @@ class TestDecomposition:
         """Tests that the sequence of gates implemented in the ApproxTimeEvolution template is correct"""
 
         op = qml.ApproxTimeEvolution(hamiltonian, time, steps)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         for expected_gate, gate in zip(expected_queue, queue):
             qml.assert_equal(expected_gate, gate)
diff --git a/tests/templates/test_subroutines/test_basis_rotation.py b/tests/templates/test_subroutines/test_basis_rotation.py
index 9578c75f6..c5c9c6434 100644
--- a/tests/templates/test_subroutines/test_basis_rotation.py
+++ b/tests/templates/test_subroutines/test_basis_rotation.py
@@ -86,7 +86,7 @@ class TestDecomposition:
             gate_wires.append(list(indices))
 
         op = qml.BasisRotation(wires=range(num_wires), unitary_matrix=unitary_matrix)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert len(queue) == len(gate_ops)  # number of gates
 
diff --git a/tests/templates/test_subroutines/test_commuting_evolution.py b/tests/templates/test_subroutines/test_commuting_evolution.py
index a578e2d19..96950dcc2 100644
--- a/tests/templates/test_subroutines/test_commuting_evolution.py
+++ b/tests/templates/test_subroutines/test_commuting_evolution.py
@@ -89,7 +89,7 @@ def test_decomposition_expand():
     assert qml.math.allclose(decomp.hyperparameters["hamiltonian"].data, hamiltonian.data)
     assert decomp.hyperparameters["n"] == 1
 
-    tape = op.expand()
+    tape = op.decomposition()
     assert len(tape) == 1
     assert isinstance(tape[0], qml.ApproxTimeEvolution)
 
diff --git a/tests/templates/test_subroutines/test_double_excitation.py b/tests/templates/test_subroutines/test_double_excitation.py
index c55a6db49..d299b7ac9 100644
--- a/tests/templates/test_subroutines/test_double_excitation.py
+++ b/tests/templates/test_subroutines/test_double_excitation.py
@@ -203,7 +203,7 @@ class TestDecomposition:
         cnots = 16 * (len(wires1) - 1 + len(wires2) - 1 + 1)
         weight = np.pi / 3
         op = qml.FermionicDoubleExcitation(weight, wires1=wires1, wires2=wires2)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert len(queue) == sqg + cnots
 
diff --git a/tests/templates/test_subroutines/test_grover.py b/tests/templates/test_subroutines/test_grover.py
index 3bb39e116..3ff3755a8 100644
--- a/tests/templates/test_subroutines/test_grover.py
+++ b/tests/templates/test_subroutines/test_grover.py
@@ -47,7 +47,7 @@ def test_work_wires():
 
     assert op.hyperparameters["work_wires"] == work_wire
 
-    ops = op.expand().operations
+    ops = op.decomposition()
 
     assert ops[2].hyperparameters["work_wires"] == work_wire
 
@@ -191,7 +191,7 @@ def test_expand(wires):
     """Asserts decomposition uses expected operations and wires"""
     op = qml.GroverOperator(wires=wires)
 
-    decomp = op.expand().operations
+    decomp = op.decomposition()
 
     expected_wires = decomposition_wires(wires)
 
diff --git a/tests/templates/test_subroutines/test_interferometer.py b/tests/templates/test_subroutines/test_interferometer.py
index 9f31ab989..6221d6f69 100644
--- a/tests/templates/test_subroutines/test_interferometer.py
+++ b/tests/templates/test_subroutines/test_interferometer.py
@@ -70,7 +70,7 @@ class TestInterferometer:
             theta, phi, varphi, mesh="triangular", beamsplitter="clements", wires=wires
         )
 
-        for rec in [op_rect.expand(), op_tria.expand()]:
+        for rec in [op_rect.decomposition(), op_tria.decomposition()]:
             assert len(rec) == 4
 
             assert isinstance(rec[0], qml.Rotation)
@@ -90,7 +90,7 @@ class TestInterferometer:
         varphi = [0.42342]
 
         op = qml.Interferometer(theta=[], phi=[], varphi=varphi, wires=0)
-        rec = op.expand()
+        rec = op.decomposition()
 
         assert len(rec) == 1
         assert isinstance(rec[0], qml.Rotation)
@@ -107,7 +107,7 @@ class TestInterferometer:
         varphi = [0.42342, 0.1121]
 
         op = qml.Interferometer(theta, phi, varphi, wires=wires)
-        rec = op.expand()
+        rec = op.decomposition()
 
         isinstance(rec[0], qml.Beamsplitter)
         assert rec[0].parameters == theta + phi
@@ -129,7 +129,7 @@ class TestInterferometer:
         varphi = [0.42342, 0.1121]
 
         op = qml.Interferometer(theta, phi, varphi, mesh="triangular", wires=wires)
-        rec = op.expand()
+        rec = op.decomposition()
 
         assert len(rec) == 3
 
@@ -155,7 +155,7 @@ class TestInterferometer:
         op_tria = qml.Interferometer(theta, phi, varphi, wires=wires, mesh="triangular")
 
         # Test rectangular mesh
-        rec = op_rect.expand()
+        rec = op_rect.decomposition()
         assert len(rec) == 6
 
         expected_bs_wires = [[0, 1], [1, 2], [0, 1]]
@@ -171,7 +171,7 @@ class TestInterferometer:
             assert op.wires == Wires([idx])
 
         # Test triangular mesh
-        rec = op_tria.expand()
+        rec = op_tria.decomposition()
         assert len(rec) == 6
 
         expected_bs_wires = [[1, 2], [0, 1], [1, 2]]
@@ -196,7 +196,7 @@ class TestInterferometer:
         varphi = [0.42342, 0.234, 0.4523, 0.1121]
 
         op = qml.Interferometer(theta, phi, varphi, wires=wires)
-        rec = op.expand()
+        rec = op.decomposition()
 
         assert len(rec) == 10
 
@@ -222,7 +222,7 @@ class TestInterferometer:
         varphi = [0.42342, 0.234, 0.4523, 0.1121]
 
         op = qml.Interferometer(theta, phi, varphi, wires=wires, mesh="triangular")
-        rec = op.expand()
+        rec = op.decomposition()
 
         assert len(rec) == 10
 
diff --git a/tests/templates/test_subroutines/test_kupccgsd.py b/tests/templates/test_subroutines/test_kupccgsd.py
index 17e9eddbd..ca1ce3f6d 100644
--- a/tests/templates/test_subroutines/test_kupccgsd.py
+++ b/tests/templates/test_subroutines/test_kupccgsd.py
@@ -91,7 +91,7 @@ class TestDecomposition:
         exp_unitary += [qml.FermionicSingleExcitation] * len(gen_single_terms_wires)
 
         op = qml.kUpCCGSD(weights, wires=wires, k=k, delta_sz=delta_sz, init_state=init_state)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         # number of gates
         assert len(queue) == n_gates
diff --git a/tests/templates/test_subroutines/test_qmc.py b/tests/templates/test_subroutines/test_qmc.py
index 0353f84b4..9a5b18f3c 100644
--- a/tests/templates/test_subroutines/test_qmc.py
+++ b/tests/templates/test_subroutines/test_qmc.py
@@ -297,7 +297,7 @@ class TestQuantumMonteCarlo:
         target_wires, estimation_wires = Wires(range(3)), Wires(range(3, 5))
 
         op = QuantumMonteCarlo(p, self.func, target_wires, estimation_wires)
-        tape = op.expand()
+        tape = qml.tape.QuantumScript(op.decomposition())
 
         # Do expansion in two steps to avoid also decomposing the first QubitUnitary
         queue_before_qpe = tape.operations[:2]
diff --git a/tests/templates/test_subroutines/test_qpe.py b/tests/templates/test_subroutines/test_qpe.py
index 7611348a6..af3d941a8 100644
--- a/tests/templates/test_subroutines/test_qpe.py
+++ b/tests/templates/test_subroutines/test_qpe.py
@@ -112,7 +112,7 @@ class TestDecomposition:
         m = qml.RX(0.3, wires=0).matrix()
 
         op = qml.QuantumPhaseEstimation(m, target_wires=[0], estimation_wires=[1, 2])
-        qscript = op.expand()
+        qscript = qml.tape.QuantumScript(op.decomposition())
 
         unitary = qml.QubitUnitary(m, wires=[0])
         with qml.queuing.AnnotatedQueue() as q:
diff --git a/tests/templates/test_subroutines/test_single_excitation.py b/tests/templates/test_subroutines/test_single_excitation.py
index 5d181cd39..f63b9ef0a 100644
--- a/tests/templates/test_subroutines/test_single_excitation.py
+++ b/tests/templates/test_subroutines/test_single_excitation.py
@@ -98,7 +98,7 @@ class TestDecomposition:
         cnots = 4 * (len(single_wires) - 1)
         weight = np.pi / 3
         op = qml.FermionicSingleExcitation(weight, wires=single_wires)
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         assert len(queue) == sqg + cnots
 
diff --git a/tests/templates/test_subroutines/test_uccsd.py b/tests/templates/test_subroutines/test_uccsd.py
index 35d86f03d..f335851bd 100644
--- a/tests/templates/test_subroutines/test_uccsd.py
+++ b/tests/templates/test_subroutines/test_uccsd.py
@@ -190,7 +190,7 @@ class TestDecomposition:
             init_state=ref_state,
             n_repeats=n_repeats,
         )
-        raw_queue = op.expand().operations
+        raw_queue = op.decomposition()
 
         # hack to avoid updating the test data:
         # expand the other templates, which now
@@ -198,7 +198,7 @@ class TestDecomposition:
         queue = []
         for op in raw_queue:
             if op.name in ["FermionicSingleExcitation", "FermionicDoubleExcitation"]:
-                queue.extend(op.expand().operations)
+                queue.extend(op.decomposition())
             else:
                 queue.append(op)
 
diff --git a/tests/templates/test_swapnetworks/test_ccl2.py b/tests/templates/test_swapnetworks/test_ccl2.py
index b77c324b5..e3ebf8e83 100644
--- a/tests/templates/test_swapnetworks/test_ccl2.py
+++ b/tests/templates/test_swapnetworks/test_ccl2.py
@@ -80,7 +80,7 @@ class TestDecomposition:
         op = qml.templates.TwoLocalSwapNetwork(
             wire_order, acquaintances, weights, fermionic=fermionic, shift=shift
         )
-        queue = op.expand().operations
+        queue = op.decomposition()
 
         # number of gates
         assert len(queue) == sum(
diff --git a/tests/test_operation.py b/tests/test_operation.py
index 4750b8feb..5fae0e13a 100644
--- a/tests/test_operation.py
+++ b/tests/test_operation.py
@@ -321,6 +321,21 @@ class TestOperatorConstruction:
         assert op._ndim_params == (ndim_params,)
         assert op.ndim_params == (0,)
 
+    def test_expand_deprecated(self):
+
+        class MyOp(qml.operation.Operation):
+            num_wires = 1
+            has_decomposition = True
+
+            @staticmethod
+            def compute_decomposition(*params, wires=None, **hyperparameters):
+                return [qml.Hadamard(wires=wires)]
+
+        op = MyOp(wires=0)
+
+        with pytest.warns(qml.PennyLaneDeprecationWarning, match="'Operator.expand' is deprecated"):
+            op.expand()
+
 
 class TestPytreeMethods:
     def test_pytree_defaults(self):