`reduce_t_depth` aborts with an assertion when three equal π/8 rotations are merged
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 57/100
Direzione di ricerca
Start with mlir/lib/PBC/Transforms/TLayerReduction.cpp, especially checkCommutationAndFindMerge and mergePPR, then review mlir/test/PBC/TLayerReduction.mlir. Run the catalyst --tool=opt --reduce-t-depth command from the report on the three-rotation example. Done when the pass handles three equal π/8 rotations without aborting and a regression test covers the case.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Issue description
reduce_t_depth aborts the compilation when three π/8 rotations with the same Pauli word and the same sign are merged into one rotation of an earlier layer. The first merge turns that rotation into a π/4 rotation. The next equal π/8 rotation is merged into the same op, and mergePPR fails its assertion that both ops have the same rotation kind. With Catalyst 0.15.0 four T gates are enough: T(0); T(1); T(0); T(0).
-
Expected behavior: The program compiles. For example, two of the three rotations are merged into a π/4 rotation and the third one is kept.
-
Actual behavior:
CompileError: catalyst failed with error code -6: Assertion failed: (rhsOp.getRotationKind() == mergeOp.getRotationKind() && "expected same rotation kind"), function mergePPR, file TLayerReduction.cpp, line 140. -
Reproduces how often: Always.
-
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)
With the development wheel pennylane-catalyst 0.16.0.dev48 the first program of the script below compiles and the second one aborts in the same way. The frontend of that build puts a qubit back into the register and extracts it again when the next gate acts on another wire, and reduce_t_depth then leaves the first program unchanged. The .mlir function below aborts with the catalyst tool of both builds. On main at 60970d7 the two functions involved differ from v0.15.0 only in formatting; I did not build main.
Source code and tracebacks
import numpy as np
import pennylane as qp
dev = qp.device("lightning.qubit", wires=2)
to_ppr, reduce_t_depth = qp.transforms.to_ppr, qp.transforms.reduce_t_depth
stage = dict(target="mlir", pipelines=[("pipe", ["quantum-compilation-stage"])])
def four_t_gates():
qp.T(0)
qp.T(1)
qp.T(0)
qp.T(0)
return qp.probs()
def five_rotations():
qp.PauliRot(np.pi / 4, "ZZ", wires=[0, 1])
qp.PauliRot(np.pi / 4, "XX", wires=[0, 1])
qp.PauliRot(np.pi / 4, "XY", wires=[0, 1])
qp.PauliRot(np.pi / 4, "ZZ", wires=[0, 1])
qp.PauliRot(np.pi / 4, "ZZ", wires=[0, 1])
return qp.probs()
def rotations(f):
text = qp.qjit(capture=True, **stage)(f).mlir_opt
return "; ".join(line.strip().split(" = ")[1].split(" : ")[0] for line in text.split("\n") if "pbc.ppr" in line)
for circuit in (four_t_gates, five_rotations):
f = to_ppr(qp.qnode(dev)(circuit))
print(circuit.__name__)
print(" to_ppr :", rotations(f))
try:
print(" to_ppr, reduce_t_depth :", rotations(reduce_t_depth(f)))
except Exception as e:
print(" to_ppr, reduce_t_depth :", type(e).__name__, str(e).split("\n")[0])
Output with Catalyst 0.15.0:
four_t_gates
to_ppr : pbc.ppr ["Z"](8) %1; pbc.ppr ["Z"](8) %3; pbc.ppr ["Z"](8) %2; pbc.ppr ["Z"](8) %5
to_ppr, reduce_t_depth : CompileError catalyst failed with error code -6: Assertion failed: (rhsOp.getRotationKind() == mergeOp.getRotationKind() && "expected same rotation kind"), function mergePPR, file TLayerReduction.cpp, line 140.
five_rotations
to_ppr : pbc.ppr ["Z", "Z"](8) %1, %2; pbc.ppr ["X", "X"](8) %3#0, %3#1; pbc.ppr ["X", "Y"](8) %4#0, %4#1; pbc.ppr ["Z", "Z"](8) %5#0, %5#1; pbc.ppr ["Z", "Z"](8) %6#0, %6#1
to_ppr, reduce_t_depth : CompileError catalyst failed with error code -6: Assertion failed: (rhsOp.getRotationKind() == mergeOp.getRotationKind() && "expected same rotation kind"), function mergePPR, file TLayerReduction.cpp, line 140.
Output with pennylane-catalyst 0.16.0.dev48:
four_t_gates
to_ppr : pbc.ppr ["Z"](8) %1; pbc.ppr ["Z"](8) %4; pbc.ppr ["Z"](8) %7; pbc.ppr ["Z"](8) %8
to_ppr, reduce_t_depth : pbc.ppr ["Z"](8) %1; pbc.ppr ["Z"](8) %4; pbc.ppr ["Z"](8) %7; pbc.ppr ["Z"](8) %8
five_rotations
to_ppr : pbc.ppr ["Z", "Z"](8) %1, %2; pbc.ppr ["X", "X"](8) %3#0, %3#1; pbc.ppr ["X", "Y"](8) %4#0, %4#1; pbc.ppr ["Z", "Z"](8) %5#0, %5#1; pbc.ppr ["Z", "Z"](8) %6#0, %6#1
to_ppr, reduce_t_depth : CompileError catalyst failed with error code -6: Assertion failed: (rhsOp.getRotationKind() == mergeOp.getRotationKind() && "expected same rotation kind"), function mergePPR, file TLayerReduction.cpp, line 140.
The same with the compiler alone. catalyst --tool=opt --reduce-t-depth three_rotations.mlir aborts with the same assertion for this file:
func.func @three_rotations(%q0: !quantum.bit, %q1: !quantum.bit) -> (!quantum.bit, !quantum.bit) {
%0 = pbc.ppr ["Z"](8) %q0 : !quantum.bit
%1 = pbc.ppr ["Z"](8) %q1 : !quantum.bit
%2 = pbc.ppr ["X"](8) %1 : !quantum.bit
%3 = pbc.ppr ["Z"](8) %0 : !quantum.bit
%4 = pbc.ppr ["Z"](8) %3 : !quantum.bit
return %4, %2 : !quantum.bit, !quantum.bit
}
Without the last rotation (%4) the tool merges %0 and %3 into pbc.ppr ["Z"](4), as expected.
Additional information
Cause, as far as I can tell. checkCommutationAndFindMerge takes a rotation of the previous layer as the merge candidate when the Pauli words and the signs are equal. It does not compare the rotation kinds:
mergePPR asserts that both kinds are equal and then halves the kind of the candidate:
After the first merge the candidate has kind 4. The second π/8 rotation has kind 8 and equals the candidate in word and sign, so it reaches the assertion. Reading the code, a build without assertions would halve the kind once more and turn three T gates into pbc.ppr ["Z"](2); I did not run such a build.
The pass only acts when there is more than one layer. In the first program the second layer starts at T(1), because qubit 1 is extracted from the register after the first T gate. In the .mlir function it starts at the X rotation, which does not commute with the Z rotation on the same qubit.
mlir/test/PBC/TLayerReduction.mlir has no function with three equal rotations. One of its seven functions has a merge of two.
This is separate from #3487. There the pass returns a different program, here it aborts.
For scale: of 6,000 random programs (4 to 24 operations on 1 to 3 qubits), 13 abort with this assertion under to_ppr followed by reduce_t_depth, or under to_ppr, commute_ppr, merge_ppr_ppm followed by reduce_t_depth. Reduced to a minimal program, each of the 13 has three π/8 rotations with the same word and sign on one qubit.
Following the PennyLane AI tool use policy: this report was drafted with an AI assistant. I reviewed it and ran the examples myself.
- Lingua principale
- Python
- Stelle
- 234
- Fork
- 84
- Merge medio
- 3g 11h
- PR unite (30g)
- 78
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PennyLaneAI/catalyst
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
PennyLaneAI/catalyst#3489 ·
I maintainer di solito rispondono entro 1 giorno
-
Fix platform tag for macOS wheelsForse di nuovo libera @sarehaskari17 l’ha presa 107 giorni fa e non c’è nessuna pull request aperta. ApertaCI/Build enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
PennyLaneAI/catalyst#2907 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
The docs page for `CompileOptions` is missing a description for the `target` attributeForse già presa @daxsh2803 l’ha presa 68 giorni fa. Apertadocumentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
PennyLaneAI/catalyst#2653 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
PennyLaneAI/catalyst#3550 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Bug: `create_encode_subroutine` omits the Z correction, so `qecl.encode ["zero"]` does not prepare the logical zero stateForse già presa @pragati903 l’ha presa 18 giorni fa. Apertabug good first issue
PennyLaneAI/catalyst#3492 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PennyLaneAI/catalyst
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
521xueweihan/HelloGitHub#4729 ·
-
auto-reported bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
cliproxy-quota: a tab around a credential email skips own-accounts and paced-accounts matchingApertaneeds-triage type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
pollen-robotics/reachy_mini_conversation_app#631 ·
I maintainer di solito rispondono entro 7 giorni
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100