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

Add a combine_global_phases transform #6644

Open
mudit2812 opened this issue Nov 27, 2024 · 0 comments
Open

Add a combine_global_phases transform #6644

mudit2812 opened this issue Nov 27, 2024 · 0 comments
Labels
enhancement ✨ New feature or request

Comments

@mudit2812
Copy link
Contributor

mudit2812 commented Nov 27, 2024

Important Note

⚠️ This issue is part of an internal assignment and not meant for external contributors.

Context

We would like to add a transform to PennyLane that combines all qml.GlobalPhase gates in a circuit into a single one applied at the end. This can be useful for circuits that include a lot of qml.GlobalPhase gates, which can be introduced directly during circuit creation, decompositions that include qml.GlobalPhase gates, etc.

Implementation Details

This task is to add a new transform called combine_global_phases. This transform should be added to the pennylane/transforms folder in a new file called combine_global_phases.py.

This transform should:

  • Find all instances of qml.GlobalPhase in a QuantumScript, regardless of the wires that it is applied to
  • Sum the phase for each qml.GlobalPhase gate
  • Create a new QuantumScript that includes all the operations and measurements other than qml.GlobalPhase of the original QuantumScript
  • Apply a qml.GlobalPhase as the last operation in the new QuantumScript with the phase being equal to the sum computed earlier. Wires do not need to be specified for this qml.GlobalPhase

Relevant functions include:

  • qml.GlobalPhase
  • qml.transforms.core.transform
  • Any transforms from the pennylane/transforms folder can be used as reference

Additional Requirements

A completed PR would:

  • Include a docstring for the new combine_global_phases transform with details about what the transform does, arguments, return values, and a code example that showcases the transform
  • Include a changelog entry at doc/releases/changelog-dev.md. Make sure to include your name in the list of contributors at the bottom!
  • Add tests to a new file tests/transforms/test_combine_global_phases.py. The tests should include an adequate suite of both unit and integration tests.
  • Pass all existing tests including black and pylint checks
@mudit2812 mudit2812 added the enhancement ✨ New feature or request label Nov 27, 2024
mudit2812 added a commit that referenced this issue Dec 16, 2024
**Description of the Change:**
I implemented a `qml.transform.combine_global_phases` transform to
combine all `qml.GlobalPhase` gates in a circuit into a single
`qml.GlobalPhase` operation (applied at the end of the new circuit
without specifying any wire) with the phase equal to the total algebraic
sum of each original phase.


**Benefits:**
This transform can be useful for circuits that include a lot of
`qml.GlobalPhase` gates, which can be introduced directly during circuit
creation, decompositions that include `qml.GlobalPhase` gates, etc.


**Related GitHub Issues:** #6644

---------

Co-authored-by: Astral Cai <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
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

No branches or pull requests

1 participant