Skip to content

Conversation

@Vivek1106-04
Copy link

Description:
This PR addresses Issue #6327 by optimizing the __pow__ method for both CliffordGate and SingleQubitCliffordGate.

Changes proposed in this PR:

  1. CliffordGate Optimization:

    • Replaced the $O(N)$ linear loop with Binary Exponentiation (exponentiation by squaring).
    • This reduces the complexity to $O(\log N)$, significantly improving performance for large exponents.
    • Added a safety check to ensure result_tableau is initialized independently to avoid reference aliasing bugs.
  2. SingleQubitCliffordGate Optimization:

    • Integer Powers: Leveraged the group structure of single-qubit Cliffords (size 24). All integer exponents are now reduced modulo 24 before calculation.
    • Rational Powers: Added support for half-integer exponents (e.g., gate**2.5). The logic decomposes $G^{k/2}$ into $(G^{0.5})^k$ and recursively calls the optimized integer power function.
    • Added type checking to ensure invalid inputs (like strings) return NotImplemented.

Related Issue:
Fixes #6327

@Vivek1106-04 Vivek1106-04 requested review from a team and vtomole as code owners November 21, 2025 18:58
@Vivek1106-04 Vivek1106-04 requested a review from maffoo November 21, 2025 18:58
@github-actions github-actions bot added the size: M 50< lines changed <250 label Nov 21, 2025
@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (4d75b4b) to head (c127a01).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7766   +/-   ##
=======================================
  Coverage   99.57%   99.57%           
=======================================
  Files        1102     1102           
  Lines       98434    98436    +2     
=======================================
+ Hits        98014    98016    +2     
  Misses        420      420           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve __pow__ for SingleQubitCliffordGate and CliffordGate class

1 participant