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

Switch QuantumCircuit.from_qasm_str and from_qasm_file to new parser #9955

Merged
merged 2 commits into from
May 9, 2023

Conversation

jakelishman
Copy link
Member

Summary

This uses the extensibility and the legacy compatiblity data in the new Rust OpenQASM 2 parser to switch over the old QuantumCircuit constructor methods to the new parser. This gives users of these methods large speedups while maintaining the same feature set (and fixing a long-standing bug surrounding U and CX!).

One test is removed for the circuit methods; the circuit methods are set to use strict=False mode of the new parser, which is more permissive, including making the empty string an allowable program. The alternative was to set strict=True, which would have made an unrelated test in SabreLayout fail instead due to its slightly improper use of floating-point values in OpenQASM 2 (the OQ2 spec technically requires decimal points even in constructs like 1e3, unlike other languages). Given that the previously OQ2 importer allowed these floats, it seemed safer to use strict=False mode, which is also generally more convenient for users.

The tests for the old paths are copied, to ensure they continue working during their potential deprecation and removal.

Details and comments

The new parser fixes several long-standing bugs/problems. Strictly we could have counted them as fixed since #9784 merged, but it's perhaps more complete to count them as fixed once the old interfaces use the new paths.

This uses the extensibility and the legacy compatiblity data in the new
Rust OpenQASM 2 parser to switch over the old `QuantumCircuit`
constructor methods to the new parser.  This gives users of these
methods large speedups while maintaining the same feature set (and
fixing a long-standing bug surrounding `U` and `CX`!).

One test is removed for the circuit methods; the circuit methods are set
to use `strict=False` mode of the new parser, which is more permissive,
including making the empty string an allowable program.  The alternative
was to set `strict=True`, which would have made an unrelated test in
`SabreLayout` fail instead due to its slightly improper use of
floating-point values in OpenQASM 2 (the OQ2 spec technically requires
decimal points even in constructs like `1e3`, unlike other languages).
Given that the previously OQ2 importer allowed these floats, it seemed
safer to use `strict=False` mode, which is also generally more
convenient for users.

The tests for the old paths are copied, to ensure they continue working
during their potential deprecation and removal.
@jakelishman jakelishman added performance Changelog: API Change Include in the "Changed" section of the changelog Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qasm2 Relating to OpenQASM 2 import or export labels Apr 12, 2023
@jakelishman jakelishman added this to the 0.25.0 milestone Apr 12, 2023
@jakelishman jakelishman requested a review from a team as a code owner April 12, 2023 22:37
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Apr 12, 2023

Pull Request Test Coverage Report for Build 4691407246

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 25 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.002%) to 85.743%

Files with Coverage Reduction New Missed Lines %
qiskit/qasm/node/unaryoperator.py 2 70.59%
qiskit/qasm/node/prefix.py 3 52.17%
crates/accelerate/src/sabre_swap/layer.rs 4 97.32%
crates/qasm2/src/lex.rs 4 90.89%
crates/qasm2/src/parse.rs 12 97.11%
Totals Coverage Status
Change from base Build 4691279270: 0.002%
Covered Lines: 70116
Relevant Lines: 81775

💛 - Coveralls

@jakelishman
Copy link
Member Author

The error on Windows in this PR is fixed by #9958. It's arguably not really an error - OSError was also fine in that situation - but for the sake of the test suite having exactly equal behaviour (except for qasm2.loads("") no longer being an error), it's better to have the fix.

Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

This looks great! Good idea to keep testing the legacy importer path.

@kevinhartman kevinhartman added this pull request to the merge queue May 9, 2023
Merged via the queue into Qiskit:main with commit b6fdb19 May 9, 2023
@jakelishman jakelishman deleted the qasm2/default-parser branch May 16, 2023 10:06
king-p3nguin pushed a commit to king-p3nguin/qiskit-terra that referenced this pull request May 22, 2023
…ser (Qiskit#9955)

This uses the extensibility and the legacy compatiblity data in the new
Rust OpenQASM 2 parser to switch over the old `QuantumCircuit`
constructor methods to the new parser.  This gives users of these
methods large speedups while maintaining the same feature set (and
fixing a long-standing bug surrounding `U` and `CX`!).

One test is removed for the circuit methods; the circuit methods are set
to use `strict=False` mode of the new parser, which is more permissive,
including making the empty string an allowable program.  The alternative
was to set `strict=True`, which would have made an unrelated test in
`SabreLayout` fail instead due to its slightly improper use of
floating-point values in OpenQASM 2 (the OQ2 spec technically requires
decimal points even in constructs like `1e3`, unlike other languages).
Given that the previously OQ2 importer allowed these floats, it seemed
safer to use `strict=False` mode, which is also generally more
convenient for users.

The tests for the old paths are copied, to ensure they continue working
during their potential deprecation and removal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qasm2 Relating to OpenQASM 2 import or export performance
Projects
None yet
4 participants