unroll() ignores inv @ on decomposed gates (cphaseshift, cv, pswap)

Aperta
#473 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@TheGupta2012 ci sta già lavorando.

Dal 19/11/2026.

  • #492 di @TheGupta2012 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
compilers

Direzione di ricerca

The bug is in unroll() in pyqasm, which drops the inv @ modifier when decomposing cphaseshift, cv and pswap. Start by reproducing with the snippet in the issue, then find where the decomposition of these gates is emitted and how modifiers are passed through. Done when inv @ G unrolls to the reversed, individually inverted decomposition for these three gates, and a test pins the negated rz/rx angles.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Problem

unroll() drops the inv @ modifier on gates it decomposes, so the inverse comes out as the original gate. Seen with pyqasm 1.3.0 on cphaseshift, cv and pswap.

import pyqasm
for line in ["inv @ cphaseshift(0.5) q[0], q[1];", "cphaseshift(-0.5) q[0], q[1];"]:
    m = pyqasm.loads(f"OPENQASM 3.0;\nqubit[2] q;\n{line}")
    m.unroll(external_gates=["cnot"])
    print(line, "->", " ".join(pyqasm.dumps(m).splitlines()[2:4]))
inv @ cphaseshift(0.5) q[0], q[1]; -> rz(0.25) q[0]; ...
cphaseshift(-0.5) q[0], q[1]; -> rz(-0.25) q[0]; ...

The unrolled inv @ cphaseshift(0.5) is identical to cphaseshift(0.5). inv @ pswap(0.5) likewise unrolls with rz(0.5), and inv @ cv with rx(0.785…) where rx(-0.785…) is expected. No error is raised, so the program silently gets the wrong unitary. qBraid's Braket→OpenQASM 3→Qiskit route hit this (worked around in qBraid/qBraid#1533 by writing negative powers as the gate's adjoint).

Expected

inv @ G unrolls to the inverse of G's decomposition (reversed order, each gate inverted), or raises if that isn't supported.

Lingua principale
Python
Stelle
29
Fork
33
Merge medio
1g 20h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di qBraid/pyqasm

Tutte le issue di qBraid/pyqasm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.