Skip to content

Added QASM Import Support for rzz, rxx, ryy, crx, cry, and iswap Gates #7290

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 10 commits into
base: main
Choose a base branch
from

Conversation

RevanthGundala
Copy link
Contributor

Description

Fixes the code in #7007
Builds on #7072

Newly Supported Gates:

rzz: Imported as cirq.ZZPowGate
rxx: Imported as cirq.XXPowGate
ryy: Imported as cirq.YYPowGate
crx: Imported as cirq.ControlledGate(cirq.Rx)
cry: Imported as cirq.ControlledGate(cirq.Ry)
iswap: Imported as cirq.ISwapPowGate

Added unit tests for these gates, and turned gates into alphabetical order for future additions

@RevanthGundala RevanthGundala requested review from vtomole and a team as code owners April 19, 2025 19:59
Copy link

codecov bot commented Apr 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.66%. Comparing base (3d0dee5) to head (5a49807).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7290      +/-   ##
==========================================
- Coverage   98.67%   98.66%   -0.01%     
==========================================
  Files        1106     1106              
  Lines       96142    96219      +77     
==========================================
+ Hits        94864    94939      +75     
- Misses       1278     1280       +2     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@daxfohl daxfohl left a comment

Choose a reason for hiding this comment

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

Is there a way to test that the unitaries are the same? I think rxx needs a global shift added to the xxpow gate, but not sure.

@RevanthGundala
Copy link
Contributor Author

I added a test to check if the unitaries are the same and the test is passing. Surprisingly they are exactly the same, but I added some extra tolerance since I'm not 100% sure if that's expected behavior

Copy link
Collaborator

@daxfohl daxfohl left a comment

Choose a reason for hiding this comment

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

I'll go ahead and give it an "lgtm", though I don't know the unitaries of the other new gates either, so I'm assuming you've verified that they're all what they should be. If you could add similar unitary equivalence tests before merging, that would improve the PR significantly (and that may be required by final review). If you can figure out a way to make a parameterized test that does this for all the gates in qelib_gates automatically, even better.

cc @pavoljuhas for final review.

@RevanthGundala
Copy link
Contributor Author

Sounds good, I'll make sure to add that

@RevanthGundala
Copy link
Contributor Author

New unit tests are reformatted to be more aligned with how other gates are tested and there is 1 test to test all unitary equivalence

)
def test_rxx_unitary_equivalence(theta_expr, theta):
def test_all_qelib_gates_unitary_equivalence(qasm_gate, cirq_gate, num_params, num_args):
theta = np.pi / 4
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very cool! The only thing I'd say is probably use different random numbers for the parameters, and maybe loop through a couple times with different parameters to make sure it's not just getting lucky and testing a parameter that happens to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a benefit to testing all gates individually? Can probably use this same logic to test all gate equivalences as well

@github-actions github-actions bot added the size: L 250< lines changed <1000 label Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants