`gridsynth` fails on controlled `RZ` inside uncalled decomposition-rule functions left behind by graph decomposition
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start by reading mlir/lib/Quantum/Transforms/gridsynth.cpp and the graph-decomposition pass that leaves the unused rule functions in the module. Use the reproducer with qp.decompose followed by qp.transforms.gridsynth to confirm the failure, then inspect whether the pre-check and rewrite process unreachable functions. Done means the reproducer compiles without rejecting controlled rotations in uncalled rules.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
When qp.transforms.gridsynth runs after qp.decompose with RZ in the gate set, it can fail with
error: Unsupported controlled gate for gridsynth. Only single-qubit RZ and PhaseShift gates can be discretized.
even though the decomposed circuit contains no controlled RZ/PhaseShift.
The offending ops are all inside decomposition-rule functions that are not called. These are the distributed control rule templates, for example __builtin__rx_to_rz_ry_2C(RX){0:[f64]}{wires:1}{}. The graph-decomposition pass puts them in the module, the solver doesn't choose them (or only calls numbered copies of chosen rules), and they stay there until a later dead-symbol cleanup. If GridsynthPass runs before that cleanup, its pre-check walks the whole module:
// mlir/lib/Quantum/Transforms/gridsynth.cpp
WalkResult controlledRotation = module->walk([](CustomOp op) {
StringRef gateName = op.getGateName();
if ((gateName == "RZ" || gateName == "PhaseShift") && !op.getInCtrlQubits().empty()) {
op.emitError("Unsupported controlled gate for gridsynth. ...");
return WalkResult::interrupt();
}
...
So it rejects the dead code in the mentioned decomposition rule(s). Running symbol-dce between the two transforms fixes the failure.
Minimal reproducer
import pennylane as qp
gate_set = {"RZ", "Hadamard", "S", "CNOT", "GlobalPhase"}
@qp.qjit(capture=True)
@qp.transforms.gridsynth(epsilon=1e-3)
# @qp.transform(pass_name="symbol-dce") # uncommenting this line makes it compile
@qp.decompose(gate_set=gate_set)
@qp.qnode(qp.device("null.qubit", wires=3))
def circuit(x):
qp.ctrl(qp.RX(x, wires=0), control=[1, 2])
return qp.expval(qp.Z(0))
circuit(0.3)
(Two control wires are needed so that the op stays a generic C(RX) instead of becoming CRX. Then the distributed control rule templates (*_2C(...)) are generated.)
Actual behaviour
circuit:222:9: error: Unsupported controlled gate for gridsynth. Only single-qubit RZ and PhaseShift gates can be discretized.
circuit:222:9: note: see current operation: %15:3 = "quantum.custom"(%1, %12, %13, %14, %2, %2) <{gate_name = "RZ", operandSegmentSizes = array<i32: 1, 1, 2, 2>, resultSegmentSizes = array<i32: 1, 2>}> : (f64, !quantum.bit, !quantum.bit, !quantum.bit, i1, i1) -> (!quantum.bit, !quantum.bit, !quantum.bit)
circuit:11:14: error: pass pipeline failed
In the IR dumped at the failure (keep_intermediate=True), all 26 functions that contain a controlled RZ/PhaseShift have zero callers. Some of them:
__builtin__rx_to_rz_ry_2C(RX){0:[f64]}{wires:1}{}
__builtin__rz_to_ps_2C(RZ){0:[f64]}{wires:1}{}
__builtin__phaseshift_to_rz_gp_2C(PhaseShift){0:[f64]}{wires:1}{}
__builtin__hadamard_to_rz_ry_2C(Hadamard){}{wires:1}{}
__builtin_adjoint_rotation_2C(Adjoint(RZ)){0:[f64]}{wires:1}{}
...
The functions the circuit actually calls (e.g. __builtin_flip_zero_ctrl_values(_controlled_rx_decomp)_2C(RX)..._0, __builtin__toffoli_Toffoli..._6) contain no controlled rotations.
Expected behaviour
The circuit compiles. Gridsynth should only care about ops that can be reached from the circuit, or graph decomposition shouldn't leave unused rule functions in the module. The former seems like the more local change, but maybe we want to have the graph decomposition clean up after itself more generally?
Possible fixes
- Have
graph-decompositionremove unused rule functions (e.g. runsymbol-dce) before it returns. - And/or limit the
GridsynthPasspre-check (and the rewrite) to functions reachable from the entry point(s).
Impact
This affects any pipeline of the form decompose(gate_set ⊇ {"RZ"}) → gridsynth on circuits with generic controlled ops.
Workaround
@qp.transforms.gridsynth(...)
@qp.transform(pass_name="symbol-dce")
@qp.decompose(gate_set=...)
Environment
- PennyLane
main@059c432d94(0.46.0-dev134) - Catalyst
mainjust now (22 Oct, 8am EST) - macOS (arm64)
- 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
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
PennyLaneAI/catalyst#3497 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PennyLaneAI/catalyst
Issue simili
-
docs(contributing): the two things that silently block a PRForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaavailable documentation good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 95/100
Nixitov/Riptide-Native#944 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
JTHCode/secretguard#24 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
omarelshamy25x/shamy-hijri#63 ·
I maintainer di solito rispondono entro 1 giorno