Skip to content

Commit

Permalink
rename quil.foo to quil/foo
Browse files Browse the repository at this point in the history
  • Loading branch information
stylewarning committed Jul 12, 2022
1 parent ddb22de commit 5860591
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 82 deletions.
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))
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
14 changes: 7 additions & 7 deletions examples/qaoa.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
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)))
(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)))
;; Parameters
(betas (loop :for i :below p :collect (quil:mref "beta" i)))
(gammas (loop :for i :below p :collect (quil:mref "gamma" i)))
;; Hamiltonian
(driver-ham (loop :for q :below n
:collect (cl-quil.clifford:embed cl-quil.clifford:+X+ n (list q))))
:collect (cl-quil/clifford:embed cl-quil/clifford:+X+ n (list q))))
(isns (quil:with-inst ()
;; Initialize
(dotimes (q n)
Expand All @@ -36,11 +36,11 @@ COST-HAM should consist of commuting Pauli terms only. (This is *not* checked.)"
(gamma (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 #'quil:inst (cl-quil/clifford::exp-pauli pauli gamma)))

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

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
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
32 changes: 16 additions & 16 deletions src/stabilizer-qvm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Map string gate name to a CLIFFORD object.")

(global-vars:define-global-var **clifford-operations**
(quil.clifford:make-clifford-hash-table)
(cl-quil/clifford:make-clifford-hash-table)
"Map a CLIFFORD to a compiled tableau function.")

(defclass stabilizer-qvm (classical-memory-mixin)
Expand All @@ -26,13 +26,13 @@
(check-type num-qubits unsigned-byte)
(check-type classical-memory-model quil:memory-model)
(make-instance 'stabilizer-qvm
:tableau (cl-quil.clifford::make-tableau-zero-state num-qubits)
:tableau (cl-quil/clifford::make-tableau-zero-state num-qubits)
:classical-memory-subsystem (make-instance 'classical-memory-subsystem
:classical-memory-model
classical-memory-model)))

(defmethod number-of-qubits ((qvm stabilizer-qvm))
(cl-quil.clifford::tableau-qubits (stabilizer-qvm-tableau qvm)))
(cl-quil/clifford::tableau-qubits (stabilizer-qvm-tableau qvm)))

(defun gate-application-to-clifford (gate-app)
(check-type gate-app quil:gate-application)
Expand All @@ -43,25 +43,25 @@
(gethash name **cliffords**)
(unless exists?
(setf (gethash name **cliffords**)
(quil.clifford:matrix-to-clifford
(cl-quil/clifford:matrix-to-clifford
(quil:gate-matrix
(pull-teeth-to-get-a-gate gate-app))))
(setf clifford (gethash name **cliffords**)))
clifford)))
(t (quil.clifford:matrix-to-clifford
(t (cl-quil/clifford:matrix-to-clifford
(quil:gate-matrix
(pull-teeth-to-get-a-gate gate-app))))))

(defun compile-clifford (c &key (cache t))
(check-type c quil.clifford:clifford)
(check-type c cl-quil/clifford:clifford)
(multiple-value-bind (compiled exists?)
(gethash c **clifford-operations**)
(cond
(exists? compiled)
(t
(when *transition-verbose*
(format *trace-output* "~&; compiling Clifford gate...~%"))
(let ((compiled (compile-lambda (cl-quil.clifford::compile-tableau-operation c))))
(let ((compiled (compile-lambda (cl-quil/clifford::compile-tableau-operation c))))
(when cache
(setf (gethash c **clifford-operations**) compiled))
compiled)))))
Expand All @@ -70,10 +70,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;; TRANSITION Methods ;;;;;;;;;;;;;;;;;;;;;;;;;

(defmethod measure ((qvm stabilizer-qvm) q)
(values qvm (cl-quil.clifford::tableau-measure (stabilizer-qvm-tableau qvm) q)))
(values qvm (cl-quil/clifford::tableau-measure (stabilizer-qvm-tableau qvm) q)))

(defmethod transition ((qvm stabilizer-qvm) (instr quil:reset))
(cl-quil.clifford::zero-out-tableau (stabilizer-qvm-tableau qvm))
(cl-quil/clifford::zero-out-tableau (stabilizer-qvm-tableau qvm))
(incf (pc qvm))
qvm)

Expand Down Expand Up @@ -104,7 +104,7 @@
(qubits (mapcar #'quil:qubit-index (quil:application-arguments instr))))
;; Do some error checking.
(let ((given-qubits (length qubits))
(expected-qubits (quil.clifford:num-qubits clifford)))
(expected-qubits (cl-quil/clifford:num-qubits clifford)))
(unless (= given-qubits expected-qubits)
(error 'invalid-instruction-encountered
:instruction instr
Expand Down Expand Up @@ -132,12 +132,12 @@

(defmethod print-object ((o clifford-application) stream)
(print-unreadable-object (o stream :type t :identity t)
(format stream "~Dq" (quil.clifford:num-qubits
(format stream "~Dq" (cl-quil/clifford:num-qubits
(clifford-application-clifford o)))))

(defun make-clifford-application (clifford &rest qubits)
(check-type clifford quil.clifford:clifford)
(assert (= (quil.clifford:num-qubits clifford) (length qubits)))
(check-type clifford cl-quil/clifford:clifford)
(assert (= (cl-quil/clifford:num-qubits clifford) (length qubits)))
(make-instance 'clifford-application :clifford clifford
:arguments (mapcar #'quil:qubit qubits)))

Expand All @@ -161,7 +161,7 @@
(let ((arity (random-range 1 (1+ max-clifford-arity))))
(setf (aref code i)
(apply #'make-clifford-application
(cl-quil.clifford:random-clifford arity)
(cl-quil/clifford:random-clifford arity)
(loop :for q :from (1- arity) :downto 0 :collect q)))))
(when measure
(dotimes (i num-qubits)
Expand All @@ -177,7 +177,7 @@
(qubits (mapcar #'quil:qubit-index (quil:application-arguments instr))))
;; Do some error checking.
(let ((given-qubits (length qubits))
(expected-qubits (quil.clifford:num-qubits clifford)))
(expected-qubits (cl-quil/clifford:num-qubits clifford)))
(unless (= given-qubits expected-qubits)
(error 'invalid-instruction-encountered
:instruction instr
Expand All @@ -194,6 +194,6 @@
(defmethod transition ((qvm pure-state-qvm) (instr clifford-application))
(transition qvm (make-instance 'quil:gate-application
:operator (quil:named-operator "dummy")
:gate (make-instance 'quil:simple-gate :matrix (cl-quil.clifford::clifford-to-matrix (clifford-application-clifford instr)))
:gate (make-instance 'quil:simple-gate :matrix (cl-quil/clifford::clifford-to-matrix (clifford-application-clifford instr)))
:parameters nil
:arguments (quil:application-arguments instr))))
3 changes: 1 addition & 2 deletions tests/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

(fiasco:define-test-package #:qvm-tests
(:use #:qvm)
#+(or sbcl ecl ccl)
(:local-nicknames (:quil :cl-quil.frontend))
(:local-nicknames (#:quil #:cl-quil/frontend))

;; suite.lisp
(:export
Expand Down
Loading

0 comments on commit 5860591

Please sign in to comment.