Skip to content

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
Contributor

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 opened by contributors outside the PennyLaneAI organization and removed external PRs opened by contributors outside the PennyLaneAI organization 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
@codecov
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 (e01b47c) to head (1978259).
⚠️ Report is 401 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7393   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         529      529           
  Lines       50698    50709   +11     
=======================================
+ Hits        50543    50554   +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.

@astralcai astralcai requested a review from isaacdevlugt May 9, 2025 13:15
Co-authored-by: Astral Cai <[email protected]>
Copy link
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

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

LGTM. Congratulations on your first contribution to PennyLane! 🎸

Copy link
Contributor

@isaacdevlugt isaacdevlugt left a comment

Choose a reason for hiding this comment

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

Nice @SimoneGasperini! I left some comments on the documentation :)

SimoneGasperini and others added 2 commits May 9, 2025 14:38
Co-authored-by: Yushao Chen (Jerry) <[email protected]>
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Potentially also include a test for precision?

@PietropaoloFrisoni
Copy link
Contributor

There is already this test for the precision argument, but since we repeated/duplicated tests for rotations and measure_all, we might add one more for consistency at this point

Co-authored-by: Isaac De Vlugt <[email protected]>
@SimoneGasperini SimoneGasperini added the merge-ready ✔️ All tests pass and the PR is ready to be merged. label May 14, 2025
@SimoneGasperini SimoneGasperini added this pull request to the merge queue May 14, 2025
Merged via the queue into master with commit 048d5d0 May 14, 2025
53 checks passed
@SimoneGasperini SimoneGasperini deleted the openqasm-transform branch May 14, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready ✔️ All tests pass and the PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants