Skip to content

Rotation Gates #95

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

sagnikpal2004
Copy link

@sagnikpal2004 sagnikpal2004 commented Jan 1, 2025

QuantumSymbolics.jl is currently missing rotation gates.
I decided to implement these gates as RGate, which are structs which take in a direction and angle.
express functionality for QuantumOpticsRepr is also implemented

CHANGELOG:

  • Added Rotation Gates: RGate, Rx, Ry, Rz
  • Implemented express in QuantumOpticsRepr

CHECKLIST:

  • The code is properly formatted and commented.
  • Substantial new functionality is documented within the docs. --TODO
  • All new functionality is tested.
  • All of the automated tests on github pass.
  • We recently started enforcing formatting checks. If formatting issues are reported in the new code you have written, please correct them. There will be plenty of old code that is flagged as we are slowly transitioning to enforced formatting. Please do not worry about or address older formatting issues -- keep your PR just focused on your planned contribution.

Edit from Stefan: closes #94

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

Attention: Patch coverage is 55.26316% with 17 lines in your changes missing coverage. Please review.

Project coverage is 75.28%. Comparing base (acbe829) to head (a8b4922).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/QSymbolicsBase/predefined.jl 45.00% 11 Missing ⚠️
ext/QuantumOpticsExt/QuantumOpticsExt.jl 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
- Coverage   75.96%   75.28%   -0.68%     
==========================================
  Files          19       19              
  Lines         828      866      +38     
==========================================
+ Hits          629      652      +23     
- Misses        199      214      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

This is a great start, thank you for engaging with this.

I am leaving a few comments on suggested structure below.

We should probably also add some simplification rules to the database of rules: https://github.com/QuantumSavory/QuantumSymbolics.jl/blob/main/src/QSymbolicsBase/rules.jl

It can be a new _ROT list of rules, containing things like Rot(a)*Rot(b) = Rot(a+b) and commutation relationships between them and commutation relationships with Paulis, and conversion of exponentials of Paulis into rot gates.

For testing we can add something that checks an equality of a bunch of expressions of the type express(expr) == express(expr(simplify(expr))) -- that way we check consistency between the numerical representation and the symbolic simplification rules.

@Krastanov Krastanov mentioned this pull request Jan 16, 2025
@sagnikpal2004 sagnikpal2004 marked this pull request as ready for review April 26, 2025 02:38
@sagnikpal2004 sagnikpal2004 requested a review from Krastanov April 26, 2025 06:24
@sagnikpal2004
Copy link
Author

Summary of changes made

  • Added abstract type AbstractRotGate
  • Created three different gates RotXGate, RotYGate, RotZGate (and aliases Rx, Ry, Rz)
  • Implemented TermInterface APIs for the gates
  • Added rules for rotation gate simplification
  • Added tests for rule application

Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

Thanks for updating this! There are a couple of simplification rules that I do not fully understand, could you address the questions below?

Are there predefined rotations gates in QuantumOptics.jl? If yes, we should probably use them or at least make sure we are consistent with them.

@Krastanov
Copy link
Member

Marking as draft just so I can keep my review queue organized. Do not hesitate to mark it back as ready and re-request a review.

@Krastanov Krastanov marked this pull request as draft April 28, 2025 01:23
@sagnikpal2004
Copy link
Author

sagnikpal2004 commented Jun 9, 2025

Summary of changes from previous review:

  • fixed TermInterface APIs
  • removed the θ == 0 rules and added the check to the constructors
  • updated tests to reflect the new constructor

CHANGELOG:

  • Added AbstractRotGate, RotXGate, RotYGate, RotZGate and accompanying symbolic traversal APIs and simplification rules
  • Implemented express for QuantumOpticsRepr for rotation gates

Notes:

  • It looks like including the θ == 0 check in the actual constructor of the rotation structs seemed to mess with the @withmetadata macro, and the metadata field would not be added.
    So, instead I have created the Rx, Ry and Rz functions that do that check and create the rotation structs. I think that using these functions as the primary way to create rotation gates would be more elegant. This is consistent with other operations in the codebase (like kraus or projector)
  • Also, I looked through the documentation but did not find any rotation operators in QuantumOptics.jl

Please let me know if I should change that, or make any other improvements

@sagnikpal2004 sagnikpal2004 marked this pull request as ready for review June 9, 2025 09:39
@sagnikpal2004 sagnikpal2004 requested a review from Krastanov June 24, 2025 14:03
@Krastanov Krastanov closed this Jun 24, 2025
@Krastanov Krastanov reopened this Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rotation Gates
2 participants