`ReflectionUsingPrepare.adjoint()` returns `self` for non-real `global_phase`
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- numpy, python
調査の方向性
Read qualtran/bloqs/reflections/reflection_using_prepare.py around adjoint() and review the linked pull request #2010 to see the current work. Run the issue’s reproducer for non-real global_phase and check that composing the gate with its adjoint gives the identity; add or run a regression test for that case.
索引モデルが issue の本文から書いたものです。
説明
ReflectionUsingPrepare implements g·(I − 2|s⟩⟨s|) with g = global_phase. For a non-real g the adjoint is conj(g)·(I − 2|s⟩⟨s|), but adjoint() returns self:
Uncontrolled, the difference is only a global phase g². With control_val set (or after .controlled()), g is a relative phase, so R followed by R.adjoint() applies a controlled g² instead of the identity. Real g (1 and −1) is unaffected. I found no validator that restricts global_phase to real values.
Reproducer
import itertools, numpy as np, cirq
from qualtran.bloqs.reflections.prepare_identity import PrepareIdentity
from qualtran.bloqs.reflections.reflection_using_prepare import ReflectionUsingPrepare
from qualtran.cirq_interop.testing import GateHelper
def unitary(gate):
g = GateHelper(gate)
ctx = cirq.DecompositionContext(cirq.GreedyQubitManager(prefix="anc"))
c = cirq.Circuit(cirq.decompose(g.operation, context=ctx))
sys_q = list(itertools.chain(*g.quregs.values()))
order = sys_q + sorted(c.all_qubits() - set(sys_q))
U = c.unitary(qubit_order=order)
n, a = len(sys_q), len(order) - len(sys_q)
return U.reshape(2**n, 2**a, 2**n, 2**a)[:, 0, :, 0] # ancillas in |0>
R = ReflectionUsingPrepare(PrepareIdentity.from_bitsizes([2]), control_val=1, global_phase=1j)
U, V = unitary(R), unitary(R.adjoint())
print(np.linalg.norm(U @ V - np.eye(8))) # prints 4.0, expected about 0
With global_phase=1 or -1 the same script prints about 3e-15.
Suggested fix
def adjoint(self) -> 'ReflectionUsingPrepare':
return attrs.evolve(self, global_phase=np.conj(self.global_phase))
With this change U @ V is the identity to about 3e-15 in the cases I tested.
Version
qualtran 0.7.0. The file is identical to main at f559b12 for these lines.
I'm happy to open a pull request with the fix and a test if that's useful. I found this with AI-assisted code review and confirmed by running the script above.
- 主要言語
- Python
- スター
- 397
- フォーク
- 127
- 平均マージ
- 2日 22時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
quantumlib/Qualtran のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
quantumlib/Qualtran#2007 ·
-
Addition call_graph inconsistent with decomposition for registers with unequal bitsizes再び着手できるかも @rupasri118 が 67 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンkind/bug-report
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
quantumlib/Qualtran#1818 · コメント 2 件 ·
-
Classical simulation fails for a QROAM with block size 1 on one axis: 0-bit `BQUInt` breaks `Partition`対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 75/100
quantumlib/Qualtran#2008 ·
-
kickmix: `Circuit.reaction_depth()` materialises every op (≈ 135–170 B/op transient), limiting verifiable circuit size対応中かも @manwithacat が 38 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
quantumlib/Qualtran#1993 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
quantumlib/Qualtran#1991 ·
quantumlib/Qualtran の issue をすべて見る
似ている issue
-
auto-reported bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
backend bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
nolte/kamerplanter#3193 ·
メンテナーはふだん 1 日以内に返信
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwise対応中かも @abdulwaarith0 が今日担当しました。 オープンneeds-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
MakazhanAlpamys/Soup#3690 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信