`tfq_ps_decompose` truncates decomposed moments when `PhasedISwapPowGate` shares a `Moment` with `PhasedXPowGate` or `FSimGate`

Đang mở
#1,141 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

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ả

area/c++ area/core kind/bug-report

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) populates temp_moment_list[0..4] and sets num_extra_moments = 5;.
  • ISP (cirq.ISwapPowGate, line 102) populates temp_moment_list[0] and guards the update with if (num_extra_moments == 0) num_extra_moments = 1;.
  • PXP (cirq.PhasedXPowGate, line 115) populates temp_moment_list[0..1] and unconditionally assigns num_extra_moments = 2;.
  • FSIM (cirq.FSimGate, line 130) populates temp_moment_list[0..1] and unconditionally assigns num_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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tensorflow/quantum

Tất cả issue của tensorflow/quantum

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.