Move the QASM 2 printer and its branch pre-processing out of qasm2.py
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 22/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 29
- フォーク
- 33
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
qBraid/pyqasm のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
メンテナーはふだん 1 日以内に返信
-
enhancement error-handling program-validation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM対応中かも @Jah-yee が 15 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
qBraid/pyqasm#438 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lost対応中かも @tonycoder-hub が 9 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 22/100
qBraid/pyqasm#436 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`extern port` / `extern frame` in `cal` blocks fail to parse, blocking nearly every spec OpenPulse example対応中かも @Riiocodee が 2 日前に担当しました。 オープンbug llm-assisted qasm3 qasm3-coverage
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
qBraid/pyqasm#401 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
521xueweihan/HelloGitHub#4063 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Vanilla-OS/apx-gui#112 ·
-
Devstral and Voxtral: section 5 fails in us-east-1 with 400 "Model does not support audio modality"オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws-samples/sample-per-model-bedrock#409 ·
メンテナーはふだん 1 日以内に返信
-
DuckDB 2.0 breaks to_pyarrow_batches対応中かも @DG47 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ibis-project/ibis#12196 ·
メンテナーはふだん 1 日以内に返信