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

Rotation Gates #95

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

sagnikpal2004
Copy link

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.

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 74.26%. Comparing base (be8cb24) to head (45d8269).

Files with missing lines Patch % Lines
ext/QuantumOpticsExt/QuantumOpticsExt.jl 0.00% 7 Missing ⚠️
src/QSymbolicsBase/predefined.jl 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
- Coverage   75.46%   74.26%   -1.21%     
==========================================
  Files          19       19              
  Lines         803      816      +13     
==========================================
  Hits          606      606              
- Misses        197      210      +13     

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

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.

Comment on lines +109 to +112
@withmetadata struct RGate <: AbstractSingleQubitGate
dir::Symbol
θ::Float64
end
Copy link
Member

Choose a reason for hiding this comment

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

A few points:

  • this object does not seem to be a "leaf" of a symbolic expression, and as such it needs to implement additional APIs that permit symbolic tree traversal
  • theta would not necessarily be a float64. It might also be a symbolic scalar, a float32, etc. There are a lot of sophisticated approaches to what this can be set to, but for the moment it would probably work best if it is unconstrained
  • the dir symbol should probably just be removed (and then have three different types RotX RotY RotZ) -- otherwise it will be very difficult to write simplification rules for these objects

See the "scaled" object as an example of the additional API that is needed for non-leaf symbolic objects https://github.com/QuantumSavory/QuantumSymbolics.jl/blob/main/src/QSymbolicsBase/basic_ops_homogeneous.jl#L22

Copy link
Member

Choose a reason for hiding this comment

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

if you want to, you can always create a AbstractRotGate if you want to avoid some minor code repetition

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.

2 participants