[FEATURE] Implement Circuit Segmentation via `.segment()` Method
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start from QasmModule and loads in the pyqasm package to see how a parsed program stores its qubit registers and gate statements. The new .segment() method needs a union-find over qubits joined by multi-qubit gates, then emits one QasmModule per component with remapped __PYQASM_SEGMENT_<idx>__ registers. Done means the example in the issue produces the two shown segments and that measurements or classical controls raise an error. The single-qubit edge case and the return-type question are unresolved in the thread, so confirm them with the maintainers first.
索引モデルが issue の本文から書いたものです。
説明
Feature Description
-
Introduce a .segment() method to
pyqasm.QasmModulethat partitions quantum circuits into independent segments where no entanglement exists between segments. -
Each segment is returned as a standalone
QasmModuleobject containing:- Remapped qubit registers (e.g., PYQASM_SEGMENT_0[i])
- Gates acting exclusively on the segment's qubits
-
Key constraints:
- We use entangling gates to define an "independently executable segment". Raises an error if the circuit contains measurements or classical controls (unsupported in v1).
- Qubit order in new registers follows first occurrence in the original circuit.
Motivation
- Parallel Execution: Enables independent segment execution across multiple QPUs.
- Resource Optimization: Splits large circuits for execution on smaller devices.
- Error Containment: Isolates quantum errors to individual segments.
Implementation (Optional)
Preprocessing:
-
Validate absence of measurements/classical controls.
-
Construct a qubit connectivity graph using multi-qubit gates (edges connect interacting qubits).
Segmentation Algorithm:
-
Identify connected components in the graph → segments. Should essentially be a disjoint set union amongst all the qubits present in our program. Inspired by the
BlockSplitterin qiskit'sdag_circuit.collect_blocks -
For each segment:
-
Create a new register
qubit[N] __PYQASM_SEGMENT_<idx>__(N = segment qubit count). -
Remap original qubits to new register indices ordered by first gate occurrence.
-
Module Generation:
- Clone original module headers (OPENQASM 3.0, includes).
- Replace original gates with remapped operations.
- Preserve gate order within segments.
Edge Cases:
- All Single-qubit gates → Divide into a default segment count (say 10) as all qubits are disjoint
- Empty circuits → No OP
Example flow
from pyqasm import loads
qasm_code = """
OPENQASM 3.0;
qubit[4] q;
h q[0];
cx q[0], q[1];
h q[2];
cx q[2], q[3];
"""
module = loads(qasm_code)
segments = module.segment() # Returns 2 QasmModules
print(segments[0])
# Output:
# OPENQASM 3.0;
# qubit[2] __PYQASM_SEGMENT_0__;
# h __PYQASM_SEGMENT_0__[0];
# cx __PYQASM_SEGMENT_0__[0], __PYQASM_SEGMENT_0__[1];
print(segments[1])
# Output:
# OPENQASM 3.0;
# qubit[2] __PYQASM_SEGMENT_1__;
# h __PYQASM_SEGMENT_1__[0];
# cx __PYQASM_SEGMENT_1__[0], __PYQASM_SEGMENT_1__[1];
This is a first draft where we return a list of modules but can potentially be changed in-place addition of these segments to existing module
- 主要言語
- 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 日以内に返信
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.py対応中かも @danielgaskins が 7 日前に担当しました。 オープンenhancement qasm2
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
qBraid/pyqasm#447 · コメント 2 件 ·
メンテナーはふだん 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 日以内に返信
似ている 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 日以内に返信