-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
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.
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:
|
Pull Request Test Coverage Report for Build 4691407246
💛 - Coveralls |
The error on Windows in this PR is fixed by #9958. It's arguably not really an error - |
There was a problem hiding this 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.
…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.
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 surroundingU
andCX
!).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 setstrict=True
, which would have made an unrelated test inSabreLayout
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 like1e3
, unlike other languages). Given that the previously OQ2 importer allowed these floats, it seemed safer to usestrict=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.
QuantumCircuit
directly, skippingDAGCircuit
qiskit-qasm2
package available, the parser itself is factored out, though it doesn't build a reusable. We're not going to be supplying that, though.DAGCircuit
, but streams a series of bytecode instructions on demand, so the intermediate memory usage is constant-sized rather than the old behaviour of being linear (with large constant factor).QuantumCircuit
, so this issue is at best obsolete.