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

rename quil.foo to quil/foo #294

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app-ng/src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

(defpackage #:qvm-app-ng
(:use #:cl #:qvm)
(:local-nicknames (#:quil #:cl-quil))

;; job.lisp
(:export
Expand Down
8 changes: 4 additions & 4 deletions app-ng/tests/test-rpc-api.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
:collect (string-downcase k) :collect v))

(defun plist->json (plist)
(with-output-to-string (*standard-output*)
Copy link
Contributor

Choose a reason for hiding this comment

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

😬

(yason:encode-plist (plist-lowercase-keys plist))))
(with-output-to-string (s)
(yason:encode-plist (plist-lowercase-keys plist) s)))

(defun plist->hash-table (plist &key (test 'equal))
"Like ALEXANDRIA:PLIST-HASH-TABLE but with TEST defaulting to EQUAL.
Expand Down Expand Up @@ -228,8 +228,8 @@ Invalid persistent QVM token. Expected a v4 UUID. Got \"5e2e05f0-f91c-5f02-96ef-
:qvm-token "5e2e05f0-f91c-4f02-96ef-361ffc55a0fa")
:status 500
:response-callback (response-error-checker "QVM RPC Error: Internal Server Error
Failed to find persistent QVM #1=5e2e05f0-f91c-4f02-96ef-361ffc55a0fa
Failed to find key #1# in SAFETY-HASH")))))
Copy link
Contributor

Choose a reason for hiding this comment

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

shoulda used a regex
j/k

Copy link
Contributor

Choose a reason for hiding this comment

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

in hindsight this check might have been a tad overly specific.

Failed to find persistent QVM 5e2e05f0-f91c-4f02-96ef-361ffc55a0fa
Failed to find key 5e2e05f0-f91c-4f02-96ef-361ffc55a0fa in SAFETY-HASH")))))

(deftest test-rpc-api-404 ()
"Requests for URIs other than \"/\" or for non-existent RPC methods return 404 Not Found."
Expand Down
4 changes: 2 additions & 2 deletions app/src/api/expectation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ amplitudes in PREPARED-STATE."
;; to apply the transpose to OP-MATRIX below, since it is
;; generally smaller. Thus we compute tr(Q^T ρ^T) = tr((ρ Q)^T) = tr(ρ Q) = tr(Q ρ).
(let ((op-matrix (magicl:transpose
(quil::parsed-program-to-logical-matrix op)))
(cl-quil::parsed-program-to-logical-matrix op)))
(density-matrix (magicl:from-array prepared-state
(list rows cols)
:type '(complex double-float))))
(reduce #'+ (magicl:diag
(quil::matrix-rescale-and-multiply op-matrix density-matrix))))))
(cl-quil::matrix-rescale-and-multiply op-matrix density-matrix))))))
17 changes: 6 additions & 11 deletions app/src/debugger.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
;;;;
;;;; Author: Juan M. Bello-Rivas

(defpackage #:qvm-app.debugger
(:use #:common-lisp #:qvm-app)
(:export #:debugger)
(:import-from #:alexandria #:assoc-value #:once-only))

(in-package #:qvm-app.debugger)
(in-package #:qvm-app/debugger)

(defparameter *threshold* (* 1e3 double-float-epsilon) "Smallest amplitude that can be printed.")

Expand Down Expand Up @@ -145,7 +140,7 @@ Run the next instruction and stop."
((program-finished-p)
(format t "Finished program execution.~%"))
(t
(format t "~/quil:instruction-fmt/~%" (qvm::current-instruction *qvm*))
(format t "~/cl-quil:instruction-fmt/~%" (qvm::current-instruction *qvm*))
(setf *qvm* (qvm:transition *qvm* (qvm::current-instruction *qvm*)))
(when *display*
(print-amplitudes)))))
Expand All @@ -166,7 +161,7 @@ Resume program execution from the current instruction."
:until (or (program-finished-p) breakpoint-p) :do
(setf *qvm* (qvm:transition *qvm* (qvm::current-instruction *qvm*)))
:finally (when breakpoint-p
(format t "Stopping at breakpoint in instruction ~D:~%~/quil:instruction-fmt/~%"
(format t "Stopping at breakpoint in instruction ~D:~%~/cl-quil:instruction-fmt/~%"
pc (qvm::current-instruction *qvm*)))
(return *qvm*)))))

Expand All @@ -176,13 +171,13 @@ Resume program execution from the current instruction."
Load a program and instantiate a suitable QVM."
(unless filename
(error "File name not specified."))
(let* ((program (quil:read-quil-file (string-trim " " filename)))
(number-of-qubits (quil:qubits-needed program)))
(let* ((program (cl-quil:read-quil-file (string-trim " " filename)))
(number-of-qubits (cl-quil:qubits-needed program)))
(format t "Read ~A using ~D qubits.~%" filename number-of-qubits)
(setf *source-filename* filename
*qvm* (qvm:make-qvm number-of-qubits
:classical-memory-model (qvm:memory-descriptors-to-qvm-memory-model
(quil:parsed-program-memory-definitions program)))
(cl-quil:parsed-program-memory-definitions program)))
*breakpoints* nil)
(qvm:load-program *qvm* program)))

Expand Down
2 changes: 1 addition & 1 deletion app/src/entry-point.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Copyright (c) 2016-2019 Rigetti Computing.~2%")
(start-server-app host port))

;; Interactive debugger mode.
(debugger (qvm-app.debugger:debugger))
(debugger (qvm-app/debugger:debugger))

;; Batch mode.
(t
Expand Down
8 changes: 7 additions & 1 deletion app/src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
;;;; Author: Robert Smith

(defpackage #:qvm-app
(:use #:cl #:qvm))
(:use #:cl #:qvm)
(:local-nicknames (#:quil #:cl-quil/frontend)))

(defpackage #:qvm-app/debugger
(:use #:cl #:qvm-app)
(:export #:debugger)
(:import-from #:alexandria #:assoc-value #:once-only))
1 change: 1 addition & 0 deletions app/tests/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

(fiasco:define-test-package #:qvm-app-tests
(:use #:qvm-app)
(:local-nicknames (#:quil #:cl-quil))

;; suite.lisp
(:export
Expand Down
2 changes: 1 addition & 1 deletion bench/quil-files.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

(defun timed-run (file)
"Load the Quil file designated by FILE and time its execution."
(let ((quil::*allow-unresolved-applications* t))
(let ((cl-quil::*allow-unresolved-applications* t))
(let* ((program (cl-quil:read-quil-file
(merge-pathnames file *bench-files-directory*)))
(qvm (qvm:make-qvm (cl-quil:qubits-needed program))))
Expand Down
34 changes: 17 additions & 17 deletions examples/qaoa.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@
COST-HAM should consist of commuting Pauli terms only. (This is *not* checked.)"
(check-type p (integer 1))
;; Every Pauli in COST-HAM should have the same number of qubits.
(let* ((n (cl-quil.clifford:num-qubits
(alexandria:extremum cost-ham #'> :key #'cl-quil.clifford:num-qubits)))
(quil (quil:parse-quil (format nil "DECLARE beta REAL[~D]; DECLARE gamma REAL[~D]" p p)))
(let* ((n (cl-quil/clifford:num-qubits
(alexandria:extremum cost-ham #'> :key #'cl-quil/clifford:num-qubits)))
(quil (cl-quil:parse-quil (format nil "DECLARE beta REAL[~D]; DECLARE gamma REAL[~D]" p p)))
;; Parameters
(betas (loop :for i :below p :collect (quil:mref "beta" i)))
(gammas (loop :for i :below p :collect (quil:mref "gamma" i)))
(betas (loop :for i :below p :collect (cl-quil:mref "beta" i)))
(gammas (loop :for i :below p :collect (cl-quil:mref "gamma" i)))
;; Hamiltonian
(driver-ham (loop :for q :below n
:collect (cl-quil.clifford:embed cl-quil.clifford:+X+ n (list q))))
(isns (quil:with-inst ()
:collect (cl-quil/clifford:embed cl-quil/clifford:+X+ n (list q))))
(isns (cl-quil:with-inst ()
;; Initialize
(dotimes (q n)
(quil:inst "H" () q))
(cl-quil:inst "H" () q))
(loop :for beta :in betas
:for gamma :in gammas
:do
(let ((beta (quil::make-delayed-expression nil nil beta))
(gamma (quil::make-delayed-expression nil nil gamma)))
(let ((beta (cl-quil::make-delayed-expression nil nil beta))
(gamma (cl-quil::make-delayed-expression nil nil gamma)))
;; Cost. All the terms are assumed to commute.
(dolist (pauli cost-ham)
(mapc #'quil:inst (cl-quil.clifford::exp-pauli pauli gamma)))
(mapc #'cl-quil:inst (cl-quil/clifford::exp-pauli pauli gamma)))

;; Driver
(dolist (pauli driver-ham)
(mapc #'quil:inst (cl-quil.clifford::exp-pauli pauli beta))))))))
(setf (quil:parsed-program-executable-code quil) (coerce isns 'simple-vector))
(mapc #'cl-quil:inst (cl-quil/clifford::exp-pauli pauli beta))))))))
(setf (cl-quil:parsed-program-executable-code quil) (coerce isns 'simple-vector))
(values quil betas gammas)))

(defun maxcut (graph)
Expand All @@ -50,9 +50,9 @@ COST-HAM should consist of commuting Pauli terms only. (This is *not* checked.)"
GRAPH should be a list of edges, each represented as a pair (A B) of integer vertices."
(loop :with n := (1+ (loop :for (from to) :in graph
:maximize (max from to)))
:with ZZ := (cl-quil.clifford:pauli-from-string "ZZ")
:with ZZ := (cl-quil/clifford:pauli-from-string "ZZ")
:for vertex :in graph
:collect (cl-quil.clifford:embed ZZ n vertex)))
:collect (cl-quil/clifford:embed ZZ n vertex)))

(defun complete-graph (n)
"Build a complete graph of N vertices."
Expand Down Expand Up @@ -93,7 +93,7 @@ After FILE is created, one may plot the data with gnuplot. The following command
(finish-output)))
(out "writing program")
(multiple-value-bind (program betas gammas) (qaoa 1 (maxcut graph))
(let* ((n (quil:qubits-needed program))
(let* ((n (cl-quil:qubits-needed program))
(beta (first betas))
(gamma (first gammas))
(qvm (qvm:make-qvm n)))
Expand Down Expand Up @@ -130,7 +130,7 @@ After FILE is created, one may plot the data with gnuplot. The following command

(defun produce-qvm-for-qaoa-problem (graph)
(multiple-value-bind (program betas gammas) (qaoa 1 (maxcut graph))
(let* ((n (quil:qubits-needed program))
(let* ((n (cl-quil:qubits-needed program))
(qvm (qvm:make-qvm n)))
(qvm:load-program qvm program :supersede-memory-subsystem t)
;(qvm::enable-all-qvm-optimizations)
Expand Down
40 changes: 20 additions & 20 deletions examples/qft.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@
(loop :for i :below (floor n 2)
:for qs :in qubits
:for qe :in (reverse qubits)
:collect (make-instance 'quil:gate-application
:operator #.(quil:named-operator "SWAP")
:name-resolution (quil:lookup-standard-gate "SWAP")
:arguments (list (quil:qubit qs)
(quil:qubit qe)))))))
:collect (make-instance 'cl-quil:gate-application
:operator #.(cl-quil:named-operator "SWAP")
:name-resolution (cl-quil:lookup-standard-gate "SWAP")
:arguments (list (cl-quil:qubit qs)
(cl-quil:qubit qe)))))))

(defun qft-circuit (qubits)
"Generate the QFT circuit on the given qubits."
(labels ((qft (qubits)
(destructuring-bind (q . qs) qubits
(if (null qs)
(list (make-instance 'quil:gate-application
:operator #. (quil:named-operator "H")
:name-resolution (quil:lookup-standard-gate "H")
:arguments (list (quil:qubit q))))
(list (make-instance 'cl-quil:gate-application
:operator #. (cl-quil:named-operator "H")
:name-resolution (cl-quil:lookup-standard-gate "H")
:arguments (list (cl-quil:qubit q))))
(let ((cR nil))
(loop :with n := (1+ (length qs))
:for i :from (1- n) :downto 1
:for qi :in qs
:for angle := (qvm:flonum (/ pi (expt 2 (- n i))))
:do (push (make-instance
'quil:gate-application
:operator #.(quil:named-operator "CPHASE")
:name-resolution (quil:lookup-standard-gate "CPHASE")
:parameters (list (quil:constant angle))
:arguments (list (quil:qubit q)
(quil:qubit qi)))
'cl-quil:gate-application
:operator #.(cl-quil:named-operator "CPHASE")
:name-resolution (cl-quil:lookup-standard-gate "CPHASE")
:parameters (list (cl-quil:constant angle))
:arguments (list (cl-quil:qubit q)
(cl-quil:qubit qi)))
cR))
(append
(qft qs)
cR
(list (make-instance 'quil:gate-application
:operator #. (quil:named-operator "H")
:name-resolution (quil:lookup-standard-gate "H")
:arguments (list (quil:qubit q))))))))))
(make-instance 'quil:parsed-program
(list (make-instance 'cl-quil:gate-application
:operator #. (cl-quil:named-operator "H")
:name-resolution (cl-quil:lookup-standard-gate "H")
:arguments (list (cl-quil:qubit q))))))))))
(make-instance 'cl-quil:parsed-program
:gate-definitions nil
:circuit-definitions nil
:executable-code
Expand Down
38 changes: 19 additions & 19 deletions examples/vqe.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,21 @@ DEFCIRCUIT ANSATZ:
0.18620984259247159d0))
"Coefficients of the Pauli operators present in the Hamiltonian.")

(defparameter *operators* (mapcar #'quil:parse-quil '("I 0"
"Z 0"
"Z 1"
"Z 2"
"Z 3"
"Z 0; Z 1"
"Y 0; X 1; X 2; Y 3"
"X 0; X 1; Y 2; Y 3"
"Y 0; Y 1; X 2; X 3"
"X 0; Y 1; Y 2; X 3"
"Z 0; Z 2"
"Z 0; Z 3"
"Z 1; Z 2"
"Z 1; Z 3"
"Z 2; Z 3"))
(defparameter *operators* (mapcar #'cl-quil:parse-quil '("I 0"
"Z 0"
"Z 1"
"Z 2"
"Z 3"
"Z 0; Z 1"
"Y 0; X 1; X 2; Y 3"
"X 0; X 1; Y 2; Y 3"
"Y 0; Y 1; X 2; X 3"
"X 0; Y 1; Y 2; X 3"
"Z 0; Z 2"
"Z 0; Z 3"
"Z 1; Z 2"
"Z 1; Z 3"
"Z 2; Z 3"))
"Pauli operators in the Hamiltonian.")

(defparameter *initial-thetas* #(0.0d0 -0.036014483d0)
Expand All @@ -242,7 +242,7 @@ DEFCIRCUIT ANSATZ:
"Return a new HAMILTONIAN with an extra term of the form COEFFICIENT times OPERATOR."
(declare (type hamiltonian hamiltonian)
(type qvm:flonum coefficient)
(type quil:parsed-program operator operator))
(type cl-quil:parsed-program operator operator))
(make-instance 'hamiltonian
:coefficients (cons coefficient (slot-value hamiltonian 'coefficients))
:operators (cons operator (slot-value hamiltonian 'operators))))
Expand Down Expand Up @@ -304,7 +304,7 @@ DEFCIRCUIT ANSATZ:
(flet ((objective-function (thetas)
"Compute the energy based on the values of THETAS."
(loop :with quil := (format nil "DECLARE theta REAL[2]~%~A~%~A~%~A~%" reference-state ansatz (make-ansatz-string thetas))
:with state-prep := (quil:parse-quil quil)
:with state-prep := (cl-quil:parse-quil quil)
:with expectations := (qvm-app::perform-expectation 'qvm-app::pure-state state-prep operators number-of-qubits)
:for u :of-type qvm:flonum :in coefficients
:for v :of-type qvm:flonum :in expectations
Expand All @@ -320,7 +320,7 @@ In other words, we return a program implementing the operator A(θ₂)† A(θ
(slot-value vqe-problem 'ansatz)
(make-ansatz-string thetas-1)
(make-ansatz-string thetas-2 :dagger dagger))))
(quil:parse-quil quil)))
(cl-quil:parse-quil quil)))

(defun find-inverse-ansatz (vqe-problem thetas initial-values)
"Let A = A(θ) be the ANSATZ determined by THETAS. Return the value of η that maximizes ⟨0|A(η) A(θ)|0⟩.
Expand All @@ -329,6 +329,6 @@ The value of η is used to implement the penalty term in the deflation method. I
(let ((number-of-qubits (slot-value vqe-problem 'number-of-qubits)))
(flet ((objective-function (etas)
(let ((operators (list (make-penalty-term vqe-problem thetas etas :dagger nil)))
(empty-state-prep (quil:parse-quil "DECLARE theta REAL[2]")))
(empty-state-prep (cl-quil:parse-quil "DECLARE theta REAL[2]")))
(first (qvm-app::perform-expectation 'qvm-app::pure-state empty-state-prep operators number-of-qubits)))))
(cl-grnm:grnm-optimize #'objective-function initial-values))))
2 changes: 1 addition & 1 deletion src/classical-memory-mixin.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
:classical-memory-subsystem (make-instance 'qvm:classical-memory-subsystem)
:wait-function 'warning-wait-function
;; XXX FIXME: To be superseded by some notion of environments.
:gate-definitions (copy-hash-table cl-quil.frontend::**default-gate-definitions**))
:gate-definitions (copy-hash-table cl-quil/frontend::**default-gate-definitions**))
(:metaclass abstract-class)
(:documentation "A mixin for quantum abstract machines making use of a classical memory subsystem and a program vector."))

Expand Down
3 changes: 1 addition & 2 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
(:shadowing-import-from #:mt19937
#:random)

#+(or sbcl ecl ccl)
(:local-nicknames (:quil :cl-quil.frontend))
(:local-nicknames (#:quil #:cl-quil/frontend))

;; config.lisp
(:export
Expand Down
Loading