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

Fix an error in qasm3 exporter when operating on unitary gates #13633

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

gadial
Copy link
Contributor

@gadial gadial commented Jan 8, 2025

Summary

Fixes a bug causing the qasm3 exporter to crash on circuits containing a unitary gate.

Fixes #13362.

Details and comments

The bug results from the params field of the unitary operation being handled incorrectly, due to it being a somewhat nonstandard field (as opposed to the params field of u gate, for instance, which is used differently).

This problem was already handled in the qasm2 exporter by a call to _qasm2_decomposition in the operation, if present. This PR integrates the same solution in the qasm3 exporter, renaming the method to _qasm_decomposition.

@gadial gadial requested a review from a team as a code owner January 8, 2025 14:28
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@coveralls
Copy link

coveralls commented Jan 8, 2025

Pull Request Test Coverage Report for Build 12769245443

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 4 files are covered.
  • 839 unchanged lines in 53 files lost coverage.
  • Overall coverage decreased (-0.02%) to 88.921%

Files with Coverage Reduction New Missed Lines %
crates/circuit/src/converters.rs 1 95.65%
crates/accelerate/src/sabre/heuristic.rs 1 32.87%
qiskit/circuit/library/iqp.py 1 96.15%
qiskit/transpiler/passes/layout/vf2_post_layout.py 1 85.71%
qiskit/circuit/library/boolean_logic/quantum_or.py 1 98.08%
qiskit/circuit/parameter.py 1 98.36%
qiskit/circuit/library/boolean_logic/quantum_and.py 1 97.96%
qiskit/circuit/library/boolean_logic/inner_product.py 1 96.0%
qiskit/synthesis/arithmetic/multipliers/rg_qft_multiplier.py 1 95.83%
crates/qasm2/src/expr.rs 1 94.02%
Totals Coverage Status
Change from base Build 12670558519: -0.02%
Covered Lines: 79440
Relevant Lines: 89338

💛 - Coveralls

@gadial gadial requested a review from jakelishman January 8, 2025 17:24
@ElePT ElePT added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Jan 10, 2025
@ElePT ElePT added this to the 1.3.2 milestone Jan 10, 2025
@ElePT ElePT added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Jan 10, 2025
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

I think this is a fine way to go about solving the problem, thanks. At first I was a bit nervous because the gate models of OQ2 and OQ3 aren't necessarily identical (OQ3 has scope to be more permissive), but in practice I doubt it'll come up any time soon, if ever. If it does, we'll deal with it then.

test/python/qasm3/test_export.py Outdated Show resolved Hide resolved
gadial and others added 2 commits January 14, 2025 16:01
Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Jake Lishman <jake@binhbar.com>
@jakelishman jakelishman enabled auto-merge January 14, 2025 14:21
@jakelishman jakelishman added this pull request to the merge queue Jan 14, 2025
Merged via the queue into Qiskit:main with commit 087e393 Jan 14, 2025
17 checks passed
mergify bot pushed a commit that referenced this pull request Jan 14, 2025
* Fix error in qasm3 exporter when operating on unitary gates

* Update test/python/qasm3/test_export.py

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Update releasenotes/notes/fix-qasm-3-unitary-2da190be6ba25bbd.yaml

Co-authored-by: Jake Lishman <jake@binhbar.com>

---------

Co-authored-by: Jake Lishman <jake@binhbar.com>
(cherry picked from commit 087e393)
github-merge-queue bot pushed a commit that referenced this pull request Jan 14, 2025
… (#13663)

* Fix error in qasm3 exporter when operating on unitary gates

* Update test/python/qasm3/test_export.py

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Update releasenotes/notes/fix-qasm-3-unitary-2da190be6ba25bbd.yaml

Co-authored-by: Jake Lishman <jake@binhbar.com>

---------

Co-authored-by: Jake Lishman <jake@binhbar.com>
(cherry picked from commit 087e393)

Co-authored-by: gadial <gadial@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

qiskit.qasm3.dumps raise TypeError: only length-1 arrays can be converted to Python scalars
5 participants