Skip to content

Add qml.to_openqasm transform #7393

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 18 commits into
base: master
Choose a base branch
from
Open

Conversation

SimoneGasperini
Copy link
Contributor

@SimoneGasperini SimoneGasperini commented May 7, 2025

This PR adds a transform to make the conversion of a quantum circuit into the corresponding OpenQASM 2.0 program easier and more user-friendly. The qml.to_openqasm function is implemented in a new openqasm module under the qml.transforms subpackage. Not sure this is the right location in the Pennylane repository.

A quite extensive set of unit and integration tests for the QuantumScript.to_openqasm method is already available in test_qasm.py. I will add a detailed description of what the transform is doing in the docstring, including a simple usage example.

[sc-83360]

@albi3ro
Copy link
Contributor

albi3ro commented May 7, 2025

Just thinking here: would it make sense it to live in the io module? We already have the load_qasm function there. So it might make sense.

Co-authored-by: Yushao Chen (Jerry) <[email protected]>
@SimoneGasperini
Copy link
Contributor Author

Just thinking here: would it make sense it to live in the io module? We already have the load_qasm function there. So it might make sense.

Ok thank you Christina! I move it to the io module then.

@PietropaoloFrisoni
Copy link
Member

PietropaoloFrisoni commented May 7, 2025

Just thinking here: would it make sense it to live in the io module? We already have the load_qasm function there. So it might make sense.

@albi3ro I think this is a good idea! Since this is not really a 'transform' but more a new public function, it would probably be confusing to put it in the pennylane.transforms module

@SimoneGasperini SimoneGasperini changed the title Add qml.to_openqasm transform Add qml.to_qasm function May 7, 2025
@SimoneGasperini SimoneGasperini changed the title Add qml.to_qasm function Add qml.to_openqasm transform May 7, 2025
@SimoneGasperini SimoneGasperini added external PRs where the author is not a part of PennyLane Org (or part of external contributors team) and removed external PRs where the author is not a part of PennyLane Org (or part of external contributors team) labels May 8, 2025
@SimoneGasperini
Copy link
Contributor Author

I added some unit tests checking the OpenQASM 2.0 code for a few different circuits but actually most of the work done by the transform already has an extensive set of tests for the QuantumScript.to_openqasmmethod (see here) so I'm not sure this is the right way to go in this case. Any kind of suggestion would be appreciated ;)

@SimoneGasperini SimoneGasperini marked this pull request as ready for review May 8, 2025 18:41
Copy link

codecov bot commented May 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.69%. Comparing base (5a28158) to head (bd3a783).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7393   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         529      529           
  Lines       50610    50621   +11     
=======================================
+ Hits        50455    50466   +11     
  Misses        155      155           

☔ 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

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

This PR looks great! 🎉

I only have a few minor comments/observations. Please let me know what you think! Thanks @SimoneGasperini : )

Comment on lines +727 to +728
# pylint: disable=import-outside-toplevel
from pennylane.workflow import construct_tape
Copy link
Member

Choose a reason for hiding this comment

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

As a reference to other reviewers, this is just a trick to avoid circular import issues. We could address this as part of this story

Copy link
Contributor

Choose a reason for hiding this comment

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

More work for @andrijapau when he's back from vacation 😆

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.

5 participants