Repository: PennyLaneAI/pennylane
Pull request #7004 (2025-02-25 16:47:45)

Deprecate pipeline=None with qml.compile
**Context:**

Currently, `qml.compile` has a default of `pipeline=None`, where `None` implies `(commute_controlled, cancel_inverses, merge_rotations, remove_barrier)`.  This is confusing, as `None` usually means "nothing".

**Description of the Change:**

Sets the default value to `(commute_controlled, cancel_inverses, merge_rotations, remove_barrier)` and deprecates passing `pipeline=None`.

**Benefits:**

Easier to determine default value from the call siganture.

**Possible Drawbacks:**

Just to make sure this looks good in the docs.

<img width="801" alt="Screenshot 2025-02-25 at 12 03 08 PM" src="https://github.com/user-attachments/assets/c975363a-cb01-442b-9ed7-a0b732800cf0" />

Is a deprecation.

**Related GitHub Issues:**

[sc-85186]


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/7004?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.59%. Comparing base [(`4a5d44f`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/4a5d44f0a85496c0456f9fee66ca21efb9fcd72d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) to head [(`103ed88`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/103ed88a82db8057bc298d57c8ec59f28dca77df?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).
> Report is 3 commits behind head on master.

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


```diff
@@           Coverage Diff           @@
##           master    #7004   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files         483      483           
  Lines       46066    46069    +3     
=======================================
+ Hits        45881    45884    +3     
  Misses        185      185           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/7004?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/development/deprecations.rst b/doc/development/deprecations.rst
index 2ca63fe33..bee8b3b80 100644
--- a/doc/development/deprecations.rst
+++ b/doc/development/deprecations.rst
@@ -9,6 +9,11 @@ deprecations are listed below.
 Pending deprecations
 --------------------
 
+* Specifying ``pipeline=None`` with ``qml.compile`` is now deprecated.
+
+  - Deprecated in v0.41
+  - Will be removed in v0.42
+
 * The ``ControlledQubitUnitary`` will stop accepting `QubitUnitary` objects as arguments as its ``base``. Instead, use ``qml.ctrl`` to construct a controlled `QubitUnitary`.
 
   - Deprecated in v0.41
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 0f54c9828..80691ca89 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -302,6 +302,10 @@
 
 <h3>Deprecations 👋</h3>
 
+* Specifying `pipeline=None` with `qml.compile` is now deprecated. A sequence of
+  transforms should always be specified.
+  [(#7004)](https://github.com/PennyLaneAI/pennylane/pull/7004)
+
 * The ``ControlledQubitUnitary`` will stop accepting `QubitUnitary` objects as arguments as its ``base``. Instead, use ``qml.ctrl`` to construct a controlled `QubitUnitary`.
   A folllow-on PR fixed accidental double-queuing when using `qml.ctrl` with `QubitUnitary`.
   [(#6840)](https://github.com/PennyLaneAI/pennylane/pull/6840)
diff --git a/pennylane/transforms/compile.py b/pennylane/transforms/compile.py
index 9205ab9d1..a97960df5 100644
--- a/pennylane/transforms/compile.py
+++ b/pennylane/transforms/compile.py
@@ -12,8 +12,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 """Code for the high-level quantum function transform that executes compilation."""
+from collections.abc import Sequence
+
 # pylint: disable=too-many-branches
 from functools import partial
+from warnings import warn
 
 import pennylane as qml
 from pennylane.ops import __all__ as all_ops
@@ -28,12 +31,15 @@ from pennylane.transforms.optimization import (
 )
 from pennylane.typing import PostprocessingFn
 
-default_pipeline = [commute_controlled, cancel_inverses, merge_rotations, remove_barrier]
+default_pipeline = (commute_controlled, cancel_inverses, merge_rotations, remove_barrier)
 
 
 @transform
 def compile(
-    tape: QuantumScript, pipeline=None, basis_set=None, num_passes=1
+    tape: QuantumScript,
+    pipeline: Sequence[TransformDispatcher] = default_pipeline,
+    basis_set=None,
+    num_passes=1,
 ) -> tuple[QuantumScriptBatch, PostprocessingFn]:
     """Compile a circuit by applying a series of transforms to a quantum function.
 
@@ -48,7 +54,7 @@ def compile(
 
     Args:
         tape (QNode or QuantumTape or Callable): A quantum circuit.
-        pipeline (list[Callable]): A list of
+        pipeline (Sequence[TransformDispatcher]): A list of
             tape and/or quantum function transforms to apply.
         basis_set (list[str]): A list of basis gates. When expanding the tape,
             expansion will continue until gates in the specific set are
@@ -166,6 +172,10 @@ def compile(
 
     # Ensure that everything in the pipeline is a valid qfunc or tape transform
     if pipeline is None:
+        warn(
+            "Specifying pipeline=None is now deprecated. Please specify a sequence of transforms",
+            qml.PennyLaneDeprecationWarning,
+        )
         pipeline = default_pipeline
     else:
         for p in pipeline:


Test patch:
diff --git a/tests/transforms/test_compile.py b/tests/transforms/test_compile.py
index e8090ebf0..bea56df3e 100644
--- a/tests/transforms/test_compile.py
+++ b/tests/transforms/test_compile.py
@@ -50,6 +50,14 @@ def build_qfunc(wires):
     return qfunc
 
 
+def test_deprecation_pipeline_None():
+    """Test that specifying `pipeline=None` is deprecated."""
+
+    tape = qml.tape.QuantumScript()
+    with pytest.warns(qml.PennyLaneDeprecationWarning, match="pipeline=None is now deprecated"):
+        qml.compile(tape, pipeline=None)
+
+
 class TestCompile:
     """Unit tests for compile function."""