`tfq_ps_decompose` truncates decomposed moments when `PhasedISwapPowGate` shares a `Moment` with `PhasedXPowGate` or `FSimGate`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 74/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python, tensorflow
- Lĩnh vực
- backend, machine-learning, testing-qa
Hướng nghiên cứu
Read tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc, especially TfqPsDecomposeOp::Compute around lines 71–147, and inspect the decomposition tests for tfq_ps_decompose. Reproduce the issue with the supplied circuit and compare the original and decomposed unitaries. Done means the output retains all six moments and the decomposed circuit matches the original unitary for the reproducer.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In TfqPsDecomposeOp::Compute (tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc, lines 71–147), each Moment initializes int num_extra_moments = 0; and decomposes parameterized gates across cur_moment plus up to max_buffer_moments = 5 extra moments in temp_moment_list:
PISP(cirq.PhasedISwapPowGate, line 82) populatestemp_moment_list[0..4]and setsnum_extra_moments = 5;.ISP(cirq.ISwapPowGate, line 102) populatestemp_moment_list[0]and guards the update withif (num_extra_moments == 0) num_extra_moments = 1;.PXP(cirq.PhasedXPowGate, line 115) populatestemp_moment_list[0..1]and unconditionally assignsnum_extra_moments = 2;.FSIM(cirq.FSimGate, line 130) populatestemp_moment_list[0..1]and unconditionally assignsnum_extra_moments = 2;.
If a single Moment contains a parameterized PhasedISwapPowGate followed by a parameterized PhasedXPowGate or FSimGate on disjoint qubits, the later PXP or FSIM branch overwrites num_extra_moments from 5 down to 2. When extra moments are appended at lines 142–147, temp_moment_list[2] (YYP), temp_moment_list[3] (ZP), and temp_moment_list[4] (ZP) from the PhasedISwapPowGate decomposition are silently dropped, changing the circuit unitary and producing incorrect ParameterShift gradients.
Minimal Reproduction
import cirq
import numpy as np
import sympy
import tensorflow_quantum as tfq
from tensorflow_quantum.core.ops import tfq_ps_util_ops
q0, q1, q2 = cirq.GridQubit.rect(1, 3)
alpha = sympy.Symbol("alpha")
beta = sympy.Symbol("beta")
circuit = cirq.Circuit(
cirq.Moment(
cirq.PhasedISwapPowGate(phase_exponent=beta, exponent=alpha).on(q0, q1),
cirq.PhasedXPowGate(phase_exponent=beta, exponent=alpha).on(q2),
)
)
decomposed_tensor = tfq_ps_util_ops.tfq_ps_decompose(
tfq.convert_to_tensor([circuit])
)
decomposed_circuit = tfq.from_tensor(decomposed_tensor)[0]
print("Moment count (expected 6, got):", len(decomposed_circuit.moments))
print(decomposed_circuit)
resolver = {"alpha": 0.35, "beta": 0.72}
u_orig = cirq.unitary(cirq.resolve_parameters(circuit, resolver))
u_decomp = cirq.unitary(cirq.resolve_parameters(decomposed_circuit, resolver))
print("Max unitary difference:", np.max(np.abs(u_orig - u_decomp)))
Observed output:
Moment count (expected 6, got): 3
(0, 0): ───Z^beta──────────────────XX────────────────
│
(0, 1): ───────────────Z^(-beta)───XX^(-0.5*alpha)───
(0, 2): ───Z^(-beta)───X^alpha─────Z^beta────────────
Max unitary difference: 1.400898757622091
Possible Fix
Include <algorithm> and update num_extra_moments using std::max across all decomposed gate branches (num_extra_moments = std::max(num_extra_moments, 5); for PISP, 1 for ISP, and 2 for PXP and FSIM) so earlier decompositions in the same Moment are never truncated.
Related: #1140
- Ngôn ngữ chính
- Python
- Star
- 2.2k
- Fork
- 674
- Merge trung bình
- 1 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tensorflow/quantum
-
area/c++ area/core kind/bug-report
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
tensorflow/quantum#1140 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Avoid hard-coding "quantum" in `scripts/` scriptsCó thể đã có người làm @openbotgit đã nhận 23 ngày trước. Đang mởarea/devops help wanted no QC knowledge needed priority/before-0.7.7
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
tensorflow/quantum#1082 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug (likely typo) in `core/serialize/serializer_test.py`Có thể đã có người làm @mhucka đã nhận 15 ngày trước. Đang mởarea/serialization area/tests
tensorflow/quantum#1129 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support Keras 3Có thể làm lại được @rosspeili đã nhận 118 ngày trước và không có pull request nào đang mở. Đang mởarea/keras help wanted skill-level/intermediate
tensorflow/quantum#1090 · 5 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support dynamic quantum circuitsĐang mởarea/circuits priority/after-0.7.7 skill-level/expert
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
tensorflow/quantum#1087 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của tensorflow/quantum
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
UKGovernmentBEIS/inspect_ai#6512 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
Kav-K/GPTDiscord#501 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
UKGovernmentBEIS/inspect_evals#2863 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: graphify query loads every language extractor just for _file_stem (about 34 ms per call)Có thể đã có người làm @rohit-jsfreaky đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Graphify-Labs/graphify#5160 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày