`tfq_ps_decompose` corrupts `PhasedISwapPowGate` when `exponent` is numeric and `phase_exponent` is symbolic
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python, tensorflow
调研方向
阅读 tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc,尤其是 getOpForISP 以及它在 TfqPsDecomposeOp::Compute 中调用 tfq_ps_decompose 的位置。对比它与 getOpForPXP、getOpForPISP 和 getOpForFSIM 处理符号指数和数值指数的方式。使用提供的电路和参数解析示例复现问题;当分解后的操作保留正确的数值指数,并且在解析时不再出现所报告的错误,即表示完成。
由索引模型根据 Issue 内容生成。
描述
In TfqPsDecomposeOp::Compute (tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc, lines 75–97), a PISP (cirq.PhasedISwapPowGate) operation is decomposed whenever either exponent or phase_exponent is symbolic (Arg::ArgCase::kSymbol):
if (exponent.arg_case() == Arg::ArgCase::kSymbol ||
phase_exponent.arg_case() == Arg::ArgCase::kSymbol) {
// Decompose cirq.PhasedISwapPowGate only if it is
// parameterized.
num_extra_moments = 5;
Operation new_op;
new_op = getOpForPISP(cur_op, 0, 0);
cur_moment.mutable_operations()->at(k) = new_op;
new_op = getOpForPISP(cur_op, 1, 1);
*temp_moment_list[0].add_operations() = new_op;
new_op = getOpForISP(cur_op, "XXP", exponent.symbol());
*temp_moment_list[1].add_operations() = new_op;
new_op = getOpForISP(cur_op, "YYP", exponent.symbol());
*temp_moment_list[2].add_operations() = new_op;
new_op = getOpForPISP(cur_op, 1, 0);
*temp_moment_list[3].add_operations() = new_op;
new_op = getOpForPISP(cur_op, 0, 1);
*temp_moment_list[4].add_operations() = new_op;
}
However, getOpForISP (lines 164–187) was written for ISP, where exponent is guaranteed to be symbolic, and unconditionally writes new_op_map["exponent"].set_symbol(symbol).
When phase_exponent is a sympy.Symbol and exponent is a numeric constant (Arg::ArgCase::kArgValue — including Cirq's default exponent=1.0, or any non-unit float such as 0.5):
exponent.symbol()evaluates to""(empty string), andexponent.arg_value().float_value()is ignored.- The decomposed
XXPandYYPoperations receive a symbolicexponentwith empty symbol name""(sympy.Symbol('')after deserialization) instead of a numeric float-0.5 * exponent.arg_value().float_value(). - Resolving circuit parameters leaves unresolved
sympy.Symbol('')expressions on theXXPowGateandYYPowGateoperations, corrupting the decomposed circuit and breakingParameterShiftdifferentiation wheneverPhasedISwapPowGatehas a symbolicphase_exponentand numericexponent.
Minimal Reproduction
import cirq
import sympy
import tensorflow_quantum as tfq
from tensorflow_quantum.core.ops import tfq_ps_util_ops
q0, q1 = cirq.GridQubit.rect(1, 2)
beta = sympy.Symbol("beta")
# Numeric exponent with symbolic phase_exponent.
circuit = cirq.Circuit(
cirq.PhasedISwapPowGate(phase_exponent=beta, exponent=0.5).on(q0, q1)
)
decomposed_tensor = tfq_ps_util_ops.tfq_ps_decompose(
tfq.convert_to_tensor([circuit])
)
decomposed_circuit = tfq.from_tensor(decomposed_tensor)[0]
print(decomposed_circuit)
# Raises TypeError because XXPowGate and YYPowGate contain sympy.Symbol('').
cirq.unitary(cirq.resolve_parameters(decomposed_circuit, {"beta": 0.72}))
Observed decomposed circuit:
(0, 0): ───Z^beta───────────────XX───────────YY───────────Z^(-beta)────────────
│ │
(0, 1): ────────────Z^(-beta)───XX^(-0.5*)───YY^(-0.5*)───────────────Z^beta───
Possible Fix
Update getOpForISP to read exponent from cur_op directly (or accept const Arg& instead of std::string symbol) and switch on exponent.arg_case(), consistent with getOpForPXP, getOpForPISP, and getOpForFSIM: keep set_symbol(...) and exponent_scalar = -0.5 * cur_exponent_scalar for Arg::ArgCase::kSymbol, and set exponent to -0.5 * exponent.arg_value().float_value() with exponent_scalar = 1.0 for Arg::ArgCase::kArgValue.
- 主要语言
- Python
- 星标
- 2.2k
- 派生
- 674
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/quantum 的其他 Issue
-
Avoid hard-coding "quantum" in `scripts/` scripts可能已有人在做 @openbotgit 于 23 天前认领。 未关闭area/devops help wanted no QC knowledge needed priority/before-0.7.7
难度 2/5 1-3 小时 新手友好度 68/100
tensorflow/quantum#1082 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
area/c++ area/core kind/bug-report
难度 3/5 1-2 天 新手友好度 74/100
tensorflow/quantum#1141 ·
维护者通常 1 天内回复
-
Bug (likely typo) in `core/serialize/serializer_test.py`可能已有人在做 @mhucka 于 15 天前认领。 未关闭area/serialization area/tests
tensorflow/quantum#1129 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Support Keras 3可能重新可做 @rosspeili 于 118 天前认领,目前没有进行中的 PR。 未关闭area/keras help wanted skill-level/intermediate
tensorflow/quantum#1090 · 5 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
area/circuits priority/after-0.7.7 skill-level/expert
难度 5/5 一周以上 新手友好度 25/100
tensorflow/quantum#1087 ·
维护者通常 1 天内回复
查看 tensorflow/quantum 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
UKGovernmentBEIS/inspect_ai#6512 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
Kav-K/GPTDiscord#501 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
UKGovernmentBEIS/inspect_evals#2863 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: graphify query loads every language extractor just for _file_stem (about 34 ms per call)可能已有人在做 @rohit-jsfreaky 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
Graphify-Labs/graphify#5160 · 1 条评论 ·
维护者通常 2 天内回复