Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Rot gates merging in merge_rotations transform #7010

Closed
andrijapau opened this issue Feb 26, 2025 · 0 comments · Fixed by #7011
Closed

Enhance Rot gates merging in merge_rotations transform #7010

andrijapau opened this issue Feb 26, 2025 · 0 comments · Fixed by #7011
Assignees
Labels
enhancement ✨ New feature or request

Comments

@andrijapau
Copy link
Contributor

Feature details

We currently have,

from pennylane.transforms.optimization import merge_rotations

def qfunc():
    qml.Rot(-1, 0, 1, wires=0)
    qml.Rot(-1, 0, 1, wires=0)

>>> transformed_qfunc = merge_rotations(qfunc)
>>> qml.tape.make_qscript(transformed_qfunc)().operations
[Rot(-1, 0, 1, wires=[0])] # Should be [] since equivalent to I

But it should simplify this to an empty tape.

Implementation

Requires modifying how we check if the cumulative_angles are close to zero,

...
        # If we are tracing/jitting or differentiating, don't perform any conditional checks and
        # apply the operation regardless of the angles. Otherwise, only apply if
        # the rotation angle is non-trivial.
        if (
            qml.math.is_abstract(cumulative_angles)
            or qml.math.requires_grad(cumulative_angles)
            or not qml.math.allclose(cumulative_angles, 0.0, atol=atol, rtol=0)
        ):
            with QueuingManager.stop_recording():
                new_operations.append(
                    current_gate.__class__(*cumulative_angles, wires=current_gate.wires)
                )
...

As it doesn't catch the case where if the Rot cumulative angles are (X, 0, -X) when it is equivalent to the identity operator.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

It is important to note that single_qubit_fusion transform handles this case correctly.

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 a pull request may close this issue.

1 participant