Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[FEATURE] Decompose `p`, `phaseshift` and `u1` as `rz` instead of `h; rx; h`

Đã đóng
#469 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

Một pull request liên quan đã được merge.

  • #470 của @tonycoder-hub — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
compilers

Hướng nghiên cứu

Start with phaseshift_gate and ONE_QUBIT_ROTATION_MAP in src/pyqasm/maps/gates.py, then read the phaseshift-gate section of docs/gate_decompositions.md and inspect the existing decomposition tests. Verify single-gate unrolling and the CLIFFORD_T rebases for p(pi/4) and p(pi/2). Run the unitary checks for the changed decomposition, including csx and rccx, and confirm they match up to global phase.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement
Feature Description

unroll decomposes p, phaseshift and u1 into three gates, h; rx(θ); h. A single rz(θ) gives the same gate up to a global phase. The longer form then grows during rebase, because each h expands again:

Input Basis Output on main Output for the same gate written as rz
p(0.3) q[0]; ROTATIONAL_CX 5 gates: ry(π/2); rx(π); rx(0.3); ry(π/2); rx(π) rz(0.3)
p(pi/4) q[0]; CLIFFORD_T 5 gates: h; h; t; h; h t
p(pi/2) q[0]; CLIFFORD_T 5 gates: h; h; s; h; h s

Reproduction on main at a742796, Python 3.12:

import pyqasm
from pyqasm.elements import BasisSet

src = 'OPENQASM 3.0;\ninclude "stdgates.inc";\nqubit[1] q;\np(pi/4) q[0];\n'
m = pyqasm.loads(src)
m.rebase(BasisSet.CLIFFORD_T)
print(pyqasm.dumps(m))  # h q[0]; h q[0]; t q[0]; h q[0]; h q[0];

OpenQASM 2 programs that use qelib1.inc unroll p and u1 the same way.

The decomposition is phaseshift_gate. ONE_QUBIT_ROTATION_MAP maps u1, U1, phaseshift and p to it. The csx and rccx decompositions also call it seven times in total.

A related point: #468 adds a p rule to rebase. Unroll rewrites a p gate written by the user before rebase sees it, so that rule only applies to the p gates that pyqasm generates itself.

Done when:

  • A single p(θ), phaseshift(θ) or u1(θ) unrolls to one gate.
  • Under CLIFFORD_T, p(pi/4) rebases to t and p(pi/2) rebases to s.
  • The unitary of each changed decomposition, including csx and rccx, still matches the original up to a global phase.
Implementation (Optional)

One option is to make phaseshift_gate emit rz(θ). gate_decompositions.md documents the current form and needs the same update. rz(θ) and p(θ) differ only by a global phase. That should be safe here, because ctrl @ p resolves to cp before this decomposition runs. This reasoning is not verified against the full test suite.

Ngôn ngữ chính
Python
Star
29
Fork
33
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
16

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 qBraid/pyqasm

Tất cả issue của qBraid/pyqasm

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.