-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Increase Accuracy of OpenQASM 2.0 Dump #8250
Conversation
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:
|
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.
Given the discussion in #7166, I'm fine with this. On the ndigits
front: probably the ideal would be for us to have the default be None
, and to use Python's default float formatting if ndigits is None
(or the current implementation if not). In that mode, Python will output the shortest string which evaluates to the same target float - that's why str(0.3)
is "0.3"
, str(0.3 * 3) == "0.8999999999999999"
and str(0.9) == "0.9"
, for example.
If you'd like to do that in this PR, let me know, otherwise we can just move on to merge. Either way, please could you add an "upgrade" release note for this change (reno new --edit change-qasm-float-output
) that explains that the number of digits output by QuantumCircuit.qasm()
has changed to more accurately represent the parameters. If you want to make the above change, it'll be a "feature" note, rather than an "upgrade".
edit: the lint CI run is also failing, probably because there's a docstring line that's a bit too long in the new test you added. Nothing major - you can just split the line in two.
Thanks for your feedback and the detailed information. Of course I'll fix the linter warnings and create a corresponding release note in the process 👍🏼 |
Ok cool! Yeah, that's exactly it - if |
I refactored the Some of the One of the (potentially easy to fix) things in the |
Yeah, your new form looks better to me, thanks, and all your changes look like they make a lot of sense. I really dislike the whole (I can't do a proper review on GitHub right now because it seems to have bugged out a little, and it's showing commits that aren't actually on the branch. Don't worry about it - your branch is actually fine, it's just GitHub being weird, and it'll fix itself in a bit, I'm sure.) |
That is a shame. It is actually quite useful for seeing when a given angle is near some commonly used fraction of pi. I agree it has been a bit mangled over time, but that is not its fault. |
…ction.Instruction.qasm`
81e5a66
to
e186f7b
Compare
I updated the respective line to properly compare against
Something seems to have gotten messed up in the git history. I rebased the commits and changes now show up properly again. |
@jakelishman gentle ping so this doesn't go stale again. |
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.
I read it quickly, and all the code looks sensible to me, thank you! I'm actually on paternity leave for the next few weeks, so it's difficult for me to check completely properly. @1ucian0, please could you take over and merge if you're happy?
@1ucian0 @jakelishman gentle ping. It's been another month 🙃 |
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.
Sorry once more for this falling through the cracks. I've fixed the merge conflict that had arisen, and we can merge this for the 0.23 series.
No worries, thanks for getting back! |
Pull Request Test Coverage Report for Build 3499080974
💛 - Coveralls |
* use tighter `eps` of `1e-12` in `qiskit.circuit.instruction.Instruction.qasm` * change to `double` precision (`ndigits=16`) in `qiskit.circuit.instruction.Instruction.qasm` * add tests * refactor `pi_check` to use default float formatting when `ndigits=None` * add release notes * fix tests * use parameter `eps` in check for zero in `pi_check` * fix tests by changing default `eps` to `1e-9` Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Summary
This PR improves the accuracy of the OpenQASM 2.0 export by not truncating parameters of gates to
single
precision and using a tighter bound for checking whether a given parameter is close to a fraction of pi.Resolves #7166.
Details and comments
For details, see the discussion in #7166. The additional precision is accomplished by relying on Python's built-in float formatting as a default in the
pi_check
function.