Move the QASM 2 printer and its branch pre-processing out of qasm2.py
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 22/100
- Tipo de issue
- Refactorización
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- compilers, quantum-computing
Línea de trabajo
Start in src/pyqasm/modules/qasm2.py, where Qasm2Printer and the helpers _flatten_branch, _collapse_broadcast_measurement and _filter_branch sit, then read tests/qasm2/test_branching.py. Done means the printer lives in its own module, _filter_branch and the printer share one definition of what QASM 2 can express, and the suite passes without changing expected output. Pull request #454 is already open and the issue depends on #338, so check those before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Feature Description
Follow-up to #338. That PR fixes QASM 2 branch output with a Qasm2Printer in src/pyqasm/modules/qasm2.py. The fix works, but it grows qasm2.py from 216 to 564 lines. Most of the growth is module-level helpers that pre-process the unrolled AST before printing:
_parse_branch_condition,_add_chain_constraint,_flatten_branch— walk the unroller's per-bitifchain back into oneif (creg == int)comparison._collapse_broadcast_measurement,_single_index,_writes_to_register— rebuildmeasure q -> cfrom per-bit measurements and guard multi-statement bodies._creg_sizes,_qreg_sizes,_qasm3_repr,_unsupported_condition_message— supporting lookups and error text.
These helpers mix three concerns in one file: the Qasm2Module class, QASM 2 validation, and QASM 2 serialization. Qasm2Module._filter_branch also calls _flatten_branch and discards the result, only to reuse its exceptions.
This issue moves the helpers and Qasm2Printer out of qasm2.py and simplifies their design. Behavior must not change.
Acceptance criteria
-
Qasm2Printerand the branch pre-processing helpers live in a separate module.qasm2.pykeeps onlyQasm2Moduleand imports what it needs. - Validation (
_filter_branch) and printing still share one definition of what QASM 2 can express, sovalidate()is never stricter or looser than the printer. - Helpers with one caller fold into it, or get a clear name and docstring if they stay separate.
-
tests/qasm2/test_branching.pyand the rest of the suite pass without changes to expected output or error messages.
Out of scope
Ideally, qasm2.py should not need this pre-processing at all. The unroller ravels if (c == 2) into a nested per-bit chain, and the printer then undoes that work. A cleaner fix is an unroller that keeps QASM 2 branches in their original form. That change touches the visitor and is larger, so this issue keeps the pre-processing and only relocates and simplifies it.
Implementation (Optional)
src/pyqasm/printer.pyalready holds circuit drawing, so the new code needs a different name. One option issrc/pyqasm/modules/qasm2_printer.py._flatten_branchcould return a small dataclass (register, value, body) in place of a tuple, and expose a separate check function for_filter_branch.
Depends on #338 merging first.
- Lenguaje dominante
- Python
- Estrellas
- 29
- Forks
- 33
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 15
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de qBraid/pyqasm
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
Los mantenedores suelen responder en 1 día
-
enhancement error-handling program-validation
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASMPosiblemente ocupada @Jah-yee la tomó hace 18 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
qBraid/pyqasm#438 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lostPosiblemente ocupada @tonycoder-hub la tomó hace 11 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 22/100
qBraid/pyqasm#436 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`extern port` / `extern frame` in `cal` blocks fail to parse, blocking nearly every spec OpenPulse examplePosiblemente ocupada @Riiocodee la tomó hace 4 días. Abiertobug llm-assisted qasm3 qasm3-coverage
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
qBraid/pyqasm#401 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de qBraid/pyqasm
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
aws-samples/sample-per-model-bedrock#464 ·
Los mantenedores suelen responder en 1 día
-
lesson-submission pending-review
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Ikalus1988/MisakaNet#3789 ·
Los mantenedores suelen responder en 1 día
-
Python Volcengine provider returns failures instead of raising themPosiblemente ocupada @Ricardo-M-L la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
agent-infra/sandbox#248 ·
-
[Bug] cloud JSON directory loading assumes a Key field in fsspec listingsPosiblemente ocupada @Ricardo-M-L la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
hiyouga/LlamaFactory#10910 ·
Los mantenedores suelen responder en 1 día
-
Bundled uv is never updated and trusts the compromised eMudhra certificatesPosiblemente ocupada @FabienDanieau la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100