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

Fail safe in the QASM 3 exporter #7336

Merged
merged 2 commits into from
Dec 2, 2021

Conversation

jakelishman
Copy link
Member

Summary

There were previously parts of the QASM 3 exporter where it attempted to
do its best guess at what should happen, even when this always produced
entirely incorrect results. These were subroutine definitions with
parameters, opaque gates (defcal) and non-included gates with
parameters.

We now choose to fail loudly with a message that we do not currently
support certain features, rather than outputting a meaningless
programme. For the parameterised gates, we now force the exporter to
output a separate definition for every instance of a gate if it cannot
be sure that it has the most general form to start with. The code it
outputs looks silly (the gates take parameters, but do not use them in
their definitions, and each gate may be defined many times), but the
semantics of the programme will actually be correct.

See gh-7335 for the parameterisation problem.

Details and comments

This very very lightly papers over #7335, but is not a proper solution. The full solution will need to come after release, and may well require a proper refactor of the expectations of Instruction.params.

There were previously parts of the QASM 3 exporter where it attempted to
do its best guess at what should happen, even when this always produced
entirely incorrect results.  These were subroutine definitions with
parameters, opaque gates (`defcal`) and non-included gates with
parameters.

We now choose to fail loudly with a message that we do not currently
support certain features, rather than outputting a meaningless
programme.  For the parameterised gates, we now force the exporter to
output a separate definition for every instance of a gate if it cannot
be sure that it has the most general form to start with.  The code it
outputs looks silly (the gates take parameters, but do not use them in
their definitions, and each gate may be defined many times), but the
semantics of the programme will actually be correct.

See Qiskitgh-7335 for the parameterisation problem.
@jakelishman jakelishman added priority: high mod: qasm2 Relating to OpenQASM 2 import or export Changelog: None Do not include in changelog labels Dec 1, 2021
@jakelishman jakelishman added this to the 0.19 milestone Dec 1, 2021
@jakelishman jakelishman requested a review from a team as a code owner December 1, 2021 22:48
@coveralls
Copy link

coveralls commented Dec 1, 2021

Pull Request Test Coverage Report for Build 1528754314

  • 13 of 14 (92.86%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 82.97%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/qasm3/exporter.py 13 14 92.86%
Files with Coverage Reduction New Missed Lines %
qiskit/qasm3/exporter.py 1 97.47%
Totals Coverage Status
Change from base Build 1528236360: 0.02%
Covered Lines: 50777
Relevant Lines: 61199

💛 - Coveralls

Copy link
Member

@levbishop levbishop 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 best to fail gracefully in these cases rather than emit potentially incorrect qasm

@mergify mergify bot merged commit c95ec37 into Qiskit:main Dec 2, 2021
@jakelishman jakelishman deleted the qasm3/louder-failures branch December 6, 2021 16:46
@jakelishman jakelishman added mod: qasm3 Related to OpenQASM 3 import or export and removed mod: qasm2 Relating to OpenQASM 2 import or export labels Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: qasm3 Related to OpenQASM 3 import or export priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants