CirqCircuit._convert_to_line_qubits merges NamedQubits whose names share an index

未關閉 適合新手
#1,553 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
tooling

研究方向

從 CirqCircuit._convert_to_line_qubits 開始,並將其行為與 #1534 中描述的 cirq_to_braket 規則進行比較。尋找涵蓋 populate_idle_qubits 的現有測試,並為衝突標籤和不符合 Cirq 順序的標籤新增回歸案例。完成意味著轉換會保留 Cirq 順序中的不同 qubit,且不改變電路。

由索引模型根據 Issue 內容生成。

描述

Problem

CirqCircuit._convert_to_line_qubits maps each NamedQubit to LineQubit(<integer in its name>). Distinct qubits with the same number collapse onto one LineQubit. populate_idle_qubits calls it for any circuit with a NamedQubit. Two registers imported from QASM (a_0, b_0) are enough to trigger it:

import cirq
from qbraid.programs.gate_model.cirq import CirqCircuit

a0, b0 = cirq.NamedQubit("a_0"), cirq.NamedQubit("b_0")
program = CirqCircuit(cirq.Circuit(cirq.H(a0), cirq.CNOT(a0, b0)))
program.populate_idle_qubits()
ValueError: Duplicate qids for <cirq.CNOT>. Expected unique qids but got <(cirq.LineQubit(0), cirq.LineQubit(0))>.

When the colliding qubits' gates are in different moments, nothing raises. Circuit(Moment(H(a_0)), Moment(X(b_0))) becomes H then X on LineQubit(0), so the circuit changes without an error. Labels that are distinct but out of Cirq's order (a_1, b_0) permute the qubits.

cirq_to_braket had the same collision and was fixed in #1534. It keeps the integer labels only when they are non-negative and rise strictly in Cirq's sorted order, and otherwise numbers the qubits 0..n-1 in that order.

Expected

_convert_to_line_qubits keeps qubits distinct and in Cirq's order. One way is to apply the same rule cirq_to_braket uses.

主要語言
Python
星號
117
分支
66
平均合併
1 天 10 小時
30 天內合併 PR
22

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

qBraid/qBraid 的其他 Issue

查看 qBraid/qBraid 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。