-
Notifications
You must be signed in to change notification settings - Fork 73
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
Parse OpenQASM #495
Parse OpenQASM #495
Conversation
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.
First round of review.
src/qasm.lisp
Outdated
(destructuring-bind (if-toks . rest-lines) | ||
tok-lines | ||
(pop if-toks) | ||
(q2q-check-token-type (pop if-toks) ':LEFT-PAREN) |
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.
sounds like we can maybe use token destructuring?
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.
Commenting to let you know that I've looked through this, & (TODOs aside) things look pretty good.
@notmgsk Ping when re-review is desired. |
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.
Made it about half-way through. All tuckered out. Time for Christmas cookies.
src/qasm.lisp
Outdated
;; a[0] -> b[0]`. | ||
;; | ||
;; TODO I wrote this while very tired. Untested. | ||
(let ((ts (mapcar #'alexandria:ensure-list (remove '_ token-idents)))) |
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.
feels like there should be a smattering of once-only
s but I didn't check carefully
0717f2a
to
b26089e
Compare
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.
There is some trailing whitespace in both qasm.lisp
and qasm-tests.lisp
. M-x whitespace-cleanup
and/or M-x delete-trailing-whitespace
to the rescue.
I don't feel like any of these are blockers per se, but I'll delay approval to maintain Code Review Best Practices®️
I'm also vaguely uneasy about *creg-names*
and *qreg-names*
but I don't know why. maybe I'm just hungry. time for lunch.
@appleby @stylewarning ping for re-review at you leisure |
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.
cool stuff
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.
Some critical things, some not so critical things.
I think this PR has been a little too liberal with TODO
s. On one hand they're good first issues for newcomers, on the other hand they're debt that people may not feel motivated to fix.
8c3e657
to
1fce003
Compare
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.
Previously approved. Just chiming in to say the latest round of changes lgtm.
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.
Comments (1/N).
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.
Comments (N/N).
LGTM.
(defun parse-qasm (string) | ||
"Parse STRING into a PARSED-PROGRAM object, applying all transforms." | ||
(let ((pp (quil::resolve-objects (parse-qasm-into-raw-program string)))) | ||
(setf pp (quil::transform 'quil::expand-circuits pp)) |
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.
Suggestion: fuse setf
forms.
(code (parse-qasm-body string))) | ||
(setf code (quil::process-includes code)) |
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.
Suggestion: compose parse-qasm-body
with quil::process-includes
in the let*
form above and discard the setf
.
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.
LGTM
*qreg-names* | ||
*qubit-count*))) | ||
|
||
(defun parse-qasm (string) |
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.
Minor request: a keyword argument transforms
which defaults a list of the three you currently use
This (late) PR implements all functionality described in the OpenQASM spec.
The following is a somewhat complex example, demonstrating a ripple-carry adder OpenQASM program:
There are some things to address:
parse-application
I explicitly define all of the gates defined in OpenQASM'sqelib1.inc
. This could be simplified (and instead just define the fundamental gatesU
andCX
), but I'm not sure (because I haven't tried) whether that will Just Work.parse-quil
if the first (non-comment) line isOPENQASM 2.0
.I think the test suite is generally in a good state. It covers all positive behaviours listed in the spec but it doesn't test for misuse.