Skip to content

✨ MLIR - Rotation Gate Merge Pass/Pattern #121

@WingCode

Description

@WingCode

Copied from munich-quantum-toolkit/core #898

What's the problem this feature will solve?

We recently introduced the first optimization passes for the MLIR ecosystem we are building munich-quantum-toolkit#892.
Now this opens up a flood of options for implementing further optimization passes.
One that would be nice to have is an optimization pass that merges rotation gates wherever possible.

Example (qasm-style):

rx(pi/2) q[0];
rx(pi/2) q[0];

could be merged into

rx(pi) q[0];

Currently, we only have a pass that cancels consecutive inverse gates (see https://github.com/munich-quantum-toolkit/core/blob/d88d1f091b1257d8b7b4ae48521f19ed60602b76/mlir/include/mlir/Dialect/MQTOpt/Transforms/Passes.td#L31-L37, https://github.com/munich-quantum-toolkit/core/blob/main/mlir/lib/Dialect/MQTOpt/Transforms/CancelConsecutiveInverses.cpp, and https://github.com/munich-quantum-toolkit/core/blob/main/mlir/lib/Dialect/MQTOpt/Transforms/CancelConsecutiveInversesPattern.cpp).
However, that pass does not handle parametrized gates such as rotation gates.

Describe the solution you'd like

I see two possible ways to implement this:

  • This new feature could be added as a new pattern to that pass as the features are related and might use similar helper methods (in that case, the pass would have to be renamed).
  • This new feature could be added as an entirely new transformation pass.

Both strategies seem reasonable at first glance.

In any case, the pass should at least cover the following rotation gates:

  • rx, ry, rz, phase
  • rxx, ryy, rzz, rzx
  • xx_minus_yy, xx_plus_yy
  • U, U2

Most likely, an optional parameter for defining a tolerance value would be useful for controlling, when two parametrized gates cancel one another.

Cancellation rules could be derived from https://github.com/munich-quantum-toolkit/core/blob/d88d1f091b1257d8b7b4ae48521f19ed60602b76/src/dd/Operations.cpp#L74-L142

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions