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

Issue #2354 Fix - qiskit QFT gates error during conversion #2404

Merged

Conversation

NnguyenHTommy
Copy link
Contributor

fixes issue #2354 where a QFT qiskit circuit would error out during conversion. Implemented a fallback mechanism to decompose and transpile the qiskit circuit into native gates. Added a unit test in the ZNE module to test this with qiskit's QFT gate.

This is my first open source contribution via unitary hack so any feedback would be appreciated!

Description


License

  • [ x] I license this contribution under the terms of the GNU GPL, version 3 and grant Unitary Fund the right to provide additional permissions as described in section 7 of the GNU GPL, version 3.

Before opening the PR, please ensure you have completed the following where appropriate.

  • [x ] I added unit tests for new code.
  • [ x] I used type hints in function signatures.
  • [ x] I used Google-style docstrings for functions.
  • [x ] I updated the documentation where relevant.
  • [ x] Added myself / the copyright holder to the AUTHORS file

…ns.py to decompose a qiskit circuit to native gates if an error occured. A test with zne was added to test for this with the QFT gate.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello @NnguyenHTommy, thank you for submitting a PR to Mitiq! We will respond as soon as possible, and if you have any questions in the meantime, you can ask us on the Unitary Fund Discord.

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.32%. Comparing base (837ea83) to head (bcd3ff1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2404      +/-   ##
==========================================
+ Coverage   98.30%   98.32%   +0.01%     
==========================================
  Files          87       87              
  Lines        4003     4048      +45     
==========================================
+ Hits         3935     3980      +45     
  Misses         68       68              

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

@cosenal cosenal self-requested a review June 7, 2024 07:55
Copy link
Contributor

@cosenal cosenal 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 your contribution, @NnguyenHTommy!
Good work so far. I left some comments, please take a look.

mitiq/interface/mitiq_qiskit/conversions.py Outdated Show resolved Hide resolved
mitiq/interface/mitiq_qiskit/conversions.py Outdated Show resolved Hide resolved
mitiq/zne/tests/test_zne.py Outdated Show resolved Hide resolved
…s pull request.

Moved the exception catch from the from_qiskit() to the from_qasm() function as that function is
more general and is called by from_qiskit().
Used a QasmException catch instead of Exception to make it more clear that Qasm has trouble converting
Adjusted code to follow the comments that cosenal placed with previous pull request.
Moved the exception catch from the from_qiskit() to the from_qasm() function as that function is
more general and is called by from_qiskit().
Used a QasmException catch instead of Exception to make it more clear that Qasm has trouble converting
different gates. Removed choosing a basis for the transpile and let qiskit decide what gates to use.
Added an additional test case to test the from_qasm() function.
@cosenal
Copy link
Contributor

cosenal commented Jun 10, 2024

@NnguyenHTommy Thanks for your second revision on this PR. I left some replies on the comments.. we are very close to merge this!

…ption catch to the from_qiskit() function from the from_qasm() function as from_qasm() can handle non-qiskit circuits. Switched the test case to test the from_qiskit() function in doing so. Also only decomposed rather than transpiling and decomposing as transpiling doesn't do anything.
Copy link
Contributor

@cosenal cosenal left a comment

Choose a reason for hiding this comment

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

Looks good. Left some small nits.

mitiq/zne/tests/test_zne.py Outdated Show resolved Hide resolved
mitiq/interface/mitiq_qiskit/conversions.py Show resolved Hide resolved
mitiq/zne/tests/test_zne.py Outdated Show resolved Hide resolved
Copy link
Contributor

@cosenal cosenal left a comment

Choose a reason for hiding this comment

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

LGTM.

🎉 Thanks for your contribution @NnguyenHTommy, and congratulations on the UnitaryHack bounty!

If you had fun and want to learn more about Mitiq, come hang out on our Discord server.

@cosenal cosenal merged commit 720079d into unitaryfund:main Jun 11, 2024
16 checks passed
cosenal pushed a commit that referenced this pull request Jun 26, 2024
* Fixed issue #2354 where a fallback was addded to conversions.py to decompose a qiskit circuit to native gates if an error occured. A test with zne was added to test for this with the QFT gate.

* added myself to the bottom of the authors file

* Adjusted code to follow the comments that cosenal placed with previous pull request.
Moved the exception catch from the from_qiskit() to the from_qasm() function as that function is
more general and is called by from_qiskit().
Used a QasmException catch instead of Exception to make it more clear that Qasm has trouble converting
Adjusted code to follow the comments that cosenal placed with previous pull request.
Moved the exception catch from the from_qiskit() to the from_qasm() function as that function is
more general and is called by from_qiskit().
Used a QasmException catch instead of Exception to make it more clear that Qasm has trouble converting
different gates. Removed choosing a basis for the transpile and let qiskit decide what gates to use.
Added an additional test case to test the from_qasm() function.

* resolving second round of changes reviewed by cosenal! moved the exception catch to the from_qiskit() function from the from_qasm() function as from_qasm() can handle non-qiskit circuits. Switched the test case to test the from_qiskit() function in doing so. Also only decomposed rather than transpiling and decomposing as transpiling doesn't do anything.

* renaming and added updated docstrings according to cosenal suggestions
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.

Qiskit Quantum Fourier Transform (QFT) circuits error out during conversion
2 participants