Skip to content

fix: decompose p, phaseshift and u1 as a single rz - #470

Merged
TheGupta2012 merged 1 commit into
qBraid:mainfrom
tonycoder-hub:fix-phaseshift-rz
Oct 30, 2026
Merged

TheGupta2012 merged 1 commit into
qBraid:mainfrom
tonycoder-hub:fix-phaseshift-rz

Conversation

@tonycoder-hub

@tonycoder-hub tonycoder-hub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changes

Fixes #469

phaseshift_gate expanded p, phaseshift and u1 into h; rx(θ); h. A single rz(θ) is the same gate up to a global phase, so it now emits that. A user-written p(pi/4) then rebases to a single t under CLIFFORD_T, and p(pi/2) to s, instead of five gates.

Changes:

  • src/pyqasm/maps/gates.py: phaseshift_gate returns one rz(theta). This also shortens csx and rccx, which call it.
  • docs/gate_decompositions.md: updated the Phaseshift section and its source link.
  • Tests: new regression tests for QASM 3 p/phaseshift/u1, QASM 2 p/u1, Clifford+T rebase of p(pi/4)/p(pi/2)/phaseshift/u1, and full csx/rccx unitaries. Updated the expectations in test_depth.py, test_device_qubits.py and the _check_phase_shift_gate_op helper that hardcoded the old three-gate form.
  • CHANGELOG.md entry.

On the global phase: controlled phase gates don't go through this function. ctrl @ p and cp/cphaseshift/cu1 use cphaseshift_gate. Controlled custom gates pass their controls down to each body statement. ctrl @ gphase with two or more controls becomes cp. So the dropped phase stays global. The csx and rccx unitaries are checked exactly in the new tests.

Test plan

@argus-eye

argus-eye Bot commented Oct 28, 2026

Copy link
Copy Markdown

Argus review

Auto-review is off for this repo. Tick the box below to run a review on this PR.

  • Trigger Argus review

Estimated cost

  • Files changed: 9
  • Diff lines (±): 184
  • Historical avg: ~336.9k tokens · ~$1.17 · across last 18 review(s)

Tip: you can also comment @argus-eye review at any time.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: qBraid/pyqasm
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: dc1b320
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b651e784-8b07-43f9-892e-ed68c829f823

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

unroll expanded p/phaseshift/u1 into h; rx(theta); h. A single rz(theta)
is the same gate up to a global phase, so use that instead. This also
lets rebase map p(pi/4) and p(pi/2) straight to t and s under
CLIFFORD_T, and shortens the csx and rccx decompositions.

Signed-off-by: Tony Coder <407243179@qq.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TheGupta2012
TheGupta2012 merged commit 7fd5e7e into qBraid:main Oct 30, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants