Skip to content

Conversation

@J4MMlE
Copy link

@J4MMlE J4MMlE commented Dec 28, 2025

Description

This PR extends the rotation merging pass in the MQTOpt dialect to support quaternion-based gate fusion. This is the first step toward closing #1029.

The existing rotation merge pass only merges consecutive rotation gates of the same type (e.g., rx + rx or ry + ry) by adding their angles.
This PR introduces quaternion-based merging, which can merge rotation gates of different types (currently only single qubit gates rx, ry, rz, u).

Quaternions are widely used to represent rotations in three-dimensional space and naturally map to qubit gate rotations around the Bloch sphere. The implementation:

  1. Converts rotation gates to quaternion representation
  2. Multiplies quaternions using the Hamilton product
  3. Converts the resulting quaternion back to a u gate. (This could also be done differently in the future, and directly decompose to the correct base gates by using the decomposition from ✨ Implement single-qubit gate decomposition pass #1182)

Since this optimization may only be beneficial on certain quantum architectures, it is disabled by default. It can be invoked using:

quantum-opt <input.mlir> --pass-pipeline='builtin.module(merge-rotation-gates{quaternion-folding})'

This implementation currently targets the legacy MQTOpt dialect. In the future, this PR will port this optimization to the new QCO dialect.
For future implementation in QCO, a separate pass will be added, since simple same-type rotation gate merging is implemented as a canonicalization there but it only makes sense to have quaternion merging as a separate pass.

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.

@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

❌ Patch coverage is 90.32258% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ct/MQTOpt/Transforms/MergeRotationGatesPattern.cpp 90.0% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@burgholzer burgholzer added feature New feature or request c++ Anything related to C++ code MLIR Anything related to MLIR labels Dec 29, 2025
@burgholzer burgholzer added this to the MLIR Support milestone Dec 29, 2025
@burgholzer
Copy link
Member

Hey @J4MMlE 👋🏻
This is great to see!

How much of an ask would it be to directly base this pass on the QCO dialect and its infrastructure?
We'd like to stop adding features to the old dialects and instead only add them to the new ones as much as possible, so that we can remove the old dialects rather sooner than later.
This is not a must, but it would be highly appreciated.

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

Labels

c++ Anything related to C++ code feature New feature or request MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants