Skip to content

⚡️ Use Gate in AE phase_estimation path#886

Merged
burgholzer merged 1 commit into
munich-quantum-toolkit:mainfrom
AxEquals-b:fix/ae-phase-estimation-gate
Apr 16, 2026
Merged

⚡️ Use Gate in AE phase_estimation path#886
burgholzer merged 1 commit into
munich-quantum-toolkit:mainfrom
AxEquals-b:fix/ae-phase-estimation-gate

Conversation

@AxEquals-b
Copy link
Copy Markdown
Contributor

Description

This PR fixes a performance issue in the ae benchmark by passing a Gate (instead of a QuantumCircuit) to phase_estimation.

What changed

  • File: src/mqt/bench/benchmarks/ae.py
  • One-line change:
    • from: pe = phase_estimation(num_eval_qubits, grover_operator)
    • to: pe = phase_estimation(num_eval_qubits, grover_operator.to_gate(label="Q"))

Why

qiskit.circuit.library.phase_estimation accepts both QuantumCircuit and Gate, and documents that passing a Gate can be more performant because control/power operations can use optimized subroutines.

Correctness validation (n = 2..16)

I compared old vs. new construction for all n in [2, 16]:

  1. Build both circuits.
  2. Remove final measurements.
  3. Compare resulting statevectors using fidelity.

Result:

  • All checks passed for n=2..16.
  • Minimum fidelity: 0.9999999999999802 (numerical precision tolerance).

Performance validation (same environment, same run, n = 2..16)

n before (s) after (s) speedup
2 0.033425 0.006768 4.9x
3 0.003550 0.003284 1.1x
4 0.005631 0.004448 1.3x
5 0.010618 0.005664 1.9x
6 0.012951 0.006786 1.9x
7 0.021017 0.007985 2.6x
8 0.036682 0.009122 4.0x
9 0.063978 0.010370 6.2x
10 0.118278 0.011781 10.0x
11 0.258973 0.013150 19.7x
12 0.544852 0.015034 36.2x
13 1.212202 0.016025 75.6x
14 2.685636 0.017285 155.4x
15 5.434519 0.018494 293.9x
16 13.701815 0.020821 658.1x

No additional dependencies are required.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • I have disclosed the use of AI tools in the PR description as per our AI Usage Guidelines.
  • AI-assisted commits include an Assisted-by: [Model Name] via [Tool Name] footer.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

Assisted-by: GPT-5.3 via codex
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0ddad19b-0938-476b-a0a5-86b5be9a9c69

📥 Commits

Reviewing files that changed from the base of the PR and between ca1df6c and 1f0d69a.

📒 Files selected for processing (1)
  • src/mqt/bench/benchmarks/ae.py

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Updated phase estimation circuit construction for improved operator representation in benchmark measurements.

Walkthrough

The phase estimation circuit now wraps the Grover operator into a named gate before passing it to the phase estimation function, changing the input type from a QuantumCircuit object to a Gate object while preserving all downstream circuit operations.

Changes

Cohort / File(s) Summary
Phase Estimation Gate Wrapping
src/mqt/bench/benchmarks/ae.py
Modified Grover operator input to phase estimation by wrapping it with to_gate(label="Q"), converting from direct QuantumCircuit to Gate representation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A gate wrapped neat in label "Q",
The Grover operator finds its view,
One line changed with careful grace,
Phase estimation finds its place! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: converting a QuantumCircuit to a Gate in the AE phase_estimation code path.
Description check ✅ Passed The description is comprehensive with detailed validation, performance data, and reasoning; however, unchecked items show tests, docs, changelog, and CI verification remain incomplete.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! 🙏

@burgholzer burgholzer merged commit 97aa30c into munich-quantum-toolkit:main Apr 16, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in MQT Applications Apr 16, 2026
@burgholzer burgholzer added the enhancement New feature or request label Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants