-
Notifications
You must be signed in to change notification settings - Fork 72
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
Feature: "DEFEXPI" #498
Feature: "DEFEXPI" #498
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 pass. I will admit I barely glanced at the parsing code, since it is the least interesting and probably the buggiest part. 😬
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.
Quick review for the moment. Things are looking good! I miss having some unit tests.
Um pequeno erro:
|
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.
Below are some more suggestions that occurred to me while studying the code.
The fact that compilation and, specifically, gate depth is non-deterministic surprises me. For example,
QUIL> (dotimes (i 10) (print (length (parsed-program-executable-code (quilc::process-program (parse-quil "
DEFGATE HAMILTONIAN(%theta) q0 q1 q2 q3 AS PAULI-SUM:
ZZIZ(%theta) q0 q1 q2 q3
HAMILTONIAN(pi/4) 0 1 2 3") (quilc::lookup-isa-descriptor-for-name "8Q"))))))
59
55
58
58
62
56
59
61
57
55
nil
produces different gate depths (the number of 2-qubit gates seems to be constant, though). Is this an artifact of qs-compiler
?
Thanks for the heads up. That's spooky indeed. By the way, just the other day I saw a link to a directly relevant compiler debugging technique: http://blog.ezyang.com/2011/06/debugging-compilers-with-optimization-fuel/ |
This is a neat suggestion. We'd have to track down and eliminate the nondeterminism to make it work for us. That's not an unreasonable task, but one would have to think very carefully about the problem we solved in the addresser by injecting randomization. |
Can we document this in the global list as an artifact for future visitors? |
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.
Overall looking good. I'd like to go through the motions of making sure the addition is (1) in the quil spec and (2) doesn't choke the QVM.
@@ -54,16 +54,32 @@ EXAMPLE: The Quil line \"CPHASE(pi) 2 3\" corresponds to the S-expression (build | |||
|
|||
(define-global-counter **anonymous-gate-counter** get-anonymous-gate-counter) | |||
|
|||
(defun anon-gate (operator matrix qubit &rest qubits) | |||
(defun anon-gate (operator-or-gate gate-or-parameters qubit &rest qubits) |
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 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 agree, and I'd take suggestions as to how to name these two cases so that the functions can be split apart. The two use cases are:
(anon-gate "DUMMY-NAME" matrix qn ... q0)
(anon-gate parametric-gate-defn parameter-list qn ... q0)
@@ -391,3 +391,35 @@ as needed so that they are the same size." | |||
(matrix-equality | |||
kroned-ref-mat | |||
(scale-out-matrix-phases kroned-mat kroned-ref-mat)))))) | |||
|
|||
(defun matrix-expt (m s &key hermitian?) | |||
"Computes EXP(M*S). Only works for unitarily diagonalizable matrices M." |
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.
are we avoiding the bad boi that is magicl.transcendental
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 suppose we are. We are calling out to MAGICL, which calls out to LAPACK, but for the diagonalization routines instead of the exponentiation routines.
Importing MAGICL.TRANSCENDENTAL
requires the somewhat uncomfortable secondary import of expokit, which we've so far avoided actually using (and which this also wouldn't use).
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.
tests would be good but I see that is under the "follow ons" section of the PR description
Added a test, which also fixed a bug introduced during PR review. |
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.
It's difficult to really verify the details on much of this (e.g. whether the compilation routines are correct, and so on), so one must rely on tests. In that regard, I think testing the output of make-matrix-from-quil
before and after compiler-hook
on exponentials of random Pauli terms is a nice idea, and gives some confidence. However, for legibility/hackability I would strongly prefer for a few additional tests which are more explicit and which exercise narrower code paths. In particular,
pauli-term->matrix
seems to basically be doing the equivalent of reducing Pauli factors viamagicl:kron
, so a test could check thatpauli-term->matrix
is in fact equivalent to something simpler but perhaps slowerparametric-pauli-compiler
could have a few explicit sanity checks. For example,exp(-iZt/2)
should be equivalent toRZ(t)
, and so on (might consider doing one for a Pauli term of degree 2 as well).- I'm not totally clear on what
parametric-diagonal-compiler
does but it could probably also be tested explicitly in some simple cases.
I concur. The |
@ecpeterson please make sure any follow ons are filed as issues |
Back at it again.
This PR adds support for:
DEFGATE ... AS PAULI-SUM
, which defines a (possibly parametric) gate as an exponentiated Pauli sum (with possibly parametrically-determined coefficients). For example, the following gives a gate definition forCPHASE
:Some possible follow-ons:
Attendant PRs:
Closes #422. Closes #423.