`reduce_t_depth` moves and merges π/8 rotations across Clifford rotations and measurements they do not commute with
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 43/100
Research direction
Start with mlir/lib/PBC/Transforms/TLayerReduction.cpp, especially checkCommutationAndFindMerge, and trace how candidates reach the previous layer through getReachingValueAt in mlir/lib/PBC/Utils/PBCOpUtils.cpp. Then inspect mlir/test/PBC/TLayerReduction.mlir, whose current inputs omit Clifford rotations and measurements. Done when the pass preserves circuit output probabilities for both reproductions and regression tests cover rotations crossing Clifford operations and measurements.
Written by the indexing model from the issue text.
Description
Issue description
reduce_t_depth changes the result of some circuits. It moves a non-Clifford PPR into an earlier layer, or merges it with an equal PPR there, after checking commutation only against the non-Clifford PPRs of that layer. Clifford PPRs and PPMs that lie in between on the same qubits are not checked.
-
Expected behavior: The circuit has the same output probabilities with and without
reduce_t_depth. -
Actual behavior: With Catalyst 0.15.0 the probabilities change from
[0.8536 0. 0.1464 0.]to[0.7286 0.125 0.125 0.0214]. The compiled IR shows theTgate of qubit 1 moved in front of the Hadamard that precedes it. -
Reproduces how often: Always. There is no randomness in the first example.
-
System information:
Name: pennylane
Version: 0.45.1
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page:
Author:
License:
Location: <venv>/lib/python3.12/site-packages
Platform info: macOS-26.5.1-arm64-arm-64bit
Python version: 3.12.13
Numpy version: 2.5.5
Scipy version: 1.18.1
JAX version: 0.7.1
Catalyst version: 0.15.0
Installed devices:
- nvidia.custatevec (pennylane_catalyst-0.15.0)
- nvidia.cutensornet (pennylane_catalyst-0.15.0)
- oqc.cloud (pennylane_catalyst-0.15.0)
- softwareq.qpp (pennylane_catalyst-0.15.0)
- default.clifford (pennylane-0.45.1)
- default.gaussian (pennylane-0.45.1)
- default.mixed (pennylane-0.45.1)
- default.qubit (pennylane-0.45.1)
- default.qutrit (pennylane-0.45.1)
- default.qutrit.mixed (pennylane-0.45.1)
- default.tensor (pennylane-0.45.1)
- null.qubit (pennylane-0.45.1)
- reference.qubit (pennylane-0.45.1)
- lightning.qubit (pennylane_lightning-0.45.0)
The two MLIR examples below are rewritten in the same way by catalyst --tool=opt from 0.15.0 and from the development wheel pennylane-catalyst 0.16.0.dev48. The Python script does not show the difference with that wheel: through the Python frontend the pass leaves the circuit unchanged there, and it also leaves the example of the reduce_t_depth docstring unchanged. On main, mlir/lib/PBC/Transforms/TLayerReduction.cpp and mlir/lib/PBC/Utils/PBCOpUtils.cpp differ from v0.15.0 only in formatting and in how the layer is iterated (checked on 2026-11-17).
Source code and tracebacks
import numpy as np
import pennylane as qp
dev = qp.device("lightning.qubit", wires=2)
def circuit():
qp.H(1)
qp.T(0)
qp.H(1)
qp.PauliRot(np.pi / 4, "Y", wires=0)
qp.T(1)
return qp.probs()
without = qp.qjit(capture=True)(qp.transforms.to_ppr(qp.qnode(dev)(circuit)))
reduced = qp.qjit(capture=True)(qp.transforms.reduce_t_depth(qp.transforms.to_ppr(qp.qnode(dev)(circuit))))
print("to_ppr ", np.round(without(), 4))
print("to_ppr + reduce_t_depth", np.round(reduced(), 4))
Output with Catalyst 0.15.0:
to_ppr [0.8536 0. 0.1464 0. ]
to_ppr + reduce_t_depth [0.7286 0.125 0.125 0.0214]
The same on the pass alone. First example, a rotation moved across a Clifford rotation, catalyst --tool=opt --reduce-t-depth example1.mlir:
func.func @repro(%q0: !quantum.bit, %q1: !quantum.bit) -> (!quantum.bit, !quantum.bit) {
%0 = pbc.ppr ["Z"](8) %q0 : !quantum.bit
%1 = pbc.ppr ["X"](4) %q1 : !quantum.bit
%2 = pbc.ppr ["Y"](8) %0 : !quantum.bit
%3 = pbc.ppr ["Z"](8) %1 : !quantum.bit
return %2, %3 : !quantum.bit, !quantum.bit
}
Output. Z(π/8) on the second qubit is now in front of X(π/4) on the same qubit:
func.func @repro(%arg0: !quantum.bit, %arg1: !quantum.bit) -> (!quantum.bit, !quantum.bit) {
%0 = pbc.ppr ["Z"](8) %arg0 : !quantum.bit
%1 = pbc.ppr ["Z"](8) %arg1 : !quantum.bit
%2 = pbc.ppr ["X"](4) %1 : !quantum.bit
%3 = pbc.ppr ["Y"](8) %0 : !quantum.bit
return %3, %2 : !quantum.bit, !quantum.bit
}
Second example, a rotation merged across a measurement:
func.func @repro(%q0: !quantum.bit, %q1: !quantum.bit) -> (i1, !quantum.bit, !quantum.bit) {
%0 = pbc.ppr ["Z"](8) %q0 : !quantum.bit
%1 = pbc.ppr ["X"](8) %q1 : !quantum.bit
%m, %2 = pbc.ppm ["X"] %0 : i1, !quantum.bit
%3 = pbc.ppr ["Z"](8) %1 : !quantum.bit
%4 = pbc.ppr ["Z"](8) %2 : !quantum.bit
return %m, %4, %3 : i1, !quantum.bit, !quantum.bit
}
Output. The Z(π/8) after the X measurement of the first qubit is merged into the one before the measurement, which becomes Z(π/4):
func.func @repro(%arg0: !quantum.bit, %arg1: !quantum.bit) -> (i1, !quantum.bit, !quantum.bit) {
%0 = pbc.ppr ["Z"](4) %arg0 : !quantum.bit
%1 = pbc.ppr ["X"](8) %arg1 : !quantum.bit
%mres, %out_qubits = pbc.ppm ["X"] %0 : i1, !quantum.bit
%2 = pbc.ppr ["Z"](8) %1 : !quantum.bit
return %mres, %out_qubits, %2 : i1, !quantum.bit, !quantum.bit
}
Additional information
Cause, as far as I can tell. In TLayerReduction.cpp the layers contain only non-Clifford PPRs, because Clifford PPRs are skipped in the walk. checkCommutationAndFindMerge compares the candidate only with the ops of the previous layer. To do so it follows the qubits of the candidate back with getReachingValueAt (PBCOpUtils.cpp), which steps through every op that implements PBCOpInterface. A Clifford PPR or a PPM between the two layers is therefore passed over without a commutation check, and the candidate is then moved or merged in front of it.
The second pattern also occurred in a circuit compiled with to_ppr, commute_ppr, merge_ppr_ppm and then reduce_t_depth, in which a mid-circuit pauli_measure is followed by a further π/8 rotation.
The inputs in mlir/test/PBC/TLayerReduction.mlir contain only π/8 rotations, no Clifford rotation and no measurement, so these cases are not covered by the tests of the pass.
- Dominant language
- Python
- Stars
- 234
- Forks
- 84
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 84
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PennyLaneAI/catalyst
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
PennyLaneAI/catalyst#3489 ·
Maintainers usually reply within 1 day
-
Fix platform tag for macOS wheelsMay be free again @sarehaskari17 claimed this 89 days ago, and no pull request is open. OpenCI/Build enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
PennyLaneAI/catalyst#2907 · 2 comments ·
Maintainers usually reply within 1 day
-
The docs page for `CompileOptions` is missing a description for the `target` attributePossibly taken @daxsh2803 claimed this 50 days ago. Opendocumentation
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
PennyLaneAI/catalyst#2653 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
PennyLaneAI/catalyst#3488 ·
Maintainers usually reply within 1 day
-
annotate-invalid-gradient-functions fails on call chains deeper than 9 functionsPossibly taken @JohannesWittmann9 claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
PennyLaneAI/catalyst#3480 · 2 comments ·
Maintainers usually reply within 1 day
All issues in PennyLaneAI/catalyst
Similar issues
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
aws-samples/sample-spec-driven-presentation-maker#648 ·
Maintainers usually reply within 1 day
-
firestore: enable live window.yaml pipeline system tests once add_window_fields is in productionOpen
Difficulty 1/5 Under an hour Newbie friendliness 64/100
googleapis/google-cloud-python#19115 ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day