`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 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 天前认领,目前没有进行中的 PR。 未关闭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`可能已有人在做 @madcpf 于 2 天前认领。 未关闭
难度 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
-
难度 2/5 1-3 小时 新手友好度 76/100
521xueweihan/HelloGitHub#4729 ·
-
auto-reported bug
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
needs-triage type:bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
pollen-robotics/reachy_mini_conversation_app#631 ·
维护者通常 7 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100