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

Abierto
#473 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@TheGupta2012 ya está trabajando en esto.

Desde el 19/11/2026.

  • #492 de @TheGupta2012 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
29
Forks
33
Merge medio
1 d 20 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de qBraid/pyqasm

Todos los issues de qBraid/pyqasm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.