From b4462b1dac607e9c89c1c2708fc5ad5685a344da Mon Sep 17 00:00:00 2001 From: Robert Smith Date: Tue, 12 Jul 2022 11:24:27 -0700 Subject: [PATCH] bulk rename . to / in packages --- app/src/chip-cache.lisp | 4 +- app/src/entry-point.lisp | 76 ++--- app/src/package.lisp | 5 +- app/src/printers.lisp | 10 +- app/src/rpc-server.lisp | 52 ++-- app/tests/misc-tests.lisp | 62 ++-- app/tests/rpcq-tests.lisp | 68 ++-- app/tests/utils.lisp | 4 +- benchmarking/qaoa-tests/qaoa-bench.lisp | 2 +- benchmarking/qasm-benchmarks.lisp | 16 +- benchmarking/quilc-perf.lisp | 6 +- benchmarking/rewiring-analysis.lisp | 174 +++++------ benchmarking/suite.lisp | 2 +- boondoggle/src/consumers.lisp | 12 +- boondoggle/src/processors.lisp | 4 +- boondoggle/src/producers.lisp | 54 ++-- boondoggle/tests/tests.lisp | 6 +- cl-quil.asd | 14 +- src/addresser/1q-queues.lisp | 2 +- src/addresser/addresser-common.lisp | 20 +- src/addresser/logical-schedule.lisp | 8 +- src/addresser/rewiring.lisp | 2 +- src/analysis/compress-qubits.lisp | 2 +- src/analysis/expand-circuits.lisp | 2 +- src/analysis/expansion.lisp | 12 +- src/analysis/fusion.lisp | 2 +- src/analysis/patch-labels.lisp | 2 +- src/analysis/process-includes.lisp | 2 +- src/analysis/qubits-needed.lisp | 2 +- src/analysis/resolve-objects.lisp | 4 +- src/analysis/rewrite-arithmetic.lisp | 2 +- src/analysis/simplification-grab-bag.lisp | 2 +- src/analysis/simplify-arithmetic.lisp | 2 +- src/analysis/type-safety.lisp | 36 +-- src/analysis/validate-sequence-gate.lisp | 2 +- src/ast.lisp | 32 +- src/build-gate.lisp | 2 +- src/cfg.lisp | 2 +- src/chip-library/chip-table.lisp | 2 +- src/chip-library/package.lisp | 2 +- src/chip/chip-reader.lisp | 4 +- src/cl-quil.lisp | 4 +- src/classical-memory.lisp | 2 +- src/clifford/benchmarking-procedures.lisp | 70 ++--- src/clifford/clifford.lisp | 6 +- src/clifford/god-table-utilities.lisp | 2 +- src/clifford/god-table.lisp | 12 +- src/clifford/pauli.lisp | 36 +-- src/clifford/perm.lisp | 2 +- src/clifford/qubit-algebra.lisp | 2 +- src/clifford/stabilizer.lisp | 4 +- src/clifford/swap-representation.lisp | 2 +- src/clifford/symplectic.lisp | 2 +- src/compilation-methods.lisp | 6 +- src/compiler-hook.lisp | 4 +- src/compilers/modifiers.lisp | 2 +- src/compilers/old-tweedledum-readme.md | 2 +- src/compilers/permutation.lisp | 2 +- src/compilers/state-prep.lisp | 2 +- src/define-pragma.lisp | 2 +- src/discrete/compilers/clifford-t.lisp | 2 +- src/discrete/discrete-chip.lisp | 2 +- src/discrete/discrete-common.lisp | 2 +- src/discrete/numeric/circle.lisp | 2 +- src/discrete/numeric/cyclotomic8.lisp | 2 +- src/discrete/numeric/dyadic.lisp | 2 +- src/discrete/numeric/interval.lisp | 2 +- src/discrete/numeric/linear-algebra.lisp | 2 +- src/discrete/numeric/modulo.lisp | 2 +- src/discrete/numeric/naturals.lisp | 2 +- src/discrete/numeric/root2plex.lisp | 2 +- src/discrete/numeric/utilities.lisp | 2 +- src/discrete/operators/c2root2.lisp | 2 +- src/discrete/operators/clifford.lisp | 2 +- src/discrete/operators/gates1.lisp | 2 +- src/discrete/operators/hadamardt.lisp | 2 +- src/discrete/operators/ma-normal-form.lisp | 2 +- src/discrete/operators/mat2.lisp | 2 +- src/discrete/operators/pauli.lisp | 2 +- src/discrete/operators/rz.lisp | 2 +- src/discrete/operators/sunitary2.lisp | 2 +- src/discrete/operators/unitary2.lisp | 2 +- src/discrete/operators/utilities.lisp | 2 +- src/discrete/package.lisp | 34 +- .../rz-approx/candidate-generation.lisp | 2 +- .../rz-approx/candidate-verification.lisp | 2 +- src/discrete/rz-approx/generate-solution.lisp | 2 +- src/frontend-options.lisp | 2 +- src/frontend-utilities.lisp | 6 +- src/gates.lisp | 2 +- src/initialize-standard-gates.lisp | 2 +- src/magicl-constructors.lisp | 2 +- src/matrix-operations.lisp | 2 +- src/package.lisp | 65 ++-- src/parser.lisp | 2 +- src/pragmas.lisp | 2 +- src/{ => qasm}/qasm.lisp | 138 +++++---- src/queue.lisp | 2 +- src/quilec/README.org | 8 +- src/quilec/cleve-gottesman.lisp | 2 +- src/quilec/matrix.lisp | 2 +- src/quilec/package.lisp | 7 +- src/quilec/stabilizer-group.lisp | 4 +- src/quilt/analysis/expand-calibrations.lisp | 2 +- src/quilt/analysis/fill-delays.lisp | 4 +- src/quilt/analysis/resolve-objects.lisp | 4 +- src/quilt/analysis/type-safety.lisp | 12 +- src/quilt/ast.lisp | 36 +-- src/quilt/cl-quilt.lisp | 4 +- src/quilt/package.lisp | 19 +- src/quilt/parser.lisp | 2 +- src/quilt/waveform.lisp | 4 +- src/resource.lisp | 2 +- src/tools/README.md | 8 +- src/tools/circuit-diagram.lisp | 72 ++--- src/tools/hasse-schedule.lisp | 20 +- src/tools/package.lisp | 9 +- src/transformable-mixin.lisp | 2 +- src/types.lisp | 2 +- src/with-inst.lisp | 2 +- tests/addresser-tests.lisp | 124 ++++---- tests/analysis-tests.lisp | 196 ++++++------ tests/ansatz-search-tests.lisp | 16 +- tests/approximation-tests.lisp | 48 +-- tests/benchmarking-procedures-tests.lisp | 76 ++--- tests/cfg-tests.lisp | 116 +++---- tests/chip-library/chip-table-tests.lisp | 2 +- tests/chip-library/package.lisp | 4 +- tests/chip-library/suite.lisp | 8 +- tests/chip-specification-tests.lisp | 22 +- tests/classical-memory-tests.lisp | 16 +- tests/clifford-tests.lisp | 258 ++++++++-------- tests/compilation-tests.lisp | 164 +++++----- tests/compiler-hook-tests.lisp | 292 +++++++++--------- tests/csd-tests.lisp | 30 +- tests/defcircuit-tests.lisp | 102 +++--- tests/discrete/compilation-tests.lisp | 8 +- tests/discrete/package.lisp | 25 +- tests/discrete/rz-approx-tests.lisp | 2 +- tests/discrete/suite.lisp | 12 +- tests/discrete/tests.lisp | 9 + tests/initial-rewiring-tests.lisp | 94 +++--- tests/lexer-tests.lisp | 2 +- tests/linear-reversible-circuit-tests.lisp | 2 +- tests/logical-matrix-sanity-tests.lisp | 26 +- tests/misc-tests.lisp | 256 +++++++-------- tests/package.lisp | 11 +- tests/parser-tests.lisp | 60 ++-- tests/permutation-tests.lisp | 34 +- tests/printer-tests.lisp | 78 ++--- tests/qasm-tests.lisp | 286 ++++++++--------- tests/quilec/cleve-gottesman-tests.lisp | 36 +-- tests/quilec/package.lisp | 11 +- tests/quilec/stabilizer-group-tests.lisp | 4 +- tests/quilec/suite.lisp | 8 +- tests/quilt/analysis-tests.lisp | 10 +- tests/quilt/calibration-tests.lisp | 4 +- tests/quilt/package.lisp | 12 +- tests/quilt/parser-tests.lisp | 20 +- tests/quilt/suite.lisp | 8 +- tests/resource-tests.lisp | 84 ++--- tests/rewrite-tests.lisp | 20 +- tests/state-prep-tests.lisp | 130 ++++---- tests/suite.lisp | 2 +- tests/tools/circuit-diagram-tests.lisp | 14 +- tests/tools/hasse-diagram-tests.lisp | 2 +- tests/tools/package.lisp | 8 +- tests/tools/suite.lisp | 6 +- tests/translator-tests.lisp | 198 ++++++------ tests/typed-memory-tests.lisp | 54 ++-- tests/utilities.lisp | 8 +- 171 files changed, 2196 insertions(+), 2243 deletions(-) rename src/{ => qasm}/qasm.lisp (87%) create mode 100644 tests/discrete/tests.lisp diff --git a/app/src/chip-cache.lisp b/app/src/chip-cache.lisp index da13d11bd..1d01d0743 100644 --- a/app/src/chip-cache.lisp +++ b/app/src/chip-cache.lisp @@ -18,7 +18,7 @@ :accessor cached-chip-chip) (addresser-state :initarg :addresser-state - :type quil::addresser-state + :type cl-quil::addresser-state :accessor cached-chip-addresser-state)) (:documentation "Represents chip and addresser state cached between server requests.")) @@ -60,7 +60,7 @@ This function has the added side-effect that it will purge old chips according t (get-internal-real-time-seconds)) cached-chip) (t - (let* ((chip (quil::qpu-hash-table-to-chip-specification qpu-hash)) + (let* ((chip (cl-quil::qpu-hash-table-to-chip-specification qpu-hash)) (cached-chip (make-instance 'cached-chip :last-accessed (get-internal-real-time-seconds) :chip chip))) diff --git a/app/src/entry-point.lisp b/app/src/entry-point.lisp index e67413366..accbf03cc 100644 --- a/app/src/entry-point.lisp +++ b/app/src/entry-point.lisp @@ -32,7 +32,7 @@ (defun lookup-isa-descriptor-for-name (isa) (or (call-chip-builder isa) (if (probe-file isa) - (quil::read-chip-spec-file isa) + (cl-quil::read-chip-spec-file isa) (error "ISA descriptor does not name a known template or an extant file.")))) (defun log-level-string-to-symbol (log-level) @@ -83,11 +83,11 @@ (defun show-backends () (format t "Available backends:~%") - (format t "~{ ~(~A~)~^~%~}~%" (mapcar #'quil:backend-name (quil:list-available-backends)))) + (format t "~{ ~(~A~)~^~%~}~%" (mapcar #'cl-quil:backend-name (cl-quil:list-available-backends)))) (defun show-chips () (format t "Available ISAs:~%") - (format t "~{ ~(~A~)~^~%~}~%" (cl-quil.chip-library:available-chips))) + (format t "~{ ~(~A~)~^~%~}~%" (cl-quil/chip-library:available-chips))) (defun check-libraries () "Check that the foreign libraries are adequate. Exits with status @@ -313,16 +313,16 @@ #-windows (cl-syslog:tee-to-stream (cl-syslog:syslog-log-writer "quilc" :local0) *error-output*))) - (quil::*prefer-ranged-gates-to-SWAPs* prefer-gate-ladders) + (cl-quil::*prefer-ranged-gates-to-SWAPs* prefer-gate-ladders) (*without-pretty-printing* without-pretty-printing) - (quil::*enable-state-prep-compression* enable-state-prep-reductions) + (cl-quil::*enable-state-prep-compression* enable-state-prep-reductions) ;; Null out the streams. If no server mode is requested, these bindings will be modified ;; before calling run-CLI-mode, below. (*human-readable-stream* (make-broadcast-stream)) (*quil-stream* (make-broadcast-stream)) (*protoquil* protoquil) (*state-aware* enable-state-prep-reductions) - (quil::*safe-include-directory* safe-include-directory) + (cl-quil::*safe-include-directory* safe-include-directory) (*chip-cache-max-size* chip-cache)) (when check-sdk-version @@ -350,7 +350,7 @@ don't make sense when using server mode. ~ Ignoring them."))) (when verbose - (setf quil::*compiler-noise* *error-output*) + (setf cl-quil::*compiler-noise* *error-output*) (warn "--verbose output is not appropriate for production multithreaded environments, and should b used when debugging and with care")) ;; launch the polling loop (start-rpc-server :host host @@ -416,7 +416,7 @@ :tolerance t) (print-matrix-comparision original-matrix - (quil::scale-out-matrix-phases processed-program-matrix original-matrix)))))) + (cl-quil::scale-out-matrix-phases processed-program-matrix original-matrix)))))) ;; New and improved flow (when compile @@ -430,7 +430,7 @@ enabled. Specify an output file with -o or ~ --output.")) - (let ((backend-class (quil:find-backend backend))) + (let ((backend-class (cl-quil:find-backend backend))) (unless backend-class (error "The backend value '~a' does not name an ~ available backend. For a list of available ~ @@ -441,7 +441,7 @@ (let ((backend (apply #'make-instance backend-class (parse-backend-options backend-option)))) - (unless (quil:backend-supports-chip-p backend chip-spec) + (unless (cl-quil:backend-supports-chip-p backend chip-spec) (error "The backend provided does not support this ISA.")) (backend-compile-program processed-program chip-spec backend output))))))))))) @@ -464,8 +464,8 @@ :element-type '(unsigned-byte 8) :if-exists ':supersede :if-does-not-exist ':create) - (let ((executable (quil:backend-compile program chip-spec backend))) - (quil:write-executable executable stream)))) + (let ((executable (cl-quil:backend-compile program chip-spec backend))) + (cl-quil:write-executable executable stream)))) (defun process-program (program chip-specification &key @@ -480,9 +480,9 @@ Note: PROGRAM is mutated by the compilation process. To avoid this, use COPY-INS Returns a values tuple (PROCESSED-PROGRAM, STATISTICS), where PROCESSED-PROGRAM is the compiled program, and STATISTICS is a HASH-TABLE whose keys are the slots of the RPCQ::|NativeQuilMetadata| class." (let* ((statistics (make-hash-table :test #'equal)) - (quil::*compiler-noise* verbose) + (cl-quil::*compiler-noise* verbose) (*random-state* (make-random-state t)) - (quil::*enable-state-prep-compression* state-aware)) + (cl-quil::*enable-state-prep-compression* state-aware)) ;; do the compilation (multiple-value-bind (processed-program topological-swaps) (compiler-hook program chip-specification :protoquil protoquil :destructive t) @@ -512,18 +512,18 @@ Returns a values tuple (PROCESSED-PROGRAM, STATISTICS), where PROCESSED-PROGRAM This function will have undefined behavior when PROCESSED-PROGRAM is not protoquil." (setf (gethash "final_rewiring" statistics) - (quil::extract-final-exit-rewiring-vector processed-program)) + (cl-quil::extract-final-exit-rewiring-vector processed-program)) - (let ((lschedule (quil::make-lscheduler))) + (let ((lschedule (cl-quil::make-lscheduler))) (loop :for instr :across (parsed-program-executable-code processed-program) :unless (typep instr 'pragma) - :do (quil::append-instruction-to-lschedule lschedule instr)) + :do (cl-quil::append-instruction-to-lschedule lschedule instr)) (setf (gethash "logical_schedule" statistics) lschedule)) ;; gate depth, gate volume, duration, and fidelity stats can ;; all share an lschedule - (let ((lschedule (quil::make-lscheduler))) + (let ((lschedule (cl-quil::make-lscheduler))) (loop :for instr :across (parsed-program-executable-code processed-program) :when (and (typep instr 'gate-application) (not (member (cl-quil::application-operator-root-name instr) @@ -533,47 +533,47 @@ This function will have undefined behavior when PROCESSED-PROGRAM is not protoqu (member (cl-quil::application-operator-root-name instr) gate-whitelist :test #'string=))) - :do (quil::append-instruction-to-lschedule lschedule instr)) + :do (cl-quil::append-instruction-to-lschedule lschedule instr)) (setf (gethash "gate_depth" statistics) - (quil::lscheduler-calculate-depth lschedule)) + (cl-quil::lscheduler-calculate-depth lschedule)) (setf (gethash "gate_volume" statistics) - (quil::lscheduler-calculate-volume lschedule)) + (cl-quil::lscheduler-calculate-volume lschedule)) (setf (gethash "program_duration" statistics) - (quil::lscheduler-calculate-duration lschedule chip-specification)) + (cl-quil::lscheduler-calculate-duration lschedule chip-specification)) (setf (gethash "program_fidelity" statistics) - (quil::lscheduler-calculate-fidelity lschedule chip-specification)) + (cl-quil::lscheduler-calculate-fidelity lschedule chip-specification)) (let* ((lscheduler-resources - (let ((collect (quil::make-null-resource))) - (quil::lscheduler-walk-graph + (let ((collect (cl-quil::make-null-resource))) + (cl-quil::lscheduler-walk-graph lschedule :bump-value (lambda (instr value) (setf collect - (quil::resource-union collect - (quil::instruction-resources instr))) + (cl-quil::resource-union collect + (cl-quil::instruction-resources instr))) value)) collect)) (unused-qubits - (loop :for i :below (quil::chip-spec-n-qubits chip-specification) - :unless (quil::resources-intersect-p (quil::make-qubit-resource i) + (loop :for i :below (cl-quil::chip-spec-n-qubits chip-specification) + :unless (cl-quil::resources-intersect-p (cl-quil::make-qubit-resource i) lscheduler-resources) :collect i))) (setf (gethash "unused_qubits" statistics) unused-qubits))) ;; multiq gate depth requires a separate lschedule - (let ((lschedule (quil::make-lscheduler))) + (let ((lschedule (cl-quil::make-lscheduler))) (loop :for instr :across (parsed-program-executable-code processed-program) :when (and (typep instr 'gate-application) (<= 2 (length (application-arguments instr)))) - :do (quil::append-instruction-to-lschedule lschedule instr) + :do (cl-quil::append-instruction-to-lschedule lschedule instr) :finally (setf (gethash "multiqubit_gate_depth" statistics) - (quil::lscheduler-calculate-depth lschedule)))) + (cl-quil::lscheduler-calculate-depth lschedule)))) statistics) @@ -581,21 +581,21 @@ This function will have undefined behavior when PROCESSED-PROGRAM is not protoqu "Remove the final HALT instruction, if any, from PROCESSED-PROGRAM, retaining any attached rewiring comments." (let* ((instructions (parsed-program-executable-code processed-program)) (last-instruction (and (plusp (length instructions)) - (quil::nth-instr 0 processed-program :from-end t))) + (cl-quil::nth-instr 0 processed-program :from-end t))) (penultimate-instruction (and (< 1 (length instructions)) - (quil::nth-instr 1 processed-program :from-end t))) + (cl-quil::nth-instr 1 processed-program :from-end t))) (must-transfer-comment-p (and (not (null penultimate-instruction)) (comment last-instruction)))) - (unless (quil::haltp last-instruction) + (unless (cl-quil::haltp last-instruction) (return-from strip-final-halt-respecting-rewirings instructions)) (when must-transfer-comment-p ;; Transfer the rewiring comment from LAST-INSTRUCTION to PENULTIMATE-INSTRUCTION. (multiple-value-bind (last-entering last-exiting) - (quil::instruction-rewirings last-instruction) + (cl-quil::instruction-rewirings last-instruction) (multiple-value-bind (penultimate-entering penultimate-exiting) - (quil::instruction-rewirings penultimate-instruction) + (cl-quil::instruction-rewirings penultimate-instruction) (flet ((assert-rewirings-compatible (rewiring-type last-rewiring penultimate-rewiring) ;; This bit of hoop-jumping guards against the unlikely event that both ;; PENULTIMATE-INSTRUCTION and LAST-INSTRUCTION have rewiring comments attached @@ -628,7 +628,7 @@ This function will have undefined behavior when PROCESSED-PROGRAM is not protoqu ;; at least one of the :ENTERING and :EXITING keyword args to MAKE-REWIRING-COMMENT is ;; non-NIL and hence the call will produce a rewiring comment. (setf (comment penultimate-instruction) - (quil::make-rewiring-comment :entering (or last-entering penultimate-entering) + (cl-quil::make-rewiring-comment :entering (or last-entering penultimate-entering) :exiting (or last-exiting penultimate-exiting)))))) ;; Strip the final HALT instruction. diff --git a/app/src/package.lisp b/app/src/package.lisp index c861a9c66..be6c4ae51 100644 --- a/app/src/package.lisp +++ b/app/src/package.lisp @@ -5,5 +5,6 @@ (in-package #:cl-user) (defpackage #:quilc - (:use #:cl #:cl-quil #:cl-quil.chip-library) - (:local-nicknames (:a :alexandria))) + (:use #:cl #:cl-quil #:cl-quil/chip-library) + (:local-nicknames (#:a #:alexandria) + (#:quil #:cl-quil))) diff --git a/app/src/printers.lisp b/app/src/printers.lisp index 581f4d17d..21a3a0901 100644 --- a/app/src/printers.lisp +++ b/app/src/printers.lisp @@ -27,21 +27,21 @@ print out their `global-phase-invariant-distance' with no error." (format stream "~%#Matrices have a global phase invariant distance of ~E~%" (cl-quil::global-phase-invariant-distance m1 m2)) (format stream "~%#Matrices are~:[ not~;~] equal~%" - (quil::matrix-equals-dwim m1 m2))) + (cl-quil::matrix-equals-dwim m1 m2))) (finish-output stream)) (defun print-program (processed-program &optional (stream *standard-output*)) (let ((program-as-string (with-output-to-string (s) - (let ((quil::*print-fractional-radians* (not *without-pretty-printing*))) - (quil::print-parsed-program processed-program s))))) + (let ((cl-quil::*print-fractional-radians* (not *without-pretty-printing*))) + (cl-quil::print-parsed-program processed-program s))))) (if stream (write-string program-as-string stream) program-as-string))) ;; custom encoder for rewiring objects -(defmethod yason:encode ((object quil::rewiring) &optional (stream *standard-output*)) - (yason:encode (quil::rewiring-l2p object) stream)) +(defmethod yason:encode ((object cl-quil::rewiring) &optional (stream *standard-output*)) + (yason:encode (cl-quil::rewiring-l2p object) stream)) (defun print-statistics (statistics &optional (stream *human-readable-stream*)) (format stream diff --git a/app/src/rpc-server.lisp b/app/src/rpc-server.lisp index 698212cf6..03ff9271c 100644 --- a/app/src/rpc-server.lisp +++ b/app/src/rpc-server.lisp @@ -17,8 +17,8 @@ (defun runtime-estimation (parsed-protoquil-program) "Estimated QPU runtime of PARSED-PROTOQUIL-PROGRAM. Likely to be an over-estimate for small depth programs, where runtime is dominated by network latency and compilation, etc. Take these results with a grain of salt." - (when (and (typep parsed-protoquil-program 'quil:parsed-program) - (quil:protoquil-program-p parsed-protoquil-program)) + (when (and (typep parsed-protoquil-program 'cl-quil:parsed-program) + (cl-quil:protoquil-program-p parsed-protoquil-program)) ;; These opaque numbers come from an analysis of the runtimes of a ;; large number of randomly generated programs targeting a 16Q ;; lattice. Those programs were a random mixture of 1- and 2Q @@ -26,9 +26,9 @@ (loop :with coeff-oneq := 1.6291 :with coeff-twoq := 1.701 :with runtime := 181.89 - :for instr :across (quil:parsed-program-executable-code parsed-protoquil-program) - :when (typep instr 'quil:application) :do - (case (length (quil:application-arguments instr)) + :for instr :across (cl-quil:parsed-program-executable-code parsed-protoquil-program) + :when (typep instr 'cl-quil:application) :do + (case (length (cl-quil:application-arguments instr)) (1 (incf runtime coeff-oneq)) (2 (incf runtime coeff-twoq))) :finally (return runtime)))) @@ -69,14 +69,14 @@ (t t)))) (unless (slot-boundp cache 'addresser-state) (setf (cached-chip-addresser-state cache) - (make-instance quil::*default-addresser-state-class* + (make-instance cl-quil::*default-addresser-state-class* :chip-spec chip-specification - :initial-l2p (quil::prog-initial-rewiring quil-program chip-specification)))) + :initial-l2p (cl-quil::prog-initial-rewiring quil-program chip-specification)))) (multiple-value-bind (processed-program statistics-dict) (process-program quil-program chip-specification :protoquil protoquil :state-aware state-aware - :verbose quil::*compiler-noise*) + :verbose cl-quil::*compiler-noise*) (when protoquil (setf (gethash "qpu_runtime_estimation" statistics-dict) (runtime-estimation processed-program))) @@ -108,7 +108,7 @@ (error "Seed must be a positive integer.")) (when (> n 2) (error "Currently no more than two qubit randomized benchmarking is supported.")) - (let* ((cliffords (mapcar #'quil.clifford::clifford-from-quil gateset)) + (let* ((cliffords (mapcar #'cl-quil/clifford::clifford-from-quil gateset)) (qubits-used (mapcar (a:compose #'qubits-used #'safely-parse-quil) gateset)) (qubits-used-by-interleaver @@ -118,13 +118,13 @@ (embedded-cliffords (loop :for clifford :in cliffords :for i :from 0 :collect - (quil.clifford:embed clifford n + (cl-quil/clifford:embed clifford n ;; See below (reverse (loop :for index :in (nth i qubits-used) :collect (position index qubits)))))) (embedded-interleaver (when interleaver - (quil.clifford:embed (quil.clifford::clifford-from-quil interleaver) + (cl-quil/clifford:embed (cl-quil/clifford::clifford-from-quil interleaver) n ;; XXX: the embedding ordering has ;; been reversed to comply with @@ -138,11 +138,11 @@ (let ((*random-state* #+sbcl (if seed (sb-ext:seed-random-state seed) *random-state*) #-sbcl *random-state*)) - (quil.clifford::rb-sequence k n embedded-cliffords embedded-interleaver))) + (cl-quil/clifford::rb-sequence k n embedded-cliffords embedded-interleaver))) (gateset-label-sequence (loop :for clifford-element :in rb-sequence :collect (loop :for generator :in clifford-element - :collect (position generator embedded-cliffords :test #'quil.clifford:clifford=))))) + :collect (position generator embedded-cliffords :test #'cl-quil/clifford:clifford=))))) (make-instance 'rpcq::|RandomizedBenchmarkingResponse| :|sequence| gateset-label-sequence)))) @@ -155,7 +155,7 @@ (pauli-terms (coerce (rpcq::|PauliTerm-symbols| pauli) 'list)) (clifford-indices (sort (cl-quil:qubits-used (cl-quil:safely-parse-quil clifford-program)) #'<)) (qubits (sort (union (copy-seq pauli-indices) (copy-seq clifford-indices)) #'<)) - (pauli (quil.clifford:pauli-from-string + (pauli (cl-quil/clifford:pauli-from-string ;; XXX: the pauli-from-string and embedding orderings ;; have been reversed to comply with the ;; computational basis convention, hence the reverse @@ -165,16 +165,16 @@ (cond ((member i pauli-indices) (write-string (nth (position i pauli-indices) pauli-terms) s)) (T (write-string "I" s)))))))) - (clifford (cl-quil.clifford::embed (quil.clifford::clifford-from-quil clifford-program) + (clifford (cl-quil/clifford::embed (cl-quil/clifford::clifford-from-quil clifford-program) (length qubits) ;; Likewise to the above. (reverse (loop :for index :in clifford-indices :collect (position index qubits))))) - (pauli-out (quil.clifford:apply-clifford clifford pauli))) + (pauli-out (cl-quil/clifford:apply-clifford clifford pauli))) (make-instance 'rpcq::|ConjugateByCliffordResponse| - :|phase| (quil.clifford::phase-factor pauli-out) + :|phase| (cl-quil/clifford::phase-factor pauli-out) :|pauli| (apply #'concatenate 'string - (mapcar (a:compose #'symbol-name #'quil.clifford::base4-to-sym) - (quil.clifford::base4-list pauli-out)))))) + (mapcar (a:compose #'symbol-name #'cl-quil/clifford::base4-to-sym) + (cl-quil/clifford::base4-list pauli-out)))))) (defun rewrite-arithmetic-handler (request) "Rewrites the request program without arithmetic in gate parameters." @@ -186,22 +186,22 @@ (let ((reformatted-rt (make-hash-table))) (maphash (lambda (key val) (setf (gethash (make-instance 'rpcq::|ParameterAref| - :|name| (quil::memory-ref-name key) - :|index| (quil::memory-ref-position key)) + :|name| (cl-quil::memory-ref-name key) + :|index| (cl-quil::memory-ref-position key)) reformatted-rt) - (quil::print-instruction val nil))) + (cl-quil::print-instruction val nil))) recalculation-table) (make-instance 'rpcq::|RewriteArithmeticResponse| :|quil| (with-output-to-string (s) - (quil::print-parsed-program rewritten-program s)) + (cl-quil::print-parsed-program rewritten-program s)) :|original_memory_descriptors| (a:alist-hash-table (mapcar (lambda (memory-defn) - (cons (quil::memory-descriptor-name memory-defn) + (cons (cl-quil::memory-descriptor-name memory-defn) (make-instance 'rpcq::|ParameterSpec| - :|type| (quil::quil-type-string (quil::memory-descriptor-type memory-defn)) - :|length| (quil::memory-descriptor-length memory-defn)))) + :|type| (cl-quil::quil-type-string (cl-quil::memory-descriptor-type memory-defn)) + :|length| (cl-quil::memory-descriptor-length memory-defn)))) original-memory-descriptors)) :|recalculation_table| reformatted-rt))))) diff --git a/app/tests/misc-tests.lisp b/app/tests/misc-tests.lisp index 721f3cb21..307034db8 100644 --- a/app/tests/misc-tests.lisp +++ b/app/tests/misc-tests.lisp @@ -21,20 +21,20 @@ (deftest test-process-program () (let ((progm "H 0") - (chip (quil::build-nq-fully-connected-chip 2)) + (chip (cl-quil::build-nq-fully-connected-chip 2)) (stats '("topological_swaps" "logical_schedule" "gate_depth" "gate_volume" "program_duration" "program_fidelity" "unused_qubits" "multiqubit_gate_depth"))) ;; Test that a direct call to PROCESS-PROGRAM respects protoquil ;; and returns a statistics dictionary. - (let ((pp (quil:parse-quil progm))) + (let ((pp (cl-quil:parse-quil progm))) (multiple-value-bind (processed-program statistics) (quilc::process-program pp chip :protoquil t) - (is (quil:protoquil-program-p processed-program)) + (is (cl-quil:protoquil-program-p processed-program)) (dolist (stat stats) (is (nth-value 1 (gethash stat statistics)))))) ;; Likewise, test that without :PROTOQUIL T there is an empty ;; stats dictionary. - (let ((pp (quil:parse-quil progm))) + (let ((pp (cl-quil:parse-quil progm))) (multiple-value-bind (_ statistics) (quilc::process-program pp chip :protoquil nil) (declare (ignore _)) @@ -49,22 +49,22 @@ (defun attach-rewirings-at-index (pp index &rest args &key entering exiting) ;; Like CL-QUIL-TESTS::ATTACH-REWIRINGS-TO-PROGRAM, but instead of attaching the rewiring on the ;; first/last instr of PP, attach the rewiring at the requested INDEX. - (check-type entering (or null quil::integer-vector)) - (check-type exiting (or null quil::integer-vector)) + (check-type entering (or null cl-quil::integer-vector)) + (check-type exiting (or null cl-quil::integer-vector)) (assert (or entering exiting)) - (setf (quil:comment (quil::nth-instr index pp)) - (apply #'quil::make-rewiring-comment args)) + (setf (cl-quil:comment (cl-quil::nth-instr index pp)) + (apply #'cl-quil::make-rewiring-comment args)) pp) (deftest test-strip-final-halt-respecting-rewirings () ;; An empty program produces an empty vector - (is (equalp #() (quilc::strip-final-halt-respecting-rewirings (quil:parse-quil "")))) + (is (equalp #() (quilc::strip-final-halt-respecting-rewirings (cl-quil:parse-quil "")))) ;; Only a single final HALT is stripped. - (let* ((pp (quil:parse-quil "X 0; HALT; HALT")) + (let* ((pp (cl-quil:parse-quil "X 0; HALT; HALT")) (stripped-code (quilc::strip-final-halt-respecting-rewirings pp))) (is (= 2 (length stripped-code))) - (is (quil::haltp (quil::vnth 1 stripped-code)))) + (is (cl-quil::haltp (cl-quil::vnth 1 stripped-code)))) ;; Mid-program HALTs are ignored. (let* ((pp (with-output-to-quil @@ -74,23 +74,23 @@ "HALT")) (stripped-code (quilc::strip-final-halt-respecting-rewirings pp))) (is (= 3 (length stripped-code))) - (is (quil::haltp (quil::vnth 1 stripped-code))) - (is (not (quil::haltp (quil::vnth 2 stripped-code))))) + (is (cl-quil::haltp (cl-quil::vnth 1 stripped-code))) + (is (not (cl-quil::haltp (cl-quil::vnth 2 stripped-code))))) ;; single non-halt instr - (let* ((pp (attach-rewirings-at-index (quil:parse-quil "X 0") + (let* ((pp (attach-rewirings-at-index (cl-quil:parse-quil "X 0") 0 :entering #(0 1 2) :exiting #(2 1 0))) (stripped-code (quilc::strip-final-halt-respecting-rewirings pp))) (is (= 1 (length stripped-code))) (multiple-value-bind (entering-rewiring exiting-rewiring) - (quil::instruction-rewirings (quil::vnth 0 stripped-code)) - (is (equalp #(0 1 2) (quil::rewiring-l2p entering-rewiring))) - (is (equalp #(2 1 0) (quil::rewiring-l2p exiting-rewiring))))) + (cl-quil::instruction-rewirings (cl-quil::vnth 0 stripped-code)) + (is (equalp #(0 1 2) (cl-quil::rewiring-l2p entering-rewiring))) + (is (equalp #(2 1 0) (cl-quil::rewiring-l2p exiting-rewiring))))) ;; single halt instr - (let* ((pp (attach-rewirings-at-index (quil:parse-quil "HALT") + (let* ((pp (attach-rewirings-at-index (cl-quil:parse-quil "HALT") 0 :entering #(0 1 2) :exiting #(2 1 0))) @@ -98,26 +98,26 @@ (is (equalp #() stripped-code))) ;; 2-instr no halts, entering/exiting rewirings untouched - (let* ((pp (quil:parse-quil "X 0; Y 1")) + (let* ((pp (cl-quil:parse-quil "X 0; Y 1")) (pp (attach-rewirings-at-index pp 0 :entering #(0 1 2) :exiting #(2 1 0))) (pp (attach-rewirings-at-index pp 1 :entering #(1 2 0) :exiting #(0 2 1))) (stripped-code (quilc::strip-final-halt-respecting-rewirings pp))) (is (= 2 (length stripped-code))) (multiple-value-bind (entering-rewiring exiting-rewiring) - (quil::instruction-rewirings (quil::vnth 0 stripped-code)) - (is (equalp #(0 1 2) (quil::rewiring-l2p entering-rewiring))) - (is (equalp #(2 1 0) (quil::rewiring-l2p exiting-rewiring)))) + (cl-quil::instruction-rewirings (cl-quil::vnth 0 stripped-code)) + (is (equalp #(0 1 2) (cl-quil::rewiring-l2p entering-rewiring))) + (is (equalp #(2 1 0) (cl-quil::rewiring-l2p exiting-rewiring)))) (multiple-value-bind (entering-rewiring exiting-rewiring) - (quil::instruction-rewirings (quil::vnth 1 stripped-code)) - (is (equalp #(1 2 0) (quil::rewiring-l2p entering-rewiring))) - (is (equalp #(0 2 1) (quil::rewiring-l2p exiting-rewiring))))) + (cl-quil::instruction-rewirings (cl-quil::vnth 1 stripped-code)) + (is (equalp #(1 2 0) (cl-quil::rewiring-l2p entering-rewiring))) + (is (equalp #(0 2 1) (cl-quil::rewiring-l2p exiting-rewiring))))) ;; {2,3}-instruction terminal halt (dolist (quil '("X 0; HALT" "H 0; CNOT 0 1; HALT")) (labels ((attach-rewirings (&key last-entering last-exiting penultimate-entering penultimate-exiting) - (let* ((pp (quil:parse-quil quil)) - (last-index (1- (length (quil::parsed-program-executable-code pp)))) + (let* ((pp (cl-quil:parse-quil quil)) + (last-index (1- (length (cl-quil::parsed-program-executable-code pp)))) (penultimate-index (1- last-index))) ;; attach the rewirings @@ -137,16 +137,16 @@ (stripped-code (quilc::strip-final-halt-respecting-rewirings pp))) ;; final HALT was stripped - (is (= (length stripped-code) (1- (length (quil::parsed-program-executable-code pp))))) + (is (= (length stripped-code) (1- (length (cl-quil::parsed-program-executable-code pp))))) ;; rewirings were correctly copied (multiple-value-bind (stripped-entering stripped-exiting) - (quil::instruction-rewirings (quil::vnth (1- (length stripped-code)) + (cl-quil::instruction-rewirings (cl-quil::vnth (1- (length stripped-code)) stripped-code)) (is (equalp (or last-entering penultimate-entering) - (and stripped-entering (quil::rewiring-l2p stripped-entering)))) + (and stripped-entering (cl-quil::rewiring-l2p stripped-entering)))) (is (equalp (or last-exiting penultimate-exiting) - (and stripped-exiting (quil::rewiring-l2p stripped-exiting))))))) + (and stripped-exiting (cl-quil::rewiring-l2p stripped-exiting))))))) (test-incompatible (&rest args &key last-entering last-exiting penultimate-entering penultimate-exiting) diff --git a/app/tests/rpcq-tests.lisp b/app/tests/rpcq-tests.lisp index a9019b32c..187753971 100644 --- a/app/tests/rpcq-tests.lisp +++ b/app/tests/rpcq-tests.lisp @@ -65,17 +65,17 @@ :|quil| quil :|target_device| target-device)) (server-response (rpcq:rpc-call client "quil-to-native-quil" server-payload :protoquil t)) - (pp (quil::parse-quil quil)) - (cpp (quil::parse-quil (rpcq::|NativeQuilResponse-quil| server-response)))) + (pp (cl-quil::parse-quil quil)) + (cpp (cl-quil::parse-quil (rpcq::|NativeQuilResponse-quil| server-response)))) (multiple-value-bind (mat1 mat2) - (quil::matrix-rescale (quil::make-matrix-from-quil - (coerce (quil:parsed-program-executable-code pp) 'list)) - (quil::make-matrix-from-quil - (coerce (quil:parsed-program-executable-code cpp) 'list))) - (setf mat1 (quil::scale-out-matrix-phases mat1 mat2)) + (cl-quil::matrix-rescale (cl-quil::make-matrix-from-quil + (coerce (cl-quil:parsed-program-executable-code pp) 'list)) + (cl-quil::make-matrix-from-quil + (coerce (cl-quil:parsed-program-executable-code cpp) 'list))) + (setf mat1 (cl-quil::scale-out-matrix-phases mat1 mat2)) (is (> 1d0 (rpcq::|NativeQuilMetadata-program_fidelity| (rpcq::|NativeQuilResponse-metadata| server-response)))) - (is (quil::matrix-equality mat1 mat2))))))) + (is (cl-quil::matrix-equality mat1 mat2))))))) (deftest test-quil-to-native-quil-protoquil-endpoint () "Test that the \"quil-to-native-quil\" endpoint will compile protoquil when given :PROTOQUIL T." @@ -96,10 +96,10 @@ :|target_device| target-device)) (server-response (rpcq:rpc-call client "quil-to-native-quil" server-payload :protoquil nil)) (server-response-protoquil (rpcq:rpc-call client "quil-to-native-quil" server-payload :protoquil t)) - (cpp (quil:parse-quil (rpcq::|NativeQuilResponse-quil| server-response))) - (cpp-protoquil (quil:parse-quil (rpcq::|NativeQuilResponse-quil| server-response-protoquil)))) - (is (not (quil:protoquil-program-p cpp))) - (is (quil:protoquil-program-p cpp-protoquil))))) + (cpp (cl-quil:parse-quil (rpcq::|NativeQuilResponse-quil| server-response))) + (cpp-protoquil (cl-quil:parse-quil (rpcq::|NativeQuilResponse-quil| server-response-protoquil)))) + (is (not (cl-quil:protoquil-program-p cpp))) + (is (cl-quil:protoquil-program-p cpp-protoquil))))) (deftest test-quil-to-native-quil-endpoint-overrides-server () "Test that the \"quil-to-native-quil\" endpoint can override a server that has been started with -P." @@ -125,13 +125,13 @@ :|quil| quil :|target_device| target-device))) (flet ((parse-response (protoquil) - (quil:parse-quil (rpcq::|NativeQuilResponse-quil| (rpcq:rpc-call client "quil-to-native-quil" server-payload :protoquil protoquil))))) + (cl-quil:parse-quil (rpcq::|NativeQuilResponse-quil| (rpcq:rpc-call client "quil-to-native-quil" server-payload :protoquil protoquil))))) ;; :protoquil nil means defer to server, i.e. this should produce protoquil - (is (quil:protoquil-program-p (parse-response nil))) + (is (cl-quil:protoquil-program-p (parse-response nil))) ;; :protoquil ':false means no protoquil, override server's -P - (is (not (quil:protoquil-program-p (parse-response ':false)))) + (is (not (cl-quil:protoquil-program-p (parse-response ':false)))) ;; :protoquil t means yes protoquil, regardless of what the server says - (is (quil:protoquil-program-p (parse-response t)))))))) + (is (cl-quil:protoquil-program-p (parse-response t)))))))) ;; Same tests but for *protoquil* = nil (quilc::special-bindings-let* ((quilc::*protoquil* nil)) @@ -152,13 +152,13 @@ :|quil| quil :|target_device| target-device))) (flet ((parse-response (protoquil) - (quil:parse-quil (rpcq::|NativeQuilResponse-quil| (rpcq:rpc-call client "quil-to-native-quil" server-payload :protoquil protoquil))))) + (cl-quil:parse-quil (rpcq::|NativeQuilResponse-quil| (rpcq:rpc-call client "quil-to-native-quil" server-payload :protoquil protoquil))))) ;; :protoquil nil means defer to server, i.e. this should not produce protoquil - (is (not (quil:protoquil-program-p (parse-response nil)))) + (is (not (cl-quil:protoquil-program-p (parse-response nil)))) ;; :protoquil ':false means no protoquil, override server's -P - (is (not (quil:protoquil-program-p (parse-response ':false)))) + (is (not (cl-quil:protoquil-program-p (parse-response ':false)))) ;; :protoquil t means yes protoquil, regardless of what the server says - (is (quil:protoquil-program-p (parse-response t))))))))) + (is (cl-quil:protoquil-program-p (parse-response t))))))))) (deftest test-native-quil-to-binary-endpoint () "Test that the \"native-quil-to-binary\" endpoint works." @@ -211,10 +211,10 @@ H 0") (request (make-instance 'rpcq::|RewriteArithmeticRequest| :|quil| quil)) (response (rpcq:rpc-call client "rewrite-arithmetic" request))) - (is (quil::matrix-equality - (quil:parsed-program-to-logical-matrix (quil:parse-quil quil)) - (quil:parsed-program-to-logical-matrix - (quil:parse-quil (rpcq::|RewriteArithmeticResponse-quil| response)))))))) + (is (cl-quil::matrix-equality + (cl-quil:parsed-program-to-logical-matrix (cl-quil:parse-quil quil)) + (cl-quil:parsed-program-to-logical-matrix + (cl-quil:parse-quil (rpcq::|RewriteArithmeticResponse-quil| response)))))))) (deftest test-quil-to-native-quil-on-nontrivial-features () "Test that non-trivial language features (such as DEFCIRCUIT) are processed correctly." (with-random-rpc-client (client) @@ -234,19 +234,19 @@ TEST 0 1 :|quil| quil :|target_device| target-device)) (server-response (rpcq:rpc-call client "quil-to-native-quil" server-payload)) - (pp (quil::parse-quil quil)) - (cpp (quil::parse-quil (rpcq::|NativeQuilResponse-quil| server-response)))) + (pp (cl-quil::parse-quil quil)) + (cpp (cl-quil::parse-quil (rpcq::|NativeQuilResponse-quil| server-response)))) (multiple-value-bind (mat1 mat2) - (quil::matrix-rescale (quil::make-matrix-from-quil - (coerce (quil:parsed-program-executable-code pp) 'list)) - (quil::make-matrix-from-quil - (coerce (quil:parsed-program-executable-code cpp) 'list))) - (setf mat1 (quil::scale-out-matrix-phases mat1 mat2)) - (is (quil::matrix-equality mat1 mat2)))))) + (cl-quil::matrix-rescale (cl-quil::make-matrix-from-quil + (coerce (cl-quil:parsed-program-executable-code pp) 'list)) + (cl-quil::make-matrix-from-quil + (coerce (cl-quil:parsed-program-executable-code cpp) 'list))) + (setf mat1 (cl-quil::scale-out-matrix-phases mat1 mat2)) + (is (cl-quil::matrix-equality mat1 mat2)))))) (deftest test-quil-safely-resolve () - "Test that the \"quil-to-native-quil\" endpoint raises an error when including a file outside of quil::*safe-include-directory*." - (quilc::special-bindings-let* ((quil::*safe-include-directory* "./")) + "Test that the \"quil-to-native-quil\" endpoint raises an error when including a file outside of cl-quil::*safe-include-directory*." + (quilc::special-bindings-let* ((cl-quil::*safe-include-directory* "./")) (quilc::special-bindings-let* ((bt:*default-special-bindings* bt:*default-special-bindings*)) (with-random-rpc-client (client) (let* ((quil "INCLUDE \"../test\"") diff --git a/app/tests/utils.lisp b/app/tests/utils.lisp index dbf5526ec..94df0dd2f 100644 --- a/app/tests/utils.lisp +++ b/app/tests/utils.lisp @@ -2,8 +2,8 @@ ;;; Cribbed from CL-QUIL-TESTs which itself cribbed from QVM-TESTS! (defmacro with-output-to-quil (&body body) - `(let ((quil:*allow-unresolved-applications* t)) - (quil:parse-quil + `(let ((cl-quil:*allow-unresolved-applications* t)) + (cl-quil:parse-quil (with-output-to-string (*standard-output*) ,@(loop :for form :in body :if (stringp form) diff --git a/benchmarking/qaoa-tests/qaoa-bench.lisp b/benchmarking/qaoa-tests/qaoa-bench.lisp index afc92e8a8..f5435cb63 100644 --- a/benchmarking/qaoa-tests/qaoa-bench.lisp +++ b/benchmarking/qaoa-tests/qaoa-bench.lisp @@ -46,7 +46,7 @@ (let ((pp (let ((*random-state* (make-random-state cl-user::*this-random-state*))) (make-program qubits valency))) - (chip (quil::build-nQ-trivalent-chip -1 1 16 16))) ;; 128 qubit chip + (chip (cl-quil::build-nQ-trivalent-chip -1 1 16 16))) ;; 128 qubit chip (sb-ext:gc :full t) (loop :for count :below repetitions :with runtime := nil diff --git a/benchmarking/qasm-benchmarks.lisp b/benchmarking/qasm-benchmarks.lisp index 48983556b..b597d4c26 100644 --- a/benchmarking/qasm-benchmarks.lisp +++ b/benchmarking/qasm-benchmarks.lisp @@ -53,12 +53,12 @@ "..."))) (defun calculate-multiqubit-gate-depth (code-vector) - (let ((lschedule (quil::make-lscheduler))) + (let ((lschedule (cl-quil::make-lscheduler))) (loop :for instr :across code-vector :when (and (typep instr 'gate-application) (<= 2 (length (application-arguments instr)))) - :do (quil::append-instruction-to-lschedule lschedule instr) - :finally (return (quil::lscheduler-calculate-depth lschedule))))) + :do (cl-quil::append-instruction-to-lschedule lschedule instr) + :finally (return (cl-quil::lscheduler-calculate-depth lschedule))))) (defun benchmark-qasm-suite (&key (timeout 30) named) "Run benchmarks from qasm suite. If NAMED is not nil, the specified test(s) will be the ONLY one(s) run; otherwise, all the tests are run. NAMED should be a short name (as shown in the output) of a test, either as a symbol or string, or a list thereof (i.e., matching mutiple tests), to be compared using string-equal. TIMEOUT specifies a timeout in seconds, defaulting to 30 seconds." @@ -69,10 +69,10 @@ (print-rule) (format t "| NAME | TIME (s) | SWAPS | 2Q DEPTH |~%") (print-rule) - (let ((chip (quil::build-ibm-qx5)) - (quil::*default-addresser-state-class* 'quil::temporal-addresser-state) - (quil::*addresser-use-1q-queues* t) - (quil::*safe-include-directory* (asdf:system-relative-pathname :cl-quil "tests/qasm-files/"))) + (let ((chip (cl-quil::build-ibm-qx5)) + (cl-quil::*default-addresser-state-class* 'cl-quil::temporal-addresser-state) + (cl-quil::*addresser-use-1q-queues* t) + (cl-quil::*safe-include-directory* (asdf:system-relative-pathname :cl-quil "tests/qasm-files/"))) (dolist (file (qasm-test-files)) (let ((short-name (trim-long-string (pathname-name file) 16))) (when (or (null named) @@ -87,7 +87,7 @@ (bordeaux-threads:with-timeout (timeout) (with-stopwatch elapsed-time (multiple-value-bind (cpp swaps) - (quil::compiler-hook (quil::parse text + (cl-quil::compiler-hook (cl-quil::parse text :originating-file file) chip :protoquil t diff --git a/benchmarking/quilc-perf.lisp b/benchmarking/quilc-perf.lisp index b2386d9e4..3faecb9ae 100644 --- a/benchmarking/quilc-perf.lisp +++ b/benchmarking/quilc-perf.lisp @@ -87,7 +87,7 @@ (defun build-benchmark-program (nq type) (ecase type (:static - (quil:parse "H 0; CNOT 2 0; H 1; CNOT 0 1; X 0")) + (cl-quil:parse "H 0; CNOT 2 0; H 1; CNOT 0 1; X 0")) (:bell (qvm-app::bell-program nq)) (:qft @@ -110,7 +110,7 @@ (defun do-one-quilc-perf-run (program chip) "Run compiler on PROGRAM for CHIP; see above re required pre-warm." - (quil::compiler-hook + (cl-quil::compiler-hook program chip :protoquil t :destructive t)) @@ -181,7 +181,7 @@ makes the compiler go through its paces, e.g., doing any warming or caching that may take considerable time and that would normally be avoided on subsequent runs. For now, the program is merely \"I 0\"." - (quil:parse "I 0")) + (cl-quil:parse "I 0")) (defun prepare-chip-for-benchmarking (chip-spec) "Do normal preparations for chip benchmarking, namely, by doing a diff --git a/benchmarking/rewiring-analysis.lisp b/benchmarking/rewiring-analysis.lisp index 25e3db9d2..a427b446c 100644 --- a/benchmarking/rewiring-analysis.lisp +++ b/benchmarking/rewiring-analysis.lisp @@ -28,30 +28,30 @@ (defun init-chip (&key (architecture ':cz)) "Initialize a chip from a given architecture with no objects" - (let ((chip-spec (quil::make-chip-specification - :objects (vector (quil::make-adjustable-vector) - (quil::make-adjustable-vector)) - :generic-rewriting-rules (coerce (quil::global-rewriting-rules) 'vector)))) - (quil::install-generic-compilers chip-spec architecture) + (let ((chip-spec (cl-quil::make-chip-specification + :objects (vector (cl-quil::make-adjustable-vector) + (cl-quil::make-adjustable-vector)) + :generic-rewriting-rules (coerce (cl-quil::global-rewriting-rules) 'vector)))) + (cl-quil::install-generic-compilers chip-spec architecture) chip-spec)) (defun make-graph-chip (graph &key (architecture ':cz)) "Make a chip from a graph" (let* ((chip-spec (init-chip :architecture architecture)) (qubits - (loop :for i :below (length graph) :collect (quil::build-qubit i :type '(:RZ :X/2 :MEASURE)))) + (loop :for i :below (length graph) :collect (cl-quil::build-qubit i :type '(:RZ :X/2 :MEASURE)))) (qubit-array (make-array (length graph) :initial-contents qubits)) (links (loop :for (a . b) :in (graph-edges graph) :for link-index :from 0 - :collect (quil::build-link a b :type architecture) - :do (vector-push-extend link-index (quil::vnth 1 (quil::hardware-object-cxns (aref qubit-array a)))) - :do (vector-push-extend link-index (quil::vnth 1 (quil::hardware-object-cxns (aref qubit-array b))))))) - (setf (quil::chip-specification-objects chip-spec) + :collect (cl-quil::build-link a b :type architecture) + :do (vector-push-extend link-index (cl-quil::vnth 1 (cl-quil::hardware-object-cxns (aref qubit-array a)))) + :do (vector-push-extend link-index (cl-quil::vnth 1 (cl-quil::hardware-object-cxns (aref qubit-array b))))))) + (setf (cl-quil::chip-specification-objects chip-spec) (make-array 2 :initial-contents (list qubit-array (coerce links 'vector)))) - (quil:warm-hardware-objects chip-spec))) + (cl-quil:warm-hardware-objects chip-spec))) ;; 0 -- 1 ;; | | @@ -59,10 +59,10 @@ ;; | | ;; 4 -- 5 (defvar *chip-6q-2ring* (make-graph-chip (make-graph 6 '(0 1 3 2 0) '(3 5 4 2 3)))) -(defvar *chip-0008q* (quil::build-8q-chip)) -(defvar *chip-0016q* (quil::build-nq-trivalent-chip 1 1 4 8)) -(defvar *chip-0020q-linear* (quil::build-nq-linear-chip 20)) -(defvar *chip-0020q-skew-rect* (quil::build-skew-rectangular-chip 0 4 5)) +(defvar *chip-0008q* (cl-quil::build-8q-chip)) +(defvar *chip-0016q* (cl-quil::build-nq-trivalent-chip 1 1 4 8)) +(defvar *chip-0020q-linear* (cl-quil::build-nq-linear-chip 20)) +(defvar *chip-0020q-skew-rect* (cl-quil::build-skew-rectangular-chip 0 4 5)) ;; We need this as symbols because we will want to iterate through ;; them at macro-expansion time and get their values dynamically. (defparameter *rewiring-explicit-test-chips* @@ -86,12 +86,12 @@ (loop :for file :in (uiop:directory-files *rewiring-test-chip-directory* #P"*.qpu") :collect (list (intern (string-upcase (pathname-name file)) 'KEYWORD) - (quil::read-chip-spec-file file))) + (cl-quil::read-chip-spec-file file))) (loop :for (name sym) :in *rewiring-explicit-test-chips* :collect (list name (symbol-value sym)))) #'< :key (lambda (cell) - (quil::chip-spec-n-qubits (second cell))))) + (cl-quil::chip-spec-n-qubits (second cell))))) (defparameter *rewiring-test-file-directory* (asdf:system-relative-pathname :cl-quil "benchmarking/quil-rewiring/")) @@ -102,22 +102,22 @@ (defun quil-file-prefix (file) "Gets the information prefix for a quil file" - (let* ((pp (quil::read-quil-file file)) + (let* ((pp (cl-quil::read-quil-file file)) (instrs (parsed-program-executable-code pp)) (multiq (loop :for inst :across instrs :thereis (and (typep inst 'application) (< 1 (length (application-arguments inst))))))) (format nil "~4,'0Dq-~7,'0Di-~:[s~;m~]" - (quil::qubits-needed pp) + (cl-quil::qubits-needed pp) (length instrs) multiq))) (defun chip-spec-file-prefix (file) - (let ((chip-spec (quil::read-chip-spec-file file))) + (let ((chip-spec (cl-quil::read-chip-spec-file file))) (format nil "~4,'0Dq-~4,'0DL" - (quil::chip-spec-n-qubits chip-spec) - (quil::chip-spec-n-links chip-spec)))) + (cl-quil::chip-spec-n-qubits chip-spec) + (cl-quil::chip-spec-n-links chip-spec)))) (defmacro with-stopwatch (elapsed-var &body body) (let ((start-time (gensym))) @@ -147,7 +147,7 @@ (let* ((progm (get-prog prog-source chip)) (max-needed (qubits-needed progm))) (when (<= max-needed - (quil::chip-spec-n-qubits chip)) + (cl-quil::chip-spec-n-qubits chip)) (funcall assn (lambda () (multiple-value-list (compiler-hook (get-prog prog-source chip) chip :destructive t)))))))) @@ -157,8 +157,8 @@ :for (label assn) :on assignments :by #'cddr :for (compiled-program swaps duration elapsed) := (by-assignment prog-source chip assn) :for fidelity := (when compiled-program - (quil::calculate-instructions-fidelity - (coerce (quil::parsed-program-executable-code compiled-program) 'list) + (cl-quil::calculate-instructions-fidelity + (coerce (cl-quil::parsed-program-executable-code compiled-program) 'list) chip)) :nconc (list label (list swaps duration elapsed fidelity)))) @@ -187,21 +187,21 @@ (let (,@fixed-vars ,@(mapcar #'list changing-vars values)) (apply ,fn-sym ,args-sym)))))) -(defun make-rewiring-prog (target &optional (initial (quil::make-rewiring (quil::rewiring-length target)))) +(defun make-rewiring-prog (target &optional (initial (cl-quil::make-rewiring (cl-quil::rewiring-length target)))) "Generate a program that forces a change from the initial rewiring to the target rewiring." (make-instance 'parsed-program :executable-code (concatenate 'vector ;; force start with the identity rewiring - (list (make-instance 'quil::application-force-rewiring :target initial)) + (list (make-instance 'cl-quil::application-force-rewiring :target initial)) ;; force end with the desired rewiring - (list (make-instance 'quil::application-force-rewiring :target target))))) + (list (make-instance 'cl-quil::application-force-rewiring :target target))))) (defun generate-random-rewiring-prog (n-qubits state) (let ((*random-state* (seed-random-state))) - (make-rewiring-prog (quil::generate-random-rewiring n-qubits)))) + (make-rewiring-prog (cl-quil::generate-random-rewiring n-qubits)))) (defun generate-ring-prog (n-qubits state &key (random-unitaries nil)) (declare (ignore state)) @@ -210,21 +210,21 @@ 'parsed-program :executable-code (concatenate 'vector - (list (make-instance 'quil::pragma-initial-rewiring :rewiring-type ':partial)) + (list (make-instance 'cl-quil::pragma-initial-rewiring :rewiring-type ':partial)) (when (null random-unitaries) - (list (make-instance 'quil::pragma-commuting-blocks))) + (list (make-instance 'cl-quil::pragma-commuting-blocks))) (loop :for i :below n-qubits :when (null random-unitaries) - :collect (make-instance 'quil::pragma-block) + :collect (make-instance 'cl-quil::pragma-block) :if (null random-unitaries) - :collect (quil::build-gate "CZ" () i (mod (1+ i) n-qubits)) + :collect (cl-quil::build-gate "CZ" () i (mod (1+ i) n-qubits)) :else - :collect (quil::anon-gate - "U" (quil::random-special-unitary 4) i (mod (1+ i) n-qubits)) + :collect (cl-quil::anon-gate + "U" (cl-quil::random-special-unitary 4) i (mod (1+ i) n-qubits)) :when (null random-unitaries) - :collect (make-instance 'quil::pragma-end-block)) + :collect (make-instance 'cl-quil::pragma-end-block)) (when (null random-unitaries) - (list (make-instance 'quil::pragma-end-commuting-blocks)))))) + (list (make-instance 'cl-quil::pragma-end-commuting-blocks)))))) (defun generate-star-prog (n-qubits state &key (random-unitaries nil)) (declare (ignore state)) @@ -233,25 +233,25 @@ 'parsed-program :executable-code (concatenate 'vector - (list (make-instance 'quil::pragma-initial-rewiring :rewiring-type ':partial)) + (list (make-instance 'cl-quil::pragma-initial-rewiring :rewiring-type ':partial)) (when (null random-unitaries) - (list (make-instance 'quil::pragma-commuting-blocks))) + (list (make-instance 'cl-quil::pragma-commuting-blocks))) (loop :for i :from 1 :to (1- n-qubits) :when (null random-unitaries) - :collect (make-instance 'quil::pragma-block) + :collect (make-instance 'cl-quil::pragma-block) :if (null random-unitaries) - :collect (quil::build-gate "CZ" () 0 i) + :collect (cl-quil::build-gate "CZ" () 0 i) :else - :collect (quil::anon-gate - "U" (quil::random-special-unitary 4) 0 i) + :collect (cl-quil::anon-gate + "U" (cl-quil::random-special-unitary 4) 0 i) :when (null random-unitaries) - :collect (make-instance 'quil::pragma-end-block)) + :collect (make-instance 'cl-quil::pragma-end-block)) (when (null random-unitaries) - (list (make-instance 'quil::pragma-end-commuting-blocks)))))) + (list (make-instance 'cl-quil::pragma-end-commuting-blocks)))))) (defun generate-handshake-prog (n-qubits state chip &key (random-unitaries nil)) (declare (ignore state)) - (let* ((pairs (loop :with live-qubits := (quil::chip-spec-live-qubits chip) + (let* ((pairs (loop :with live-qubits := (cl-quil::chip-spec-live-qubits chip) :for qi :in live-qubits :for i :from 0 :when (< i n-qubits) @@ -265,21 +265,21 @@ 'parsed-program :executable-code (concatenate 'vector - (list (make-instance 'quil::pragma-initial-rewiring :rewiring-type ':partial)) + (list (make-instance 'cl-quil::pragma-initial-rewiring :rewiring-type ':partial)) (when (null random-unitaries) - (list (make-instance 'quil::pragma-commuting-blocks))) + (list (make-instance 'cl-quil::pragma-commuting-blocks))) (loop :for (qi qj) :in pairs :when (null random-unitaries) - :collect (make-instance 'quil::pragma-block) + :collect (make-instance 'cl-quil::pragma-block) :if (null random-unitaries) - :collect (quil::build-gate "CZ" () qi qj) + :collect (cl-quil::build-gate "CZ" () qi qj) :else - :collect (quil::anon-gate - "U" (quil::random-special-unitary 4) qi qj) + :collect (cl-quil::anon-gate + "U" (cl-quil::random-special-unitary 4) qi qj) :when (null random-unitaries) - :collect (make-instance 'quil::pragma-end-block)) + :collect (make-instance 'cl-quil::pragma-end-block)) (when (null random-unitaries) - (list (make-instance 'quil::pragma-end-commuting-blocks))))))) + (list (make-instance 'cl-quil::pragma-end-commuting-blocks))))))) (defun measure-rewiring-swap-search (assn &rest args &key break-on-error include-runtime @@ -291,7 +291,7 @@ (remf args :trials) (setf (getf args :chips) (loop :for (name chip) :in chips - :when (= (quil::chip-spec-n-qubits chip) rewiring-qubits) :collect (cons name chip))) + :when (= (cl-quil::chip-spec-n-qubits chip) rewiring-qubits) :collect (cons name chip))) (apply #'measure-performance assn :progs (loop :for i :below trials @@ -310,7 +310,7 @@ (remf args :trials) (setf (getf args :chips) (loop :for (name chip) :in chips - :when (= (quil::chip-spec-n-qubits chip) n-qubits) :collect (cons name chip))) + :when (= (cl-quil::chip-spec-n-qubits chip) n-qubits) :collect (cons name chip))) (apply #'measure-performance assn :progs (loop :for i :below trials @@ -332,7 +332,7 @@ (remf args :trials) (setf (getf args :chips) (loop :for (name chip) :in chips - :when (= (quil::chip-spec-n-qubits chip) n-qubits) :collect (cons name chip))) + :when (= (cl-quil::chip-spec-n-qubits chip) n-qubits) :collect (cons name chip))) (apply #'measure-performance assn :progs (loop :for i :below trials @@ -354,7 +354,7 @@ (remf args :trials) (setf (getf args :chips) (loop :for (name chip) :in chips - :when (= (length (quil::chip-spec-live-qubits chip)) n-qubits) + :when (= (length (cl-quil::chip-spec-live-qubits chip)) n-qubits) :collect (cons name chip))) (print (getf args :chips)) (apply #'measure-performance assn @@ -378,7 +378,7 @@ (remf args :trials) (setf (getf args :chips) (loop :for (name chip) :in chips - :when (= (length (quil::chip-spec-live-qubits chip)) n-qubits) + :when (= (length (cl-quil::chip-spec-live-qubits chip)) n-qubits) :collect (cons name chip))) (apply #'measure-performance assn :progs (loop @@ -393,9 +393,9 @@ (defvar *basic-swap-search-assn* (make-assignments ((*random-state* (seed-random-state)) - (quil::*compressor-passes* 0)) - (quil::*addresser-gates-swap-search-type* - quil::*addresser-rewiring-swap-search-type*) + (cl-quil::*compressor-passes* 0)) + (cl-quil::*addresser-gates-swap-search-type* + cl-quil::*addresser-rewiring-swap-search-type*) :control (:greedy-qubit :greedy-qubit) :path (:greedy-path :greedy-path) :a* (:a* :a*) @@ -404,11 +404,11 @@ (defvar *2q-tiers-assn* (make-assignments ((*random-state* (seed-random-state)) - (quil::*compressor-passes* 0)) - (quil::*initial-rewiring-default-type* - quil::*addresser-gates-swap-search-type* - quil::*addresser-rewiring-swap-search-type* - quil::*addresser-a*-swap-search-heuristic-scale*) + (cl-quil::*compressor-passes* 0)) + (cl-quil::*initial-rewiring-default-type* + cl-quil::*addresser-gates-swap-search-type* + cl-quil::*addresser-rewiring-swap-search-type* + cl-quil::*addresser-a*-swap-search-heuristic-scale*) :control (:random :greedy-qubit :greedy-qubit 1d0) :naive (:naive :greedy-qubit :greedy-qubit 1d0) :partial (:partial :greedy-qubit :greedy-qubit 1d0) @@ -423,11 +423,11 @@ (defvar *swap-search-assn* (make-assignments ((*random-state* (seed-random-state)) - (quil::*compressor-passes* 0)) - (quil::*initial-rewiring-default-type* - quil::*addresser-gates-swap-search-type* - quil::*addresser-rewiring-swap-search-type* - quil::*addresser-a*-swap-search-heuristic-scale*) + (cl-quil::*compressor-passes* 0)) + (cl-quil::*initial-rewiring-default-type* + cl-quil::*addresser-gates-swap-search-type* + cl-quil::*addresser-rewiring-swap-search-type* + cl-quil::*addresser-a*-swap-search-heuristic-scale*) :control (:random :greedy-qubit :greedy-qubit 1d0) :path (:partial :greedy-path :greedy-path 1d0) :naive (:naive :greedy-qubit :greedy-qubit 1d0) @@ -440,9 +440,9 @@ (defvar *initial-rewiring-assn* (make-assignments ((*random-state* (seed-random-state)) - (quil::*compressor-passes* 0) - (quil::*addresser-gates-swap-search-type* :greedy-qubit)) - (quil::*initial-rewiring-default-type*) + (cl-quil::*compressor-passes* 0) + (cl-quil::*addresser-gates-swap-search-type* :greedy-qubit)) + (cl-quil::*initial-rewiring-default-type*) :control (:random) :naive (:naive) :initial (:greedy) @@ -452,12 +452,12 @@ (defvar *depth-vs-swaps-assn* (make-assignments ((*random-state* (seed-random-state)) - (quil::*compressor-passes* 0)) - (quil::*initial-rewiring-default-type* - quil::*addresser-gates-swap-search-type* - quil::*addresser-rewiring-swap-search-type* - quil::*addresser-a*-swap-search-heuristic-scale* - quil::*addresser-a*-distance-metric* + (cl-quil::*compressor-passes* 0)) + (cl-quil::*initial-rewiring-default-type* + cl-quil::*addresser-gates-swap-search-type* + cl-quil::*addresser-rewiring-swap-search-type* + cl-quil::*addresser-a*-swap-search-heuristic-scale* + cl-quil::*addresser-a*-distance-metric* ) :partial (:partial :greedy-qubit :greedy-qubit 1d0 nil) :a*-swaps (:partial :a* :a* 1d0 :size) @@ -468,8 +468,8 @@ (defvar *cost-fn-weight-style-assn* (make-assignments ((*random-state* (seed-random-state)) - (quil::*compressor-passes* 1)) - (quil::*cost-fn-weight-style*) + (cl-quil::*compressor-passes* 1)) + (cl-quil::*cost-fn-weight-style*) :duration (:duration) :fidelity (:fidelity) )) @@ -477,8 +477,8 @@ (defvar *addresser-style-assn* (make-assignments ((*random-state* (seed-random-state)) - (quil::*compressor-passes* 1)) - (quil::*default-addresser-state-class* quil::*addresser-use-1q-queues*) - :duration ('quil::temporal-addresser-state t) - :fidelity ('quil::fidelity-addresser-state nil) + (cl-quil::*compressor-passes* 1)) + (cl-quil::*default-addresser-state-class* cl-quil::*addresser-use-1q-queues*) + :duration ('cl-quil::temporal-addresser-state t) + :fidelity ('cl-quil::fidelity-addresser-state nil) )) diff --git a/benchmarking/suite.lisp b/benchmarking/suite.lisp index 9895c0a37..ee950667c 100644 --- a/benchmarking/suite.lisp +++ b/benchmarking/suite.lisp @@ -30,7 +30,7 @@ (defmacro generate-rewiring-benchmarks () (labels ((enough-qubits-p (chip quil-file) - (<= (quil::qubits-needed quil-file) (quil::chip-spec-n-qubits chip))) + (<= (cl-quil::qubits-needed quil-file) (cl-quil::chip-spec-n-qubits chip))) (bench-name (quil-file rewiring chip) (intern (string-upcase (concatenate 'string "bench-" quil-file diff --git a/boondoggle/src/consumers.lisp b/boondoggle/src/consumers.lisp index 754b8dd24..08c8da43a 100644 --- a/boondoggle/src/consumers.lisp +++ b/boondoggle/src/consumers.lisp @@ -5,7 +5,7 @@ ;;; The main job of this file is to provide interfaces to different ;;; execution environments for Quil, currently just the local QVM. We ;;; provide a generic `consume-quil` method that takes a -;;; `quil::parsed-program` object and returns probability amplitudes +;;; `cl-quil::parsed-program` object and returns probability amplitudes ;;; as sterilized output. (in-package #:boondoggle) @@ -31,10 +31,10 @@ (:documentation "Returns a list of amplitude registered associated to a consumer.") (:method ((consumer consumer-local-qvm) parsed-program) (remove-duplicates - (loop :for instr :across (quil::parsed-program-executable-code parsed-program) - :when (typep instr 'quil::measure) - :collect (quil::memory-ref-position - (quil::measure-address + (loop :for instr :across (cl-quil::parsed-program-executable-code parsed-program) + :when (typep instr 'cl-quil::measure) + :collect (cl-quil::memory-ref-position + (cl-quil::measure-address instr)))))) (defmethod consume-quil ((consumer consumer-local-qvm) parsed-program) @@ -45,7 +45,7 @@ For a program constructing a bell state with a large sampling count, the returne (:http (let* ((quil-instructions (with-output-to-string (s) - (quil::print-parsed-program parsed-program s))) + (cl-quil::print-parsed-program parsed-program s))) (classical-addresses (a:plist-hash-table (list "ro" (get-consumer-registers consumer parsed-program)))) diff --git a/boondoggle/src/processors.lisp b/boondoggle/src/processors.lisp index 0dd2255a0..236ea22bd 100644 --- a/boondoggle/src/processors.lisp +++ b/boondoggle/src/processors.lisp @@ -20,11 +20,11 @@ (defmethod apply-process ((processor processor-quilc) &rest data) (let ((data (first data))) - (quil::parse-quil + (cl-quil::parse-quil (uiop:run-program (processor-quilc-executable-path processor) :input (make-string-input-stream (with-output-to-string (s) - (quil::print-parsed-program data s))) + (cl-quil::print-parsed-program data s))) :output :string)))) (defclass processor-identity (processor) diff --git a/boondoggle/src/producers.lisp b/boondoggle/src/producers.lisp index 0d3bd040a..02fd517c1 100644 --- a/boondoggle/src/producers.lisp +++ b/boondoggle/src/producers.lisp @@ -24,7 +24,7 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters." (error "This producer has not been implemented.")) (defclass producer-random (producer) - ((chip-specification :initform (quil::build-8Q-chip) + ((chip-specification :initform (cl-quil::build-8Q-chip) :initarg :chip-specification :reader producer-random-chip-specification) (program-depth-limit :initform nil @@ -67,10 +67,10 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters." (defun measure-at-close-instrs (chip-specification) "Apply MEASURE instructions on all qubits in a chip-specification. Assumes qubits are ordered from 0 to n with no skipped indices." - (loop :for j :below (quil::chip-spec-n-qubits chip-specification) - :collect (make-instance 'quil:measure - :address (quil:mref "ro" j) - :qubit (quil:qubit j)))) + (loop :for j :below (cl-quil::chip-spec-n-qubits chip-specification) + :collect (make-instance 'cl-quil:measure + :address (cl-quil:mref "ro" j) + :qubit (cl-quil:qubit j)))) (defun random-protoquil (chip-specification ; chip topology program-depth-limit ; limit to randomly generated program depth @@ -81,7 +81,7 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters." respect-topology ; place multiqubit gates only on chip-specification links ) "Generates random Quil strings to the statistics specifications set out by the argument list." - (let ((parsed-program (make-instance 'quil::parsed-program)) + (let ((parsed-program (make-instance 'cl-quil::parsed-program)) (instruction-list nil) (random-gate-count 0)) (dotimes (j (random program-volume-limit)) @@ -90,7 +90,7 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters." (gate-record (unless random-gate-flag (nth (random (length gate-set)) gate-set))) - (qubits-on-device (length (aref (quil::chip-specification-objects chip-specification) 0))) + (qubits-on-device (length (aref (cl-quil::chip-specification-objects chip-specification) 0))) (gate-name (cond (random-gate-flag @@ -115,12 +115,12 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters." (respect-topology (let* ((available-devices (progn - (assert (elt (quil::chip-specification-objects chip-specification) gate-order) + (assert (elt (cl-quil::chip-specification-objects chip-specification) gate-order) nil "This gate spec expects higher order hardware objects to exist.") - (elt (quil::chip-specification-objects chip-specification) gate-order))) + (elt (cl-quil::chip-specification-objects chip-specification) gate-order))) (device-index (random (length available-devices)))) - (quil::vnth 0 (quil::hardware-object-cxns (quil::vnth device-index available-devices))))) + (cl-quil::vnth 0 (cl-quil::hardware-object-cxns (cl-quil::vnth device-index available-devices))))) (t (assert (< gate-order qubits-on-device) nil @@ -133,8 +133,8 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters." :finally (return ret))))) (gate-definition (when random-gate-flag - (let ((gate-matrix (quil::random-special-unitary (expt 2 (1+ gate-order))))) - (quil::make-gate-definition gate-name + (let ((gate-matrix (cl-quil::random-special-unitary (expt 2 (1+ gate-order))))) + (cl-quil::make-gate-definition gate-name nil (loop :for i :below (magicl:ncols gate-matrix) :nconc (loop :for j :below (magicl:nrows gate-matrix) @@ -142,36 +142,36 @@ PARAMETER-BOUNDS is a list of maximum random values for the gate parameters." (gate-parameters (unless random-gate-flag (mapcar #'random (gate-set-record-parameter-bounds gate-record)))) - (gate-invocation (make-instance 'quil::gate-application - :operator (quil:named-operator gate-name) - :arguments (map 'list #'quil:qubit qubit-indices) - :parameters (map 'list #'quil:constant gate-parameters)))) + (gate-invocation (make-instance 'cl-quil::gate-application + :operator (cl-quil:named-operator gate-name) + :arguments (map 'list #'cl-quil:qubit qubit-indices) + :parameters (map 'list #'cl-quil:constant gate-parameters)))) (push gate-invocation instruction-list) ;; check to see if we need to bail because of depth (when (and program-depth-limit (< program-depth-limit - (let ((lschedule (make-instance 'quil::lscheduler-empty))) - (quil::append-instructions-to-lschedule lschedule instruction-list) - (quil::lscheduler-calculate-depth lschedule)))) + (let ((lschedule (make-instance 'cl-quil::lscheduler-empty))) + (cl-quil::append-instructions-to-lschedule lschedule instruction-list) + (cl-quil::lscheduler-calculate-depth lschedule)))) (pop instruction-list) (return)) ;; if we built a random gate, store its definition (when random-gate-flag (incf random-gate-count) - (push gate-definition (quil::parsed-program-gate-definitions parsed-program))))) - (setf (quil::parsed-program-executable-code parsed-program) + (push gate-definition (cl-quil::parsed-program-gate-definitions parsed-program))))) + (setf (cl-quil::parsed-program-executable-code parsed-program) (make-array (length instruction-list) :initial-contents instruction-list)) ;; Add readout memory definitions to the program - (push (quil::make-memory-descriptor + (push (cl-quil::make-memory-descriptor :name "ro" - :type quil::quil-bit - :length (quil::chip-spec-n-qubits chip-specification)) - (quil:parsed-program-memory-definitions parsed-program)) + :type cl-quil::quil-bit + :length (cl-quil::chip-spec-n-qubits chip-specification)) + (cl-quil:parsed-program-memory-definitions parsed-program)) ;; Add measure instructions to the end of the program - (setf (quil::parsed-program-executable-code parsed-program) + (setf (cl-quil::parsed-program-executable-code parsed-program) (concatenate 'vector - (quil::parsed-program-executable-code parsed-program) + (cl-quil::parsed-program-executable-code parsed-program) (measure-at-close-instrs chip-specification))) parsed-program)) diff --git a/boondoggle/tests/tests.lisp b/boondoggle/tests/tests.lisp index c05a33fed..2bf803ff1 100644 --- a/boondoggle/tests/tests.lisp +++ b/boondoggle/tests/tests.lisp @@ -29,7 +29,7 @@ The processor-two-sample-chi-squared post-process takes all consumers and proces " (let ((boondoggle::*debug-noise-stream* *standard-output*) - (chip-spec (quil::build-8q-chip))) + (chip-spec (cl-quil::build-8q-chip))) (let ((chi-squared-results (boondoggle::pipeline ((producer () (make-instance 'boondoggle::producer-random @@ -45,11 +45,11 @@ The processor-two-sample-chi-squared post-process takes all consumers and proces (produced-program () (boondoggle::produce-quil-program (producer))) (compiled-program ((i processors)) (progn - (quil::print-parsed-program (produced-program)) + (cl-quil::print-parsed-program (produced-program)) (boondoggle::apply-process (processors i) (produced-program)))) (qvm-results ((i processors)) (progn - (quil::print-parsed-program (compiled-program i)) + (cl-quil::print-parsed-program (compiled-program i)) (boondoggle::consume-quil (consumer) (compiled-program i)))) (chi-squared-result ((k processors) (i processors)) (boondoggle::apply-process (post-process) (qvm-results i) (qvm-results k)))))) diff --git a/cl-quil.asd b/cl-quil.asd index 6829a090c..1372c2685 100644 --- a/cl-quil.asd +++ b/cl-quil.asd @@ -136,7 +136,9 @@ (:file "pragmas") (:file "parser") (:file "cl-quil") - (:file "qasm") + (:module "qasm" + :serial t + :components ((:file "qasm"))) (:file "gates") (:file "build-gate") (:file "with-inst") @@ -190,7 +192,7 @@ #:cl-quil/chip-library #:fiasco) :perform (asdf:test-op (o s) - (uiop:symbol-call ':cl-quil.chip-library-tests + (uiop:symbol-call ':cl-quil/chip-library-tests '#:run-chip-library-tests)) :pathname "tests/chip-library/" :serial t @@ -234,7 +236,7 @@ :depends-on (#:cl-quil-tests #:cl-quil/quilt) :perform (asdf:test-op (o s) - (uiop:symbol-call ':cl-quil.quilt-tests + (uiop:symbol-call ':cl-quil/quilt-tests '#:run-quilt-tests)) :pathname "tests/quilt/" :serial t @@ -301,7 +303,7 @@ :license "Apache License 2.0 (See LICENSE.txt)" :depends-on (#:cl-quil/discrete #:coalton #:coalton/testing #:fiasco) :perform (asdf:test-op (o s) - (uiop:symbol-call ':cl-quil.discrete-tests + (uiop:symbol-call ':cl-quil/discrete-tests '#:run-discrete-tests)) :pathname "tests/discrete/" :serial t @@ -335,7 +337,7 @@ #:qvm #:fiasco) :perform (asdf:test-op (o s) - (uiop:symbol-call ':cl-quil.quilec-tests + (uiop:symbol-call ':cl-quil/quilec-tests '#:run-quilec-tests)) :pathname "tests/quilec/" :serial t @@ -366,7 +368,7 @@ :depends-on (#:cl-quil-tests #:cl-quil/tools) :perform (asdf:test-op (o s) - (uiop:symbol-call ':cl-quil.tools-tests + (uiop:symbol-call ':cl-quil/tools-tests '#:run-tools-tests)) :pathname "tests/tools/" :serial t diff --git a/src/addresser/1q-queues.lisp b/src/addresser/1q-queues.lisp index 740b7a7d3..9bc4ad3fd 100644 --- a/src/addresser/1q-queues.lisp +++ b/src/addresser/1q-queues.lisp @@ -155,7 +155,7 @@ following swaps." (check-type state addresser-state) (assert (= 1 (length (application-arguments instr))) nil - "Attempted to add instruction ~/quil:instruction-fmt/ to 1Q queues." + "Attempted to add instruction ~/cl-quil:instruction-fmt/ to 1Q queues." instr) (lscheduler-dequeue-instruction (addresser-state-logical-schedule state) instr) (push instr (aref (addresser-state-1q-queues state) diff --git a/src/addresser/addresser-common.lisp b/src/addresser/addresser-common.lisp index c1cc91746..4ede4cda1 100644 --- a/src/addresser/addresser-common.lisp +++ b/src/addresser/addresser-common.lisp @@ -303,7 +303,7 @@ Returns two values: a list of links, and an updated list of rewirings tried." ;; otherwise, we don't know what to do (t - (error "The instruction type of \"~/quil:instruction-fmt/\" is not supported by the addresser." instr))) + (error "The instruction type of \"~/cl-quil:instruction-fmt/\" is not supported by the addresser." instr))) ;; turns out we're always always dirty t)) @@ -326,7 +326,7 @@ Two other values are returned: a list of fully rewired instructions for later sc (addresser-state-chip-specification state)))) (application-arguments instr)) nil - "Instruction qubit indices are out of bounds for target QPU: ~/quil:instruction-fmt/" + "Instruction qubit indices are out of bounds for target QPU: ~/cl-quil:instruction-fmt/" instr) (when dry-run-escape (funcall dry-run-escape)) @@ -348,7 +348,7 @@ Two other values are returned: a list of fully rewired instructions for later sc (assert (every (lambda (q) (< -1 (qubit-index q) (chip-spec-n-qubits chip-spec))) (application-arguments instr)) nil - "Instruction qubit indices are out of bounds for target QPU: ~/quil:instruction-fmt/" + "Instruction qubit indices are out of bounds for target QPU: ~/cl-quil:instruction-fmt/" instr) (let* ((assignments (mapcar (lambda (q) (apply-rewiring-l2p working-l2p (qubit-index q))) (application-arguments instr))) @@ -384,10 +384,10 @@ Two other values are returned: a list of fully rewired instructions for later sc (assert (every (lambda (q) (< -1 (qubit-index q) (chip-spec-n-qubits chip-spec))) (application-arguments instr)) nil - "Instruction qubit indices are out of bounds for target QPU: ~/quil:instruction-fmt/" + "Instruction qubit indices are out of bounds for target QPU: ~/cl-quil:instruction-fmt/" instr) (format-noise - "DEQUEUE-GATE-APPLICATION: ~/quil:instruction-fmt/ is a ~dQ>2Q instruction, compiling." + "DEQUEUE-GATE-APPLICATION: ~/cl-quil:instruction-fmt/ is a ~dQ>2Q instruction, compiling." instr (length (application-arguments instr))) ;; then we know we can't find a hardware object to support @@ -507,12 +507,12 @@ If DRY-RUN, this returns T as soon as it finds an instruction it can handle." ;; ... and dispatch it. (format-noise - "DEQUEUE-BEST-INSTR: Elected to schedule ~/quil:instruction-fmt/." + "DEQUEUE-BEST-INSTR: Elected to schedule ~/cl-quil:instruction-fmt/." instr) (let ((rewired-instr (copy-instance instr))) (rewire-l2p-instruction working-l2p rewired-instr) (format-noise - "DEQUEUE-BEST-INSTR: ~/quil:instruction-fmt/ is ~/quil:instruction-fmt/ in the current rewiring." + "DEQUEUE-BEST-INSTR: ~/cl-quil:instruction-fmt/ is ~/cl-quil:instruction-fmt/ in the current rewiring." instr rewired-instr) ;; Figure out if we need to compile the instruction, @@ -521,7 +521,7 @@ If DRY-RUN, this returns T as soon as it finds an instruction it can handle." ;; if we found a link and the instruction is native... ((hardware-object-native-instruction-p (lookup-hardware-object chip-spec rewired-instr) rewired-instr) (format-noise - "DEQUEUE-BEST-INSTR: ~/quil:instruction-fmt/ is native in l2p rewiring ~A, flushing 1Q lines and dequeueing." + "DEQUEUE-BEST-INSTR: ~/cl-quil:instruction-fmt/ is native in l2p rewiring ~A, flushing 1Q lines and dequeueing." instr (rewiring-l2p working-l2p)) ;; dequeue the instruction so we can push the @@ -533,7 +533,7 @@ If DRY-RUN, this returns T as soon as it finds an instruction it can handle." ;; otherwise, we found a link but the instruction is not native (t (format-noise - "DEQUEUE-BEST-INSTR: ~/quil:instruction-fmt/ is non-native in the current rewiring, compiling." + "DEQUEUE-BEST-INSTR: ~/cl-quil:instruction-fmt/ is non-native in the current rewiring, compiling." instr) ;; ...release the hounds @@ -589,7 +589,7 @@ If DRY-RUN, this returns T as soon as it finds an instruction it can handle." "Get all qubits referenced in INSTRS which are not assigned in REWIRING." (let ((unassigned-qubits nil)) (dolist (instr instrs unassigned-qubits) - (dolist (qubit (cl-quil.resource::resource-qubits-list + (dolist (qubit (cl-quil/resource::resource-qubits-list (instruction-resources instr))) (unless (apply-rewiring-l2p rewiring qubit) (pushnew qubit unassigned-qubits)))))) diff --git a/src/addresser/logical-schedule.lisp b/src/addresser/logical-schedule.lisp index 25b23823b..c4f670760 100644 --- a/src/addresser/logical-schedule.lisp +++ b/src/addresser/logical-schedule.lisp @@ -201,16 +201,16 @@ as the size keyword arg to make-hash-table." (defun print-lschedule (lschedule &optional (stream *standard-output*)) (format stream "First instructions:~%") (dolist (instr (lscheduler-first-instrs lschedule)) - (format stream " ~/quil:instruction-fmt/~%" instr)) + (format stream " ~/cl-quil:instruction-fmt/~%" instr)) (format stream "Last instructions:~%") (dolist (instr (lscheduler-last-instrs lschedule)) - (format stream " ~/quil:instruction-fmt/~%" instr)) + (format stream " ~/cl-quil:instruction-fmt/~%" instr)) (dohash ((key val) (lscheduler-later-instrs lschedule)) - (format stream "Instrs beneath ~/quil:instruction-fmt/: ~{~/quil:instruction-fmt/~^, ~}~%" + (format stream "Instrs beneath ~/cl-quil:instruction-fmt/: ~{~/cl-quil:instruction-fmt/~^, ~}~%" key val)) (dohash ((key val) (lscheduler-earlier-instrs lschedule)) - (format stream "Instrs above ~/quil:instruction-fmt/: ~{~/quil:instruction-fmt/~^, ~}~%" + (format stream "Instrs above ~/cl-quil:instruction-fmt/: ~{~/cl-quil:instruction-fmt/~^, ~}~%" key val))) diff --git a/src/addresser/rewiring.lisp b/src/addresser/rewiring.lisp index 0dd83d2bd..2a6a9e2d9 100644 --- a/src/addresser/rewiring.lisp +++ b/src/addresser/rewiring.lisp @@ -195,7 +195,7 @@ Returns NIL. This mutates the instruction." (qubit-index (reset-qubit-target instr)) :assert-wired t)))) (otherwise - (error "Requested to rewire ~/quil:instruction-fmt/, but we don't know how to do this." + (error "Requested to rewire ~/cl-quil:instruction-fmt/, but we don't know how to do this." instr))) ;; Return nil to emphasize side effect. nil) diff --git a/src/analysis/compress-qubits.lisp b/src/analysis/compress-qubits.lisp index ade1f9d3a..cefe8811f 100644 --- a/src/analysis/compress-qubits.lisp +++ b/src/analysis/compress-qubits.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; This file contains an analysis to compute the qubits used by a ;;; program. diff --git a/src/analysis/expand-circuits.lisp b/src/analysis/expand-circuits.lisp index 5e3a72475..1883597ae 100644 --- a/src/analysis/expand-circuits.lisp +++ b/src/analysis/expand-circuits.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (define-transform expand-circuits (expand-circuits) "This transform expands all circuits to create a circuit-free program.") diff --git a/src/analysis/expansion.lisp b/src/analysis/expansion.lisp index f2721fd0d..e47d76225 100644 --- a/src/analysis/expansion.lisp +++ b/src/analysis/expansion.lisp @@ -3,7 +3,7 @@ ;;;; Authors: Robert Smith ;;;; Erik Davis -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; Since both circuit and calibration expansion rely on some common code, but ;;; we would like error messages to be as specific as possible, we choose to @@ -185,7 +185,7 @@ An instruction is unitary if it is of type APPLICATION, whether that be INSTR it args))) (dolist (instr instrs) (unless (unitary-instruction-p instr) - (error "DAGGER cannot be applied to the impure instruction ~/quil:instruction-fmt/" + (error "DAGGER cannot be applied to the impure instruction ~/cl-quil:instruction-fmt/" instr)) (setf (application-operator instr) (involutive-dagger-operator (application-operator instr)))) @@ -195,12 +195,12 @@ An instruction is unitary if it is of type APPLICATION, whether that be INSTR it ((simple-controlled-operator-p (application-operator instr)) (let ((arguments (arguments instr))) (when (endp arguments) - (error "CONTROLLED requires at least one control qubit in ~/quil:instruction-fmt/." instr)) + (error "CONTROLLED requires at least one control qubit in ~/cl-quil:instruction-fmt/." instr)) (destructuring-bind (control-qubit . target-qubits) arguments (when (member control-qubit target-qubits :test #'argument=) (error "CONTROLLED cannot be applied when the control qubit is among the target qubits ~ - in ~/quil:instruction-fmt/" instr)) + in ~/cl-quil:instruction-fmt/" instr)) (let ((definition (circuit-application-definition instr))) ;; Check that the instructions in the body of a given circuit @@ -223,7 +223,7 @@ An instruction is unitary if it is of type APPLICATION, whether that be INSTR it (dolist (instr instrs instrs) (unless (unitary-instruction-p instr) (error "CONTROLLED cannot be applied to the impure instruction ~ - ~/quil:instruction-fmt/" instr)) + ~/cl-quil:instruction-fmt/" instr)) (setf (application-operator instr) (controlled-operator (application-operator instr)) (application-arguments instr) (cons control-qubit (arguments instr))))))))) @@ -232,7 +232,7 @@ An instruction is unitary if it is of type APPLICATION, whether that be INSTR it params args)) (t - (error "Unable to instantiate the modifiers in the complex instruction ~/quil:instruction-fmt/." + (error "Unable to instantiate the modifiers in the complex instruction ~/cl-quil:instruction-fmt/." instr))))) (:method ((instr application) param-value arg-value) diff --git a/src/analysis/fusion.lisp b/src/analysis/fusion.lisp index 2ca7fdc3b..6dd5e8a1c 100644 --- a/src/analysis/fusion.lisp +++ b/src/analysis/fusion.lisp @@ -5,7 +5,7 @@ ;;;; (Many ideas inspired by Aaron Vontell, who write the first but ;;;; altogether different implementation of gate fusion.) -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; This file has data structures and algorithms for performing "gate ;;; fusion", a program transformation to reduce the number of gates by diff --git a/src/analysis/patch-labels.lisp b/src/analysis/patch-labels.lisp index 80546bd47..4a281b55b 100644 --- a/src/analysis/patch-labels.lisp +++ b/src/analysis/patch-labels.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (define-transform patch-labels (patch-labels) "This transform resolves labels. Label positions are calculated, and corresponding JUMP instruction labels are patched with their absolute position in a program. diff --git a/src/analysis/process-includes.lisp b/src/analysis/process-includes.lisp index cfec9d488..e2ef867bf 100644 --- a/src/analysis/process-includes.lisp +++ b/src/analysis/process-includes.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (defun process-includes (raw-quil &optional originating-file) "Recursively process all INCLUDE instructions in the list RAW-QUIL. The result is a new sequence with the included quil instructions spliced in." diff --git a/src/analysis/qubits-needed.lisp b/src/analysis/qubits-needed.lisp index 182688d06..0dd5eca38 100644 --- a/src/analysis/qubits-needed.lisp +++ b/src/analysis/qubits-needed.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; This analysis counts the number of qubits needed to run a program. diff --git a/src/analysis/resolve-objects.lisp b/src/analysis/resolve-objects.lisp index 43564eca9..e9bb45701 100644 --- a/src/analysis/resolve-objects.lisp +++ b/src/analysis/resolve-objects.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; Used solely for object resolution to detect if we are resolving things ;;; inside of a circuit or calibration. @@ -14,7 +14,7 @@ ((assert-and-print-instruction (test-form &optional places datum &rest arguments) `(assert ,test-form ,places - "Error in resolving ~/quil:instruction-fmt/: ~@?" + "Error in resolving ~/cl-quil:instruction-fmt/: ~@?" instr ,datum ,@arguments))) diff --git a/src/analysis/rewrite-arithmetic.lisp b/src/analysis/rewrite-arithmetic.lisp index 824529504..046e55f4c 100644 --- a/src/analysis/rewrite-arithmetic.lisp +++ b/src/analysis/rewrite-arithmetic.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Authors: Lauren Capelluto, Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; This file contains a transformation to rewrite the given program ;;; with general arithmetic in gate arguments each replaced by a diff --git a/src/analysis/simplification-grab-bag.lisp b/src/analysis/simplification-grab-bag.lisp index 896fe150a..bf1c1c8e9 100644 --- a/src/analysis/simplification-grab-bag.lisp +++ b/src/analysis/simplification-grab-bag.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;;; This file contains a grab bag of INDIVIDUAL INSTRUCTION ;;;; SIMPLIFICATIONS. The reason for the "grab bag" nature is to avoid diff --git a/src/analysis/simplify-arithmetic.lisp b/src/analysis/simplify-arithmetic.lisp index 30a9103bb..cdfde7782 100644 --- a/src/analysis/simplify-arithmetic.lisp +++ b/src/analysis/simplify-arithmetic.lisp @@ -32,7 +32,7 @@ ;;;; expressions (ones that are linear). However, for the majority of ;;;; our use cases at this time, this subset is sufficient. -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (define-condition expression-not-simplifiable (serious-condition) () diff --git a/src/analysis/type-safety.lisp b/src/analysis/type-safety.lisp index 552126ac0..7abbe8d78 100644 --- a/src/analysis/type-safety.lisp +++ b/src/analysis/type-safety.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Eric Peterson -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (define-condition quil-type-error (simple-error) () @@ -42,7 +42,7 @@ (defun enforce-mref-bounds (mref memory-descriptor) (when (and (typep mref 'memory-ref) (not (plusp (memory-segment-length memory-descriptor :offset mref)))) - (quil-type-error "Memory ref \"~/quil:instruction-fmt/\" exceeds region size ~A." + (quil-type-error "Memory ref \"~/cl-quil:instruction-fmt/\" exceeds region size ~A." mref (memory-descriptor-length memory-descriptor)))) @@ -63,7 +63,7 @@ (defun check-mref (obj) (unless (typep obj 'memory-ref) - (quil-type-error "Argument expected to be a memory reference, but got ~/quil:instruction-fmt/." + (quil-type-error "Argument expected to be a memory reference, but got ~/cl-quil:instruction-fmt/." obj))) ;;; helper functions for type-check-instr ;;; @@ -74,7 +74,7 @@ (let ((mdesc (find-descriptor-for-mref (classical-left-operand instr) memory-regions))) (when (and object-to-type (equalp object-to-type (memory-descriptor-type mdesc))) - (quil-type-error "Argument should be a binary memory reference, but got real ~/quil:instruction-fmt/." + (quil-type-error "Argument should be a binary memory reference, but got real ~/cl-quil:instruction-fmt/." (classical-left-operand instr))) (adt:match quil-type (memory-descriptor-type mdesc) (quil-real @@ -88,7 +88,7 @@ quil-real memory-regions) t - (quil-type-error "Expected REAL assignment based on ~/quil:instruction-fmt/, but got ~/quil:instruction-fmt/." + (quil-type-error "Expected REAL assignment based on ~/cl-quil:instruction-fmt/, but got ~/cl-quil:instruction-fmt/." (classical-left-operand instr) (classical-right-operand instr)))) (quil-octet @@ -98,7 +98,7 @@ (and (typep (classical-right-operand instr) 'constant) (equal quil-integer (constant-value-type (classical-right-operand instr))))) t - (quil-type-error "Expected OCTET assignment based on ~/quil:instruction-fmt/, but got ~/quil:instruction-fmt/." + (quil-type-error "Expected OCTET assignment based on ~/cl-quil:instruction-fmt/, but got ~/cl-quil:instruction-fmt/." (classical-left-operand instr) (classical-right-operand instr)))) (quil-bit @@ -145,7 +145,7 @@ (defun typecheck-comparison-instruction (instr memory-regions) (check-mref (classical-target instr)) (unless (constant-or-mref-typep (classical-target instr) quil-bit memory-regions) - (quil-type-error "Conditional tests write to BIT memory, but got ~/quil:instruction-fmt/ instead." + (quil-type-error "Conditional tests write to BIT memory, but got ~/cl-quil:instruction-fmt/ instead." (classical-target instr))) (check-mref (classical-left-operand instr)) (let ((mdesc (find-descriptor-for-mref (classical-left-operand instr) @@ -154,22 +154,22 @@ (adt:match quil-type (memory-descriptor-type mdesc) (quil-bit (unless (constant-or-mref-typep rop (list quil-bit quil-integer) memory-regions) - (quil-type-error "Conditional test for left-hand operand of type BIT requires right-hand operand of type BIT or immediate INT but got ~/quil:instruction-fmt/ and ~/quil:instruction-fmt/." + (quil-type-error "Conditional test for left-hand operand of type BIT requires right-hand operand of type BIT or immediate INT but got ~/cl-quil:instruction-fmt/ and ~/cl-quil:instruction-fmt/." (classical-left-operand instr) rop ))) (quil-real (unless (constant-or-mref-typep rop quil-real memory-regions) - (quil-type-error "Conditional test for left-hand operand of type REAL requires right-hand operand of type REAL or immediate REAL but got ~/quil:instruction-fmt/ and ~/quil:instruction-fmt/." + (quil-type-error "Conditional test for left-hand operand of type REAL requires right-hand operand of type REAL or immediate REAL but got ~/cl-quil:instruction-fmt/ and ~/cl-quil:instruction-fmt/." (classical-left-operand instr) rop))) (quil-octet (unless (constant-or-mref-typep rop (list quil-octet quil-integer) memory-regions) - (quil-type-error "Conditional test for left-hand operand of type OCTET requires right-hand operand of type OCTET or immediate INTEGER but got ~/quil:instruction-fmt/ and ~/quil:instruction-fmt/." + (quil-type-error "Conditional test for left-hand operand of type OCTET requires right-hand operand of type OCTET or immediate INTEGER but got ~/cl-quil:instruction-fmt/ and ~/cl-quil:instruction-fmt/." (classical-left-operand instr) rop))) (quil-integer (unless (constant-or-mref-typep rop quil-integer memory-regions) - (quil-type-error "Conditional test for left-hand operand of type INTEGER requires right-hand operand of type INTEGER or immediate INTEGER but got ~/quil:instruction-fmt/ and ~/quil:instruction-fmt/." + (quil-type-error "Conditional test for left-hand operand of type INTEGER requires right-hand operand of type INTEGER or immediate INTEGER but got ~/cl-quil:instruction-fmt/ and ~/cl-quil:instruction-fmt/." (classical-left-operand instr) rop)))))) @@ -194,7 +194,7 @@ (let ((mdesc (find-descriptor-for-mref param memory-regions))) (setf (memory-ref-descriptor param) mdesc) (unless (equal quil-real (memory-descriptor-type mdesc)) - (quil-type-error "Memory reference ~/quil:instruction-fmt/ is used as a gate parameter but is not a REAL value." + (quil-type-error "Memory reference ~/cl-quil:instruction-fmt/ is used as a gate parameter but is not a REAL value." param)))))) ;;; real deal ;;; @@ -240,7 +240,7 @@ (adt:match quil-type (memory-descriptor-type mdesc) (quil-real (call-next-method)) (quil-integer (call-next-method)) - (_ (quil-type-error "NEG argument should be a signed memory reference, but got ~/quil:instruction-fmt/." + (_ (quil-type-error "NEG argument should be a signed memory reference, but got ~/cl-quil:instruction-fmt/." (classical-target instr)))))) ;; NOT can't be REAL @@ -249,7 +249,7 @@ (let ((mdesc (find-descriptor-for-mref (classical-target instr) memory-regions))) (adt:match quil-type (memory-descriptor-type mdesc) (quil-real - (quil-type-error "NOT argument should be a binary memory reference, but got ~/quil:instruction-fmt/." + (quil-type-error "NOT argument should be a binary memory reference, but got ~/cl-quil:instruction-fmt/." (classical-target instr))) (_ (call-next-method))))) @@ -311,7 +311,7 @@ (unless (constant-or-mref-typep (classical-target instr) (memory-descriptor-type mdesc) memory-regions) - (quil-type-error "Memory region types do not match for ~A and ~/quil:instruction-fmt/." + (quil-type-error "Memory region types do not match for ~A and ~/cl-quil:instruction-fmt/." (memory-name-region-name (classical-left-operand instr)) (classical-target instr))) (unless (constant-or-mref-typep (classical-right-operand instr) @@ -336,13 +336,13 @@ (constant-or-mref-typep (classical-right-operand instr) quil-integer memory-regions))) - (quil-type-error "Memory region types do not match for ~A and ~/quil:instruction-fmt/." + (quil-type-error "Memory region types do not match for ~A and ~/cl-quil:instruction-fmt/." (memory-name-region-name (classical-target instr)) (classical-right-operand instr))) (unless (constant-or-mref-typep (classical-left-operand instr) quil-integer memory-regions) - (quil-type-error "STORE middle operand must be an INTEGER, but got ~/quil:instruction-fmt/." + (quil-type-error "STORE middle operand must be an INTEGER, but got ~/cl-quil:instruction-fmt/." (classical-left-operand instr))))) ;; comparison operators require bit target in first, agreement in last two @@ -373,7 +373,7 @@ t) (_ (quil-type-error "MEASURE instruction target must be of type ~ - BIT or INTEGER, but got ~/quil:instruction-fmt/ of type ~A." + BIT or INTEGER, but got ~/cl-quil:instruction-fmt/ of type ~A." (measure-address instr) (quil-type-string (memory-descriptor-type mdesc))))))) diff --git a/src/analysis/validate-sequence-gate.lisp b/src/analysis/validate-sequence-gate.lisp index 02e5ac2b7..138cc94a2 100644 --- a/src/analysis/validate-sequence-gate.lisp +++ b/src/analysis/validate-sequence-gate.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Parker Williams -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (defun validate-resolved-seq-gate-definition (gate-def) (declare (type sequence-gate-definition gate-def)) diff --git a/src/ast.lisp b/src/ast.lisp index 7031e6199..b80fc58de 100644 --- a/src/ast.lisp +++ b/src/ast.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;;;;;;;;;;;;;;;;;;;;;;;;; Atomic Elements ;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -504,7 +504,7 @@ If no exit rewiring is found, return NIL." (defstruct (pauli-term) "Records a word of Pauli operators, together with an ordered list of qubit formals on which they act, as well as a scalar prefix. This is part of the internal representation of a EXP-PAULI-SUM-GATE-DEFINITION and probably shouldn't be instantiated otherwise. -This replicates some of the behavior of CL-QUIL.CLIFFORD::PAULI, but it extends it slightly: a Clifford Pauli is constrained to carry a phase which is a fourth root of unity, but the phase of a PAULI-TERM can be arbitrary (indeed, even a delayed expression). The reader looking for an embodiment of Pauli words is better off using that data structure without CAREFUL CONSIDERATION." +This replicates some of the behavior of CL-QUIL/CLIFFORD::PAULI, but it extends it slightly: a Clifford Pauli is constrained to carry a phase which is a fourth root of unity, but the phase of a PAULI-TERM can be arbitrary (indeed, even a delayed expression). The reader looking for an embodiment of Pauli words is better off using that data structure without CAREFUL CONSIDERATION." pauli-word prefactor arguments) @@ -1572,7 +1572,7 @@ For example, (format stream "RESET")) (:method ((instr reset-qubit) stream) - (format stream "RESET ~/quil:instruction-fmt/" (reset-qubit-target instr))) + (format stream "RESET ~/cl-quil:instruction-fmt/" (reset-qubit-target instr))) (:method ((instr wait) (stream stream)) (format stream "WAIT")) @@ -1583,7 +1583,7 @@ For example, (:method ((instr classical-instruction) (stream stream)) (format stream "~A" (mnemonic instr)) (loop :for arg :across (arguments instr) - :do (format stream " ~/quil:instruction-fmt/" arg))) + :do (format stream " ~/cl-quil:instruction-fmt/" arg))) (:method ((instr pragma) (stream stream)) (format stream "PRAGMA ~{~A~^ ~}~@[ ~S~]" @@ -1591,7 +1591,7 @@ For example, (pragma-freeform-string instr))) (:method ((instr jump-target) (stream stream)) - (format stream "LABEL ~/quil:instruction-fmt/" + (format stream "LABEL ~/cl-quil:instruction-fmt/" (jump-target-label instr))) (:method ((instr jump) (stream stream)) @@ -1600,18 +1600,18 @@ For example, ((integerp l) (format stream "JUMP {absolute address ~D}" l)) (t - (format stream "JUMP ~/quil:instruction-fmt/" + (format stream "JUMP ~/cl-quil:instruction-fmt/" (jump-label instr)))))) (:method ((instr jump-when) (stream stream)) (let ((l (jump-label instr))) (cond ((integerp l) - (format stream "JUMP-WHEN {absolute address ~D} ~/quil:instruction-fmt/" + (format stream "JUMP-WHEN {absolute address ~D} ~/cl-quil:instruction-fmt/" l (conditional-jump-address instr))) (t - (format stream "JUMP-WHEN ~/quil:instruction-fmt/ ~/quil:instruction-fmt/" + (format stream "JUMP-WHEN ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/" (jump-label instr) (conditional-jump-address instr)))))) @@ -1619,26 +1619,26 @@ For example, (let ((l (jump-label instr))) (cond ((integerp l) - (format stream "JUMP-UNLESS {absolute address ~D} ~/quil:instruction-fmt/" + (format stream "JUMP-UNLESS {absolute address ~D} ~/cl-quil:instruction-fmt/" l (conditional-jump-address instr))) (t - (format stream "JUMP-UNLESS ~/quil:instruction-fmt/ ~/quil:instruction-fmt/" + (format stream "JUMP-UNLESS ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/" (jump-label instr) (conditional-jump-address instr)))))) (:method ((instr measure) (stream stream)) - (format stream "MEASURE ~/quil:instruction-fmt/ ~/quil:instruction-fmt/" + (format stream "MEASURE ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/" (measurement-qubit instr) (measure-address instr))) (:method ((instr measure-discard) (stream stream)) - (format stream "MEASURE ~/quil:instruction-fmt/" + (format stream "MEASURE ~/cl-quil:instruction-fmt/" (measurement-qubit instr))) (:method ((instr application) (stream stream)) (print-operator-description (application-operator instr) stream) - (format stream "~@[(~{~/quil:instruction-fmt/~^, ~})~]~{ ~/quil:instruction-fmt/~}" + (format stream "~@[(~{~/cl-quil:instruction-fmt/~^, ~})~]~{ ~/cl-quil:instruction-fmt/~}" (application-parameters instr) (application-arguments instr))) @@ -1686,10 +1686,10 @@ For example, (format stream "DEFCIRCUIT ~A" (circuit-definition-name defn)) (unless (endp (circuit-definition-parameters defn)) - (format stream "(~{~/quil:instruction-fmt/~^, ~})" + (format stream "(~{~/cl-quil:instruction-fmt/~^, ~})" (circuit-definition-parameters defn))) (unless (endp (circuit-definition-arguments defn)) - (format stream "~{ ~/quil:instruction-fmt/~}" + (format stream "~{ ~/cl-quil:instruction-fmt/~}" (circuit-definition-arguments defn))) (format stream ":~%") (print-instruction-sequence (circuit-definition-body defn) @@ -1702,7 +1702,7 @@ For example, (mapcar #'param-name (sequence-gate-definition-parameters gate)) (mapcar #'formal-name (sequence-gate-definition-arguments gate))) (dolist (operation (sequence-gate-definition-sequence gate)) - (format stream " ~/quil:instruction-fmt/~%" operation))) + (format stream " ~/cl-quil:instruction-fmt/~%" operation))) (:method ((gate exp-pauli-sum-gate-definition) (stream stream)) (format stream "DEFGATE ~A~@[(~{%~A~^, ~})~]~{ ~A~} AS PAULI-SUM:~%" diff --git a/src/build-gate.lisp b/src/build-gate.lisp index 05c206454..5ad846d82 100644 --- a/src/build-gate.lisp +++ b/src/build-gate.lisp @@ -7,7 +7,7 @@ ;;;; ;;;; (make-instance 'gate-application :blah 'blah-blah ...) . -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; first, some simple utilities for constructing gate objects diff --git a/src/cfg.lisp b/src/cfg.lisp index cee642d4c..2afc34306 100644 --- a/src/cfg.lisp +++ b/src/cfg.lisp @@ -625,7 +625,7 @@ Return the following values: (when (slot-boundp blk 'outgoing) (adt:match outgoing-edge (outgoing blk) ((conditional-edge instr _ _) - (format s "\\nConditioned on ~/quil:instruction-fmt/" instr) + (format s "\\nConditioned on ~/cl-quil:instruction-fmt/" instr) (format s "\\l")) (_ nil))))) diff --git a/src/chip-library/chip-table.lisp b/src/chip-library/chip-table.lisp index eb56a2c74..284fb2172 100644 --- a/src/chip-library/chip-table.lisp +++ b/src/chip-library/chip-table.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(in-package cl-quil.chip-library) +(in-package cl-quil/chip-library) ;;; Mutable table that stores functions for defining chips diff --git a/src/chip-library/package.lisp b/src/chip-library/package.lisp index 6ceb29c43..f351efb01 100644 --- a/src/chip-library/package.lisp +++ b/src/chip-library/package.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(defpackage #:cl-quil.chip-library +(defpackage #:cl-quil/chip-library (:use #:cl) (:local-nicknames (:q :cl-quil) (:a :alexandria)) diff --git a/src/chip/chip-reader.lisp b/src/chip/chip-reader.lisp index af02d227f..bc58717a2 100644 --- a/src/chip/chip-reader.lisp +++ b/src/chip/chip-reader.lisp @@ -420,7 +420,7 @@ (instruction :initarg :instruction :reader illegal-qubits-used-error-instruction)) (:documentation "Error representing the use of an illegal qubit.") (:report (lambda (c s) - (format s "Instruction '~/quil:instruction-fmt/' uses the illegal qubits ~{~A~^, ~}." + (format s "Instruction '~/cl-quil:instruction-fmt/' uses the illegal qubits ~{~A~^, ~}." (illegal-qubits-used-error-instruction c) (illegal-qubits-used-error-illegal-qubits c))))) @@ -428,7 +428,7 @@ () (:documentation "Error representing the use of an illegal qubit in a preserved block.") (:report (lambda (c s) - (format s "Within a preserved block, instruction '~/quil:instruction-fmt/' uses the illegal qubits ~{~A~^, ~}." + (format s "Within a preserved block, instruction '~/cl-quil:instruction-fmt/' uses the illegal qubits ~{~A~^, ~}." (illegal-qubits-used-error-instruction c) (illegal-qubits-used-error-illegal-qubits c))))) diff --git a/src/cl-quil.lisp b/src/cl-quil.lisp index 3e942f708..67db22d54 100644 --- a/src/cl-quil.lisp +++ b/src/cl-quil.lisp @@ -3,7 +3,7 @@ ;;;; Authors: Robert Smith ;;; Erik Davis -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (defvar *standard-post-parsing-transforms* '(validate-defgate-loops expand-circuits type-check) @@ -181,7 +181,7 @@ This also signals ambiguous definitions, which may be handled as needed." (ambiguous-definition-handler *default-ambiguous-definition-handler*)) "Parse the input STRING which can be either Quil or OpenQASM code." (if (%check-for-qasm-header string) - (quil.qasm:parse-qasm string) + (cl-quil/qasm:parse-qasm string) (parse-quil string :originating-file originating-file :transforms transforms diff --git a/src/classical-memory.lisp b/src/classical-memory.lisp index 36e6658a8..bdb832104 100644 --- a/src/classical-memory.lisp +++ b/src/classical-memory.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (define-condition quil-memory-model-error (a:simple-parse-error) () diff --git a/src/clifford/benchmarking-procedures.lisp b/src/clifford/benchmarking-procedures.lisp index 6a2347489..9bba28c75 100644 --- a/src/clifford/benchmarking-procedures.lisp +++ b/src/clifford/benchmarking-procedures.lisp @@ -4,7 +4,7 @@ ;;;; ;;;; Procedures to respond to quilc requests about cliffords, specifically for benchmarking quantum gate sets and circuits. -(in-package :cl-quil.clifford) +(in-package :cl-quil/clifford) (defconstant +god-table-cache-limit+ 10) (global-vars:define-global-var **god-tables** (make-gateset-hash-table)) @@ -80,24 +80,24 @@ nil))) (define-factorize factor-I "I" - (quil::double= top-left bottom-right) - (and (quil::double= top-right 0) - (quil::double= top-right bottom-left))) + (cl-quil::double= top-left bottom-right) + (and (cl-quil::double= top-right 0) + (cl-quil::double= top-right bottom-left))) (define-factorize factor-X "X" - (and (quil::double= top-left 0) - (quil::double= top-left bottom-right)) - (quil::double= top-right bottom-left)) + (and (cl-quil::double= top-left 0) + (cl-quil::double= top-left bottom-right)) + (cl-quil::double= top-right bottom-left)) (define-factorize factor-Y "Y" - (and (quil::double= top-left 0) - (quil::double= top-left bottom-right)) - (quil::double= top-right (- bottom-left))) + (and (cl-quil::double= top-left 0) + (cl-quil::double= top-left bottom-right)) + (cl-quil::double= top-right (- bottom-left))) (define-factorize factor-Z "Z" - (quil::double= top-left (- bottom-right)) - (and (quil::double= top-right 0) - (quil::double= top-right bottom-left))) + (cl-quil::double= top-left (- bottom-right)) + (and (cl-quil::double= top-right 0) + (cl-quil::double= top-right bottom-left))) (defun valid-pauli-dim (m n) "T if M and N are valid dimensions of a Pauli matrix, NIL otherwise." @@ -119,16 +119,16 @@ (phase-wf (copy-seq wfa))) (loop :for i :below 8 :do (map-into phase-wf (lambda (x) (* x phase-factor)) phase-wf) - :when (every #'quil::double~ phase-wf wfb) + :when (every #'cl-quil::double~ phase-wf wfb) :return t :finally (return nil)))) (defun phase-to-string (phase) "Returns a string representation of a fourth root of unity, given by PHASE, NIL otherwise." - (cond ((quil::double~ phase 1) "") - ((quil::double~ phase -1) "-") - ((quil::double~ phase #C(0 1)) "i") - ((quil::double~ phase #C(0 -1)) "-i") + (cond ((cl-quil::double~ phase 1) "") + ((cl-quil::double~ phase -1) "-") + ((cl-quil::double~ phase #C(0 1)) "i") + ((cl-quil::double~ phase #C(0 -1)) "-i") (t (error "Invalid phase number: ~A~%" phase)))) (defun string-to-phase (phase-str) @@ -178,15 +178,15 @@ "Return a list of the n qubit pauli basis matrices. Note that this is the basis for group action, consisting of strings with one X or Z, not the basis for the vector space of complex matrices." (or (gethash n memo-table) (setf (gethash n memo-table) - (let ((X (quil::from-list '(0 1 1 0) '(2 2))) - (Z (quil::from-list '(1 0 0 -1) '(2 2)))) + (let ((X (cl-quil::from-list '(0 1 1 0) '(2 2))) + (Z (cl-quil::from-list '(1 0 0 -1) '(2 2)))) (loop :for i :below n - :collect (quil::kq-gate-on-lines X n `(,i)) - :collect (quil::kq-gate-on-lines Z n `(,i)))))))) + :collect (cl-quil::kq-gate-on-lines X n `(,i)) + :collect (cl-quil::kq-gate-on-lines Z n `(,i)))))))) (defun matrix-to-clifford (gate) "Convert a matrix GATE into a CLIFFORD object." - (let ((num-qubits (quil:ilog2 (magicl:ncols gate)))) + (let ((num-qubits (cl-quil:ilog2 (magicl:ncols gate)))) (make-clifford :num-qubits num-qubits :basis-map (make-array @@ -206,12 +206,12 @@ (defun apply-pauli-to-wavefunction (ph index q wf) "Apply the pauli specified by index (0 = I, 1 = X, 2 = Z, 3 = Y) to qubit Q of the wavefunction WF, with a phase PH." - (assert (quil::positive-power-of-two-p (length wf)) + (assert (cl-quil::positive-power-of-two-p (length wf)) (wf) "The provided wavefunction must have a positive power-of-two length.") (multiple-value-bind (b a) (floor index 2) (let* ((phase (expt #C(0.0d0 1.0d0) (b* a b))) - (n (quil::ilog2 (length wf)))) + (n (cl-quil::ilog2 (length wf)))) (declare (type (integer 1) n)) ; Due to ASSERT above. (flet ((xz (w0 w1) (setf w0 (* ph phase w0)) @@ -255,7 +255,7 @@ (defun clifford-to-matrix (cliff) "Converts a clifford element into its matrix form, operating on the usual computational basis Bn x B(n-1) x ... x B0." (let* ((n (num-qubits cliff)) - (mat (quil::zeros (list (expt 2 n) (expt 2 n)))) + (mat (cl-quil::zeros (list (expt 2 n) (expt 2 n)))) (scratch-wf (make-array (expt 2 n) :element-type '(complex double-float) :initial-element #C(0.0d0 0.0d0))) (zero-image-tab (make-tableau-zero-state n)) (pauli-map (clifford-basis-map cliff))) @@ -287,21 +287,21 @@ Note: will raise an error if PARSED-QUIL contains instruction types other than APPLICATION, PRAGMA, or UNRESOLVED-APPLICATION." - (loop :for instr :across (quil:parsed-program-executable-code parsed-quil) - :for qubits-used := (quil::qubits-used instr) - :unless (or (typep instr 'quil:application) - (typep instr 'quil:pragma) - (and quil::*allow-unresolved-applications* - (typep instr 'quil:unresolved-application))) :do + (loop :for instr :across (cl-quil:parsed-program-executable-code parsed-quil) + :for qubits-used := (cl-quil::qubits-used instr) + :unless (or (typep instr 'cl-quil:application) + (typep instr 'cl-quil:pragma) + (and cl-quil::*allow-unresolved-applications* + (typep instr 'cl-quil:unresolved-application))) :do (error "Cannot extract clifford from the instr ~/cl-quil:instruction-fmt/" instr) - :collect (list (matrix-to-clifford (quil:gate-matrix instr)) + :collect (list (matrix-to-clifford (cl-quil:gate-matrix instr)) qubits-used))) (defun clifford-circuit-p (parsed-quil) "If the parsed circuit PARSED-QUIL is a clifford circuit, return the CLIFFORD corresponding to it. Otherwise return NIL. This will generate a clifford that acts on the number of qubits in the program, rather than a number of qubits that is the difference between the maximum and minimum index." (let* ((cliffords (extract-cliffords parsed-quil)) - (qubits (sort (quil::qubits-used parsed-quil) #'<)) + (qubits (sort (cl-quil::qubits-used parsed-quil) #'<)) (num-qubits (length qubits))) (reduce #'group-mul (loop :for (clifford targets) :in (reverse cliffords) :collect (embed clifford num-qubits @@ -310,4 +310,4 @@ other than APPLICATION, PRAGMA, or UNRESOLVED-APPLICATION." (defun clifford-from-quil (quil) "Given a STRING of quil, produce the associated CLIFFORD element. If QUIL does not represent a Clifford circuit, return NIL. " - (clifford-circuit-p (quil::safely-parse-quil quil))) + (clifford-circuit-p (cl-quil::safely-parse-quil quil))) diff --git a/src/clifford/clifford.lisp b/src/clifford/clifford.lisp index dbd13eaa6..70e902378 100644 --- a/src/clifford/clifford.lisp +++ b/src/clifford/clifford.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Nik Tezak -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; This file contains the Pauli basis representation of Clifford ;;; operators. @@ -80,7 +80,7 @@ qubits." (declaim (ftype (function (t) simple-vector) basis-map)) (defstruct (clifford (:include qubit-algebra)) "An element of the Clifford group on NUM-QUBITS qubits." - (num-qubits 0 :type quil::unsigned-fixnum) + (num-qubits 0 :type cl-quil::unsigned-fixnum) (basis-map nil :type simple-vector)) (defmethod num-qubits ((c clifford)) @@ -236,7 +236,7 @@ NOTE: THERE IS NO CHECKING OF THE VALIDITY OF THE MAP. ANTICOMMUTATIVITY IS NOT (declare (type clifford c)) (declare (inline pauli-hash)) (sxhash - (loop :with h :of-type quil::unsigned-fixnum := 0 + (loop :with h :of-type cl-quil::unsigned-fixnum := 0 :for p :of-type pauli :across (basis-map c) :do (setf h (hash-mix h (pauli-hash p))) :finally (return h)))) diff --git a/src/clifford/god-table-utilities.lisp b/src/clifford/god-table-utilities.lisp index a2cd1d005..6db5642f2 100644 --- a/src/clifford/god-table-utilities.lisp +++ b/src/clifford/god-table-utilities.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) (defun write-gt-stream (gt f) "Write out the God table GT to the stream F." diff --git a/src/clifford/god-table.lisp b/src/clifford/god-table.lisp index 5d4e543b2..dc6d9f7fd 100644 --- a/src/clifford/god-table.lisp +++ b/src/clifford/god-table.lisp @@ -3,7 +3,7 @@ ;;;; Author: Nik Tezak ;;;; Robert Smith -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; This file contains an implementation of a Clifford "God table", a ;;; lookup table used to reconstruct Clifford elements from some @@ -85,7 +85,7 @@ allows to compute a minimal length sequence of generators to invert it.")) (defun make-god-table (gateset) "Compute the God table for the closure of some specific generators." - (let* ((q (quil:make-queue)) + (let* ((q (cl-quil:make-queue)) (n (num-qubits gateset)) #+#:debug(num-cliffords (count-clifford n)) (generators (cliffords gateset)) @@ -106,7 +106,7 @@ allows to compute a minimal length sequence of generators to invert it.")) g-idx) ;; enqueue the generator to recursively generate more ;; cliffords below - (quil:enqueue q g))) + (cl-quil:enqueue q g))) ;; At this point we know all cliffords that are 0 and 1 generator ;; applications removed from the identity. @@ -119,8 +119,8 @@ allows to compute a minimal length sequence of generators to invert it.")) ;; etc. until we have reached all cliffords. (let ((explored 0) #+#:debug(time (get-internal-real-time))) - (loop :until (quil:queue-empty-p q) - :for next := (quil:dequeue q) + (loop :until (cl-quil:queue-empty-p q) + :for next := (cl-quil:dequeue q) :do ;; For each clifford one generator removed from NEXT ;; check if it has been seen before in which case we have @@ -146,7 +146,7 @@ allows to compute a minimal length sequence of generators to invert it.")) internal-time-units-per-second)) (setf time (get-internal-real-time))) (setf (gethash next-s gt) s-idx) - (quil:enqueue q next-s))))) + (cl-quil:enqueue q next-s))))) (make-instance 'god-table :gateset gateset :mapping gt))) diff --git a/src/clifford/pauli.lisp b/src/clifford/pauli.lisp index 5f455e2f8..fd8888c16 100644 --- a/src/clifford/pauli.lisp +++ b/src/clifford/pauli.lisp @@ -3,7 +3,7 @@ ;;;; Authors: Nik Tezak ;;;; Robert Smith -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; This file implements an efficient representation of the Pauli ;;; group. @@ -28,7 +28,7 @@ (1- (length (pauli-components p)))) (defun make-components (num-qubits) - (declare (type quil::unsigned-fixnum num-qubits)) + (declare (type cl-quil::unsigned-fixnum num-qubits)) (make-array (1+ num-qubits) :element-type 'base4 :initial-element 0)) @@ -299,7 +299,7 @@ hash-function." (declare (optimize speed (safety 0) (debug 0) (space 0)) (type pauli p)) (sxhash - (loop :with h :of-type quil::unsigned-fixnum := 0 + (loop :with h :of-type cl-quil::unsigned-fixnum := 0 :for x :across (pauli-components p) :do (setf h (hash-mix h x)) :finally (return h)))) @@ -341,8 +341,8 @@ hash-function." (forward nil)) (map nil (lambda (from to) ;; We make copies because quilc doens't like EQ things. - (push (quil:build-gate "CNOT" () from to) reverse) - (push (quil:build-gate "CNOT" () from to) forward)) + (push (cl-quil:build-gate "CNOT" () from to) reverse) + (push (cl-quil:build-gate "CNOT" () from to) forward)) qubits (subseq qubits 1)) (values (nreverse forward) @@ -361,7 +361,7 @@ Note that this function is somewhat informed by the variable *EXP-PAULI-COLLECT- which isn't allowed in EXP-PAULI." phase) (setf phase (coerce (realpart phase) 'double-float)) - (quil:with-inst () + (cl-quil:with-inst () (cond ((pauli-identity-p p) ;; PyQuil would generate @@ -382,9 +382,9 @@ Note that this function is somewhat informed by the variable *EXP-PAULI-COLLECT- :unless (eq 'I op) :return (values op (1- i))) (ecase op - (X (quil:inst "RX" (list (quil::param-* (* 2.0d0 phase) x)) qubit)) - (Y (quil:inst "RY" (list (quil::param-* (* 2.0d0 phase) x)) qubit)) - (Z (quil:inst "RZ" (list (quil::param-* (* 2.0d0 phase) x)) qubit))))) + (X (cl-quil:inst "RX" (list (cl-quil::param-* (* 2.0d0 phase) x)) qubit)) + (Y (cl-quil:inst "RY" (list (cl-quil::param-* (* 2.0d0 phase) x)) qubit)) + (Z (cl-quil:inst "RZ" (list (cl-quil::param-* (* 2.0d0 phase) x)) qubit))))) ;; The general case. (t @@ -395,15 +395,15 @@ Note that this function is somewhat informed by the variable *EXP-PAULI-COLLECT- :collect qubit :into toggle-qubits ;; This collect builds pairs of basis-changing gates. :when (eq 'X pauli-component) - :collect (quil:build-gate "H" () qubit) :into to-z - :and :collect (quil:build-gate "H" () qubit) :into from-z + :collect (cl-quil:build-gate "H" () qubit) :into to-z + :and :collect (cl-quil:build-gate "H" () qubit) :into from-z :when (eq 'Y pauli-component) - :collect (quil:build-gate "RX" (list quil:pi/2) qubit) :into to-z - :and :collect (quil:build-gate "RX" (list quil:-pi/2) qubit) :into from-z + :collect (cl-quil:build-gate "RX" (list cl-quil:pi/2) qubit) :into to-z + :and :collect (cl-quil:build-gate "RX" (list cl-quil:-pi/2) qubit) :into from-z :finally (multiple-value-bind (forward reverse) (funcall *exp-pauli-toggles* toggle-qubits) - (mapc #'quil:inst to-z) - (mapc #'quil:inst forward) - (quil:inst "RZ" (list (quil::param-* (* 2.0d0 phase) x)) (first (last toggle-qubits))) - (mapc #'quil:inst reverse) - (mapc #'quil:inst from-z))))))))) + (mapc #'cl-quil:inst to-z) + (mapc #'cl-quil:inst forward) + (cl-quil:inst "RZ" (list (cl-quil::param-* (* 2.0d0 phase) x)) (first (last toggle-qubits))) + (mapc #'cl-quil:inst reverse) + (mapc #'cl-quil:inst from-z))))))))) diff --git a/src/clifford/perm.lisp b/src/clifford/perm.lisp index 933e8a9d1..35a4a95ea 100644 --- a/src/clifford/perm.lisp +++ b/src/clifford/perm.lisp @@ -3,7 +3,7 @@ ;;;; Author: Robert Smith (in collab with Charles Hadfield) ;;;; -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; This files deals with the permutation group representation of the ;;; Clifford group. diff --git a/src/clifford/qubit-algebra.lisp b/src/clifford/qubit-algebra.lisp index c7d879007..d014d11d6 100644 --- a/src/clifford/qubit-algebra.lisp +++ b/src/clifford/qubit-algebra.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Nik Tezak -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; This file contains an abstract base class representing "qubit ;;; algebras", corresponding to algebras that have some correspondence diff --git a/src/clifford/stabilizer.lisp b/src/clifford/stabilizer.lisp index 50b02c152..238703b29 100644 --- a/src/clifford/stabilizer.lisp +++ b/src/clifford/stabilizer.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Authors: Robert Smith, Andrew Shi -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; Most of this is from or inspired by https://arxiv.org/pdf/quant-ph/0406196.pdf ;;; @@ -296,7 +296,7 @@ Note that no expressions calculating the phase update are created. This is becau ;; record the X or Z variable in that bit's ;; running list. In the end, the running list ;; represents a disjunction of contributions. - (when (quil::power-of-two-p i) ; X and Z's will have power of two indexes. + (when (cl-quil::power-of-two-p i) ; X and Z's will have power of two indexes. (let ((var (nth (1- (integer-length i)) variables))) ;; The var that contributes to X- and Z-FACTORS (loop :with bits := (pauli-index cp) diff --git a/src/clifford/swap-representation.lisp b/src/clifford/swap-representation.lisp index 5ac2fa2d3..fc4a9b46d 100644 --- a/src/clifford/swap-representation.lisp +++ b/src/clifford/swap-representation.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Anthony Polloreno -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; This file contains functions to explore the Clifford group mod the swap group. diff --git a/src/clifford/symplectic.lisp b/src/clifford/symplectic.lisp index af7bd3cb9..6a86c8a5e 100644 --- a/src/clifford/symplectic.lisp +++ b/src/clifford/symplectic.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.clifford) +(in-package #:cl-quil/clifford) ;;; In this file we write some routines to deal with elements of ;;; the symplectic group Sp(2n, F_2). diff --git a/src/compilation-methods.lisp b/src/compilation-methods.lisp index 08054f164..cc815f30a 100644 --- a/src/compilation-methods.lisp +++ b/src/compilation-methods.lisp @@ -64,9 +64,9 @@ (let ((result (funcall compilation-method instruction :context context))) (let ((*print-pretty* nil)) (format-noise - "APPLY-TRANSLATION-COMPILERS: Applying ~A to ~/quil:instruction-fmt/." + "APPLY-TRANSLATION-COMPILERS: Applying ~A to ~/cl-quil:instruction-fmt/." compilation-method instruction)) - (format-noise "~{ ~/quil:instruction-fmt/~%~}" result) + (format-noise "~{ ~/cl-quil:instruction-fmt/~%~}" result) (return-from apply-translation-compilers result)) (compiler-does-not-apply () nil)) (try-next-compiler () @@ -82,7 +82,7 @@ (map nil #'try-compiler (chip-specification-generic-compilers chip-spec)) ;; if those failed too, there's really nothing more to do. (format-noise - "APPLY-TRANSLATION-COMPILERS: Could not find a compiler for ~/quil:instruction-fmt/." + "APPLY-TRANSLATION-COMPILERS: Could not find a compiler for ~/cl-quil:instruction-fmt/." instruction) (give-up-compilation)))) diff --git a/src/compiler-hook.lisp b/src/compiler-hook.lisp index 3d057e048..3cb81833d 100644 --- a/src/compiler-hook.lisp +++ b/src/compiler-hook.lisp @@ -188,7 +188,7 @@ Returns a value list: (processed-program, of type parsed-program ((null processed-quil) (format-noise " *empty program*")) (t - (format-noise "~{ ~/quil:instruction-fmt/~%~}" processed-quil)))) + (format-noise "~{ ~/cl-quil:instruction-fmt/~%~}" processed-quil)))) (dotimes (n *compressor-passes*) (format-noise "COMPILER-HOOK: Compressing, pass ~D/~D." (1+ n) *compressor-passes*) (setf processed-quil @@ -203,7 +203,7 @@ Returns a value list: (processed-program, of type parsed-program ((null processed-quil) (format-noise " *empty program*")) (t - (format-noise "~{ ~/quil:instruction-fmt/~%~}" processed-quil)))) + (format-noise "~{ ~/cl-quil:instruction-fmt/~%~}" processed-quil)))) ;; we're done processing. store the results back into the CFG block. (setf (basic-block-code blk) processed-quil) (setf (basic-block-in-rewiring blk) initial-l2p) diff --git a/src/compilers/modifiers.lisp b/src/compilers/modifiers.lisp index 6f88716f5..5dd2097ee 100644 --- a/src/compilers/modifiers.lisp +++ b/src/compilers/modifiers.lisp @@ -6,7 +6,7 @@ ;;;; algebraic way. This file contains those methods, except for ;;;; FORKED rotation expansion, which lives in ucr-explode.lisp . -(in-package #:quil) +(in-package #:cl-quil) (define-compiler undagger-rotation ((rotation-gate :where (and (member (operator-description-root-name (application-operator rotation-gate)) diff --git a/src/compilers/old-tweedledum-readme.md b/src/compilers/old-tweedledum-readme.md index b76190147..e16b68c8e 100644 --- a/src/compilers/old-tweedledum-readme.md +++ b/src/compilers/old-tweedledum-readme.md @@ -122,7 +122,7 @@ $ git submodule update --init You can then load the `cl-quil/tweedledum` package ``` CL-USER> (ql:quickload :cl-quil/tweedledum) -CL-USER> (cl-quil.tweedledum:synthesis-dbs '(0 1 3 2)) +CL-USER> (cl-quil/tweedledum:synthesis-dbs '(0 1 3 2)) "H 0 RZ(1.57079637050628662) 1 RZ(1.57079637050628662) 0 diff --git a/src/compilers/permutation.lisp b/src/compilers/permutation.lisp index 81447966f..a279ed238 100644 --- a/src/compilers/permutation.lisp +++ b/src/compilers/permutation.lisp @@ -170,7 +170,7 @@ in accordance with how Quil interprets a gate application." (defun permutation-gate-to-mcx (instr &key context) "Compile instructions representing permutation gates to n-qubit Toffoli gates." (declare (ignore context)) - (unless (slot-boundp instr 'cl-quil.frontend::name-resolution) + (unless (slot-boundp instr 'cl-quil/frontend::name-resolution) (give-up-compilation)) (let ((res (gate-application-resolution instr))) (when (typep res 'gate-definition) diff --git a/src/compilers/state-prep.lisp b/src/compilers/state-prep.lisp index a2092b88e..0af124b53 100644 --- a/src/compilers/state-prep.lisp +++ b/src/compilers/state-prep.lisp @@ -25,7 +25,7 @@ nil) (defmethod print-instruction-generic ((thing state-prep-application) (s stream)) - (format s "STATE-PREP[(~{~5$~^, ~}) -> (~{~5$~^, ~})] ~{~/quil:instruction-fmt/~^ ~}" + (format s "STATE-PREP[(~{~5$~^, ~}) -> (~{~5$~^, ~})] ~{~/cl-quil:instruction-fmt/~^ ~}" (coerce (state-prep-application-source-wf thing) 'list) (coerce (state-prep-application-target-wf thing) 'list) (application-arguments thing))) diff --git a/src/define-pragma.lisp b/src/define-pragma.lisp index 9cf90b07b..e63154d18 100644 --- a/src/define-pragma.lisp +++ b/src/define-pragma.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Zach Beane -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (defvar *pragma-definitions* (make-hash-table :test 'equal) "A table mapping a pragma Quil name to a specialized pragma class.") diff --git a/src/discrete/compilers/clifford-t.lisp b/src/discrete/compilers/clifford-t.lisp index 4cf859916..5f1205d9d 100644 --- a/src/discrete/compilers/clifford-t.lisp +++ b/src/discrete/compilers/clifford-t.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(in-package #:cl-quil.discrete) +(in-package #:cl-quil/discrete) ;;; Compilers targeting Clifford+T (i.e. H, S, T) diff --git a/src/discrete/discrete-chip.lisp b/src/discrete/discrete-chip.lisp index e973e1c0a..a3de9ec8f 100644 --- a/src/discrete/discrete-chip.lisp +++ b/src/discrete/discrete-chip.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith, A.J. Nyquist -(in-package #:cl-quil.discrete) +(in-package #:cl-quil/discrete) ;;; A "discrete gate set" is purposefully vague, since the definition ;;; may change over time. For now, though, the gate set is {H, S, T, diff --git a/src/discrete/discrete-common.lisp b/src/discrete/discrete-common.lisp index 11589d1d1..57045e9c6 100644 --- a/src/discrete/discrete-common.lisp +++ b/src/discrete/discrete-common.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(in-package #:cl-quil.discrete) +(in-package #:cl-quil/discrete) (defvar *tolerance* cl-quil.frontend::+double-comparison-threshold-loose+ "Holds the value of the TOLERANCE pragma.") diff --git a/src/discrete/numeric/circle.lisp b/src/discrete/numeric/circle.lisp index 954d76e8e..afbfcfff5 100644 --- a/src/discrete/numeric/circle.lisp +++ b/src/discrete/numeric/circle.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;;; Operations on the complex Circle group and its subgroups ;;; (e.g. roots of unity) diff --git a/src/discrete/numeric/cyclotomic8.lisp b/src/discrete/numeric/cyclotomic8.lisp index 568d2eea3..7d3715426 100644 --- a/src/discrete/numeric/cyclotomic8.lisp +++ b/src/discrete/numeric/cyclotomic8.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;;; Defines functions on the type of cyclotomic polynomials of degree 8 diff --git a/src/discrete/numeric/dyadic.lisp b/src/discrete/numeric/dyadic.lisp index 3d46577d9..6f2204738 100644 --- a/src/discrete/numeric/dyadic.lisp +++ b/src/discrete/numeric/dyadic.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;; Arbitrarily sized dyadic rationals diff --git a/src/discrete/numeric/interval.lisp b/src/discrete/numeric/interval.lisp index 496bfb6f3..e7b7e9fa2 100644 --- a/src/discrete/numeric/interval.lisp +++ b/src/discrete/numeric/interval.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;;; Interval arithmetic diff --git a/src/discrete/numeric/linear-algebra.lisp b/src/discrete/numeric/linear-algebra.lisp index 206848017..cc94f1356 100644 --- a/src/discrete/numeric/linear-algebra.lisp +++ b/src/discrete/numeric/linear-algebra.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;;; Common classes, types, and functions for (linear) algebra code (e.g. group ;;; actions, modules/vectors, matrices, (linear) transformations, eigenvalues). diff --git a/src/discrete/numeric/modulo.lisp b/src/discrete/numeric/modulo.lisp index b6496fea8..52592875f 100644 --- a/src/discrete/numeric/modulo.lisp +++ b/src/discrete/numeric/modulo.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;;; Typed modulo arithmetic where every Modulo type has a unique group order. diff --git a/src/discrete/numeric/naturals.lisp b/src/discrete/numeric/naturals.lisp index cefdddaad..a8ed7dfd3 100644 --- a/src/discrete/numeric/naturals.lisp +++ b/src/discrete/numeric/naturals.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;;; Type-level programming using Peano natural numbers diff --git a/src/discrete/numeric/root2plex.lisp b/src/discrete/numeric/root2plex.lisp index 94cda52ba..7c62e0744 100644 --- a/src/discrete/numeric/root2plex.lisp +++ b/src/discrete/numeric/root2plex.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) ;;; Defines functions on the type representing the form a + b √2 diff --git a/src/discrete/numeric/utilities.lisp b/src/discrete/numeric/utilities.lisp index a1f0d3e41..2b8ed28ed 100644 --- a/src/discrete/numeric/utilities.lisp +++ b/src/discrete/numeric/utilities.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/numeric) +(cl:in-package #:cl-quil/discrete/numeric) (coalton-toplevel diff --git a/src/discrete/operators/c2root2.lisp b/src/discrete/operators/c2root2.lisp index f6ccb921c..8515202a8 100644 --- a/src/discrete/operators/c2root2.lisp +++ b/src/discrete/operators/c2root2.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Instead of repeatedly multiplying/dividing by √2, define the asscoiated ;;; linear transformation, "compose" it repeadedly, and then apply it. diff --git a/src/discrete/operators/clifford.lisp b/src/discrete/operators/clifford.lisp index 384c4e39a..5f6204c42 100644 --- a/src/discrete/operators/clifford.lisp +++ b/src/discrete/operators/clifford.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Wrapper around Quilc's Clifford groups diff --git a/src/discrete/operators/gates1.lisp b/src/discrete/operators/gates1.lisp index 3018ff28e..82a46a3aa 100644 --- a/src/discrete/operators/gates1.lisp +++ b/src/discrete/operators/gates1.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) (coalton-toplevel diff --git a/src/discrete/operators/hadamardt.lisp b/src/discrete/operators/hadamardt.lisp index 421a5cff1..35a6f690a 100644 --- a/src/discrete/operators/hadamardt.lisp +++ b/src/discrete/operators/hadamardt.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Defines an exact synthsis algorithm and its output type diff --git a/src/discrete/operators/ma-normal-form.lisp b/src/discrete/operators/ma-normal-form.lisp index d5b647617..15e8134ec 100644 --- a/src/discrete/operators/ma-normal-form.lisp +++ b/src/discrete/operators/ma-normal-form.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Implements a canonical form for Clifford+T elements for 1 qubit diff --git a/src/discrete/operators/mat2.lisp b/src/discrete/operators/mat2.lisp index 5bb881854..41126687b 100644 --- a/src/discrete/operators/mat2.lisp +++ b/src/discrete/operators/mat2.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Defines 2x2 matrices and its operations diff --git a/src/discrete/operators/pauli.lisp b/src/discrete/operators/pauli.lisp index 057769894..f78d81331 100644 --- a/src/discrete/operators/pauli.lisp +++ b/src/discrete/operators/pauli.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Wrapper around Quilc's Pauli groups diff --git a/src/discrete/operators/rz.lisp b/src/discrete/operators/rz.lisp index 01786264d..f1d6130e1 100644 --- a/src/discrete/operators/rz.lisp +++ b/src/discrete/operators/rz.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Defines an RZ(θ) gate, mainly used for converting to Mat2 diff --git a/src/discrete/operators/sunitary2.lisp b/src/discrete/operators/sunitary2.lisp index 29be90e9f..0cb2c5f43 100644 --- a/src/discrete/operators/sunitary2.lisp +++ b/src/discrete/operators/sunitary2.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Defines SU(2) and its operations diff --git a/src/discrete/operators/unitary2.lisp b/src/discrete/operators/unitary2.lisp index a87c15d3d..195aa9a8b 100644 --- a/src/discrete/operators/unitary2.lisp +++ b/src/discrete/operators/unitary2.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) ;;; Defines U(2) and its operations diff --git a/src/discrete/operators/utilities.lisp b/src/discrete/operators/utilities.lisp index de8c5cf59..52d3e217a 100644 --- a/src/discrete/operators/utilities.lisp +++ b/src/discrete/operators/utilities.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/operators) +(cl:in-package #:cl-quil/discrete/operators) (coalton-toplevel ;; Helps conceptualize matrix multiplication in correct order diff --git a/src/discrete/package.lisp b/src/discrete/package.lisp index 948750c0d..19ec929e0 100644 --- a/src/discrete/package.lisp +++ b/src/discrete/package.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith, A.J. Nyquist -(defpackage #:cl-quil.discrete/numeric +(defpackage #:cl-quil/discrete/numeric (:documentation "Numeric systems") (:use #:coalton #:coalton-prelude @@ -125,12 +125,12 @@ #:rootunity4->integer )) -(defpackage #:cl-quil.discrete/operators +(defpackage #:cl-quil/discrete/operators (:documentation "Linear operators") (:use #:coalton #:coalton-prelude #:coalton-library/math - #:cl-quil.discrete/numeric + #:cl-quil/discrete/numeric ) ;; mat2.lisp (:export #:Mat2) @@ -159,13 +159,13 @@ ;; maform.lisp (:export #:MAForm)) -(defpackage #:cl-quil.discrete/rz-approx +(defpackage #:cl-quil/discrete/rz-approx (:documentation "Approximator for Rz gates") (:use #:coalton #:coalton-prelude #:coalton-library/math - #:cl-quil.discrete/numeric - #:cl-quil.discrete/operators + #:cl-quil/discrete/numeric + #:cl-quil/discrete/operators ) ;; generate-solution.lisp (:export @@ -174,21 +174,19 @@ ) #+sbcl (:import-from #:coalton-library/big-float #:Big-Float) (:local-nicknames - (#:operators #:cl-quil.discrete/operators))) + (#:operators #:cl-quil/discrete/operators))) -(defpackage #:cl-quil.discrete +(defpackage #:cl-quil/discrete (:use #:cl - #:cl-quil.discrete/operators - #:cl-quil.discrete/rz-approx - ) - (:import-from #:cl-quil.discrete/numeric + #:cl-quil/discrete/operators + #:cl-quil/discrete/rz-approx) + (:import-from #:cl-quil/discrete/numeric #:RootUnity8 #:Root2plex - #:Dyadic - ) + #:Dyadic) (:local-nicknames (#:q #:cl-quil) - (#:chips #:cl-quil.chip-library)) + (#:chips #:cl-quil/chip-library)) ;; discrete-chip.lisp (:export #:+discrete-gate-names+ ; CONSTANT @@ -205,6 +203,6 @@ (package-local-nicknames parent)) nil)) - (inherit-local-nicknames "CL-QUIL.DISCRETE/NUMERIC" "COALTON-USER") - (inherit-local-nicknames "CL-QUIL.DISCRETE/OPERATORS" "COALTON-USER") - (inherit-local-nicknames "CL-QUIL.DISCRETE/RZ-APPROX" "COALTON-USER")) + (inherit-local-nicknames "CL-QUIL/DISCRETE/NUMERIC" "COALTON-USER") + (inherit-local-nicknames "CL-QUIL/DISCRETE/OPERATORS" "COALTON-USER") + (inherit-local-nicknames "CL-QUIL/DISCRETE/RZ-APPROX" "COALTON-USER")) diff --git a/src/discrete/rz-approx/candidate-generation.lisp b/src/discrete/rz-approx/candidate-generation.lisp index d563df15e..063f14ffa 100644 --- a/src/discrete/rz-approx/candidate-generation.lisp +++ b/src/discrete/rz-approx/candidate-generation.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/rz-approx) +(cl:in-package #:cl-quil/discrete/rz-approx) ;;; Implements the candidate generation portion of the algirithm described in ;;; arXiv:1212.6253v2. Note that a different candidate generation technique can diff --git a/src/discrete/rz-approx/candidate-verification.lisp b/src/discrete/rz-approx/candidate-verification.lisp index c0511e91c..d41de2916 100644 --- a/src/discrete/rz-approx/candidate-verification.lisp +++ b/src/discrete/rz-approx/candidate-verification.lisp @@ -7,7 +7,7 @@ ;;; but one could alternativly implement the prime factorization method described in ;;; arXiv:1403.2975. -(cl:in-package #:cl-quil.discrete/rz-approx) +(cl:in-package #:cl-quil/discrete/rz-approx) (coalton-toplevel diff --git a/src/discrete/rz-approx/generate-solution.lisp b/src/discrete/rz-approx/generate-solution.lisp index 0977f6095..3a8529690 100644 --- a/src/discrete/rz-approx/generate-solution.lisp +++ b/src/discrete/rz-approx/generate-solution.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete/rz-approx) +(cl:in-package #:cl-quil/discrete/rz-approx) ;;; Implements an algorithm for approximating RZ(θ) into a U made up of ;;; Clifford+T such that |RZ(θ) - U| is less than or equal to some ɛ. Currently diff --git a/src/frontend-options.lisp b/src/frontend-options.lisp index 29e7d0777..952819d7b 100644 --- a/src/frontend-options.lisp +++ b/src/frontend-options.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith, Erik Davis -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; The variables below allow for general configuration of the ;;; compiler frontend. diff --git a/src/frontend-utilities.lisp b/src/frontend-utilities.lisp index 04aaddbf0..182f3d7ca 100644 --- a/src/frontend-utilities.lisp +++ b/src/frontend-utilities.lisp @@ -3,7 +3,7 @@ ;;;; Initial author: Eric Peterson ;;;; Revised by: Erik Davis -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (defgeneric copy-instance (instance) (:documentation @@ -186,8 +186,8 @@ contains the bits of INTEGER. See http://www.cliki.net/ROTATE-BYTE" ;;; Cribbed from QVM-TESTS (defmacro with-output-to-quil (&body body) "Collect all data sent to *STANDARD-OUTPUT* and return it parsed as as a Quil program." - `(let ((quil:*allow-unresolved-applications* t)) - (quil:parse-quil + `(let ((cl-quil:*allow-unresolved-applications* t)) + (cl-quil:parse-quil (with-output-to-string (*standard-output*) ,@(loop :for form :in body :if (stringp form) diff --git a/src/gates.lisp b/src/gates.lisp index b7897d627..138a8797e 100644 --- a/src/gates.lisp +++ b/src/gates.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;;;;;;;;;;;;;;;;;;;;;;;;;; Gate Protocol ;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/initialize-standard-gates.lisp b/src/initialize-standard-gates.lisp index eb9d2b386..38efd96a5 100644 --- a/src/initialize-standard-gates.lisp +++ b/src/initialize-standard-gates.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Parker Williams -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;; Some standard gates may require specialized processing that ;; prohibits them from being defined much earlier. (For example, diff --git a/src/magicl-constructors.lisp b/src/magicl-constructors.lisp index 71da6451f..0066c2002 100644 --- a/src/magicl-constructors.lisp +++ b/src/magicl-constructors.lisp @@ -4,7 +4,7 @@ ;;;; ;;;; Collaborators: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; This file aims to provide shims for magicl constructors with ;;; '(COMPLEX DOUBLE-FLOAT) as the default tensor type. diff --git a/src/matrix-operations.lisp b/src/matrix-operations.lisp index 2a855613d..88f2535ca 100644 --- a/src/matrix-operations.lisp +++ b/src/matrix-operations.lisp @@ -47,7 +47,7 @@ "The resulting matrix must have at least ~D rows, but only ~D were requested." n d) - (quil::kq-gate-on-lines + (kq-gate-on-lines mat d (loop :for i :from (1- n) :downto 0 :collect i)))) diff --git a/src/package.lisp b/src/package.lisp index 43561f5d8..1968fbf4f 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -2,15 +2,9 @@ ;;;; ;;;; Author: Robert Smith -;;; Allegro (and other Lisps) don't support the non-standard "package -;;; local nicknames". -#-(or sbcl ecl ccl) -(rename-package :alexandria :alexandria '(:a)) - -(defpackage #:cl-quil.resource +(defpackage #:cl-quil/resource (:use #:cl) - #+(or sbcl ecl ccl) - (:local-nicknames (:a :alexandria)) + (:local-nicknames (#:a #:alexandria)) (:export #:resource-collection ; TYPE #:make-resource-collection ; FUNCTION @@ -30,13 +24,12 @@ #:resource-all-p ; PREDICATE )) -(defpackage #:cl-quil.frontend +(defpackage #:cl-quil/frontend (:use #:cl #:parse-float #:abstract-classes #:singleton-classes) - #+(or sbcl ecl ccl) - (:local-nicknames (:a :alexandria)) + (:local-nicknames (#:a #:alexandria)) ;; frontend-options.lisp (:export #:*allow-unresolved-applications* ; VARIABLE @@ -729,17 +722,23 @@ ) (:shadow - #:pi) - ) + #:pi)) + +(defpackage #:cl-quil/qasm + (:use #:cl) + (:local-nicknames (#:a #:alexandria) + (#:quilfe #:cl-quil/frontend)) + (:import-from #:cl-quil/frontend #:tok #:token-type #:token-payload) + + (:export + #:parse-qasm)) (defpackage #:cl-quil - (:nicknames #:quil) (:use #:cl - #:cl-quil.resource - #:cl-quil.frontend + #:cl-quil/resource + #:cl-quil/frontend #:abstract-classes) - #+(or sbcl ecl ccl) - (:local-nicknames (:a :alexandria)) + (:local-nicknames (#:a #:alexandria)) ;; options.lisp (:export @@ -1248,16 +1247,13 @@ #:program-fidelity ; FUNCTION ) - (:shadowing-import-from #:cl-quil.frontend + (:shadowing-import-from #:cl-quil/frontend #:pi)) -(defpackage #:cl-quil.clifford - (:nicknames #:quil.clifford) +(defpackage #:cl-quil/clifford (:use #:cl #:cl-permutation) - #+(or sbcl ecl ccl) - (:local-nicknames (:a :alexandria) - (:quil :cl-quil.frontend)) + (:local-nicknames (#:a #:alexandria)) ;; clifford/ module (:export @@ -1327,21 +1323,8 @@ ) ) -(defpackage #:cl-quil.qasm - (:nicknames #:quil.qasm) - (:use #:cl) - (:local-nicknames (:a :alexandria) - (:quil :cl-quil.frontend)) - (:import-from #:cl-quil.frontend #:tok #:token-type #:token-payload) - - (:export - #:parse-qasm)) - - - - -;;;; The CL-Quil.SI Package +;;;; The CL-Quil/SI Package ;;; This package is special: it "exports" symbols internal to the ;;; CL-Quil package for "system internal" use. Note that these @@ -1353,7 +1336,7 @@ ;;; access "internal" symbols. Having such symbols cataloged here is ;;; preferable to simply accessing any symbol whatsoever via full ;;; qualification, ala the use of package name "quil" with double -;;; colons (quil::). +;;; colons (cl-quil::). (eval-when (:compile-toplevel :load-toplevel :execute) (defun pre-intern-exposed-symbols (symbols package-name) @@ -1397,7 +1380,7 @@ -(define-exposing-package #:cl-quil.si (#:cl-quil (:nicknames #:quil.si)) +(define-exposing-package #:cl-quil/si (#:cl-quil) ;; logical-schedule.lisp #:append-instructions-to-lschedule ; FUNCTION @@ -1410,5 +1393,5 @@ ;; ;; (find-symbol "PARSE-PARAMETERS" (find-package "QUIL")) ;; => CL-QUIL::PARSE-PARAMETERS, :INTERNAL -;; (find-symbol "PARSE-PARAMETERS" (find-package "QUIL.SI")) +;; (find-symbol "PARSE-PARAMETERS" (find-package "QUIL/SI")) ;; => CL-QUIL::PARSE-PARAMETERS, :EXTERNAL diff --git a/src/parser.lisp b/src/parser.lisp index 6869f941e..4bd4171ed 100644 --- a/src/parser.lisp +++ b/src/parser.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; There are three main steps on the journey from Quil string to Quil program, ;;; namely lexing, parsing, and analysis. diff --git a/src/pragmas.lisp b/src/pragmas.lisp index 57fc02ea1..a91daefbb 100644 --- a/src/pragmas.lisp +++ b/src/pragmas.lisp @@ -1,6 +1,6 @@ ;;;; pragmas.lisp -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (define-pragma "PRESERVE_BLOCK" pragma-preserve-block (:documentation "PRAGMA denoting the start of a basic-block immune to the optimizing compiler. diff --git a/src/qasm.lisp b/src/qasm/qasm.lisp similarity index 87% rename from src/qasm.lisp rename to src/qasm/qasm.lisp index 3a51b903a..27a844e73 100644 --- a/src/qasm.lisp +++ b/src/qasm/qasm.lisp @@ -1,6 +1,6 @@ ;;;; qasm.lisp -(in-package #:cl-quil.qasm) +(in-package #:cl-quil/qasm) (defvar *line-start-position*) (defvar *line-number*) @@ -61,20 +61,20 @@ (:method ((qreg qreg)) (with-slots (name index) qreg (if *gate-applications-are-formal* - (quil:formal name) + (quilfe:formal name) (destructuring-bind (offset size) (gethash name *qreg-names*) (assert (< index size) () - "The index ~s is out-of-bounds for qreg ~/quil.qasm::reg-fmt/." + "The index ~s is out-of-bounds for qreg ~/cl-quil/qasm::reg-fmt/." index qreg) - (quil:qubit (+ offset index)))))) + (quilfe:qubit (+ offset index)))))) (:method ((creg creg)) (with-slots (name index) creg (let ((size (gethash name *creg-names*))) (assert (< index size) () - "The index ~s is out-of-bounds for creg ~/quil.qasm::reg-fmt/." + "The index ~s is out-of-bounds for creg ~/cl-quil/qasm::reg-fmt/." index creg) - (quil::mref name index))))) + (quilfe::mref name index))))) (defun register-namespace (register) (etypecase register @@ -145,7 +145,7 @@ ("#pragma" (return (tok :PRAGMA))) ("pi" - (return (tok ':PI (quil:constant quil::pi)))) + (return (tok ':PI (quilfe:constant quilfe::pi)))) ((eager "\\+") (return (tok :PLUS "+"))) ((eager "\\-") (return (tok :MINUS "-"))) ((eager "\\*") (return (tok :TIMES "*"))) @@ -257,7 +257,7 @@ (parse-include tok-lines)) ((:PRAGMA) - (quil::parse-pragma tok-lines)) + (quilfe::parse-pragma tok-lines)) ((:QREG) (parse-qreg-definition tok-lines)) @@ -267,9 +267,9 @@ ((:BARRIER) ;; TODO Prettier pragma - (values (quil::make-pragma + (values (quilfe::make-pragma (list "QASM_BARRIER") - (format nil "~{~/quil::instruction-fmt/~^, ~}" + (format nil "~{~/cl-quil::instruction-fmt/~^, ~}" (let ((*gate-applications-are-formal* t)) (mapcar (lambda (qreg) (register-to-quil-object qreg)) (parse-qregisters (rest line)))))) @@ -286,7 +286,7 @@ ((:RESET) (values - (map-registers (lambda (qub) (make-instance 'quil:reset-qubit :target qub)) + (map-registers (lambda (qub) (make-instance 'quilfe:reset-qubit :target qub)) (parse-qregister (rest line))) (rest tok-lines))) @@ -341,9 +341,9 @@ (let ((name (token-payload name-tok)) (length (token-payload length-tok))) (setf (gethash name *creg-names*) length) - (values (quil::make-memory-descriptor + (values (quilfe::make-memory-descriptor :name name - :type quil::quil-bit + :type quilfe::quil-bit :length length) rest-toks))))) @@ -384,8 +384,8 @@ include-toks ;; TODO Some error checking. (let ((file (uiop:read-file-string - (if quil::*safe-include-directory* - (quil::resolve-safely (token-payload path-tok)) + (if quilfe::*safe-include-directory* + (quilfe::resolve-safely (token-payload path-tok)) (token-payload path-tok))))) (values (parse-qasm-body file) rest-toks))))) @@ -405,7 +405,7 @@ (assert (null rest-toks)) (values (map-registers (lambda (src dest) - (make-instance 'quil:measure + (make-instance 'quilfe:measure :qubit src :address dest)) qreg creg) @@ -418,7 +418,7 @@ tok-lines (destructuring-token-bind ((_ :OPENQASM) (version :REAL)) openqasm-toks - (values (quil::make-pragma (list "OPENQASM" + (values (quilfe::make-pragma (list "OPENQASM" (format nil "~A" (token-payload version)))) rest-toks)))) @@ -455,24 +455,26 @@ :then (multiple-value-list (parse-qregister rest-toks)) :for next-tok := (first rest-toks) :collect register :into registers - :if (null next-tok) :do - (return-from parse-qregisters registers) + :if (null next-tok) + :do + (return-from parse-qregisters registers) :if (and (not (null next-tok)) - (eql (token-type next-tok) ':COMMA)) :do - (setf rest-toks (rest rest-toks)))) + (eql (token-type next-tok) ':COMMA)) + :do + (setf rest-toks (rest rest-toks)))) (defun %stringify-token-payload (token) (let ((payload (token-payload token))) (cond ((and *gate-params* - (find payload *gate-params* :test #'equalp :key #'quil:param-name)) + (find payload *gate-params* :test #'equalp :key #'quilfe:param-name)) (format nil "(%~A)" payload)) ((eql (token-type token) ':LEFT-PAREN) "(") ((eql (token-type token) ':RIGHT-PAREN) ")") - ((typep payload 'quil:constant) - (let ((*read-default-float-format* (type-of (quil:constant-value payload)))) - (format nil "~F" (quil:constant-value payload)))) + ((typep payload 'quilfe:constant) + (let ((*read-default-float-format* (type-of (quilfe:constant-value payload)))) + (format nil "~F" (quilfe:constant-value payload)))) (t (format nil "~A" payload))))) @@ -483,14 +485,14 @@ (let* ((param (first tokens)) (payload (token-payload param))) (cond ((member (token-type param) '(:NNINTEGER :REAL)) - (quil:constant (coerce payload 'double-float))) + (quilfe:constant (coerce payload 'double-float))) ((eql (token-type param) ':PI) payload) ((and *gate-params* (find payload *gate-params* :test #'equalp)) (%formalize payload)) (t - (quil::param payload)))) + (quilfe::param payload)))) ;; Otherwise we have a compound expression like lambda/2, in ;; which case we need to recombine that into a single string, ;; and then pass it through cl-quil's arithmetic parsing stuff. @@ -499,11 +501,11 @@ (let* ((str (with-output-to-string (s) (dolist (tok tokens) (write-string (%stringify-token-payload tok) s)))) - (quil-tokens (first (quil::tokenize str))) - (quil::*parse-context* ':DEFCIRCUIT) - (quil::*formal-arguments-allowed* t)) - (declare (special quil::*parse-context* quil::*formal-arguments-allowed*)) - (quil::simplify-arithmetic (quil::parse-parameter-or-expression quil-tokens))))) + (quil-tokens (first (quilfe::tokenize str))) + (quilfe::*parse-context* ':DEFCIRCUIT) + (quilfe::*formal-arguments-allowed* t)) + (declare (special quilfe::*parse-context* quilfe::*formal-arguments-allowed*)) + (quilfe::simplify-arithmetic (quilfe::parse-parameter-or-expression quil-tokens))))) (defun parse-params (tokens) "Parse a list of qasm params (e.g. in the instruction rx(0.5) q;). Returns a list of parameter values (type float), and a second value which is the remaining tokens (not including closing parenthesis)." @@ -550,9 +552,9 @@ (defun build-u-gate (θ ϕ λ qubit) "As per the OpenQASM spec: U(θ, ϕ, λ) = RZ(ϕ) . RY(θ) . RZ(λ)." (list - (quil::build-gate "RZ" `(,λ) qubit) - (quil::build-gate "RY" `(,θ) qubit) - (quil::build-gate "RZ" `(,ϕ) qubit))) + (quilfe::build-gate "RZ" `(,λ) qubit) + (quilfe::build-gate "RY" `(,θ) qubit) + (quilfe::build-gate "RZ" `(,ϕ) qubit))) (defun map-registers (function register &rest more-registers) "Apply FUNCTION to successive sets of registers. @@ -617,7 +619,7 @@ Note: the above \"expansion\" is not performed when in a gate body." ((string= name "CX") (check-number-of-parameters params 0) (values (apply #'map-registers (lambda (ctl tgt) - (quil::build-gate "CNOT" nil ctl tgt)) + (quilfe::build-gate "CNOT" nil ctl tgt)) registers) rest-toks)) @@ -632,19 +634,19 @@ Note: the above \"expansion\" is not performed when in a gate body." (a:if-let ((gate (gethash (%qasm-gate-name name) *gate-names*))) (values (if (eql gate ':opaque) - (let* ((params-constant-values (mapcar #'quil:constant-value params)) + (let* ((params-constant-values (mapcar #'quilfe:constant-value params)) (*read-default-float-format* (or (and (null params) 'single-float) (type-of (car params-constant-values))))) - (quil::make-pragma (list "QASM_OPAQUE_APPLICATION" name) - (format nil "(~{~F~^, ~}) ~{~/quil:instruction-fmt/~^, ~}" - params-constant-values - (mapcar #'register-to-quil-object - registers)))) + (quilfe::make-pragma (list "QASM_OPAQUE_APPLICATION" name) + (format nil "(~{~F~^, ~}) ~{~/cl-quil:instruction-fmt/~^, ~}" + params-constant-values + (mapcar #'register-to-quil-object + registers)))) (apply #'map-registers (lambda (&rest qubits) - (make-instance 'quil:unresolved-application - :operator (quil:named-operator (%qasm-gate-name name)) - :parameters params - :arguments qubits)) + (make-instance 'quilfe:unresolved-application + :operator (quilfe:named-operator (%qasm-gate-name name)) + :parameters params + :arguments qubits)) registers)) rest-toks) (qasm-parse-error "Found unknown gate application '~A'." @@ -667,7 +669,7 @@ Note: the above \"expansion\" is not performed when in a gate body." :key (a:compose #'token-type #'first))) (defun %formalize (param) - (quil:param param)) + (quilfe:param param)) (defun parse-gate-decl (tok-lines) (check-qasm-unexpected-eof tok-lines "gate") @@ -682,10 +684,10 @@ Note: the above \"expansion\" is not performed when in a gate body." ;; TODO Store more info about the gate, for later validating an ;; application (num params, qubits, etc). (setf (gethash (%qasm-gate-name gate-name) *gate-names*) t) - (values (quil::make-circuit-definition + (values (quilfe::make-circuit-definition (%qasm-gate-name gate-name) gate-params - (mapcar #'quil::formal gate-qargs) + (mapcar #'quilfe::formal gate-qargs) (parse-gate-body (subseq tok-lines 2 close-pos)) :context nil) (subseq tok-lines (1+ close-pos)))))) @@ -703,10 +705,10 @@ Note: the above \"expansion\" is not performed when in a gate body." (let ((*gate-applications-are-formal* t) (qregs (parse-qregisters rest-toks))) (setf (gethash (%qasm-gate-name (token-payload name-tok)) *gate-names*) ':opaque) - (values (quil::make-pragma + (values (quilfe::make-pragma (list "QASM_OPAQUE_DEFINITION" (token-payload name-tok)) - (format nil "(~{~A~^, ~}) ~{~/quil:instruction-fmt/~^, ~}" - (mapcar #'quil:param-name params) + (format nil "(~{~A~^, ~}) ~{~/cl-quil:instruction-fmt/~^, ~}" + (mapcar #'quilfe:param-name params) (mapcar #'register-to-quil-object qregs))) rest-lines))))) @@ -728,11 +730,11 @@ Note: the above \"expansion\" is not performed when in a gate body." (parse-application (list rest-toks)) (assert (null rest-toks)) (let* ((cmp-name (string (gensym "CMP-"))) - (cmp-desc (quil::make-memory-descriptor + (cmp-desc (quilfe::make-memory-descriptor :name cmp-name - :type quil::quil-bit + :type quilfe::quil-bit :length 1)) - (jmp-label (quil::label (string (gensym "JMP-"))))) + (jmp-label (quilfe::label (string (gensym "JMP-"))))) (unless (< (token-payload val) (expt 2 (register-size register))) (qasm-parse-error "Cannot compare the integer ~A to the creg ~A of size ~A." @@ -762,18 +764,18 @@ Note: the above \"expansion\" is not performed when in a gate body." :collect ;; TODO Make this more efficient by using AND. See ;; https://github.com/rigetti/quilc/pull/495/files#r353990886 - (make-instance 'quil::classical-equality-bit/bit/immediate + (make-instance 'quilfe::classical-equality-bit/bit/immediate :left (register-to-quil-object reg) - :right (quil::constant + :right (quilfe::constant (if (logbitp i (token-payload val)) 1 0) - quil::quil-bit) - :target (quil::mref cmp-name 0)) + quilfe::quil-bit) + :target (quilfe::mref cmp-name 0)) :collect - (make-instance 'quil::jump-unless - :address (quil::mref cmp-name 0) + (make-instance 'quilfe::jump-unless + :address (quilfe::mref cmp-name 0) :label jmp-label)) gate-application - (make-instance 'quil::jump-target + (make-instance 'quilfe::jump-target :label jmp-label)) rest-lines))))))) @@ -799,17 +801,17 @@ Note: the above \"expansion\" is not performed when in a gate body." (*gate-params* nil) (*gate-names* (make-hash-table :test #'equalp)) (code (parse-qasm-body string))) - (setf code (quil::process-includes code)) + (setf code (quilfe::process-includes code)) ;; Return the parsed sequence of objects. (values - (quil::raw-quil-to-unresolved-program code) + (quilfe::raw-quil-to-unresolved-program code) *creg-names* *qreg-names* *qubit-count*))) (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)) - (setf pp (quil::transform 'quil::type-check pp)) - (setf pp (quil::transform 'quil::simplify-individual-instructions pp)))) + (let ((pp (quilfe::resolve-objects (parse-qasm-into-raw-program string)))) + (setf pp (quilfe::transform 'quilfe::expand-circuits pp)) + (setf pp (quilfe::transform 'quilfe::type-check pp)) + (setf pp (quilfe::transform 'quilfe::simplify-individual-instructions pp)))) diff --git a/src/queue.lisp b/src/queue.lisp index 7d7b1c49e..64a5eeebd 100644 --- a/src/queue.lisp +++ b/src/queue.lisp @@ -1,4 +1,4 @@ -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;;; Queues, taken with permission from https://bitbucket.org/tarballs_are_good/lisp-random/raw/a595eb662c2dce87f362dd0dd2541a93efe9c902/stack-queue.lisp diff --git a/src/quilec/README.org b/src/quilec/README.org index 8e6b98fa1..779b1bf6c 100644 --- a/src/quilec/README.org +++ b/src/quilec/README.org @@ -2,10 +2,10 @@ #+AUTHOR: Juan M. Bello-Rivas #+EMAIL: jbellorivas@rigetti.com -This document is an introduction to =cl-quil.quilec=, a package that provides +This document is an introduction to =cl-quil/quilec=, a package that provides support for handling stabilizer codes in Quilc. -After loading the =cl-quil.quilec= package, we can create a new stabilizer +After loading the =cl-quil/quilec= package, we can create a new stabilizer group by passing its generators in symbolic form as the arguments of =make-stabilizer-group=. Each generator must appear in its own sublist when calling =make-stabilizer-group=, as follows: @@ -44,7 +44,7 @@ As anticipated above, we encode the |1> state by executing an X gate on the zeroth qubit. #+BEGIN_SRC lisp - (qvm:load-program *qvm* (quil:parse-quil "X 0")) + (qvm:load-program *qvm* (cl-quil:parse-quil "X 0")) (qvm:run *qvm*) #+END_SRC @@ -75,7 +75,7 @@ Now let us corrupt one of the qubits, say qubit number 4 by shifting its phase and measure the syndromes again. #+BEGIN_SRC lisp - (qvm:load-program *qvm* (quil:parse-quil "Z 4")) + (qvm:load-program *qvm* (cl-quil:parse-quil "Z 4")) (qvm:run *qvm*) (qvm:load-program *qvm* *syndromes* :supersede-memory-subsystem t) diff --git a/src/quilec/cleve-gottesman.lisp b/src/quilec/cleve-gottesman.lisp index 8c1e8f7df..677aa19ec 100644 --- a/src/quilec/cleve-gottesman.lisp +++ b/src/quilec/cleve-gottesman.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Juan M. Bello-Rivas -(in-package #:cl-quil.quilec) +(in-package #:cl-quil/quilec) ;;; This file contains an implementation of the algorithm introduced in: ;;; diff --git a/src/quilec/matrix.lisp b/src/quilec/matrix.lisp index 1eb8b22eb..677e0c638 100644 --- a/src/quilec/matrix.lisp +++ b/src/quilec/matrix.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Juan M. Bello-Rivas -(in-package #:cl-quil.quilec) +(in-package #:cl-quil/quilec) ;;; Linear algebra routines in GF(2). diff --git a/src/quilec/package.lisp b/src/quilec/package.lisp index 72ec6fb67..1db9098e4 100644 --- a/src/quilec/package.lisp +++ b/src/quilec/package.lisp @@ -2,14 +2,13 @@ ;;;; ;;;; Author: Juan M. Bello-Rivas -(defpackage #:cl-quil.quilec - (:nicknames #:qec) +(defpackage #:cl-quil/quilec (:use #:common-lisp #:alexandria #:cl-quil - #:cl-quil.clifford) + #:cl-quil/clifford) (:import-from #:alexandria #:non-negative-fixnum #:if-let #:when-let) - (:import-from #:cl-quil.clifford #:pauli-components #:print-pauli) + (:import-from #:cl-quil/clifford #:pauli-components #:print-pauli) (:export #:cleve-gottesman ; FUNCTION #:codeword-circuit ; FUNCTION diff --git a/src/quilec/stabilizer-group.lisp b/src/quilec/stabilizer-group.lisp index 765e7be45..6218b0183 100644 --- a/src/quilec/stabilizer-group.lisp +++ b/src/quilec/stabilizer-group.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Juan M. Bello-Rivas -(in-package #:cl-quil.quilec) +(in-package #:cl-quil/quilec) ;;; Data structures for representing and using stabilizer groups. @@ -134,7 +134,7 @@ :reader seed-generators :documentation "Array of seed generators (i.e., logical X gates) for the code.") (codeword-circuit - :type quil:parsed-program + :type cl-quil:parsed-program :reader codeword-circuit :documentation "Circuit for encoding bitstrings using the code.")) (:documentation "Stabilizer group. The naming of primary, secondary, and seed generators follows D. Gottesman's nomenclature.")) diff --git a/src/quilt/analysis/expand-calibrations.lisp b/src/quilt/analysis/expand-calibrations.lisp index 907f390c7..9828c1bd6 100644 --- a/src/quilt/analysis/expand-calibrations.lisp +++ b/src/quilt/analysis/expand-calibrations.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) ;;; Calibration Expansion ;;; diff --git a/src/quilt/analysis/fill-delays.lisp b/src/quilt/analysis/fill-delays.lisp index b0a07e48d..1a0e5099d 100644 --- a/src/quilt/analysis/fill-delays.lisp +++ b/src/quilt/analysis/fill-delays.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) (define-transform fill-delays (fill-delays) "This transform fills empty time on Quilt frames with explicit DELAY instructions in a greedy fashion." @@ -204,7 +204,7 @@ If SYNCHRONIZE-AT-END is T, additional delays will be introduced at the end so t (flet ((process-instr (instr) (unless (typep instr 'simple-quilt-instruction) - (quil-parse-error "Cannot resolve timing information for non-Quilt instruction ~/quil:instruction-fmt/." instr)) + (quil-parse-error "Cannot resolve timing information for non-Quilt instruction ~/cl-quil:instruction-fmt/." instr)) ;; Add delays before the instruction (dolist (delay (emit-delays instr frame-clocks)) (push delay new-instrs)) diff --git a/src/quilt/analysis/resolve-objects.lisp b/src/quilt/analysis/resolve-objects.lisp index 34e02254b..70f4f8c47 100644 --- a/src/quilt/analysis/resolve-objects.lisp +++ b/src/quilt/analysis/resolve-objects.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) (defun validate-waveform-parameters (waveform-ref expected-parameters) "Determines whether the waveform reference WAVEFORM-REF has parameter names conforming to the list of EXPECTED-PARAMETERS." @@ -72,7 +72,7 @@ :key #'frame-definition-frame :test #'frame=))) (setf (frame-name-resolution frame) defn) - (quil-parse-error "No frame definition found for referenced frame ~/quil:instruction-fmt/." + (quil-parse-error "No frame definition found for referenced frame ~/cl-quil:instruction-fmt/." frame)))) frame) diff --git a/src/quilt/analysis/type-safety.lisp b/src/quilt/analysis/type-safety.lisp index 0c0840a5d..4dfbf49ea 100644 --- a/src/quilt/analysis/type-safety.lisp +++ b/src/quilt/analysis/type-safety.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) (defun raw-capture-num-real-samples (instr) (check-type instr raw-capture) @@ -22,13 +22,13 @@ (adt:match quil-type (memory-descriptor-type mdesc) (quil-real (if (> 2 (memory-segment-length mdesc :offset mref)) - (quil-type-error "CAPTURE instruction target ~/quil:instruction-fmt/ must be a REAL ~ + (quil-type-error "CAPTURE instruction target ~/cl-quil:instruction-fmt/ must be a REAL ~ vector of length no less than 2." mref) t)) (_ (quil-type-error "CAPTURE instruction target must be of type ~ - REAL, but got ~/quil:instruction-fmt/ of type ~A." + REAL, but got ~/cl-quil:instruction-fmt/ of type ~A." mref (quil-type-string (memory-descriptor-type mdesc))))))) @@ -43,14 +43,14 @@ (quil-real (a:if-let ((samples (raw-capture-num-real-samples instr))) (if (> samples (memory-segment-length mdesc :offset mref)) - (quil-type-error "RAW-CAPTURE instruction target ~/quil:instruction-fmt/ must be a REAL ~ + (quil-type-error "RAW-CAPTURE instruction target ~/cl-quil:instruction-fmt/ must be a REAL ~ vector of length no less than ~A." mref samples)) - (warn "RAW-CAPTURE on frame ~/quil:instruction-fmt/ with unknown sample rate." + (warn "RAW-CAPTURE on frame ~/cl-quil:instruction-fmt/ with unknown sample rate." (frame-definition-frame frame-defn)))) (_ (quil-type-error "RAW-CAPTURE instruction target must be of type ~ - REAL, but got ~/quil:instruction-fmt/ of type ~A." + REAL, but got ~/cl-quil:instruction-fmt/ of type ~A." mref (quil-type-string (memory-descriptor-type mdesc))))))) diff --git a/src/quilt/ast.lisp b/src/quilt/ast.lisp index dd42ed974..32ecba548 100644 --- a/src/quilt/ast.lisp +++ b/src/quilt/ast.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Objects ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -32,7 +32,7 @@ (qubit-index qubit)))))) (defmethod print-instruction-generic ((thing frame) (stream stream)) - (format stream "~{~/quil:instruction-fmt/ ~}\"~A\"" + (format stream "~{~/cl-quil:instruction-fmt/ ~}\"~A\"" (frame-qubits thing) (frame-name thing))) @@ -52,7 +52,7 @@ (declare (ignore colon-modifier at-modifier)) (let ((param (car alist-entry)) (value (cdr alist-entry))) - (format stream "~A: ~/quil:instruction-fmt/" (param-name param) value))) + (format stream "~A: ~/cl-quil:instruction-fmt/" (param-name param) value))) (defmethod print-instruction-generic ((thing waveform-ref) (stream stream)) (format stream "~A~@[(~{~/quilt::waveform-parameter-association-fmt/~^, ~})~]" @@ -120,7 +120,7 @@ (defmethod print-instruction-generic ((instr simple-frame-mutation) (stream stream)) (format stream "~A" (mnemonic instr)) (loop :for arg :across (arguments instr) - :do (format stream " ~/quil:instruction-fmt/" arg))) + :do (format stream " ~/cl-quil:instruction-fmt/" arg))) (defclass swap-phase (instruction) ((left-frame :initarg :left-frame @@ -132,7 +132,7 @@ (:documentation "An instruction representing a phase swap between two frames.")) (defmethod print-instruction-generic ((instr swap-phase) (stream stream)) - (format stream "SWAP-PHASE ~/quil:instruction-fmt/ ~/quil:instruction-fmt/" + (format stream "SWAP-PHASE ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/" (swap-phase-left-frame instr) (swap-phase-right-frame instr))) @@ -155,7 +155,7 @@ (:documentation "A pulse instruction.")) (defmethod print-instruction-generic ((instr pulse) (stream stream)) - (format stream "~:[~;NONBLOCKING ~]PULSE ~/quil:instruction-fmt/ ~/quil:instruction-fmt/" + (format stream "~:[~;NONBLOCKING ~]PULSE ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/" (nonblocking-p instr) (pulse-frame instr) (pulse-waveform instr))) @@ -181,7 +181,7 @@ (:documentation "An instruction expressing the readout and integration of raw IQ values, to be stored in a region of classical memory.")) (defmethod print-instruction-generic ((instr capture) (stream stream)) - (format stream "~:[~;NONBLOCKING ~]CAPTURE ~/quil:instruction-fmt/ ~/quil:instruction-fmt/ ~/quil:instruction-fmt/" + (format stream "~:[~;NONBLOCKING ~]CAPTURE ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/" (nonblocking-p instr) (capture-frame instr) (capture-waveform instr) @@ -208,7 +208,7 @@ (:documentation "An instruction expressing the readout of raw IQ values, to be stored in a region of classical memory.")) (defmethod print-instruction-generic ((instr raw-capture) (stream stream)) - (format stream "~:[~;NONBLOCKING ~]RAW-CAPTURE ~/quil:instruction-fmt/ ~/quil:instruction-fmt/ ~/quil:instruction-fmt/" + (format stream "~:[~;NONBLOCKING ~]RAW-CAPTURE ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/ ~/cl-quil:instruction-fmt/" (nonblocking-p instr) (raw-capture-frame instr) (raw-capture-duration instr) @@ -237,7 +237,7 @@ (assert (every (lambda (frame) (equalp qubits (frame-qubits frame))) frames)) - (format stream "DELAY~{ ~/quil:instruction-fmt/~}~{ ~S~} ~/quil:instruction-fmt/" + (format stream "DELAY~{ ~/cl-quil:instruction-fmt/~}~{ ~S~} ~/cl-quil:instruction-fmt/" qubits (mapcar #'frame-name (delay-frames instr)) (delay-duration instr)))) @@ -249,7 +249,7 @@ :documentation "A list of qubits. Any frame on these qubits will be delayed."))) (defmethod print-instruction-generic ((instr delay-on-qubits) (stream stream)) - (format stream "DELAY~{ ~/quil:instruction-fmt/~} ~/quil:instruction-fmt/" + (format stream "DELAY~{ ~/cl-quil:instruction-fmt/~} ~/cl-quil:instruction-fmt/" (delay-qubits instr) (delay-duration instr))) @@ -261,7 +261,7 @@ (:documentation "A synchronization barrier on a set of qubits, demarcating preceding and succeeding instructions.")) (defmethod print-instruction-generic ((instr fence) (stream stream)) - (format stream "FENCE~{ ~/quil:instruction-fmt/~}" + (format stream "FENCE~{ ~/cl-quil:instruction-fmt/~}" (fence-qubits instr))) (defclass fence-all (instruction) @@ -311,13 +311,13 @@ (defmethod print-instruction-generic ((defn frame-definition) (stream stream)) (with-slots (frame sample-rate initial-frequency direction hardware-object) defn - (format stream "DEFFRAME ~/quil:instruction-fmt/" frame) + (format stream "DEFFRAME ~/cl-quil:instruction-fmt/" frame) (when (or sample-rate initial-frequency direction hardware-object) (format stream ":") (when sample-rate - (format stream "~% SAMPLE-RATE: ~/quil:instruction-fmt/" sample-rate)) + (format stream "~% SAMPLE-RATE: ~/cl-quil:instruction-fmt/" sample-rate)) (when initial-frequency - (format stream "~% INITIAL-FREQUENCY: ~/quil:instruction-fmt/" initial-frequency)) + (format stream "~% INITIAL-FREQUENCY: ~/cl-quil:instruction-fmt/" initial-frequency)) (when direction (format stream "~% DIRECTION: ~S" (ecase direction @@ -376,7 +376,7 @@ :context context))) (defmethod print-instruction-generic ((defn waveform-definition) (stream stream)) - (format stream "DEFWAVEFORM ~A~@[(~{%~A~^, ~})~] ~/quil:instruction-fmt/:" + (format stream "DEFWAVEFORM ~A~@[(~{%~A~^, ~})~] ~/cl-quil:instruction-fmt/:" (waveform-definition-name defn) (if (typep defn 'static-waveform-definition) '() @@ -424,10 +424,10 @@ (format stream "DEFCAL ") (print-operator-description (calibration-definition-operator defn) stream) (unless (endp (calibration-definition-parameters defn)) - (format stream "(~{~/quil:instruction-fmt/~^, ~})" + (format stream "(~{~/cl-quil:instruction-fmt/~^, ~})" (calibration-definition-parameters defn))) (unless (endp (calibration-definition-arguments defn)) - (format stream "~{ ~/quil:instruction-fmt/~}" + (format stream "~{ ~/cl-quil:instruction-fmt/~}" (calibration-definition-arguments defn))) (format stream ":~%") (print-instruction-sequence (calibration-definition-body defn) @@ -454,7 +454,7 @@ (:documentation "A representation of a user-specifieed MEASURE (discard) calibration.")) (defmethod print-instruction-generic ((defn measurement-calibration-definition) (stream stream)) - (format stream "DEFCAL MEASURE ~/quil:instruction-fmt/~@[ ~/quil:instruction-fmt/~]:~%" + (format stream "DEFCAL MEASURE ~/cl-quil:instruction-fmt/~@[ ~/cl-quil:instruction-fmt/~]:~%" (measurement-calibration-qubit defn) (if (typep defn 'measure-calibration-definition) (measure-calibration-address defn) diff --git a/src/quilt/cl-quilt.lisp b/src/quilt/cl-quilt.lisp index 6d4a4db0e..ea3b6acce 100644 --- a/src/quilt/cl-quilt.lisp +++ b/src/quilt/cl-quilt.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) (defmethod definition-signature ((instr waveform-definition)) (cons 'waveform-definition @@ -57,7 +57,7 @@ This also signals ambiguous definitions, which may be handled as needed." (token (token-pathname (lexical-context instr))) (t - (quil-parse-error "Unable to resolve definition context ~/quil:instruction-fmt/" instr))))) + (quil-parse-error "Unable to resolve definition context ~/cl-quil:instruction-fmt/" instr))))) ;; check for conflicts (a:when-let ((entries (gethash signature all-seen-defns))) (cerror "Continue with ambiguous definition." diff --git a/src/quilt/package.lisp b/src/quilt/package.lisp index e752ea72c..8f01261c3 100644 --- a/src/quilt/package.lisp +++ b/src/quilt/package.lisp @@ -2,21 +2,15 @@ ;;;; ;;;; Author: Erik Davis -;;; Allegro (and other Lisps) don't support the non-standard "package -;;; local nicknames". -#-(or sbcl ecl ccl) -(rename-package :alexandria :alexandria '(:a)) - -(defpackage #:cl-quil.quilt - (:nicknames #:quilt) +(defpackage #:cl-quil/quilt (:use #:cl - #:cl-quil.frontend + #:cl-quil/frontend #:abstract-classes #:singleton-classes) ;; We define a number of methods on generic functions from ;; CL-QUIL. We import these here, as well as other internal symbols ;; that we want to get our hands on. - (:import-from #:cl-quil.frontend + (:import-from #:cl-quil/frontend ;; frontend-utilities.lisp #:list= ;; ast.lisp @@ -64,11 +58,10 @@ #:find-descriptor-for-mref #:memory-segment-length ) - (:shadowing-import-from #:cl-quil.frontend + (:shadowing-import-from #:cl-quil/frontend #:pi) - #+(or sbcl ecl ccl) - (:local-nicknames (:a :alexandria) - (:quil :cl-quil.frontend)) + (:local-nicknames (#:a #:alexandria) + (#:quil #:cl-quil/frontend)) (:export diff --git a/src/quilt/parser.lisp b/src/quilt/parser.lisp index e7b5a4a29..d9b93d961 100644 --- a/src/quilt/parser.lisp +++ b/src/quilt/parser.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tokenization ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/quilt/waveform.lisp b/src/quilt/waveform.lisp index bb1dd2628..9256c79da 100644 --- a/src/quilt/waveform.lisp +++ b/src/quilt/waveform.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt) +(in-package #:cl-quil/quilt) ;;; Standard Waveform Definitions ;;; @@ -47,7 +47,7 @@ Parameters: Any other entries in the plist are passed on to the slot specification of the waveform class." ;; Re: RPCQ-TYPE, note that this is the type which RPCQ expects, but is not - ;; necessarily the type that CL-QUIL.QUILT will use place in the slot (for the + ;; necessarily the type that CL-QUIL/QUILT will use place in the slot (for the ;; latter, generally one of QUIL:CONSTANT or QUIL:PARAM). We do not currently ;; make use of this information, but it is informative to readers. (check-type quilt-name string) diff --git a/src/resource.lisp b/src/resource.lisp index d563dd4f4..31b9fb2ea 100644 --- a/src/resource.lisp +++ b/src/resource.lisp @@ -3,7 +3,7 @@ ;;;; Authors: Corwin de Boor ;;;; Erik Davis -(in-package #:cl-quil.resource) +(in-package #:cl-quil/resource) ;;; Bit Sets diff --git a/src/tools/README.md b/src/tools/README.md index 9a15b80b0..b1b0af8e6 100644 --- a/src/tools/README.md +++ b/src/tools/README.md @@ -1,4 +1,4 @@ -# CL-Quil.Tools +# CL-QUIL/TOOLS Tools for cl-quil developers. @@ -48,13 +48,13 @@ brew install mactex brew install pdf2svg ``` -These executables are referred to in `cl-quil.tools` by `*pdflatex-exe*` and `*pdf2svg-exe`, should you wish to override them. +These executables are referred to in `cl-quil/tools` by `*pdflatex-exe*` and `*pdf2svg-exe`, should you wish to override them. To use this in a Jupyter notebook, you should use [common-lisp-jupyter](https://github.com/yitzchak/common-lisp-jupyter). As an installation note, some users have found that on macOS the default SBCL path associated with the jupyter kernel (e.g. in `~/Library/Jupyter/kernels/common-lisp/kernel.json`) is incorrect; this will result in `jupyter` being unable to start the Common Lisp kernel. #### `:slime-png` -You need `pdflatex` (cf. above) and `convert` (from ImageMagick) in your path. These executables are referred to in `cl-quil.tools` by `*pdflatex-exe*` and `*convert-exe*`, should you wish to override them. +You need `pdflatex` (cf. above) and `convert` (from ImageMagick) in your path. These executables are referred to in `cl-quil/tools` by `*pdflatex-exe*` and `*convert-exe*`, should you wish to override them. The Slime interaction requires two SLIME contribs: `slime-media` and `slime-repl` (which is included in `slime-fancy`). In addition, you must enable SLIME evaluation in Emacs. This all can be done, for example, by the following (from `config.el`): @@ -96,7 +96,7 @@ dot -Tpng example-1.gv -o g.png The resulting image file can then be shown in various software, such as image viewers, PDF viewers, and web browsers. Here is an example of using this tool: -In Lisp, if necessary, evaluate the following to load cl-quil.tools: +In Lisp, if necessary, evaluate the following to load cl-quil/tools: ``` (asdf:load-system :cl-quil/tools) ``` diff --git a/src/tools/circuit-diagram.lisp b/src/tools/circuit-diagram.lisp index 45be60695..bc740b8db 100644 --- a/src/tools/circuit-diagram.lisp +++ b/src/tools/circuit-diagram.lisp @@ -2,7 +2,7 @@ ;;; ;;; Author: Erik Davis -(in-package #:cl-quil.tools) +(in-package #:cl-quil/tools) ;;; This file contains routines to render a subset of Quil programs as ;;; quantikz circuits (cf. https://ctan.org/pkg/quantikz). @@ -85,9 +85,9 @@ For example, if T, the diagram for `CNOT 0 2` would have three qubit lines: 0, 1 (defun tikz-gate (name &key (size 1) params dagger) ;; TeXify names - (let* ((cl-quil.frontend::*pi-literal* "\\pi") + (let* ((cl-quil/frontend::*pi-literal* "\\pi") (texified-name - (format nil "~A~:[~;^{\\dagger}~]~@[(~{~/quil:instruction-fmt/~^, ~})~]" + (format nil "~A~:[~;^{\\dagger}~]~@[(~{~/cl-quil:instruction-fmt/~^, ~})~]" (cond ((string= "RX" name) "R_x") ((string= "RY" name) "R_y") @@ -246,23 +246,23 @@ The convention is that the source operation takes two arguments: the qubit index (:method (diagram instr) (error "Unable to update diagram with instruction ~A" instr)) - (:method (diagram (instr quil:measurement)) + (:method (diagram (instr cl-quil:measurement)) (append-to-diagram diagram - (quil:qubit-index (quil:measurement-qubit instr)) + (cl-quil:qubit-index (cl-quil:measurement-qubit instr)) (tikz-measure))) - (:method (diagram (instr quil:pragma)) + (:method (diagram (instr cl-quil:pragma)) nil) - (:method (diagram (instr quil:reset)) + (:method (diagram (instr cl-quil:reset)) nil) - (:method (diagram (instr quil:gate-application)) - (let ((qubits (mapcar #'quil:qubit-index - (quil:application-arguments instr)))) + (:method (diagram (instr cl-quil:gate-application)) + (let ((qubits (mapcar #'cl-quil:qubit-index + (cl-quil:application-arguments instr)))) ;; special case: 2Q operator with special SOURCE-TARGET structure - (adt:match quil:operator-description (quil:application-operator instr) - ((quil:named-operator name) + (adt:match cl-quil:operator-description (cl-quil:application-operator instr) + ((cl-quil:named-operator name) (when (gethash name custom-source-target-ops) (destructuring-bind (source target) qubits (append-custom-source-target-gate diagram name source target)) @@ -274,19 +274,19 @@ The convention is that the source operation takes two arguments: the qubit index (let ((dagger nil) (num-controls 0)) (labels ((destruct-application (od) - (adt:match quil:operator-description od - ((quil:named-operator name) + (adt:match cl-quil:operator-description od + ((cl-quil:named-operator name) name) - ((quil:dagger-operator inner-od) + ((cl-quil:dagger-operator inner-od) (setf dagger (not dagger)) (destruct-application inner-od)) - ((quil:controlled-operator inner-od) + ((cl-quil:controlled-operator inner-od) (incf num-controls) (destruct-application inner-od)) - ((quil:forked-operator _) + ((cl-quil:forked-operator _) (error "LaTeX output does not currently support FORKED modifiers: ~A" instr))))) (let ((name - (destruct-application (quil:application-operator instr)))) + (destruct-application (cl-quil:application-operator instr)))) (let ((control-qubits (subseq qubits 0 num-controls)) (target-qubits (subseq qubits num-controls))) (when (not (adjacent-lines-p diagram target-qubits)) @@ -303,7 +303,7 @@ The convention is that the source operation takes two arguments: the qubit index actual-target (tikz-gate name :size (length target-qubits) - :params (quil:application-parameters instr) + :params (cl-quil:application-parameters instr) :dagger dagger)) ;; and then NOP on the rest (loop :for q :in target-qubits @@ -322,12 +322,12 @@ The convention is that the source operation takes two arguments: the qubit index (delete-duplicates (mapcan (lambda (instr) (typecase instr - (quil::application - (mapcar #'quil:qubit-index - (quil:application-arguments instr))) - (quil::measurement - (list (quil:qubit-index - (quil:measurement-qubit instr)))))) + (cl-quil::application + (mapcar #'cl-quil:qubit-index + (cl-quil:application-arguments instr))) + (cl-quil::measurement + (list (cl-quil:qubit-index + (cl-quil:measurement-qubit instr)))))) instrs))) @@ -339,18 +339,18 @@ The convention is that the source operation takes two arguments: the qubit index (setf (gethash q adjacency-list) nil)))) (loop :for instr :in instructions :do (typecase instr - (quil:application - (cond ((= 1 (length (quil:application-arguments instr))) - (ensure-present (quil:qubit-index (first (quil:application-arguments instr))))) + (cl-quil:application + (cond ((= 1 (length (cl-quil:application-arguments instr))) + (ensure-present (cl-quil:qubit-index (first (cl-quil:application-arguments instr))))) (t - (loop :for q1 :in (quil:application-arguments instr) - :for i1 := (quil:qubit-index q1) - :do (loop :for q2 :in (quil:application-arguments instr) - :for i2 := (quil:qubit-index q2) + (loop :for q1 :in (cl-quil:application-arguments instr) + :for i1 := (cl-quil:qubit-index q1) + :do (loop :for q2 :in (cl-quil:application-arguments instr) + :for i2 := (cl-quil:qubit-index q2) :unless (= i1 i2) :do (pushnew i1 (gethash i2 adjacency-list))))))) - (quil:measurement - (let ((q (quil:qubit-index (quil:measurement-qubit instr)))) + (cl-quil:measurement + (let ((q (cl-quil:qubit-index (cl-quil:measurement-qubit instr)))) (when (null (nth-value 1 (gethash q adjacency-list))) (setf (gethash q adjacency-list) nil))))) :finally (return adjacency-list))))) @@ -427,7 +427,7 @@ The convention is that the source operation takes two arguments: the qubit index (when *right-align-measurements* (loop :with seen-measure := nil :for instr :in instructions - :if (typep instr 'quil:measurement) + :if (typep instr 'cl-quil:measurement) :do (setf seen-measure t) :and :collect instr :into measurements :else @@ -488,7 +488,7 @@ The convention is that the source operation takes two arguments: the qubit index (defun print-parsed-program-as-quantikz (pp &optional (stream *standard-output*)) (let ((diagram - (build-diagram (quil:parsed-program-executable-code pp)))) + (build-diagram (cl-quil:parsed-program-executable-code pp)))) (print-quantikz-header stream) (print-quantikz-diagram diagram stream) (print-quantikz-footer stream))) diff --git a/src/tools/hasse-schedule.lisp b/src/tools/hasse-schedule.lisp index f1acbc07b..c2640fa23 100644 --- a/src/tools/hasse-schedule.lisp +++ b/src/tools/hasse-schedule.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Mark David -(in-package #:cl-quil.tools) +(in-package #:cl-quil/tools) ;;; This file implements utilities for creating a Hasse Diagram for a ;;; logical-scheduler instance. The resulting diagram indicates the @@ -89,13 +89,13 @@ (defun format-hasse-instr-label (format-dest instr counter) (format format-dest (if *show-instr-instance-counters* - "~/quil::instruction-fmt/ [~d]" - "~/quil::instruction-fmt/") + "~/cl-quil::instruction-fmt/ [~d]" + "~/cl-quil::instruction-fmt/") instr counter)) (defun format-hasse-instr-name (format-dest instr counter) (format format-dest - "~/quil::instruction-fmt/ [~d]" + "~/cl-quil::instruction-fmt/ [~d]" instr counter)) (defun hasse-instr-visited-p (instr) @@ -156,12 +156,12 @@ (defun quil-text-to-logical-scheduler (source-text) "Make a logical scheduler corresponding to SOURCE-TEXT." - (quil-parse-to-logical-scheduler (quil:parse-quil source-text))) + (quil-parse-to-logical-scheduler (cl-quil:parse-quil source-text))) (defun quil-parse-to-logical-scheduler (parse) "Make a logical scheduler corresponding to PARSE." - (let* ((instructions-vector (quil:parsed-program-executable-code parse)) + (let* ((instructions-vector (cl-quil:parsed-program-executable-code parse)) (instructions-list (concatenate 'list instructions-vector)) (lsched (quil.si:make-lscheduler))) (quil.si:append-instructions-to-lschedule lsched instructions-list) @@ -173,7 +173,7 @@ (defun program-to-string (program) "Return a string representation of PROGRAM. -PROGRAM should be either a parsed program (i.e., a quil:parsed-program +PROGRAM should be either a parsed program (i.e., a cl-quil:parsed-program instance), a string, or a list of strings. If a string, it is assumed to have its own internal line breaks, and it is returned as is. If a list of strings, each string is assumed to represent a line, and this @@ -186,9 +186,9 @@ quil:print-parsed-program, to a string that is returned." (with-output-to-string (out) (loop :for line :in program :do (write-line line out)))) - (quil:parsed-program + (cl-quil:parsed-program (with-output-to-string (out) - (quil:print-parsed-program program out))))) + (cl-quil:print-parsed-program program out))))) (defun write-program-to-graphviz-comment (program &key stream comment-line-start) @@ -286,7 +286,7 @@ default/expected type for a Graphviz DOT file is: gv In the case of writing to a file, this returns the true name of the resulting file a string. Otherwise, this returns nil." (let* ((program-string (program-to-string program)) - (parse (quil:parse program-string)) + (parse (cl-quil:parse program-string)) (logical-scheduler (quil-parse-to-logical-scheduler parse))) (write-hasse-for-logical-scheduler logical-scheduler diff --git a/src/tools/package.lisp b/src/tools/package.lisp index bfb048db5..31c3646ef 100644 --- a/src/tools/package.lisp +++ b/src/tools/package.lisp @@ -3,15 +3,8 @@ ;;;; Authors: Mark David ;;; Erik Davis -;;; Allegro (and other Lisps) don't support the non-standard "package -;;; local nicknames". -#-(or sbcl ecl ccl) -(rename-package :alexandria :alexandria '(:a)) - -(defpackage #:cl-quil.tools - (:nicknames #:tools) +(defpackage #:cl-quil/tools (:use #:cl) - #+(or sbcl ecl ccl) (:local-nicknames (:a :alexandria)) ;; hasse-schedule.lisp diff --git a/src/transformable-mixin.lisp b/src/transformable-mixin.lisp index e64bffd70..b733cc41f 100644 --- a/src/transformable-mixin.lisp +++ b/src/transformable-mixin.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; This file doesn't itself have any transforms in it, but rather ;;; manages the documentation and recording of transforms that have diff --git a/src/types.lisp b/src/types.lisp index a3b112a44..137ac33cf 100644 --- a/src/types.lisp +++ b/src/types.lisp @@ -6,7 +6,7 @@ ;;;; do not belong here and should live in the file or package where they are most used, ;;;; e.g. OPTIMAL-2Q-TARGET-ATOM in compilers/approx.lisp. -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) (eval-when (:compile-toplevel :load-toplevel :execute) (macrolet diff --git a/src/with-inst.lisp b/src/with-inst.lisp index 47537d9b7..5c50abcba 100644 --- a/src/with-inst.lisp +++ b/src/with-inst.lisp @@ -6,7 +6,7 @@ ;;;; Quil instructions. Originally this was written to support ;;;; DEFINE-COMPILER, but is useful more generally. -(in-package #:cl-quil.frontend) +(in-package #:cl-quil/frontend) ;;; Within the dynamic extent of a DEFINE-COMPILER, we publish ;;; instructions to output using a DEFINE-VOP-like INST macro, and we diff --git a/tests/addresser-tests.lisp b/tests/addresser-tests.lisp index 971693e7f..e2a3b532f 100644 --- a/tests/addresser-tests.lisp +++ b/tests/addresser-tests.lisp @@ -5,100 +5,100 @@ (in-package #:cl-quil-tests) (deftest test-rewiring-shuffle () - (dolist (quil::*addresser-gates-swap-search-type* '(:a* :greedy-qubit :greedy-path)) + (dolist (cl-quil::*addresser-gates-swap-search-type* '(:a* :greedy-qubit :greedy-path)) (not-signals error (let ((text "CNOT 2 0")) - (is (quil::operator= - (quil:parsed-program-to-logical-matrix - (quil::parse-quil text)) - (quil:parsed-program-to-logical-matrix - (quil::compiler-hook (quil::parse-quil text) (quil::build-8q-chip) + (is (cl-quil::operator= + (cl-quil:parsed-program-to-logical-matrix + (cl-quil::parse-quil text)) + (cl-quil:parsed-program-to-logical-matrix + (cl-quil::compiler-hook (cl-quil::parse-quil text) (cl-quil::build-8q-chip) :protoquil nil :rewiring-type ':naive)))))))) (deftest test-addresser-subclasses () - (let* ((chip (quil::build-8q-chip)) + (let* ((chip (cl-quil::build-8q-chip)) (text "CNOT 0 1 ; CNOT 0 2 ; CNOT 1 2") - (orig-mat (quil:parsed-program-to-logical-matrix (quil::parse-quil text)))) - (dolist (quil::*default-addresser-state-class* - (list 'quil::temporal-addresser-state - 'quil::fidelity-addresser-state)) - (dolist (quil::*addresser-use-1q-queues* (list t nil)) - (let* ((pp (quil::parse-quil text)) - (cpp (quil::compiler-hook pp chip :protoquil t))) - (is (quil::operator= orig-mat (quil:parsed-program-to-logical-matrix cpp)))))))) + (orig-mat (cl-quil:parsed-program-to-logical-matrix (cl-quil::parse-quil text)))) + (dolist (cl-quil::*default-addresser-state-class* + (list 'cl-quil::temporal-addresser-state + 'cl-quil::fidelity-addresser-state)) + (dolist (cl-quil::*addresser-use-1q-queues* (list t nil)) + (let* ((pp (cl-quil::parse-quil text)) + (cpp (cl-quil::compiler-hook pp chip :protoquil t))) + (is (cl-quil::operator= orig-mat (cl-quil:parsed-program-to-logical-matrix cpp)))))))) (deftest test-fidelity-addresser-subschedule () (flet ((gate= (gate-1 gate-2) - (and (string= (quil::application-operator-root-name gate-1) - (quil::application-operator-root-name gate-2)) - (equalp (quil::application-parameters gate-1) - (quil::application-parameters gate-2)) - (equalp (quil::application-arguments gate-1) - (quil::application-arguments gate-2))))) + (and (string= (cl-quil::application-operator-root-name gate-1) + (cl-quil::application-operator-root-name gate-2)) + (equalp (cl-quil::application-parameters gate-1) + (cl-quil::application-parameters gate-2)) + (equalp (cl-quil::application-arguments gate-1) + (cl-quil::application-arguments gate-2))))) - (let* ((chip (quil::build-nq-fully-connected-chip 3))) + (let* ((chip (cl-quil::build-nq-fully-connected-chip 3))) (let* ((progm (parse "H 0; CNOT 2 0; H 1; CNOT 0 1; X 0")) - (sched (quil::make-chip-schedule chip)) + (sched (cl-quil::make-chip-schedule chip)) (expected-subschedule (list (build-gate "X" nil 0)))) (loop :for instr :across (parsed-program-executable-code progm) :do - (quil::chip-schedule-append sched instr)) + (cl-quil::chip-schedule-append sched instr)) (is (every #'gate= - (quil::chip-contiguous-subschedule-from-last-instructions - sched (quil::make-qubit-resource 0)) + (cl-quil::chip-contiguous-subschedule-from-last-instructions + sched (cl-quil::make-qubit-resource 0)) expected-subschedule)))) - (let* ((chip (quil::build-nq-fully-connected-chip 3))) + (let* ((chip (cl-quil::build-nq-fully-connected-chip 3))) (let* ((progm (parse "H 0; CNOT 2 0; H 1; CNOT 0 1; X 0")) - (sched (quil::make-chip-schedule chip)) + (sched (cl-quil::make-chip-schedule chip)) (expected-subschedule (list))) (loop :for instr :across (parsed-program-executable-code progm) :do - (quil::chip-schedule-append sched instr)) + (cl-quil::chip-schedule-append sched instr)) (is (every #'gate= - (quil::chip-contiguous-subschedule-from-last-instructions - sched (quil::make-qubit-resource 1)) + (cl-quil::chip-contiguous-subschedule-from-last-instructions + sched (cl-quil::make-qubit-resource 1)) expected-subschedule)))) - (let* ((chip (quil::build-nq-fully-connected-chip 3))) + (let* ((chip (cl-quil::build-nq-fully-connected-chip 3))) (let* ((progm (parse "H 0; CNOT 2 0; H 1; CNOT 0 1; X 0")) - (sched (quil::make-chip-schedule chip)) + (sched (cl-quil::make-chip-schedule chip)) (expected-subschedule (list (build-gate "H" nil 1) (build-gate "CNOT" nil 0 1) (build-gate "X" nil 0)))) (loop :for instr :across (parsed-program-executable-code progm) :do - (quil::chip-schedule-append sched instr)) + (cl-quil::chip-schedule-append sched instr)) (is (every #'gate= - (quil::chip-contiguous-subschedule-from-last-instructions - sched (quil::make-qubit-resource 0 1)) + (cl-quil::chip-contiguous-subschedule-from-last-instructions + sched (cl-quil::make-qubit-resource 0 1)) expected-subschedule)))) - (let* ((chip (quil::build-nq-fully-connected-chip 3))) + (let* ((chip (cl-quil::build-nq-fully-connected-chip 3))) (let* ((progm (parse "H 0; H 1; CNOT 2 0; H 1; CNOT 0 1; X 0")) - (sched (quil::make-chip-schedule chip)) + (sched (cl-quil::make-chip-schedule chip)) (expected-subschedule (list (build-gate "H" nil 1) (build-gate "H" nil 1) (build-gate "CNOT" nil 0 1) (build-gate "X" nil 0)))) (loop :for instr :across (parsed-program-executable-code progm) :do - (quil::chip-schedule-append sched instr)) + (cl-quil::chip-schedule-append sched instr)) (is (every #'gate= - (quil::chip-contiguous-subschedule-from-last-instructions - sched (quil::make-qubit-resource 0 1)) + (cl-quil::chip-contiguous-subschedule-from-last-instructions + sched (cl-quil::make-qubit-resource 0 1)) expected-subschedule)))) - (let* ((chip (quil::build-nq-linear-chip 3))) + (let* ((chip (cl-quil::build-nq-linear-chip 3))) (let* ((progm (parse "H 0; H 1; CNOT 2 0; H 1; CNOT 0 1; X 0")) - (sched (quil::make-chip-schedule chip)) + (sched (cl-quil::make-chip-schedule chip)) (expected-subschedule (list (build-gate "X" nil 0)))) (loop :for instr :across (parsed-program-executable-code progm) :do - (quil::chip-schedule-append sched instr)) + (cl-quil::chip-schedule-append sched instr)) (is (every #'gate= - (quil::chip-contiguous-subschedule-from-last-instructions - sched (quil::make-qubit-resource 0 2)) + (cl-quil::chip-contiguous-subschedule-from-last-instructions + sched (cl-quil::make-qubit-resource 0 2)) expected-subschedule)))))) ;;; Check that we can compile "parallel" programs onto disconnected @@ -112,8 +112,8 @@ MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2]")) (not-signals error - (quil:compiler-hook (quil:parse-quil program) - (quil::build-disconnected-chip 3))))) + (cl-quil:compiler-hook (cl-quil:parse-quil program) + (cl-quil::build-disconnected-chip 3))))) ;;; Check that the naive assignment works correctly. (deftest test-addresser-multiple-components-naive () @@ -125,8 +125,8 @@ MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2]")) (not-signals error - (quil:compiler-hook (quil:parse-quil program) - (quil::build-disconnected-chip 3) + (cl-quil:compiler-hook (cl-quil:parse-quil program) + (cl-quil::build-disconnected-chip 3) :rewiring-type :naive)))) ;;; Check that greedy assignments work as well. @@ -139,8 +139,8 @@ MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2]")) (not-signals error - (quil:compiler-hook (quil:parse-quil program) - (quil::build-disconnected-chip 3) + (cl-quil:compiler-hook (cl-quil:parse-quil program) + (cl-quil::build-disconnected-chip 3) :rewiring-type :greedy)))) ;; Check that we can give a random rewiring type and the compiler will satisfy the component constraints. @@ -153,8 +153,8 @@ MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2]")) (not-signals error - (quil:compiler-hook (quil:parse-quil program) - (quil::build-disconnected-chip 3) + (cl-quil:compiler-hook (cl-quil:parse-quil program) + (cl-quil::build-disconnected-chip 3) :rewiring-type :random)))) ;;; Check that we can compile a more complicated program on a more @@ -168,8 +168,8 @@ MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2]")) (not-signals error - (quil:compiler-hook (quil:parse-quil program) - (quil::build-chip-from-digraph '((1 2))))))) + (cl-quil:compiler-hook (cl-quil:parse-quil program) + (cl-quil::build-chip-from-digraph '((1 2))))))) ;;; Check that we signal the right condition when the naive rewiring ;;; crosses chip component boundaries. @@ -180,9 +180,9 @@ RX(pi/2) 2 MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2]")) - (signals quil::naive-rewiring-crosses-chip-boundaries - (quil:compiler-hook (quil:parse-quil program) - (quil::build-disconnected-chip 3) + (signals cl-quil::naive-rewiring-crosses-chip-boundaries + (cl-quil:compiler-hook (cl-quil:parse-quil program) + (cl-quil::build-disconnected-chip 3) :rewiring-type :naive)))) ;;; Check that we signal the right condition when there aren't enough qubits on the chip. @@ -194,6 +194,6 @@ RX(pi/2) 2 MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2]")) - (signals quil::chip-insufficient-qubits - (quil:compiler-hook (quil:parse-quil program) - (quil::build-disconnected-chip 2))))) + (signals cl-quil::chip-insufficient-qubits + (cl-quil:compiler-hook (cl-quil:parse-quil program) + (cl-quil::build-disconnected-chip 2))))) diff --git a/tests/analysis-tests.lisp b/tests/analysis-tests.lisp index 930e59d3d..480957a8d 100644 --- a/tests/analysis-tests.lisp +++ b/tests/analysis-tests.lisp @@ -31,24 +31,24 @@ DEFGATE I: (p2 (with-output-to-quil (write-line "RESET") (write-line "NOP")))) - (is (= 7 (quil::qubits-needed p1))) - (is (= 0 (quil::qubits-needed p2))) + (is (= 7 (cl-quil::qubits-needed p1))) + (is (= 0 (cl-quil::qubits-needed p2))) (is (same-list-p '(0 1 6) - (quil::qubits-used p1))) - (is (null (quil::qubits-used p2))) + (cl-quil::qubits-used p1))) + (is (null (cl-quil::qubits-used p2))) - (quil::transform 'quil::compress-qubits p1) - (quil::transform 'quil::compress-qubits p2) + (cl-quil::transform 'cl-quil::compress-qubits p1) + (cl-quil::transform 'cl-quil::compress-qubits p2) - (is (= 3 (quil::qubits-needed p1))) - (is (= 0 (quil::qubits-needed p2))) + (is (= 3 (cl-quil::qubits-needed p1))) + (is (= 0 (cl-quil::qubits-needed p2))) (is (same-list-p '(0 1 2) - (quil::qubits-used p1))) - (is (null (quil::qubits-used p2))))) + (cl-quil::qubits-used p1))) + (is (null (cl-quil::qubits-used p2))))) (deftest test-repeat-labels () "Test that repeat labels are detected." @@ -56,7 +56,7 @@ DEFGATE I: "LABEL @a" "LABEL @a"))) (signals simple-error - (quil::transform 'quil::patch-labels pp)))) + (cl-quil::transform 'cl-quil::patch-labels pp)))) (defun identity-test-program (quil-instr) (with-output-to-string (s) @@ -108,25 +108,25 @@ DEFGATE I: "ISWAP 0 1" "PSWAP(0.0) 0 1"))) (is (every (lambda (isn) - (typep isn 'quil:gate-application)) - (quil:parsed-program-executable-code quil))))) + (typep isn 'cl-quil:gate-application)) + (cl-quil:parsed-program-executable-code quil))))) (deftest test-qubit-relabeler () "Test that qubit relabeling seems to be sane." - (let ((r1 (cl-quil.frontend::qubit-relabeler #(0 1 2))) - (r2 (cl-quil.frontend::qubit-relabeler #(2 1 0))) - (r3 (cl-quil.frontend::qubit-relabeler #(5))) - (r4 (cl-quil.frontend::qubit-relabeler #()))) + (let ((r1 (cl-quil/frontend::qubit-relabeler #(0 1 2))) + (r2 (cl-quil/frontend::qubit-relabeler #(2 1 0))) + (r3 (cl-quil/frontend::qubit-relabeler #(5))) + (r4 (cl-quil/frontend::qubit-relabeler #()))) (flet ((test-success (relabeler qubit-input qubit-output) - (let ((q (quil:qubit qubit-input))) + (let ((q (cl-quil:qubit qubit-input))) (is (eq t (funcall relabeler q))) - (is (= qubit-output (quil:qubit-index q))))) + (is (= qubit-output (cl-quil:qubit-index q))))) (test-choke (relabeler bad-input) - (signals simple-error (funcall relabeler (quil:qubit bad-input)))) + (signals simple-error (funcall relabeler (cl-quil:qubit bad-input)))) (test-dont-choke (relabeler bad-input) - (let ((q (quil:qubit bad-input))) + (let ((q (cl-quil:qubit bad-input))) (is (eq nil (funcall relabeler q :dont-choke t))) - (is (= bad-input (quil:qubit-index q)))))) + (is (= bad-input (cl-quil:qubit-index q)))))) ;; Identity map (test-success r1 0 0) (test-success r1 1 1) @@ -149,7 +149,7 @@ DEFGATE I: (deftest test-kraus-stuff-rewritten-properly () "Test that COMPRESS-QUBITS acts correctly on Kraus/POVM PRAGMAs." - (let ((p (quil:parse-quil " + (let ((p (cl-quil:parse-quil " DECLARE ro BIT[6] PRAGMA ADD-KRAUS X 0 \"(0 0 0 0)\" PRAGMA ADD-KRAUS X 5 \"(5 0 0 0)\" @@ -158,19 +158,19 @@ PRAGMA READOUT-POVM 5 \"(5 0 0 0)\" X 5 MEASURE 5 ro[5] "))) - (setf p (quil::compress-qubits p)) - (let ((code (quil:parsed-program-executable-code p))) - (is (typep (aref code 0) 'quil:no-operation)) - (is (typep (aref code 1) 'quil::pragma-add-kraus)) - (is (typep (aref code 2) 'quil:no-operation)) - (is (typep (aref code 3) 'quil::pragma-readout-povm)) - (is (equal '(0) (quil:pragma-qubit-arguments (aref code 1)))) - (is (zerop (quil:pragma-qubit-index (aref code 3))))))) + (setf p (cl-quil::compress-qubits p)) + (let ((code (cl-quil:parsed-program-executable-code p))) + (is (typep (aref code 0) 'cl-quil:no-operation)) + (is (typep (aref code 1) 'cl-quil::pragma-add-kraus)) + (is (typep (aref code 2) 'cl-quil:no-operation)) + (is (typep (aref code 3) 'cl-quil::pragma-readout-povm)) + (is (equal '(0) (cl-quil:pragma-qubit-arguments (aref code 1)))) + (is (zerop (cl-quil:pragma-qubit-index (aref code 3))))))) (deftest test-parameter-arithmetic-rewriting () "Test rewriting arithmetic for gates with and without parameters." - (let ((in-p (let ((quil:*allow-unresolved-applications* t)) - (quil:parse-quil " + (let ((in-p (let ((cl-quil:*allow-unresolved-applications* t)) + (cl-quil:parse-quil " DECLARE a REAL DECLARE b REAL[2] A(1, 1 + 1, a, 1 + a) @@ -182,12 +182,12 @@ E(a + 3 * b[1]) 0 1 2 3 (multiple-value-bind (p mem-descriptors recalc-table) (rewrite-arithmetic in-p) (let ((__p (find-if (lambda (name) (eql 0 (search "__P" name))) - (quil:parsed-program-memory-definitions p) - :key #'quil::memory-descriptor-name))) + (cl-quil:parsed-program-memory-definitions p) + :key #'cl-quil::memory-descriptor-name))) ;; Do we have the memory descriptor? (is (not (null __p))) ;; Is it the right length? - (is (= 3 (quil::memory-descriptor-length __p))) + (is (= 3 (cl-quil::memory-descriptor-length __p))) ;; Is the recalc table of equal size? (is (= 3 (hash-table-count recalc-table))) ;; Are the members of the table correct? @@ -199,8 +199,8 @@ E(a + 3 * b[1]) 0 1 2 3 ;; delete the descriptors from any mrefs present in ;; expr (cond - ((typep expr 'quil::memory-ref) - (setf (quil::memory-ref-descriptor expr) nil) + ((typep expr 'cl-quil::memory-ref) + (setf (cl-quil::memory-ref-descriptor expr) nil) expr) ((atom expr) expr) @@ -208,7 +208,7 @@ E(a + 3 * b[1]) 0 1 2 3 (cleanse-mrefs (cdr expr)))))) (get-mref (i) (cleanse-mrefs - (quil::delayed-expression-expression + (cl-quil::delayed-expression-expression (gethash (mref __p-name i) recalc-table))))) (let ((A (get-mref 0)) (D (get-mref 1)) @@ -220,8 +220,8 @@ E(a + 3 * b[1]) 0 1 2 3 ;; E should be a[0] + 3 * b[1] (is (equalp E `(+ ,(mref "a" 0) (* 3.0d0 ,(mref "b" 1)))))))) ;; Now we go through the program to make sure that is correct. - (let ((old-code (quil:parsed-program-executable-code in-p)) - (new-code (quil:parsed-program-executable-code p))) + (let ((old-code (cl-quil:parsed-program-executable-code in-p)) + (new-code (cl-quil:parsed-program-executable-code p))) ;; Is it the same length as the old one? (is (= (length old-code) (length new-code))) ;; Are the untouched instructions' parameters the same? @@ -234,23 +234,23 @@ E(a + 3 * b[1]) 0 1 2 3 (let ((rewritten-param (nth parameter-index (application-parameters (aref new-code program-index))))) - (is (typep rewritten-param 'quil::delayed-expression)) - (let ((new-mref (quil::delayed-expression-expression rewritten-param))) - (is (typep new-mref 'quil::memory-ref)) - (is (zerop (search "__P" (quil::memory-ref-name new-mref)))) - (is (= mref-index (quil::memory-ref-position new-mref))))))) + (is (typep rewritten-param 'cl-quil::delayed-expression)) + (let ((new-mref (cl-quil::delayed-expression-expression rewritten-param))) + (is (typep new-mref 'cl-quil::memory-ref)) + (is (zerop (search "__P" (cl-quil::memory-ref-name new-mref)))) + (is (= mref-index (cl-quil::memory-ref-position new-mref))))))) (checkem 0 3 0) (checkem 3 0 1) (checkem 4 0 2)) ;; Are our returned memory descriptors the same as the old ones? - (let ((old-defs (quil:parsed-program-memory-definitions in-p))) + (let ((old-defs (cl-quil:parsed-program-memory-definitions in-p))) (is (and (subsetp old-defs mem-descriptors) (subsetp mem-descriptors old-defs))))))))) (deftest test-plain-arithmetic-rewriting () "Test rewriting arithmetic for a program without any parameters to rewrite." - (let ((in-p (let ((quil:*allow-unresolved-applications* t)) - (quil:parse-quil " + (let ((in-p (let ((cl-quil:*allow-unresolved-applications* t)) + (cl-quil:parse-quil " DECLARE a REAL DECLARE b REAL[2] A(1, 1 + 1, a) @@ -260,11 +260,11 @@ B(b) 0 1 (rewrite-arithmetic in-p) ;; Is the recalc table empty? (is (= 0 (hash-table-count recalc-table))) - (let ((old-code (quil:parsed-program-executable-code in-p)) - (new-code (quil:parsed-program-executable-code p))) + (let ((old-code (cl-quil:parsed-program-executable-code in-p)) + (new-code (cl-quil:parsed-program-executable-code p))) ;; Is the old program the same length as the new one? (is (= (length old-code) (length new-code)))) - (let ((old-defs (quil:parsed-program-memory-definitions in-p))) + (let ((old-defs (cl-quil:parsed-program-memory-definitions in-p))) ;; Are our returned memory descriptors the same as the old ones? (is (and (subsetp old-defs mem-descriptors) (subsetp mem-descriptors old-defs))) @@ -275,27 +275,27 @@ B(b) 0 1 (deftest test-grid-node () "Tests on the grid node data structure and associated functions." - (let ((q0 (cl-quil.frontend::make-grid-node 'q0 0)) - (q1 (cl-quil.frontend::make-grid-node 'q1 1)) - (q2 (cl-quil.frontend::make-grid-node 'q2 2)) - (q01 (cl-quil.frontend::make-grid-node 'q01 0 1)) - (q12 (cl-quil.frontend::make-grid-node 'q12 1 2)) - (q02 (cl-quil.frontend::make-grid-node 'q02 0 2))) + (let ((q0 (cl-quil/frontend::make-grid-node 'q0 0)) + (q1 (cl-quil/frontend::make-grid-node 'q1 1)) + (q2 (cl-quil/frontend::make-grid-node 'q2 2)) + (q01 (cl-quil/frontend::make-grid-node 'q01 0 1)) + (q12 (cl-quil/frontend::make-grid-node 'q12 1 2)) + (q02 (cl-quil/frontend::make-grid-node 'q02 0 2))) ;; All nodes start as root nodes. - (is (every #'cl-quil.frontend::root-node-p (list q0 q1 q2 q01 q12 q02))) + (is (every #'cl-quil/frontend::root-node-p (list q0 q1 q2 q01 q12 q02))) ;; Set succeeding, check preceding. - (setf (cl-quil.frontend::succeeding-node-on-qubit q0 0) q01) - (is (eq q01 (cl-quil.frontend::succeeding-node-on-qubit q0 0))) + (setf (cl-quil/frontend::succeeding-node-on-qubit q0 0) q01) + (is (eq q01 (cl-quil/frontend::succeeding-node-on-qubit q0 0))) ;; Set preceding, check succeeding - (setf (cl-quil.frontend::preceding-node-on-qubit q12 2) q2) - (is (eq q2 (cl-quil.frontend::preceding-node-on-qubit q12 2))) + (setf (cl-quil/frontend::preceding-node-on-qubit q12 2) q2) + (is (eq q2 (cl-quil/frontend::preceding-node-on-qubit q12 2))) ;; Check that we can't set a preceding or succeeding node on ;; invalid qubits. - (signals error (setf (cl-quil.frontend::succeeding-node-on-qubit q2 0) q02)) - (signals error (setf (cl-quil.frontend::preceding-node-on-qubit q02 1) q1)) + (signals error (setf (cl-quil/frontend::succeeding-node-on-qubit q2 0) q02)) + (signals error (setf (cl-quil/frontend::preceding-node-on-qubit q02 1) q1)) ;; Check trailer dealios. - (is (cl-quil.frontend::trailer-node-on-qubit-p q01 0)) - (is (not (cl-quil.frontend::trailer-node-on-qubit-p q0 0))))) + (is (cl-quil/frontend::trailer-node-on-qubit-p q01 0)) + (is (not (cl-quil/frontend::trailer-node-on-qubit-p q0 0))))) (defclass dummy-node () ((value :initarg :value @@ -304,7 +304,7 @@ B(b) 0 1 (defun dummy-node (x) (make-instance 'dummy-node :value (a:ensure-list x))) -(defmethod quil::fuse-objects ((a dummy-node) (b dummy-node)) +(defmethod cl-quil::fuse-objects ((a dummy-node) (b dummy-node)) (make-instance 'dummy-node :value (append (a:ensure-list (dummy-node-value a)) @@ -314,32 +314,32 @@ B(b) 0 1 "Test that FUSE-OBJECTS behaves properly in MERGE-GRID-NODES." (is (equal '(a b) (dummy-node-value - (cl-quil.frontend::grid-node-tag - (cl-quil.frontend::merge-grid-nodes - (cl-quil.frontend::make-grid-node (dummy-node 'a) 1) - (cl-quil.frontend::make-grid-node (dummy-node 'b) 1))))))) + (cl-quil/frontend::grid-node-tag + (cl-quil/frontend::merge-grid-nodes + (cl-quil/frontend::make-grid-node (dummy-node 'a) 1) + (cl-quil/frontend::make-grid-node (dummy-node 'b) 1))))))) (defun build-grid (&rest proto-nodes) - (loop :with pg := (make-instance 'cl-quil.frontend::program-grid) + (loop :with pg := (make-instance 'cl-quil/frontend::program-grid) :for (x . qs) :in proto-nodes - :for gn := (apply #'cl-quil.frontend::make-grid-node + :for gn := (apply #'cl-quil/frontend::make-grid-node (dummy-node x) qs) - :do (cl-quil.frontend::append-node pg gn) + :do (cl-quil/frontend::append-node pg gn) :finally (return pg))) (deftest test-trivial-fusion () "Test that a bunch of trivially fuseable gates can be fused." (flet ((test-it (&rest proto-nodes) - (let ((output-pg (cl-quil.frontend::fuse-trivially (apply #'build-grid proto-nodes)))) - (is (= 1 (length (cl-quil.frontend::roots output-pg)))) - (let ((root (first (cl-quil.frontend::roots output-pg)))) - (is (cl-quil.frontend::root-node-p root)) - (is (every (a:curry #'eq root) (cl-quil.frontend::trailers output-pg))) - (is (every #'null (cl-quil.frontend::grid-node-back root))) - (is (every #'null (cl-quil.frontend::grid-node-forward root))) + (let ((output-pg (cl-quil/frontend::fuse-trivially (apply #'build-grid proto-nodes)))) + (is (= 1 (length (cl-quil/frontend::roots output-pg)))) + (let ((root (first (cl-quil/frontend::roots output-pg)))) + (is (cl-quil/frontend::root-node-p root)) + (is (every (a:curry #'eq root) (cl-quil/frontend::trailers output-pg))) + (is (every #'null (cl-quil/frontend::grid-node-back root))) + (is (every #'null (cl-quil/frontend::grid-node-forward root))) (is (equalp (mapcar #'first proto-nodes) - (dummy-node-value (cl-quil.frontend::grid-node-tag root)))))))) + (dummy-node-value (cl-quil/frontend::grid-node-tag root)))))))) (test-it '(a 0) '(b 0 1) '(c 0 1 2) @@ -364,42 +364,42 @@ B(b) 0 1 (deftest test-simplify-arithmetic-linear () "Test that a linear expression can simplified" - (let ((in-p (quil:parse-quil " + (let ((in-p (cl-quil:parse-quil " DECLARE theta REAL[1] RX(2.0+3.0*theta[0]-3.0*theta[0]/4.0-2.0) 0 ")) - (out-p (quil::parse-quil " + (out-p (cl-quil::parse-quil " DECLARE theta REAL[1] RX(2.25*theta[0]) 0 "))) - (setf in-p (quil::simplify-arithmetic in-p)) - (is (equalp (quil::application-parameters (quil::nth-instr 0 in-p)) - (quil::application-parameters (quil::nth-instr 0 out-p)))))) + (setf in-p (cl-quil::simplify-arithmetic in-p)) + (is (equalp (cl-quil::application-parameters (cl-quil::nth-instr 0 in-p)) + (cl-quil::application-parameters (cl-quil::nth-instr 0 out-p)))))) (deftest test-simplify-arithmetic-non-linear () "Test that a non-linear expression is left alone" - (let ((in-p (quil:parse-quil " + (let ((in-p (cl-quil:parse-quil " DECLARE theta REAL[1] RX(2.0+3.0*cos(theta[0])-3.0*theta[0]-2.0) 0 ")) - (out-p (quil:parse-quil " + (out-p (cl-quil:parse-quil " DECLARE theta REAL[1] RX(2.0+3.0*cos(theta[0])-3.0*theta[0]-2.0) 0 "))) - (setf in-p (quil::simplify-arithmetic in-p)) - (is (equalp (quil::application-parameters (quil::nth-instr 0 in-p)) - (quil::application-parameters (quil::nth-instr 0 out-p)))))) + (setf in-p (cl-quil::simplify-arithmetic in-p)) + (is (equalp (cl-quil::application-parameters (cl-quil::nth-instr 0 in-p)) + (cl-quil::application-parameters (cl-quil::nth-instr 0 out-p)))))) (deftest test-simplify-arithmetic-negative-references () "Test that simplification works on negative-prefixed memory references e.g. RX(-theta[0] + 2.0*theta[0] + 2.0) 0 -> RX(2.0 + 1.0*theta[0]) 0" - (let ((in-p (quil:parse-quil " + (let ((in-p (cl-quil:parse-quil " DECLARE theta REAL[1] RX(-theta[0]+2.0*theta[0]+2.0) 0 ")) - (out-p (quil:parse-quil " + (out-p (cl-quil:parse-quil " DECLARE theta REAL[1] RX(2.0+theta[0]) 0 "))) - (setf in-p (quil::simplify-arithmetic in-p)) - (is (equalp (quil::application-parameters (quil::nth-instr 0 in-p)) - (quil::application-parameters (quil::nth-instr 0 out-p)))))) + (setf in-p (cl-quil::simplify-arithmetic in-p)) + (is (equalp (cl-quil::application-parameters (cl-quil::nth-instr 0 in-p)) + (cl-quil::application-parameters (cl-quil::nth-instr 0 out-p)))))) diff --git a/tests/ansatz-search-tests.lisp b/tests/ansatz-search-tests.lisp index 9dfb82f1c..3e1e67369 100644 --- a/tests/ansatz-search-tests.lisp +++ b/tests/ansatz-search-tests.lisp @@ -8,24 +8,24 @@ "Can we reproduce simple Euler decompositions?" (flet ((test-rz () (let* ((a (random pi)) - (zyz (quil::example-matrix->zyz (quil::rz-matrix a)))) + (zyz (cl-quil::example-matrix->zyz (cl-quil::rz-matrix a)))) ;; We double-noodle these zero-equal tests because ansatz ;; stuff isn't terribly accurate. ;; ;; Y-component should be 0. - (is (quil::double~ 0.0d0 (aref zyz 1))) + (is (cl-quil::double~ 0.0d0 (aref zyz 1))) ;; Z-components should add to 0. - (is (quil::double~ a (mod (+ (aref zyz 0) + (is (cl-quil::double~ a (mod (+ (aref zyz 0) (aref zyz 2)) (* 2 pi)))) )) (test-random () - (let* ((a (quil::random-unitary '(2 2))) - (zyz (quil::example-matrix->zyz a))) - (is (quil::matrix-equals-dwim a (magicl:@ (quil::rz-matrix (aref zyz 2)) - (quil::ry-matrix (aref zyz 1)) - (quil::rz-matrix (aref zyz 0)))))))) + (let* ((a (cl-quil::random-unitary '(2 2))) + (zyz (cl-quil::example-matrix->zyz a))) + (is (cl-quil::matrix-equals-dwim a (magicl:@ (cl-quil::rz-matrix (aref zyz 2)) + (cl-quil::ry-matrix (aref zyz 1)) + (cl-quil::rz-matrix (aref zyz 0)))))))) (dotimes (i 100) (test-rz)) (dotimes (i 100) diff --git a/tests/approximation-tests.lisp b/tests/approximation-tests.lisp index 5376eded9..920f590ef 100644 --- a/tests/approximation-tests.lisp +++ b/tests/approximation-tests.lisp @@ -6,41 +6,41 @@ (deftest test-approximate-compilation () - (let* ((chip (quil::build-nq-linear-chip 3 :architecture ':cz)) + (let* ((chip (cl-quil::build-nq-linear-chip 3 :architecture ':cz)) (fidelity-hash (a:plist-hash-table (list "fCZ" 0.50d0 "f1QRB" 0.99d0) :test #'equalp)) - (pp (quil::parse-quil "CPHASE(pi/4) 0 1")) - (m-in (quil::make-matrix-from-quil (coerce (quil::parsed-program-executable-code pp) 'list))) + (pp (cl-quil::parse-quil "CPHASE(pi/4) 0 1")) + (m-in (cl-quil::make-matrix-from-quil (coerce (cl-quil::parsed-program-executable-code pp) 'list))) cpp m-out) (loop - :for obj :across (quil::vnth 1 (quil::chip-specification-objects chip)) - :do (setf (gethash "specs" (quil::hardware-object-misc-data obj)) fidelity-hash)) - (let ((quil::*enable-approximate-compilation* t)) - (setf cpp (quil::compiler-hook pp chip))) + :for obj :across (cl-quil::vnth 1 (cl-quil::chip-specification-objects chip)) + :do (setf (gethash "specs" (cl-quil::hardware-object-misc-data obj)) fidelity-hash)) + (let ((cl-quil::*enable-approximate-compilation* t)) + (setf cpp (cl-quil::compiler-hook pp chip))) ;; check: results are approximately correct - (setf m-out (quil::make-matrix-from-quil (coerce (quil::parsed-program-executable-code cpp) 'list))) - (is (< 0.95d0 (quil::trace-distance m-in m-out))) + (setf m-out (cl-quil::make-matrix-from-quil (coerce (cl-quil::parsed-program-executable-code cpp) 'list))) + (is (< 0.95d0 (cl-quil::trace-distance m-in m-out))) ;; check: reduction actually happened - (is (> 13 (length (quil::parsed-program-executable-code cpp)))))) + (is (> 13 (length (cl-quil::parsed-program-executable-code cpp)))))) (deftest test-fidelity-calculation-agreement () - (let* ((quil (list (quil::build-gate "ISWAP" () 0 1) - (quil::build-gate "RY" '(#.(/ pi 4)) 0) - (quil::build-gate "RY" '(#.(/ pi 4)) 1) - (quil::build-gate "CPHASE" '(#.pi) 0 1))) - (swap-gate (quil::build-gate "SWAP" () 0 1)) - (m (quil::make-matrix-from-quil quil)) - (mprime (quil::make-matrix-from-quil (list swap-gate)))) - (multiple-value-bind (a d b) (quil::orthogonal-decomposition m) - (multiple-value-bind (aprime dprime bprime) (quil::orthogonal-decomposition mprime) + (let* ((quil (list (cl-quil::build-gate "ISWAP" () 0 1) + (cl-quil::build-gate "RY" '(#.(/ pi 4)) 0) + (cl-quil::build-gate "RY" '(#.(/ pi 4)) 1) + (cl-quil::build-gate "CPHASE" '(#.pi) 0 1))) + (swap-gate (cl-quil::build-gate "SWAP" () 0 1)) + (m (cl-quil::make-matrix-from-quil quil)) + (mprime (cl-quil::make-matrix-from-quil (list swap-gate)))) + (multiple-value-bind (a d b) (cl-quil::orthogonal-decomposition m) + (multiple-value-bind (aprime dprime bprime) (cl-quil::orthogonal-decomposition mprime) (declare (ignore aprime bprime)) - (let* ((coord-d (quil::get-canonical-coords-from-diagonal d)) - (coord-dprime (quil::get-canonical-coords-from-diagonal dprime)) - (fast-distance (quil::fidelity-coord-distance + (let* ((coord-d (cl-quil::get-canonical-coords-from-diagonal d)) + (coord-dprime (cl-quil::get-canonical-coords-from-diagonal dprime)) + (fast-distance (cl-quil::fidelity-coord-distance coord-d coord-dprime))) (multiple-value-bind (circ slow-nearness) - (quil::sandwich-with-local-gates (list swap-gate) a d b 1 0) + (cl-quil::sandwich-with-local-gates (list swap-gate) a d b 1 0) (declare (ignore circ)) - (is (quil::double= fast-distance (- 1 slow-nearness))))))))) + (is (cl-quil::double= fast-distance (- 1 slow-nearness))))))))) diff --git a/tests/benchmarking-procedures-tests.lisp b/tests/benchmarking-procedures-tests.lisp index 5451698e6..58ea12f6e 100644 --- a/tests/benchmarking-procedures-tests.lisp +++ b/tests/benchmarking-procedures-tests.lisp @@ -9,33 +9,33 @@ (let* ((sequence-length 10) (num-qubits1 1) (num-qubits2 2) - (gateset1 (quil.clifford:default-gateset num-qubits1)) - (gateset2 (quil.clifford:default-gateset num-qubits2)) - (cliffords1 (cl-quil.clifford::cliffords gateset1)) - (cliffords2 (cl-quil.clifford::cliffords gateset2)) + (gateset1 (cl-quil/clifford:default-gateset num-qubits1)) + (gateset2 (cl-quil/clifford:default-gateset num-qubits2)) + (cliffords1 (cl-quil/clifford::cliffords gateset1)) + (cliffords2 (cl-quil/clifford::cliffords gateset2)) (sequence1 (rb-sequence sequence-length num-qubits1 cliffords1)) (sequence2 (rb-sequence sequence-length num-qubits2 cliffords2))) ;; Check that they compose to the identity. - (is (cl-quil.clifford:clifford-identity-p (reduce #'cl-quil.clifford:group-mul (apply #'append sequence1)))) - (is (cl-quil.clifford:clifford-identity-p (reduce #'cl-quil.clifford:group-mul (apply #'append sequence2)))) + (is (cl-quil/clifford:clifford-identity-p (reduce #'cl-quil/clifford:group-mul (apply #'append sequence1)))) + (is (cl-quil/clifford:clifford-identity-p (reduce #'cl-quil/clifford:group-mul (apply #'append sequence2)))) ;; Check they are of the right length. (is (= (length sequence1) (length sequence2) sequence-length)) ;; Check that the clifford elements consist of element from the gateset. (is (loop :for clifford :in (apply #'append sequence1) - :always (member clifford cliffords1 :test #'cl-quil.clifford:clifford=))) + :always (member clifford cliffords1 :test #'cl-quil/clifford:clifford=))) (is (loop :for clifford :in (apply #'append sequence2) - :always (member clifford cliffords2 :test #'cl-quil.clifford:clifford=))) + :always (member clifford cliffords2 :test #'cl-quil/clifford:clifford=))) ;; Ensure that decompositions are always non-empty. (is (loop :for clifford :in sequence1 :always (plusp (length clifford)))))) (deftest test-interleaved-rb-sequence () (let* ((sequence-length 10) - (gateset (quil.clifford:default-gateset 1)) - (cliffords (cl-quil.clifford::cliffords gateset)) + (gateset (cl-quil/clifford:default-gateset 1)) + (cliffords (cl-quil/clifford::cliffords gateset)) (sequence (rb-sequence sequence-length 1 cliffords (first cliffords)))) ;; Check that they compose to the identity. - (is (cl-quil.clifford:clifford-identity-p (reduce #'cl-quil.clifford:group-mul (apply #'append sequence)))) + (is (cl-quil/clifford:clifford-identity-p (reduce #'cl-quil/clifford:group-mul (apply #'append sequence)))) ;; Check they are of the right length. (is (= (length sequence) (1- (* 2 sequence-length)))) (loop :for s :in sequence @@ -44,14 +44,14 @@ :do (is (clifford= (first s) (first cliffords)))) ;; Check that the clifford elements consist of element from the gateset. (is (loop :for clifford :in (apply #'append sequence) - :always (member clifford cliffords :test #'cl-quil.clifford:clifford=))) + :always (member clifford cliffords :test #'cl-quil/clifford:clifford=))) ;; Ensure that decompositions are always non-empty. (is (loop :for clifford :in sequence :always (plusp (length clifford)))))) (deftest test-serialize-clifford-sequence () - (let ((cliff-id1 (list (cl-quil.clifford:clifford-identity 1))) - (cliff-id2 (list (cl-quil.clifford:clifford-identity 2)))) + (let ((cliff-id1 (list (cl-quil/clifford:clifford-identity 1))) + (cliff-id2 (list (cl-quil/clifford:clifford-identity 2)))) (is (equalp (serialize-clifford-sequence cliff-id1) (list (list "X" "Z")))) (is (equalp (serialize-clifford-sequence cliff-id2) (list (list "IX" "IZ" "XI" "ZI")))))) @@ -64,11 +64,11 @@ (= na nb) (loop :for i :below ma :always (loop :for j :below na - :always (quil::double= (magicl:tref a i j) (magicl:tref b i j))))))) + :always (cl-quil::double= (magicl:tref a i j) (magicl:tref b i j))))))) (deftest test-n-qubit-pauli-basis-matrices () - (let* ((x (quil::from-list '(0 1 1 0) '(2 2))) - (z (quil::from-list '(1 0 0 -1) '(2 2))) + (let* ((x (cl-quil::from-list '(0 1 1 0) '(2 2))) + (z (cl-quil::from-list '(1 0 0 -1) '(2 2))) (paulis1 (list x z)) (generated-paulis1 (n-qubit-pauli-basis-matrices 1)) (generated-paulis2 (n-qubit-pauli-basis-matrices 2))) @@ -80,10 +80,10 @@ (deftest test-pauli-matrix-p () - (let* ((eye (quil::eye 2)) - (x (quil::from-list '(0 1 1 0) '(2 2))) - (y (quil::from-list '(0 #C(0 1) #C(0 -1) 0) '(2 2))) - (z (quil::from-list '(1 0 0 -1) '(2 2))) + (let* ((eye (cl-quil::eye 2)) + (x (cl-quil::from-list '(0 1 1 0) '(2 2))) + (y (cl-quil::from-list '(0 #C(0 1) #C(0 -1) 0) '(2 2))) + (z (cl-quil::from-list '(1 0 0 -1) '(2 2))) (paulis (list eye x y z)) (phases (loop :for i :below 4 :collect (expt #C(0 1) i)))) ;; Make sure the 1 and 2 qubit pauli groups are accepted. @@ -94,7 +94,7 @@ :always (loop :for pauli2 :in paulis :always (loop :for phase :in phases :always (pauli-matrix-p (magicl:scale (magicl:kron pauli1 pauli2) phase)))))) - (is (not (pauli-matrix-p (quil::from-list '(0 1 1 1) '(2 2))))) + (is (not (pauli-matrix-p (cl-quil::from-list '(0 1 1 1) '(2 2))))) (is (not (loop :for pauli :in paulis :always (loop :for phase :in phases :always (pauli-matrix-p (magicl:scale pauli (* 2 phase))))))))) @@ -119,7 +119,7 @@ (basis-size 4) (non-memo-times (loop :for i :from 0 :upto num-calls - :do (cl-quil.clifford::%clear-memo-table) + :do (cl-quil/clifford::%clear-memo-table) :sum (nth-value 1 (time-it (n-qubit-pauli-basis-matrices basis-size))))) (memo-times (loop :for i :from 0 :upto num-calls @@ -133,32 +133,32 @@ (deftest test-clifford-from-quil () (let ((clifford-quil (format nil "~{~A~%~}" (list "CNOT 0 1" "H 5" "CNOT 0 5" "X 3" "Y 1")))) - (is (not (null (cl-quil.clifford:clifford-from-quil clifford-quil))))) + (is (not (null (cl-quil/clifford:clifford-from-quil clifford-quil))))) ;; Check to make sure the indices are being parsed correctly (big endian) (let ((clifford-quil "CZ 0 5")) - (is (cl-quil.clifford:clifford= - (cl-quil.clifford:clifford-from-quil clifford-quil) - (cl-quil.clifford::make-clifford :num-qubits 2 + (is (cl-quil/clifford:clifford= + (cl-quil/clifford:clifford-from-quil clifford-quil) + (cl-quil/clifford::make-clifford :num-qubits 2 :basis-map (make-array 4 :initial-contents (mapcar 'pauli-from-string '("ZX" "IZ" "XZ" "ZI"))))))) ;; Check to make sure that the program is being parsed the correct way (The top is applied first) - (let* ((ZI (cl-quil.clifford:pauli-from-string "ZI")) - (IZ (cl-quil.clifford:pauli-from-string "IZ")) - (ZZ (cl-quil.clifford:pauli-from-string "ZZ")) - (IX (cl-quil.clifford:pauli-from-string "IX")) - (ZX (cl-quil.clifford:pauli-from-string "ZX")) - (-YY (cl-quil.clifford:pauli-from-string "-YY")) - (XX (cl-quil.clifford:pauli-from-string "XX")) + (let* ((ZI (cl-quil/clifford:pauli-from-string "ZI")) + (IZ (cl-quil/clifford:pauli-from-string "IZ")) + (ZZ (cl-quil/clifford:pauli-from-string "ZZ")) + (IX (cl-quil/clifford:pauli-from-string "IX")) + (ZX (cl-quil/clifford:pauli-from-string "ZX")) + (-YY (cl-quil/clifford:pauli-from-string "-YY")) + (XX (cl-quil/clifford:pauli-from-string "XX")) (CN0T01H0-quil (format nil "~{~A~%~}" (list "CNOT 0 1" "H 0"))) - (CN0T01H0 (cl-quil.clifford:clifford-from-quil CN0T01H0-quil)) + (CN0T01H0 (cl-quil/clifford:clifford-from-quil CN0T01H0-quil)) (H0CNOT01-quil (format nil "~{~A~%~}" (list "H 0" "CNOT 0 1"))) - (H0CNOT01 (cl-quil.clifford:clifford-from-quil H0CNOT01-quil))) + (H0CNOT01 (cl-quil/clifford:clifford-from-quil H0CNOT01-quil))) (loop :for pauli-in :in `(,ZI ,IZ ,ZZ) :for pauli-out :in `(,ZX ,IX ,ZI) - :do (is (cl-quil.clifford:pauli= pauli-out (cl-quil.clifford:apply-clifford CN0T01H0 pauli-in)))) + :do (is (cl-quil/clifford:pauli= pauli-out (cl-quil/clifford:apply-clifford CN0T01H0 pauli-in)))) (loop :for pauli-in :in `(,ZI ,IZ ,ZZ) :for pauli-out :in `(,ZZ ,XX ,-YY) - :do (is (cl-quil.clifford:pauli= pauli-out (cl-quil.clifford:apply-clifford H0CNOT01 pauli-in)))))) + :do (is (cl-quil/clifford:pauli= pauli-out (cl-quil/clifford:apply-clifford H0CNOT01 pauli-in)))))) diff --git a/tests/cfg-tests.lisp b/tests/cfg-tests.lisp index 7b28ef4b4..a1e19bb3f 100644 --- a/tests/cfg-tests.lisp +++ b/tests/cfg-tests.lisp @@ -15,7 +15,7 @@ ;; Make sure that code contains the proper components (let ((code-string (with-output-to-string (out) - (quil::print-code-list code out)))) + (cl-quil::print-code-list code out)))) (is (search (format nil "H 0~%CNOT 0 1") code-string)) (is (search "HALT" code-string)))) @@ -23,14 +23,14 @@ "Tests the operations of the code-printing helper method" (is (string= (format nil "H 0~%CNOT 0 1~%") (with-output-to-string (out) - (quil::print-code-list (quil:parsed-program-executable-code - (quil::parse-quil "H 0;CNOT 0 1")) out))))) + (cl-quil::print-code-list (cl-quil:parsed-program-executable-code + (cl-quil::parse-quil "H 0;CNOT 0 1")) out))))) (defun assert-cfg-edge-invariant (cfg) "Asserts that the outgoing and incoming fields of blocks in CFG are a valid match." - (dolist (blk (quil::cfg-blocks cfg)) - (dolist (successor (quil::children blk)) - (assert (find blk (quil::incoming successor)))))) + (dolist (blk (cl-quil::cfg-blocks cfg)) + (dolist (successor (cl-quil::children blk)) + (assert (find blk (cl-quil::incoming successor)))))) (deftest test-reconstitute-no-jumps () @@ -38,31 +38,31 @@ (let* ((p (with-output-to-quil "H 0" "CNOT 0 1")) - (cfg (quil::program-cfg p)) - (result (quil::reconstitute-program cfg))) - (verify-h-cnot-code-with-end (quil:parsed-program-executable-code result)))) + (cfg (cl-quil::program-cfg p)) + (result (cl-quil::reconstitute-program cfg))) + (verify-h-cnot-code-with-end (cl-quil:parsed-program-executable-code result)))) (deftest test-reconstitute-unconditional-jump () "Test that the correct program is parsed from a CFG with one edge" - (let* ((p (quil::parse-quil "H 0;JUMP @NEXT;LABEL @NEXT;X 1")) + (let* ((p (cl-quil::parse-quil "H 0;JUMP @NEXT;LABEL @NEXT;X 1")) (blk-1 (format nil "H 0~%JUMP")) (blk-2 "X 1") - (cfg (quil::program-cfg p)) - (result (quil::reconstitute-program cfg)) + (cfg (cl-quil::program-cfg p)) + (result (cl-quil::reconstitute-program cfg)) (string-result (with-output-to-string (out) - (quil::print-code-list (quil::parsed-program-executable-code result) out)))) + (cl-quil::print-code-list (cl-quil::parsed-program-executable-code result) out)))) (is (search blk-1 string-result)) (is (search blk-2 string-result)))) (deftest test-reconstitute-conditional-jump () - (let* ((p (quil::parse-quil "DECLARE ro BIT;H 0;JUMP-UNLESS @NEXT ro[0];LABEL @NEXT;Z 0")) + (let* ((p (cl-quil::parse-quil "DECLARE ro BIT;H 0;JUMP-UNLESS @NEXT ro[0];LABEL @NEXT;Z 0")) (blk-0 (format nil "H 0~%JUMP-WHEN")) (blk-1 "LABEL @NEXT") (blk-2 "Z 0") - (cfg (quil::program-cfg p)) - (result (quil::reconstitute-program cfg)) + (cfg (cl-quil::program-cfg p)) + (result (cl-quil::reconstitute-program cfg)) (string-result (with-output-to-string (out) - (quil::print-code-list (quil::parsed-program-executable-code result) out)))) + (cl-quil::print-code-list (cl-quil::parsed-program-executable-code result) out)))) ;; Essentially checking that @NEXT and Z 0 are in the same block in the correct order, ;; and that a JUMP-UNLESS exists for the H 0 block. Once we have more gaurantees of the @@ -79,35 +79,35 @@ (deftest test-remove-block () "Tests that removing a block from the CFG preserves the validity of the CFG." - (let* ((p (quil::parse-quil "X 0;JUMP @END;LABEL @END")) - (cfg (quil::program-cfg p)) - (to-remove (first (quil::cfg-blocks cfg)))) + (let* ((p (cl-quil::parse-quil "X 0;JUMP @END;LABEL @END")) + (cfg (cl-quil::program-cfg p)) + (to-remove (first (cl-quil::cfg-blocks cfg)))) ;; Arbitrarily remove a block that is not the exit, and assert that the blocks are still valid - (quil::remove-block to-remove cfg :update-edges t) + (cl-quil::remove-block to-remove cfg :update-edges t) (assert-cfg-edge-invariant cfg))) (deftest test-dce-none () "Tests the operation of dead code elimination when the cfg is already optimal." - (let* ((p (quil::parse-quil "X 0;JUMP @END;LABEL @END")) - (cfg (quil::program-cfg p :dce t)) - (blocks-result (quil::cfg-blocks cfg))) + (let* ((p (cl-quil::parse-quil "X 0;JUMP @END;LABEL @END")) + (cfg (cl-quil::program-cfg p :dce t)) + (blocks-result (cl-quil::cfg-blocks cfg))) (is (= 2 (length blocks-result))))) (deftest test-dce-simple-extras () "Tests the operation of dead code elimination when presented with a simple graph with extra labels." - (let* ((p (quil::parse-quil "X 0;JUMP @END;LABEL @END;Y 0;JUMP @ANOTHER;LABEL @ANOTHER;Z 0;JUMP @END;LABEL @END")) - (cfg (quil::program-cfg p :dce t)) - (blocks-result (quil::cfg-blocks cfg))) + (let* ((p (cl-quil::parse-quil "X 0;JUMP @END;LABEL @END;Y 0;JUMP @ANOTHER;LABEL @ANOTHER;Z 0;JUMP @END;LABEL @END")) + (cfg (cl-quil::program-cfg p :dce t)) + (blocks-result (cl-quil::cfg-blocks cfg))) ;; We want to ensure that this large graph has been cut down to 3 block (ENTRY, END, EXIT) (is (= 2 (length blocks-result))))) (deftest test-dce-dead-loop () "Tests the operation of dead code elimination when the cfg has a dead loop." - (let* ((p (quil::parse-quil "JUMP @L;LABEL @D;X 0;JUMP @D;LABEL @L;H 0")) - (cfg (quil::program-cfg p :dce t)) - (blocks-result (quil::cfg-blocks cfg))) + (let* ((p (cl-quil::parse-quil "JUMP @L;LABEL @D;X 0;JUMP @D;LABEL @L;H 0")) + (cfg (cl-quil::program-cfg p :dce t)) + (blocks-result (cl-quil::cfg-blocks cfg))) ;; Want to ensure that the loop from label D is excised (is (= 2 (length blocks-result))))) @@ -119,12 +119,12 @@ (deftest test-block-fusion-maximally-simplified () "Tests the operation of block fusion when the CGF is already maximally simplified." - (let* ((p (quil::parse-quil "X 0")) - (cfg (quil::program-cfg p :dce t :simplify t)) - (blocks-result (quil::cfg-blocks cfg)) - (entry (quil::entry-point cfg)) + (let* ((p (cl-quil::parse-quil "X 0")) + (cfg (cl-quil::program-cfg p :dce t :simplify t)) + (blocks-result (cl-quil::cfg-blocks cfg)) + (entry (cl-quil::entry-point cfg)) (string-result (with-output-to-string (out) - (quil::print-code-list (quil::basic-block-code entry) out)))) + (cl-quil::print-code-list (cl-quil::basic-block-code entry) out)))) ;; Check that there is one block, and that the entry has a single command (is (= 1 (length blocks-result))) @@ -132,21 +132,21 @@ (deftest test-block-fusion-simple-contraction () "Tests the operation of block fusion when the CFG has a single edge that can be contracted." - (let* ((p (quil::parse-quil "X 0;JUMP @NEXT;LABEL @NEXT;JUMP @ANOTHER;LABEL @ANOTHER;JUMP @END;LABEL @END")) - (cfg (quil::program-cfg p :dce t :simplify t)) - (blocks-result (quil::cfg-blocks cfg))) + (let* ((p (cl-quil::parse-quil "X 0;JUMP @NEXT;LABEL @NEXT;JUMP @ANOTHER;LABEL @ANOTHER;JUMP @END;LABEL @END")) + (cfg (cl-quil::program-cfg p :dce t :simplify t)) + (blocks-result (cl-quil::cfg-blocks cfg))) ;; Check that there are only two or less blocks (start, end, and conjoined), although the cfg starts with 4 or more. (is (>= 2 (length blocks-result))))) (deftest test-block-fusion-multiple-contraction-unique-code () "Tests the operation of block fusion when the CFG has multiple edges that can be contracted, where each block has disimilar code." - (let* ((p (quil::parse-quil "LABEL @START;X 0;JUMP @MID;LABEL @MID;Y 0;JUMP @END;LABEL @END;Z 0")) - (cfg (quil::program-cfg p :dce t :simplify t)) - (blocks-result (quil::cfg-blocks cfg)) + (let* ((p (cl-quil::parse-quil "LABEL @START;X 0;JUMP @MID;LABEL @MID;Y 0;JUMP @END;LABEL @END;Z 0")) + (cfg (cl-quil::program-cfg p :dce t :simplify t)) + (blocks-result (cl-quil::cfg-blocks cfg)) (merged-blk (first (remove-if (lambda (blk) (when blk - (not (= 3 (length (quil::basic-block-code blk)))))) + (not (= 3 (length (cl-quil::basic-block-code blk)))))) blocks-result)))) ;; Check that there are 2 or less blocks (the original CFG has 6) @@ -154,14 +154,14 @@ ;; Check that code has been merged properly (i.e. the block after the first entry has X 0 / Y 0) (is (string= (with-output-to-string (out) - (quil::print-code-list (quil::basic-block-code merged-blk) out)) + (cl-quil::print-code-list (cl-quil::basic-block-code merged-blk) out)) (format nil "X 0~%Y 0~%Z 0~%"))))) (deftest test-block-fusion-empty-single-unconditional-self-loop () "Tests the operation of block fusion when the CFG has an unconditional self-loop with a single empty block." - (let* ((p (quil::parse-quil "LABEL @START;H 0;JUMP @LOOPER;LABEL @LOOPER;JUMP @START")) - (cfg (quil::program-cfg p :dce t :simplify t)) - (blocks-result (quil::cfg-blocks cfg))) + (let* ((p (cl-quil::parse-quil "LABEL @START;H 0;JUMP @LOOPER;LABEL @LOOPER;JUMP @START")) + (cfg (cl-quil::program-cfg p :dce t :simplify t)) + (blocks-result (cl-quil::cfg-blocks cfg))) ;; Although an invalid program, the original CFG features a loop, for a total of three blocks ;; The new CFG should have a direct loop and at most 2 blocks @@ -169,9 +169,9 @@ (deftest test-block-fusion-nonempty-conditional-multiple-self-loop () "Tests the operation of block fusion when the CFG has a long self loop with code inside." - (let* ((p (quil::parse-quil "DECLARE ro BIT;LABEL @START;H 0;JUMP-WHEN @LOOPER ro[0];JUMP @END;LABEL @LOOPER;JUMP @LOOPER2;LABEL @LOOPER2;X 0;JUMP @LOOPER3;LABEL @LOOPER3;JUMP @START;LABEL @END")) - (cfg (quil::program-cfg p :dce t :simplify t)) - (blocks-result (quil::cfg-blocks cfg))) + (let* ((p (cl-quil::parse-quil "DECLARE ro BIT;LABEL @START;H 0;JUMP-WHEN @LOOPER ro[0];JUMP @END;LABEL @LOOPER;JUMP @LOOPER2;LABEL @LOOPER2;X 0;JUMP @LOOPER3;LABEL @LOOPER3;JUMP @START;LABEL @END")) + (cfg (cl-quil::program-cfg p :dce t :simplify t)) + (blocks-result (cl-quil::cfg-blocks cfg))) ;; Originally this program has an unnecessary jump-when loop with 3 blocks when it could be a single one, ;; as well as a trail of blocks to the end. This 8 block program should now be a 4 block program (at most). @@ -179,9 +179,9 @@ (deftest test-block-fusion-empty-conditional-self-loop () "Tests the operaton of block fusion when the CFG has an empty self loop with a conditional control." - (let* ((p (quil::parse-quil "DECLARE ro BIT;LABEL @START;H 0;JUMP-WHEN @LOOPER ro[0];JUMP @END;LABEL @LOOPER;JUMP @LOOPER2;LABEL @LOOPER2;JUMP @LOOPER3;LABEL @LOOPER3;JUMP @START;LABEL @END")) - (cfg (quil::program-cfg p :dce t :simplify t)) - (blocks-result (quil::cfg-blocks cfg))) + (let* ((p (cl-quil::parse-quil "DECLARE ro BIT;LABEL @START;H 0;JUMP-WHEN @LOOPER ro[0];JUMP @END;LABEL @LOOPER;JUMP @LOOPER2;LABEL @LOOPER2;JUMP @LOOPER3;LABEL @LOOPER3;JUMP @START;LABEL @END")) + (cfg (cl-quil::program-cfg p :dce t :simplify t)) + (blocks-result (cl-quil::cfg-blocks cfg))) ;; Originally this program has an unnecessary jump-when loop with 3 blocks when it could be completely removed, ;; as well as a trail of blocks to the end. This 8 block program should now be a 3 block program (at most). @@ -192,8 +192,8 @@ This is a regression test for https://github.com/rigetti/quilc/issues/244" (dolist (jump-instr '("JUMP-WHEN" "JUMP-UNLESS")) - (let ((p (quil::parse-quil (format nil "DECLARE ro BIT;LABEL @START;~A @START ro[0]" jump-instr)))) - (not-signals error (quil::program-cfg p :dce t :simplify t))))) + (let ((p (cl-quil::parse-quil (format nil "DECLARE ro BIT;LABEL @START;~A @START ro[0]" jump-instr)))) + (not-signals error (cl-quil::program-cfg p :dce t :simplify t))))) (deftest test-consecutive-reset-blocks-collapse () "Verify that consecutive RESET instructions are collapsed into a single block in the graph." @@ -203,11 +203,11 @@ This is a regression test for https://github.com/rigetti/quilc/issues/244" ("RESET; RESET; X 0; RESET" . 2) ("RESET; RESET; X 0; RESET; RESET" . 2)))) (loop :for (program . length) :in program-and-length - :for cfg := (quil::program-cfg (parse program)) :do - (is (= (length (quil::cfg-blocks cfg)) + :for cfg := (cl-quil::program-cfg (parse program)) :do + (is (= (length (cl-quil::cfg-blocks cfg)) length))))) (deftest test-reset-block-survives-preserve-block-pragma () (let* ((program (parse "RESET; PRAGMA PRESERVE_BLOCK; X 0; PRAGMA END_PRESERVE_BLOCK")) - (cfg (quil::program-cfg program))) - (is (typep (quil::entry-point cfg) 'quil::reset-block)))) + (cfg (cl-quil::program-cfg program))) + (is (typep (cl-quil::entry-point cfg) 'cl-quil::reset-block)))) diff --git a/tests/chip-library/chip-table-tests.lisp b/tests/chip-library/chip-table-tests.lisp index fcf325bd3..f610a0d0d 100644 --- a/tests/chip-library/chip-table-tests.lisp +++ b/tests/chip-library/chip-table-tests.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(in-package #:cl-quil.chip-library-tests) +(in-package #:cl-quil/chip-library-tests) (deftest default-chips () (is (equalp (call-chip-builder "8q") (q::build-8q-chip))) diff --git a/tests/chip-library/package.lisp b/tests/chip-library/package.lisp index b34728711..e63453da5 100644 --- a/tests/chip-library/package.lisp +++ b/tests/chip-library/package.lisp @@ -2,8 +2,8 @@ ;;;; ;;;; Author: A.J. Nyquist -(fiasco:define-test-package #:cl-quil.chip-library-tests - (:use #:cl #:cl-quil.chip-library) +(fiasco:define-test-package #:cl-quil/chip-library-tests + (:use #:cl #:cl-quil/chip-library) (:local-nicknames (:q :cl-quil)) ;; suite.lisp (:export diff --git a/tests/chip-library/suite.lisp b/tests/chip-library/suite.lisp index fff9b0490..4f800f0b8 100644 --- a/tests/chip-library/suite.lisp +++ b/tests/chip-library/suite.lisp @@ -2,22 +2,22 @@ ;;;; ;;;; Author: A.J. Nyquist -(in-package #:cl-quil.chip-library-tests) +(in-package #:cl-quil/chip-library-tests) (defun run-chip-library-tests (&key (verbose nil) (headless nil)) "Run all CL-QUIL/CHIP-LIBRARY tests. If VERBOSE is T, print out lots of test info. If HEADLESS is T, disable interactive debugging and quit on completion." ;; Bug in Fiasco commit fe89c0e924c22c667cc11c6fc6e79419fc7c1a8b (let ((fiasco::*test-run-standard-output* (make-broadcast-stream *standard-output*)) - (quil::*compress-carefully* t)) + (cl-quil::*compress-carefully* t)) (cond ((null headless) - (run-package-tests :package ':cl-quil.chip-library-tests + (run-package-tests :package ':cl-quil/chip-library-tests :verbose verbose :describe-failures t :interactive t)) (t - (let ((successp (run-package-tests :package ':cl-quil.chip-library-tests + (let ((successp (run-package-tests :package ':cl-quil/chip-library-tests :verbose t :describe-failures t :interactive nil))) diff --git a/tests/chip-specification-tests.lisp b/tests/chip-specification-tests.lisp index 4f39b93fa..f45c21f11 100644 --- a/tests/chip-specification-tests.lisp +++ b/tests/chip-specification-tests.lisp @@ -10,7 +10,7 @@ "tests/qpu-test-files/")) (defun %read-test-chipspec (file-name) - (quil::read-chip-spec-file (merge-pathnames file-name *qpu-test-file-directory*))) + (cl-quil::read-chip-spec-file (merge-pathnames file-name *qpu-test-file-directory*))) (deftest test-read-chipspec () "Test that READ-CHIPSPEC can parse some representative Aspen-* qpu files." @@ -19,7 +19,7 @@ (is (not (null test-files))) (dolist (file test-files) (format t "~& Testing file ~A~%" (pathname-name file)) - (not-signals error (quil::read-chip-spec-file file))))) + (not-signals error (cl-quil::read-chip-spec-file file))))) (deftest test-gh-378-regression () "Regression test for github issue #378." @@ -63,25 +63,25 @@ \"14-15\": {}, \"15-16\": {}, \"16-17\": {}}}}")) - (chip-spec (quil::qpu-hash-table-to-chip-specification isa))) - (is (quil::chip-specification-p chip-spec)) - (is (= 18 (quil::chip-spec-n-qubits chip-spec))) + (chip-spec (cl-quil::qpu-hash-table-to-chip-specification isa))) + (is (cl-quil::chip-specification-p chip-spec)) + (is (= 18 (cl-quil::chip-spec-n-qubits chip-spec))) ;; check we got the goods (dolist (presumed-dead '(4 8 9 10 11 12)) - (is (quil::chip-spec-qubit-dead? chip-spec presumed-dead))))) ; RIP in piece + (is (cl-quil::chip-spec-qubit-dead? chip-spec presumed-dead))))) ; RIP in piece (deftest test-bristlecone-chip () "Test construction of Google's Bristlecone 72-qubit chip" - (let* ((chip (quil::build-bristlecone-chip)) + (let* ((chip (cl-quil::build-bristlecone-chip)) (prgm (parse-quil (with-output-to-string (s) - (loop :for i :below (quil::chip-spec-n-qubits chip) + (loop :for i :below (cl-quil::chip-spec-n-qubits chip) :do (format s "H ~D~%" i))))) ;; Bit of a kludge here. Since this is a large number of ;; qubits, calculating its matrix representation will be a ;; terribly long-winded affair. - (quil::*compress-carefully* nil)) - (is (= 72 (quil::chip-spec-n-qubits chip))) - (is (= (* 11 11) (quil::chip-spec-n-links chip))) + (cl-quil::*compress-carefully* nil)) + (is (= 72 (cl-quil::chip-spec-n-qubits chip))) + (is (= (* 11 11) (cl-quil::chip-spec-n-links chip))) (is (plusp (length (parsed-program-executable-code prgm)))) (is (plusp (length (parsed-program-executable-code (compiler-hook prgm chip))))))) diff --git a/tests/classical-memory-tests.lisp b/tests/classical-memory-tests.lisp index 3c0fe3640..87462c315 100644 --- a/tests/classical-memory-tests.lisp +++ b/tests/classical-memory-tests.lisp @@ -26,9 +26,9 @@ :alignment 8 :real-bits 64 :integer-bits 64))) - (is (= 1 (length (quil::memory-model-roots model)))) - (is (= 254 (length (quil::memory-model-aliases model)))) - (is (= 255 (hash-table-count (quil::memory-model-names model)))))) + (is (= 1 (length (cl-quil::memory-model-roots model)))) + (is (= 254 (length (cl-quil::memory-model-aliases model)))) + (is (= 255 (hash-table-count (cl-quil::memory-model-names model)))))) (deftest test-bad-inherit-small-from-large () "Test we can't inherit from a smaller memory region to a larger one." @@ -49,7 +49,7 @@ DECLARE o OCTET[4] DECLARE ix INTEGER SHARING o "))) (dolist (bad baddies) - (signals quil:quil-memory-model-error + (signals cl-quil:quil-memory-model-error (memory-descriptors-to-model (parsed-program-memory-definitions (parse-quil bad)) @@ -60,11 +60,11 @@ DECLARE ix INTEGER SHARING o #+#:ignore ; Not sure if this is needed. (deftest test-divisible-alignment () "Test that we detect when data types are indivisible in their size to alignment." - (signals quil:quil-memory-model-error + (signals cl-quil:quil-memory-model-error (memory-descriptors-to-model nil :alignment 8 :real-bits 9 :integer-bits 8)) - (signals quil:quil-memory-model-error + (signals cl-quil:quil-memory-model-error (memory-descriptors-to-model nil :alignment 8 :real-bits 8 :integer-bits 9))) @@ -96,7 +96,7 @@ DECLARE y OCTET SHARING x # no no ))) ;; OK (dolist (p ok-programs) - (not-signals quil:quil-memory-model-error + (not-signals cl-quil:quil-memory-model-error (memory-descriptors-to-model (parsed-program-memory-definitions (parse-quil @@ -106,7 +106,7 @@ DECLARE y OCTET SHARING x # no no :integer-bits 64))) ;; NOT OK (dolist (p not-ok-programs) - (signals quil:quil-memory-model-error + (signals cl-quil:quil-memory-model-error (memory-descriptors-to-model (parsed-program-memory-definitions (parse-quil diff --git a/tests/clifford-tests.lisp b/tests/clifford-tests.lisp index 10b1bda26..d85b03831 100644 --- a/tests/clifford-tests.lisp +++ b/tests/clifford-tests.lisp @@ -10,65 +10,65 @@ :collect k)) (deftest test-clifford-utilities () - (is (= 10 (list-length (quil.clifford::sample-from '(a b c) 10)))) + (is (= 10 (list-length (cl-quil/clifford::sample-from '(a b c) 10)))) - (is (every (lambda (x) (member x '(a b c))) (quil.clifford::sample-from '(a b c) 10))) + (is (every (lambda (x) (member x '(a b c))) (cl-quil/clifford::sample-from '(a b c) 10))) - (let ((q (quil:make-queue))) - (quil:enqueue q 'A) - (quil:enqueue q 'B) - (is (equalp (quil:dequeue q) 'A)) - (is (equalp (quil:dequeue q) 'B)) - (is (equalp (quil:dequeue q) nil)))) + (let ((q (cl-quil:make-queue))) + (cl-quil:enqueue q 'A) + (cl-quil:enqueue q 'B) + (is (equalp (cl-quil:dequeue q) 'A)) + (is (equalp (cl-quil:dequeue q) 'B)) + (is (equalp (cl-quil:dequeue q) nil)))) (deftest test-paulis () - (is (quil.clifford::pauli-sym-p 'quil.clifford::X)) - (is (quil.clifford::pauli-sym-p 'quil.clifford::Y)) - (is (quil.clifford::pauli-sym-p 'quil.clifford::Z)) - (is (quil.clifford::pauli-sym-p 'quil.clifford::I)) - (is (not (quil.clifford::pauli-sym-p 'quil.clifford::A))) + (is (cl-quil/clifford::pauli-sym-p 'cl-quil/clifford::X)) + (is (cl-quil/clifford::pauli-sym-p 'cl-quil/clifford::Y)) + (is (cl-quil/clifford::pauli-sym-p 'cl-quil/clifford::Z)) + (is (cl-quil/clifford::pauli-sym-p 'cl-quil/clifford::I)) + (is (not (cl-quil/clifford::pauli-sym-p 'cl-quil/clifford::A))) - (is (quil.clifford::pauli-sym-p 'X)) - (is (quil.clifford::pauli-sym-p 'Y)) - (is (quil.clifford::pauli-sym-p 'Z)) - (is (quil.clifford::pauli-sym-p 'I)) - (is (not (quil.clifford::pauli-sym-p 'A))) + (is (cl-quil/clifford::pauli-sym-p 'X)) + (is (cl-quil/clifford::pauli-sym-p 'Y)) + (is (cl-quil/clifford::pauli-sym-p 'Z)) + (is (cl-quil/clifford::pauli-sym-p 'I)) + (is (not (cl-quil/clifford::pauli-sym-p 'A))) - (is (quil.clifford::base4-p 0)) - (is (quil.clifford::base4-p 1)) - (is (quil.clifford::base4-p 2)) - (is (quil.clifford::base4-p 3)) - (is (not (quil.clifford::base4-p -1))) - (is (not (quil.clifford::base4-p 4))) + (is (cl-quil/clifford::base4-p 0)) + (is (cl-quil/clifford::base4-p 1)) + (is (cl-quil/clifford::base4-p 2)) + (is (cl-quil/clifford::base4-p 3)) + (is (not (cl-quil/clifford::base4-p -1))) + (is (not (cl-quil/clifford::base4-p 4))) - (is (equalp (quil.clifford::base4-to-sym 0) 'quil.clifford::I)) - (is (equalp (quil.clifford::base4-to-sym 1) 'quil.clifford::X)) - (is (equalp (quil.clifford::base4-to-sym 2) 'quil.clifford::Z)) - (is (equalp (quil.clifford::base4-to-sym 3) 'quil.clifford::Y)) + (is (equalp (cl-quil/clifford::base4-to-sym 0) 'cl-quil/clifford::I)) + (is (equalp (cl-quil/clifford::base4-to-sym 1) 'cl-quil/clifford::X)) + (is (equalp (cl-quil/clifford::base4-to-sym 2) 'cl-quil/clifford::Z)) + (is (equalp (cl-quil/clifford::base4-to-sym 3) 'cl-quil/clifford::Y)) - (is (equalp (quil.clifford::pack-base4 3 2) 14)) + (is (equalp (cl-quil/clifford::pack-base4 3 2) 14)) - (loop :for sym :in '(quil.clifford::I quil.clifford::X quil.clifford::Y quil.clifford::Z) - :do (is (equalp (quil.clifford::base4-to-sym (quil.clifford::sym-to-base4 sym)) sym))) + (loop :for sym :in '(cl-quil/clifford::I cl-quil/clifford::X cl-quil/clifford::Y cl-quil/clifford::Z) + :do (is (equalp (cl-quil/clifford::base4-to-sym (cl-quil/clifford::sym-to-base4 sym)) sym))) - (is (quil.clifford:pauli= (quil.clifford:pauli-identity 3) (quil.clifford:pauli-from-symbols '(I I I)))) - (is (not (quil.clifford:pauli= (quil.clifford:pauli-identity 3) (quil.clifford:pauli-from-symbols '(I X I))))) + (is (cl-quil/clifford:pauli= (cl-quil/clifford:pauli-identity 3) (cl-quil/clifford:pauli-from-symbols '(I I I)))) + (is (not (cl-quil/clifford:pauli= (cl-quil/clifford:pauli-identity 3) (cl-quil/clifford:pauli-from-symbols '(I X I))))) - (is (quil.clifford:pauli= (quil.clifford:group-mul (quil.clifford:pauli-from-symbols '(I X Z)) - (quil.clifford:pauli-from-symbols '(I Y X))) - (quil.clifford:pauli-from-symbols '(I Z Y) 2))) + (is (cl-quil/clifford:pauli= (cl-quil/clifford:group-mul (cl-quil/clifford:pauli-from-symbols '(I X Z)) + (cl-quil/clifford:pauli-from-symbols '(I Y X))) + (cl-quil/clifford:pauli-from-symbols '(I Z Y) 2))) - (is (quil.clifford:pauli= (quil.clifford:embed (quil.clifford:pauli-from-symbols '(X Y) 2) 4 '(1 2)) - (quil.clifford:pauli-from-symbols '(I Y X I) 2))) + (is (cl-quil/clifford:pauli= (cl-quil/clifford:embed (cl-quil/clifford:pauli-from-symbols '(X Y) 2) 4 '(1 2)) + (cl-quil/clifford:pauli-from-symbols '(I Y X I) 2))) - (is (quil.clifford:pauli= (quil.clifford:tensor-mul quil.clifford::+X+ quil.clifford::+Z+) - (quil.clifford:pauli-from-symbols '(X Z))))) + (is (cl-quil/clifford:pauli= (cl-quil/clifford:tensor-mul cl-quil/clifford::+X+ cl-quil/clifford::+Z+) + (cl-quil/clifford:pauli-from-symbols '(X Z))))) (deftest test-pauli-integer () (flet ((int (s) - (cl-quil.clifford::pauli-integer - (cl-quil.clifford:pauli-from-string s)))) + (cl-quil/clifford::pauli-integer + (cl-quil/clifford:pauli-from-string s)))) (loop :for i :from 1 :to 10 :do (is (= 0 (int (make-string i :initial-element #\I))))) (is (= 1 (int "iI"))) @@ -78,8 +78,8 @@ (is (= 4 (int "IIIIX"))) (loop :for n :from 1 :to 9 :do (is (loop :for i :below (expt 4 (1+ n)) - :always (= i (cl-quil.clifford::pauli-integer - (cl-quil.clifford::integer-pauli i n)))))))) + :always (= i (cl-quil/clifford::pauli-integer + (cl-quil/clifford::integer-pauli i n)))))))) (deftest test-exp-pauli () (signals simple-error (exp-pauli (pauli-from-symbols '(I) 1) 1.0d0)) @@ -87,19 +87,19 @@ (flet ((random-pauli (n &key (fixed-phase-factor t)) "Return a random Pauli term. If FIXED-PHASE-FACTOR is T then the phase is set to 1, otherwise its uniformly chosen among the four possible ones." - (let ((c (make-array (1+ n) :element-type 'cl-quil.clifford::base4 + (let ((c (make-array (1+ n) :element-type 'cl-quil/clifford::base4 :initial-contents (loop :repeat (1+ n) :collect (random 4))))) (when fixed-phase-factor (setf (aref c 0) 0)) - (cl-quil.clifford::%make-pauli :components c))) + (cl-quil/clifford::%make-pauli :components c))) (pauli-to-parsed-program (p) "Convert Pauli term to parsed program." (let ((program-string (format nil "~{~A~^; ~}" (loop :for i :below (num-qubits p) - :for c :across (subseq (cl-quil.clifford::pauli-components p) 1) - :collect (format nil "~A ~D" (symbol-name (cl-quil.clifford::base4-to-sym c)) i))))) - (quil:parse-quil program-string)))) + :for c :across (subseq (cl-quil/clifford::pauli-components p) 1) + :collect (format nil "~A ~D" (symbol-name (cl-quil/clifford::base4-to-sym c)) i))))) + (cl-quil:parse-quil program-string)))) (loop :for num-qubits :from 1 :upto 4 :do (loop :with n := 0 @@ -107,12 +107,12 @@ :for p := (random-pauli num-qubits) :for x := (1- (random 1.0d0)) :for reference := (magicl:expih - (magicl:scale (quil:parsed-program-to-logical-matrix + (magicl:scale (cl-quil:parsed-program-to-logical-matrix (pauli-to-parsed-program p)) (- x))) - :for actual := (quil:parsed-program-to-logical-matrix - (cl-quil.frontend::raw-quil-to-unresolved-program (exp-pauli p x))) - :unless (let ((c (cl-quil.clifford::pauli-components p))) + :for actual := (cl-quil:parsed-program-to-logical-matrix + (cl-quil/frontend::raw-quil-to-unresolved-program (exp-pauli p x))) + :unless (let ((c (cl-quil/clifford::pauli-components p))) ;; This condition is meant to avoid matrices of different ;; dimensions coming from parsed-program-to-logical-matrix. (or (zerop (aref c 1)) @@ -122,63 +122,63 @@ (deftest test-clifford-identity () (loop :for i :from 1 :to 10 :do - (is (cl-quil.clifford::clifford-identity-p - (cl-quil.clifford::clifford-identity i))))) + (is (cl-quil/clifford::clifford-identity-p + (cl-quil/clifford::clifford-identity i))))) (deftest test-clifford-element () ;; TODO: should test more here - (is (cl-quil.clifford::clifford-identity-p - (cl-quil.clifford::clifford-element + (is (cl-quil/clifford::clifford-identity-p + (cl-quil/clifford::clifford-element X -> X Z -> Z)))) (deftest test-cliffords () (let ( - (xyz (quil.clifford:pauli-from-symbols '(X Y Z))) - (xyx (quil.clifford:pauli-from-symbols '(X Y X))) - (gt1 (quil.clifford:make-god-table (quil.clifford:default-gateset 1))) - (gt2 (quil.clifford:make-god-table (quil.clifford:default-gateset 2))) + (xyz (cl-quil/clifford:pauli-from-symbols '(X Y Z))) + (xyx (cl-quil/clifford:pauli-from-symbols '(X Y X))) + (gt1 (cl-quil/clifford:make-god-table (cl-quil/clifford:default-gateset 1))) + (gt2 (cl-quil/clifford:make-god-table (cl-quil/clifford:default-gateset 2))) ) - (is (quil.clifford:pauli= (quil.clifford:apply-clifford (quil.clifford:clifford-identity 3) xyz) + (is (cl-quil/clifford:pauli= (cl-quil/clifford:apply-clifford (cl-quil/clifford:clifford-identity 3) xyz) xyz)) - (is (quil.clifford:pauli= (quil.clifford:apply-clifford (quil.clifford:hadamard 3 0) xyz) + (is (cl-quil/clifford:pauli= (cl-quil/clifford:apply-clifford (cl-quil/clifford:hadamard 3 0) xyz) xyx)) - (is (quil.clifford:pauli= (quil.clifford:apply-clifford (quil.clifford::clifford-from-pauli (quil.clifford:pauli-from-symbols '(Z Y Z))) xyz) - (quil.clifford:pauli-from-symbols '(X Y Z) 2))) - (is (quil.clifford:clifford= (quil.clifford:group-mul (quil.clifford:cnot 3 2 1) (quil.clifford:cnot 3 2 1)) - (quil.clifford:clifford-identity 3))) - (is (= (hash-table-count (quil.clifford::mapping gt1)) 24)) - (is (= (hash-table-count (quil.clifford::mapping gt2)) 11520)) + (is (cl-quil/clifford:pauli= (cl-quil/clifford:apply-clifford (cl-quil/clifford::clifford-from-pauli (cl-quil/clifford:pauli-from-symbols '(Z Y Z))) xyz) + (cl-quil/clifford:pauli-from-symbols '(X Y Z) 2))) + (is (cl-quil/clifford:clifford= (cl-quil/clifford:group-mul (cl-quil/clifford:cnot 3 2 1) (cl-quil/clifford:cnot 3 2 1)) + (cl-quil/clifford:clifford-identity 3))) + (is (= (hash-table-count (cl-quil/clifford::mapping gt1)) 24)) + (is (= (hash-table-count (cl-quil/clifford::mapping gt2)) 11520)) - (let ((gt1-10 (nth 10 (hash-keys (quil.clifford::mapping gt1)))) - (gt2-1231 (nth 1231 (hash-keys (quil.clifford::mapping gt2))))) - (is (typep gt1-10 'quil.clifford::clifford)) - (is (typep gt2-1231 'quil.clifford::clifford)) + (let ((gt1-10 (nth 10 (hash-keys (cl-quil/clifford::mapping gt1)))) + (gt2-1231 (nth 1231 (hash-keys (cl-quil/clifford::mapping gt2))))) + (is (typep gt1-10 'cl-quil/clifford::clifford)) + (is (typep gt2-1231 'cl-quil/clifford::clifford)) - (is (quil.clifford:clifford= gt1-10 (reduce #'quil.clifford:group-mul (quil.clifford:reconstruct gt1-10 gt1)))) - (is (quil.clifford:clifford= gt2-1231 (reduce #'quil.clifford:group-mul (quil.clifford:reconstruct gt2-1231 gt2))))))) + (is (cl-quil/clifford:clifford= gt1-10 (reduce #'cl-quil/clifford:group-mul (cl-quil/clifford:reconstruct gt1-10 gt1)))) + (is (cl-quil/clifford:clifford= gt2-1231 (reduce #'cl-quil/clifford:group-mul (cl-quil/clifford:reconstruct gt2-1231 gt2))))))) (deftest test-sample () (let ((gt (make-god-table (default-gateset 1)))) - (dotimes (num-samples 5) (is (= (length (quil.clifford:sample num-samples gt)) num-samples))) - (let ((sample (quil.clifford::sample 1 gt))) - (is (gethash (car sample) (quil.clifford::mapping gt)))))) + (dotimes (num-samples 5) (is (= (length (cl-quil/clifford:sample num-samples gt)) num-samples))) + (let ((sample (cl-quil/clifford::sample 1 gt))) + (is (gethash (car sample) (cl-quil/clifford::mapping gt)))))) (deftest test-count-things () ;; |Sp(2n, 2)|*|P*(n)| ;; = |Sp(2n, 2)|*2^(2n) ;; = |C(n)| (is (= 6 - (cl-quil.clifford::count-symplectic 1) + (cl-quil/clifford::count-symplectic 1) (/ (count-clifford 1) (expt 2 (* 2 1))))) (is (= 720 - (cl-quil.clifford::count-symplectic 2) + (cl-quil/clifford::count-symplectic 2) (/ (count-clifford 2) (expt 2 (* 2 2))))) (is (= 1451520 - (cl-quil.clifford::count-symplectic 3) + (cl-quil/clifford::count-symplectic 3) (/ (count-clifford 3) (expt 2 (* 2 3))))) (is (= 47377612800 - (cl-quil.clifford::count-symplectic 4) + (cl-quil/clifford::count-symplectic 4) (/ (count-clifford 4) (expt 2 (* 2 4)))))) (deftest test-direct-sum () @@ -190,7 +190,7 @@ (dotimes (j i) (setf (aref s j j) 1)) ;; the test - (let ((result (cl-quil.clifford::direct-sum s s))) + (let ((result (cl-quil/clifford::direct-sum s s))) (is (loop :for row :below (* 2 i) :always (loop :for col :below (* 2 i) :always (if (= row col) @@ -199,9 +199,9 @@ (deftest test-integer-bits () (flet ((test-both-ways (i x n) - (is (equal x (cl-quil.clifford::integer-bits i n))) - (is (equal i (cl-quil.clifford::bits-integer x))) - (is (= i (cl-quil.clifford::bits-integer (cl-quil.clifford::integer-bits i n)))))) + (is (equal x (cl-quil/clifford::integer-bits i n))) + (is (equal i (cl-quil/clifford::bits-integer x))) + (is (= i (cl-quil/clifford::bits-integer (cl-quil/clifford::integer-bits i n)))))) (is (test-both-ways #b0 #*0 1)) (is (test-both-ways #b0 #*000 3)) (is (test-both-ways #b1 #*1 1)) @@ -213,7 +213,7 @@ ;; There is a very tiny probability this test won't pass in the ;; worst case that out of 10k runs we never reach all 24. This is ;; extremely, extremely rare. - (let ((tab (cl-quil.clifford::make-clifford-hash-table))) + (let ((tab (cl-quil/clifford::make-clifford-hash-table))) (loop :repeat 10000 :do (let ((r (random-clifford 1))) (assert (= 1 (num-qubits r))) @@ -227,20 +227,20 @@ (is (loop :repeat 1000 :always (let ((c (random-clifford n))) (multiple-value-bind (sp r s) - (cl-quil.clifford::clifford-symplectic c) - (clifford= c (cl-quil.clifford::symplectic-clifford sp r s)))))))) + (cl-quil/clifford::clifford-symplectic c) + (clifford= c (cl-quil/clifford::symplectic-clifford sp r s)))))))) (deftest test-canonical-swap-representative () ;;Verify that this map canonizes SWAP to identity - ;; (is (quil.clifford:clifford= (canonical-swap-representative (quil.clifford:SWAP 2 (cl-permutation:make-perm 2 1))) (SWAP 2 (cl-permutation:perm-identity 2)))) + ;; (is (cl-quil/clifford:clifford= (canonical-swap-representative (cl-quil/clifford:SWAP 2 (cl-permutation:make-perm 2 1))) (SWAP 2 (cl-permutation:perm-identity 2)))) (let ((gt (make-god-table (default-gateset 2))) - (equivalence-classes (quil.clifford::make-clifford-hash-table))) - (loop :for key :being :the :hash-keys :of (quil.clifford::mapping gt) :do + (equivalence-classes (cl-quil/clifford::make-clifford-hash-table))) + (loop :for key :being :the :hash-keys :of (cl-quil/clifford::mapping gt) :do ;;Check that each element canonizes to the same representative (is (clifford= (canonical-swap-representative key) (canonical-swap-representative - (quil.clifford:group-mul - (quil.clifford:SWAP 2 (cl-permutation:make-perm 2 1)) + (cl-quil/clifford:group-mul + (cl-quil/clifford:SWAP 2 (cl-permutation:make-perm 2 1)) key)))) (let ((rep (canonical-swap-representative key))) (if (not (gethash rep equivalence-classes)) @@ -263,7 +263,7 @@ (let ((start-time (get-internal-real-time))) (not-signals error (let ((*standard-output* (make-broadcast-stream))) - (cl-quil.clifford::interpret-chp-file file))) + (cl-quil/clifford::interpret-chp-file file))) (format t " ~D ms~%" (round (* 1000 (- (get-internal-real-time) start-time)) internal-time-units-per-second))))) @@ -272,16 +272,16 @@ (loop :with results := (vector 0 0) :repeat 500 :do - (let ((tab (cl-quil.clifford::make-tableau-zero-state 6)) + (let ((tab (cl-quil/clifford::make-tableau-zero-state 6)) (qubits (a:iota 6) #+igh(a:shuffle '(0 1 2 3 4 5)))) - (cl-quil.clifford::tableau-apply-h tab 0) - (cl-quil.clifford::tableau-apply-cnot tab 0 1) - (cl-quil.clifford::tableau-apply-cnot tab 1 2) - (cl-quil.clifford::tableau-apply-cnot tab 2 3) - (cl-quil.clifford::tableau-apply-cnot tab 3 4) - (cl-quil.clifford::tableau-apply-cnot tab 4 5) + (cl-quil/clifford::tableau-apply-h tab 0) + (cl-quil/clifford::tableau-apply-cnot tab 0 1) + (cl-quil/clifford::tableau-apply-cnot tab 1 2) + (cl-quil/clifford::tableau-apply-cnot tab 2 3) + (cl-quil/clifford::tableau-apply-cnot tab 3 4) + (cl-quil/clifford::tableau-apply-cnot tab 4 5) (multiple-value-bind (v d?) - (cl-quil.clifford::tableau-measure tab (pop qubits)) + (cl-quil/clifford::tableau-measure tab (pop qubits)) ;; First measurement is *not* deterministic! It's a GHZ ;; state! (is (not d?)) @@ -289,7 +289,7 @@ (incf (aref results v)) (loop :repeat 5 :do (multiple-value-bind (v1 d?) - (cl-quil.clifford::tableau-measure tab (pop qubits)) + (cl-quil/clifford::tableau-measure tab (pop qubits)) ;; This measurement *is* deterministic, and the ;; same as V. (is d?) @@ -312,49 +312,49 @@ (bell-wf (blank-wf 2)) (x-wf (blank-wf 2)) (phased-bell-wf (blank-wf 2)) - (zero-tab (cl-quil.clifford::make-tableau-zero-state 2)) - (bell-tab (cl-quil.clifford::make-tableau-zero-state 2)) - (x-tab (cl-quil.clifford::make-tableau-zero-state 2)) - (phased-bell-tab (cl-quil.clifford::make-tableau-zero-state 2))) + (zero-tab (cl-quil/clifford::make-tableau-zero-state 2)) + (bell-tab (cl-quil/clifford::make-tableau-zero-state 2)) + (x-tab (cl-quil/clifford::make-tableau-zero-state 2)) + (phased-bell-tab (cl-quil/clifford::make-tableau-zero-state 2))) ;; zero state wavefunction (setf (aref zero-wf 0) 1) - (is (cl-quil.clifford::global-phase~ + (is (cl-quil/clifford::global-phase~ zero-wf - (cl-quil.clifford::tableau-wavefunction zero-tab))) + (cl-quil/clifford::tableau-wavefunction zero-tab))) ;; bell state wavefunction (setf (aref bell-wf 0) (/ (sqrt 2))) (setf (aref bell-wf 3) (/ (sqrt 2))) - (cl-quil.clifford::tableau-apply-h bell-tab 0) - (cl-quil.clifford::tableau-apply-cnot bell-tab 0 1) - (is (cl-quil.clifford::global-phase~ + (cl-quil/clifford::tableau-apply-h bell-tab 0) + (cl-quil/clifford::tableau-apply-cnot bell-tab 0 1) + (is (cl-quil/clifford::global-phase~ bell-wf - (cl-quil.clifford::tableau-wavefunction bell-tab))) + (cl-quil/clifford::tableau-wavefunction bell-tab))) ;; simple x gate test (setf (aref x-wf 1) 1) - (cl-quil.clifford::tableau-apply-h x-tab 0) - (cl-quil.clifford::tableau-apply-phase x-tab 0) - (cl-quil.clifford::tableau-apply-phase x-tab 0) - (cl-quil.clifford::tableau-apply-h x-tab 0) - (is (cl-quil.clifford::global-phase~ + (cl-quil/clifford::tableau-apply-h x-tab 0) + (cl-quil/clifford::tableau-apply-phase x-tab 0) + (cl-quil/clifford::tableau-apply-phase x-tab 0) + (cl-quil/clifford::tableau-apply-h x-tab 0) + (is (cl-quil/clifford::global-phase~ x-wf - (cl-quil.clifford::tableau-wavefunction x-tab))) + (cl-quil/clifford::tableau-wavefunction x-tab))) ;; wavefunction with complex phase (setf (aref phased-bell-wf 0) (/ (sqrt 2))) (setf (aref phased-bell-wf 3) (/ #C(0 -1) (sqrt 2))) - (cl-quil.clifford::tableau-apply-h phased-bell-tab 0) - (cl-quil.clifford::tableau-apply-cnot phased-bell-tab 0 1) - (cl-quil.clifford::tableau-apply-phase phased-bell-tab 1) - (cl-quil.clifford::tableau-apply-phase phased-bell-tab 1) - (cl-quil.clifford::tableau-apply-phase phased-bell-tab 1) - (is (cl-quil.clifford::global-phase~ + (cl-quil/clifford::tableau-apply-h phased-bell-tab 0) + (cl-quil/clifford::tableau-apply-cnot phased-bell-tab 0 1) + (cl-quil/clifford::tableau-apply-phase phased-bell-tab 1) + (cl-quil/clifford::tableau-apply-phase phased-bell-tab 1) + (cl-quil/clifford::tableau-apply-phase phased-bell-tab 1) + (is (cl-quil/clifford::global-phase~ phased-bell-wf - (cl-quil.clifford::tableau-wavefunction phased-bell-tab))))) + (cl-quil/clifford::tableau-wavefunction phased-bell-tab))))) (deftest test-clifford-as-perm () (loop :for i :from 1 :to 4 :do (format t "~& Testing n=~D..." i) - (is (= (cl-quil.clifford:count-clifford i) - (perm:group-order (cl-quil.clifford::clifford-group-as-perm-group i)))) + (is (= (cl-quil/clifford:count-clifford i) + (perm:group-order (cl-quil/clifford::clifford-group-as-perm-group i)))) (finish-output))) diff --git a/tests/compilation-tests.lisp b/tests/compilation-tests.lisp index 16bf975c5..0949d563c 100644 --- a/tests/compilation-tests.lisp +++ b/tests/compilation-tests.lisp @@ -7,8 +7,8 @@ (deftest test-su4-to-su2x2 () "Ensures that Optimal 2Q Compilation decomposes SU(2)xSU(2) matrices correctly." - (let* ((a1 (quil::random-special-unitary 2)) - (a0 (quil::random-special-unitary 2)) + (let* ((a1 (cl-quil::random-special-unitary 2)) + (a0 (cl-quil::random-special-unitary 2)) (a (magicl:@ (cl-quil::su2-on-line 1 a1) (cl-quil::su2-on-line 0 a0)))) (multiple-value-bind (b1 b0) (cl-quil::convert-su4-to-su2x2 a) @@ -17,28 +17,28 @@ (deftest test-optimal-2q-on-su2x2 () "Tests that optimal 2Q compilation can handle a gate of the form SU(2) x SU(2)." - (let* ((m (quil::make-matrix-from-quil - (list (quil::anon-gate "U0" (quil::random-special-unitary 2) 0) - (quil::anon-gate "U1" (quil::random-special-unitary 2) 1)))) + (let* ((m (cl-quil::make-matrix-from-quil + (list (cl-quil::anon-gate "U0" (cl-quil::random-special-unitary 2) 0) + (cl-quil::anon-gate "U1" (cl-quil::random-special-unitary 2) 1)))) (compiled-list (cl-quil::approximate-2q-compiler - (list #'quil::nearest-circuit-of-depth-0) + (list #'cl-quil::nearest-circuit-of-depth-0) (build-anonymous-gate m 1 0) - :context (quil::make-compilation-context :chip-specification (build-8Q-chip)))) - (u (quil::make-matrix-from-quil compiled-list))) + :context (cl-quil::make-compilation-context :chip-specification (build-8Q-chip)))) + (u (cl-quil::make-matrix-from-quil compiled-list))) (fiasco-assert-matrices-are-equal m u))) (deftest test-QSD-on-4Q () "Tests Quantum Shannon Compilation on a random 4Q gate." - (let* ((m (quil::random-special-unitary 16)) - (compiled-list (quil::qs-compiler (build-anonymous-gate m 3 2 1 0))) - (u (quil::make-matrix-from-quil compiled-list))) + (let* ((m (cl-quil::random-special-unitary 16)) + (compiled-list (cl-quil::qs-compiler (build-anonymous-gate m 3 2 1 0))) + (u (cl-quil::make-matrix-from-quil compiled-list))) (check-type u magicl:matrix) - (quil::scale-out-matrix-phases u m) + (cl-quil::scale-out-matrix-phases u m) (fiasco-assert-matrices-are-equal m u))) (deftest test-cnot->cnot () (let ((progm (parse-quil "CNOT 1 0")) - (chip (quil::build-ibm-qx5))) + (chip (cl-quil::build-ibm-qx5))) (let* ((comp (compiler-hook progm chip)) (code (remove-if-not (lambda (isn) (typep isn 'application)) (parsed-program-executable-code comp)))) @@ -58,7 +58,7 @@ (deftest test-cnot-flipped-edge () (let ((progm (parse-quil "CNOT 0 1")) - (chip (quil::build-ibm-qx5))) + (chip (cl-quil::build-ibm-qx5))) (let* ((comp (compiler-hook progm chip)) (code (program-applications comp)) (2q-code (program-2q-instructions comp))) @@ -67,25 +67,25 @@ (is (string= "CNOT 1 0" (print-instruction (aref 2q-code 0) nil)))))) (deftest test-cnot-to-native-cnots () - (let* ((cnot-gate (quil::build-gate "CNOT" () 1 15)) - (chip (quil::build-ibm-qx5)) + (let* ((cnot-gate (cl-quil::build-gate "CNOT" () 1 15)) + (chip (cl-quil::build-ibm-qx5)) (possible-paths '(((1 2) (2 15) (1 2) (2 15)) ((1 0) (0 15) (1 0) (0 15)))) - (path (quil::cnot-to-native-cnots cnot-gate - :context (quil::make-compilation-context + (path (cl-quil::cnot-to-native-cnots cnot-gate + :context (cl-quil::make-compilation-context :chip-specification chip)))) (is (find (mapcar #'application-argument-indicies path) possible-paths :test #'equalp)))) (defun link-nativep (chip-spec) (reduce #'a:disjoin - (quil::chip-spec-links chip-spec) + (cl-quil::chip-spec-links chip-spec) :initial-value (constantly t) - :key (lambda (x) (lambda (y) (quil::hardware-object-native-instruction-p x y))))) + :key (lambda (x) (lambda (y) (cl-quil::hardware-object-native-instruction-p x y))))) (defun test-rewiring-in-cnot-for (chip gate-name i j) - (let* ((sssppp (quil::parse-quil (format nil "~A ~D ~D" gate-name i j))) - (code (program-2q-instructions (quil::compiler-hook sssppp chip)))) + (let* ((sssppp (cl-quil::parse-quil (format nil "~A ~D ~D" gate-name i j))) + (code (program-2q-instructions (cl-quil::compiler-hook sssppp chip)))) (is (= 1 (length code))) (is (funcall (link-nativep chip) (aref code 0))))) @@ -95,8 +95,8 @@ (finish-output) ;; don't let nobody bully you into allocating (2^16)^2 elements (let ((fiasco:*print-test-run-progress* nil) - (quil::*compress-carefully* nil) - (chip (quil::build-ibm-qx5))) + (cl-quil::*compress-carefully* nil) + (chip (cl-quil::build-ibm-qx5))) (dotimes (i 16) (format t " ") (dotimes (j 16) @@ -113,8 +113,8 @@ (format t "~& [Test output: ~%") (finish-output) (let ((fiasco:*print-test-run-progress* nil) - (quil::*compress-carefully* nil) - (chip (quil::build-ibm-qx5))) + (cl-quil::*compress-carefully* nil) + (chip (cl-quil::build-ibm-qx5))) (dotimes (i 16) (format t " ") (dotimes (j 16) @@ -127,7 +127,7 @@ (format t "]")) (deftest test-absolute-unit-cnot-compilation () - (let* ((chip (quil::build-ibm-qx5)) + (let* ((chip (cl-quil::build-ibm-qx5)) (pp (parse-quil " # in awe at the size of this lad CCNOT 8 9 2 @@ -135,61 +135,61 @@ CNOT 15 4 CZ 5 7 CPHASE(pi/8) 1 3 ISWAP 5 2")) - (cp (let ((quil::*compress-carefully* nil)) + (cp (let ((cl-quil::*compress-carefully* nil)) (compiler-hook pp chip))) (2q-code (program-2q-instructions cp))) (is (every (link-nativep chip) 2q-code)))) (deftest test-bloch-gate-compilation () - (let* ((chip (quil::build-ibm-qx5)) + (let* ((chip (cl-quil::build-ibm-qx5)) (pp (parse-quil " BLOCH(0,0,0) 0 BLOCH(0.1, 0.2, 0.3) 1 CONTROLLED BLOCH(-pi, pi/2, 0.1) 2 3 DAGGER BLOCH(-0.1, -0.2, -0.3) 4 ")) - (cp (let ((quil::*compress-carefully* nil)) + (cp (let ((cl-quil::*compress-carefully* nil)) (compiler-hook pp chip))) (2q-code (program-2q-instructions cp))) (is (every (link-nativep chip) 2q-code)))) (deftest test-cnot-triangle () - (let* ((chip (quil::build-nq-linear-chip 3 :architecture ':cnot)) - (orig-prog (quil::parse-quil " + (let* ((chip (cl-quil::build-nq-linear-chip 3 :architecture ':cnot)) + (orig-prog (cl-quil::parse-quil " CNOT 1 0 CNOT 2 1 CNOT 0 2")) - (orig-matrix (quil:parsed-program-to-logical-matrix orig-prog)) - (proc-prog (quil::compiler-hook orig-prog chip)) - (proc-matrix (quil:parsed-program-to-logical-matrix proc-prog)) + (orig-matrix (cl-quil:parsed-program-to-logical-matrix orig-prog)) + (proc-prog (cl-quil::compiler-hook orig-prog chip)) + (proc-matrix (cl-quil:parsed-program-to-logical-matrix proc-prog)) (2q-code (program-2q-instructions proc-prog))) - (is (quil::matrix-equals-dwim orig-matrix proc-matrix)) + (is (cl-quil::matrix-equals-dwim orig-matrix proc-matrix)) (is (every (link-nativep chip) 2q-code)))) (deftest test-ccnot-compilation-well-behaved () "Test that CCNOT on a line compiles into the best possible outcome of 7 CZ's." - (let* ((chip (quil::build-nq-linear-chip 3)) + (let* ((chip (cl-quil::build-nq-linear-chip 3)) (ccnot-prog (parse "CCNOT 0 1 2")) (ccnot-comp (compiler-hook ccnot-prog chip)) (ccnot-code (program-2q-instructions ccnot-comp)) (2q-code (program-2q-instructions ccnot-comp))) - (is (quil::matrix-equals-dwim - (quil:parsed-program-to-logical-matrix ccnot-prog) - (quil:parsed-program-to-logical-matrix ccnot-comp))) + (is (cl-quil::matrix-equals-dwim + (cl-quil:parsed-program-to-logical-matrix ccnot-prog) + (cl-quil:parsed-program-to-logical-matrix ccnot-comp))) (is (every (link-nativep chip) 2q-code)) (is (= 7 (length ccnot-code))))) (deftest test-ccnot-compilation-on-cphase-iswap () "Test that CCNOT compiles nicely on a line having the (:CPHASE ISWAP) architecture." - (let* ((quil::*default-addresser-state-class* 'quil::temporal-addresser-state) - (quil::*addresser-use-1q-queues* t) - (chip (quil::build-nq-linear-chip 3 :architecture '(:cphase :cz :iswap))) - (orig-prog (quil::parse-quil "CCNOT 0 1 2")) - (orig-matrix (quil:parsed-program-to-logical-matrix orig-prog)) - (proc-prog (quil::compiler-hook orig-prog chip)) - (proc-matrix (quil:parsed-program-to-logical-matrix proc-prog)) + (let* ((cl-quil::*default-addresser-state-class* 'cl-quil::temporal-addresser-state) + (cl-quil::*addresser-use-1q-queues* t) + (chip (cl-quil::build-nq-linear-chip 3 :architecture '(:cphase :cz :iswap))) + (orig-prog (cl-quil::parse-quil "CCNOT 0 1 2")) + (orig-matrix (cl-quil:parsed-program-to-logical-matrix orig-prog)) + (proc-prog (cl-quil::compiler-hook orig-prog chip)) + (proc-matrix (cl-quil:parsed-program-to-logical-matrix proc-prog)) (2q-code (program-2q-instructions proc-prog))) - (is (quil::matrix-equals-dwim orig-matrix proc-matrix)) + (is (cl-quil::matrix-equals-dwim orig-matrix proc-matrix)) (is (every (link-nativep chip) 2q-code)) ;; NOTE: Decomposing into fewer 2q gates is more of a regression ;; test on quality of compilation, and not on correctness. @@ -197,15 +197,15 @@ CNOT 0 2")) (deftest test-cswap-compiles-with-qs () "Test that CSWAP compiles with QS-COMPILER. (Don't test the output's validity.)" - (let ((result (quil::qs-compiler (quil::build-gate "CSWAP" () 0 1 2)))) + (let ((result (cl-quil::qs-compiler (cl-quil::build-gate "CSWAP" () 0 1 2)))) ;; Just check we get compilation output. (is (plusp (length result))))) (deftest test-anons-compile-with-qs () "Test that a few anonymous gates compile with QS-COMPILER. (Don't test the output's validity.)" - (let ((result3 (quil::qs-compiler (quil::anon-gate "ANON" (quil::random-special-unitary (expt 2 3)) 0 1 2))) - (result4 (quil::qs-compiler (quil::anon-gate "ANON" (quil::random-special-unitary (expt 2 4)) 0 1 2 3))) - (result5 (quil::qs-compiler (quil::anon-gate "ANON" (quil::random-special-unitary (expt 2 5)) 0 1 2 3 4)))) + (let ((result3 (cl-quil::qs-compiler (cl-quil::anon-gate "ANON" (cl-quil::random-special-unitary (expt 2 3)) 0 1 2))) + (result4 (cl-quil::qs-compiler (cl-quil::anon-gate "ANON" (cl-quil::random-special-unitary (expt 2 4)) 0 1 2 3))) + (result5 (cl-quil::qs-compiler (cl-quil::anon-gate "ANON" (cl-quil::random-special-unitary (expt 2 5)) 0 1 2 3 4)))) ;; Just check we get compilation output. (is (plusp (length result3))) (is (plusp (length result4))) @@ -214,15 +214,15 @@ CNOT 0 2")) (deftest test-qs-dont-compile-nonsense () "Test that QS-COMPILER doesn't compile an anonymous 1Q or 2Q gate." (signals CL-QUIL::COMPILER-DOES-NOT-APPLY - (quil::qs-compiler (quil::anon-gate "ANON" (quil::random-special-unitary 2) 0))) + (cl-quil::qs-compiler (cl-quil::anon-gate "ANON" (cl-quil::random-special-unitary 2) 0))) (signals CL-QUIL::COMPILER-DOES-NOT-APPLY - (quil::qs-compiler (quil::anon-gate "ANON" (quil::random-special-unitary 4) 0 1)))) + (cl-quil::qs-compiler (cl-quil::anon-gate "ANON" (cl-quil::random-special-unitary 4) 0 1)))) (deftest test-sohaib-fidelity-rewiring-regression () (not-signals bt:timeout (bt:with-timeout (1) (compiler-hook (parse "CZ 0 1") - (quil::build-chip-from-digraph '((2 3) (3 2))))))) + (cl-quil::build-chip-from-digraph '((2 3) (3 2))))))) (deftest test-aspen-28q-no-swap-bug () (let* ((pp (parse "H 5 @@ -236,30 +236,30 @@ CNOT 4 7 CNOT 4 7 CNOT 4 8 ")) - (chip (quil::read-chip-spec-file + (chip (cl-quil::read-chip-spec-file (merge-pathnames *qpu-test-file-directory* "Aspen-7-28Q-A.qpu")))) ;; An absolute unit of a matrix. Better compress those qubits. - (is (quil::matrix-equals-dwim - (quil:parsed-program-to-logical-matrix pp :compress-qubits t) - (quil:parsed-program-to-logical-matrix (compiler-hook pp chip) + (is (cl-quil::matrix-equals-dwim + (cl-quil:parsed-program-to-logical-matrix pp :compress-qubits t) + (cl-quil:parsed-program-to-logical-matrix (compiler-hook pp chip) :compress-qubits t))))) (deftest test-rx-agglutination-with-wildcard-chip () ;; See #567 - (let* ((chip (quil::read-chip-spec-file + (let* ((chip (cl-quil::read-chip-spec-file (merge-pathnames *qpu-test-file-directory* "1q-wildcard-arguments.qpu"))) (progm (parse "RX(pi/2) 0; RX(pi/2) 0")) (comp (compiler-hook progm chip)) (code (%filter-halt comp))) - (is (quil::matrix-equals-dwim - (quil:parsed-program-to-logical-matrix + (is (cl-quil::matrix-equals-dwim + (cl-quil:parsed-program-to-logical-matrix (parse "RX(pi) 0")) - (quil:parsed-program-to-logical-matrix comp))) + (cl-quil:parsed-program-to-logical-matrix comp))) (is (= 1 (length code))) - (is (string= "RX" (quil::application-operator-root-name (elt code 0)))) - (is (quil::double= pi + (is (string= "RX" (cl-quil::application-operator-root-name (elt code 0)))) + (is (cl-quil::double= pi (abs (constant-value (first (application-parameters (elt code 0))))))))) (defun %random-rz-rx-program (length) @@ -281,7 +281,7 @@ CNOT 4 8 (deftest test-rx-rz-strings-reduce () ;; Any string of RXs and RYs should reduce to a string of at most 3 ;; RZs and 2 RXs. - (let ((chips (list (quil::build-nq-linear-chip 1) + (let ((chips (list (cl-quil::build-nq-linear-chip 1) (%read-test-chipspec "1q-wildcard-arguments.qpu") (%read-test-chipspec "Aspen-4-2Q-A.qpu") (%read-test-chipspec "Aspen-6-2Q-A.qpu") @@ -295,17 +295,17 @@ CNOT 4 8 (deftest test-symbolic-parameter-compiles-in-examples () "There have been bugs where symbolic compilers aren't found because non-symbolic ones are lower cost. (Bug #667)" ;; Check we can compute this fact right. - (is (quil::compiler-allows-symbolic-parameters-p #'quil::RX-to-ZXZXZ)) + (is (cl-quil::compiler-allows-symbolic-parameters-p #'cl-quil::RX-to-ZXZXZ)) ;; If this happens to change in the future... let me know! - (is (not (quil::compiler-allows-symbolic-parameters-p #'quil::EULER-ZYZ-COMPILER))) + (is (not (cl-quil::compiler-allows-symbolic-parameters-p #'cl-quil::EULER-ZYZ-COMPILER))) ;; Some full stack test cases that arose out of bug reports. (not-signals error - (quil:compiler-hook (quil:parse-quil " + (cl-quil:compiler-hook (cl-quil:parse-quil " DECLARE theta REAL RX(theta) 0") - (quil::build-nq-linear-chip 2))) + (cl-quil::build-nq-linear-chip 2))) (not-signals error - (quil:compiler-hook (quil:parse-quil " + (cl-quil:compiler-hook (cl-quil:parse-quil " PRAGMA INITIAL_REWIRING \"NAIVE\" DECLARE ro BIT[5] DECLARE theta REAL[2] @@ -329,26 +329,26 @@ MEASURE 3 ro[2] MEASURE 4 ro[3] MEASURE 5 ro[4] ") - (quil::build-nq-linear-chip 6)))) + (cl-quil::build-nq-linear-chip 6)))) (deftest test-swap-native-compile () "Test that SWAP can be compiled natively." - (let* ((chip (quil::build-8q-chip :architecture '(:cz :swap))) + (let* ((chip (cl-quil::build-8q-chip :architecture '(:cz :swap))) (compiled-prog-code - (quil::parsed-program-executable-code - (quil::compiler-hook (quil::parse-quil "SWAP 0 1") + (cl-quil::parsed-program-executable-code + (cl-quil::compiler-hook (cl-quil::parse-quil "SWAP 0 1") chip)))) - (is (quil::swap-application-p (aref compiled-prog-code 0))) - (is (quil::haltp (aref compiled-prog-code 1))))) + (is (cl-quil::swap-application-p (aref compiled-prog-code 0))) + (is (cl-quil::haltp (aref compiled-prog-code 1))))) (deftest test-swap-native-compile-chip-reader () "Test that SWAP is recognized as a type in a chip file." - (let* ((chip (quil::read-chip-spec-file + (let* ((chip (cl-quil::read-chip-spec-file (merge-pathnames *qpu-test-file-directory* "swap.qpu"))) (compiled-prog-code - (quil::parsed-program-executable-code - (quil::compiler-hook (quil::parse-quil "SWAP 0 1") + (cl-quil::parsed-program-executable-code + (cl-quil::compiler-hook (cl-quil::parse-quil "SWAP 0 1") chip)))) - (is (quil::swap-application-p (aref compiled-prog-code 0))) - (is (quil::haltp (aref compiled-prog-code 1))))) + (is (cl-quil::swap-application-p (aref compiled-prog-code 0))) + (is (cl-quil::haltp (aref compiled-prog-code 1))))) diff --git a/tests/compiler-hook-tests.lisp b/tests/compiler-hook-tests.lisp index cb9dfa3f1..6a0b93afb 100644 --- a/tests/compiler-hook-tests.lisp +++ b/tests/compiler-hook-tests.lisp @@ -10,40 +10,40 @@ "tests/compiler-hook-test-files/")) (defun attach-rewirings-to-program (pp in-rewiring-vector out-rewiring-vector) - (check-type in-rewiring-vector (or null quil::integer-vector)) - (check-type out-rewiring-vector (or null quil::integer-vector)) + (check-type in-rewiring-vector (or null cl-quil::integer-vector)) + (check-type out-rewiring-vector (or null cl-quil::integer-vector)) (unless (and (null in-rewiring-vector) (null out-rewiring-vector)) - (let ((code (quil::parsed-program-executable-code pp))) + (let ((code (cl-quil::parsed-program-executable-code pp))) (cond ((< (length code) 1) (error "Cannot attach rewirings to program with no instructions")) ((= (length code) 1) - (setf (quil::comment (aref code 0)) - (quil::make-rewiring-comment :entering in-rewiring-vector + (setf (cl-quil::comment (aref code 0)) + (cl-quil::make-rewiring-comment :entering in-rewiring-vector :exiting out-rewiring-vector))) (t (when (not (null in-rewiring-vector)) - (setf (quil::comment (aref code 0)) - (quil::make-rewiring-comment :entering in-rewiring-vector))) + (setf (cl-quil::comment (aref code 0)) + (cl-quil::make-rewiring-comment :entering in-rewiring-vector))) (when (not (null out-rewiring-vector)) - (setf (quil::comment (aref code (1- (length code)))) - (quil::make-rewiring-comment :exiting out-rewiring-vector))))))) + (setf (cl-quil::comment (aref code (1- (length code)))) + (cl-quil::make-rewiring-comment :exiting out-rewiring-vector))))))) pp) (defun %parsed-program-to-logical-matrix-rewiring-test (pp-a pp-b) (dolist (compress-qubits '(nil t)) - (is (quil::operator= - (quil:parsed-program-to-logical-matrix pp-a) - (quil:parsed-program-to-logical-matrix pp-b :compress-qubits compress-qubits))))) + (is (cl-quil::operator= + (cl-quil:parsed-program-to-logical-matrix pp-a) + (cl-quil:parsed-program-to-logical-matrix pp-b :compress-qubits compress-qubits))))) (deftest test-parsed-program-to-logical-matrix-cnot-rewiring () "Test whether parsed-program-to-logical-matrix converts equivalent programs (modulo rewiring) to equivalent matrices." - (let ((pp (quil::parse-quil " + (let ((pp (cl-quil::parse-quil " CNOT 1 2 CNOT 1 0")) - (pp-rewired (attach-rewirings-to-program (quil::parse-quil " + (pp-rewired (attach-rewirings-to-program (cl-quil::parse-quil " CNOT 0 1 CNOT 0 2 ") @@ -53,11 +53,11 @@ CNOT 0 2 (deftest test-parsed-program-to-logical-matrix-swap-rewiring () "Test whether parsed-program-to-logical-matrix converts equivalent programs (modulo rewiring) to equivalent matrices." - (let ((pp (quil::parse-quil " + (let ((pp (cl-quil::parse-quil " CNOT 0 1 Z 0 SWAP 0 1")) - (pp-rewired (attach-rewirings-to-program (quil::parse-quil " + (pp-rewired (attach-rewirings-to-program (cl-quil::parse-quil " CNOT 0 1 Z 0") #(0 1) #(1 0)))) @@ -66,10 +66,10 @@ Z 0") (deftest test-parsed-program-to-logical-matrix-entering-exiting-rewiring () "Test whether parsed-program-to-logical-matrix handles single-instruction entering/exiting rewirings correctly." - (let ((pp (quil::parse-quil " + (let ((pp (cl-quil::parse-quil " CNOT 0 1 SWAP 0 1")) - (pp-rewired (attach-rewirings-to-program (quil::parse-quil " + (pp-rewired (attach-rewirings-to-program (cl-quil::parse-quil " CNOT 0 1") #(0 1) #(1 0)))) (%parsed-program-to-logical-matrix-rewiring-test pp pp-rewired))) @@ -77,50 +77,50 @@ CNOT 0 1") (deftest test-rewiring-modes () "Iterates over the rewiring modes and tests that the addresser is well-behaved on each of them." ;; first, the straight-line rewiring methods - (dolist (quil::*initial-rewiring-default-type* '(:naive :random :partial :greedy)) - (format t "~& Testing rewiring type ~A~%" quil::*initial-rewiring-default-type*) + (dolist (cl-quil::*initial-rewiring-default-type* '(:naive :random :partial :greedy)) + (format t "~& Testing rewiring type ~A~%" cl-quil::*initial-rewiring-default-type*) (dolist (pstring (list "CNOT 2 0" (format nil "CNOT 0 2~%CNOT 1 3"))) - (let* ((pp (quil::parse-quil pstring)) - (cpp (quil::compiler-hook (quil::parse-quil pstring) - (quil::build-nQ-linear-chip (quil:qubits-needed pp)) + (let* ((pp (cl-quil::parse-quil pstring)) + (cpp (cl-quil::compiler-hook (cl-quil::parse-quil pstring) + (cl-quil::build-nQ-linear-chip (cl-quil:qubits-needed pp)) :protoquil t))) (format t "~& Testing program ~A~%" (parsed-program-executable-code pp)) (finish-output) (%parsed-program-to-logical-matrix-rewiring-test pp cpp)))) ;; then, the block-to-block rewiring methods. ;; i'm too lazy to check correctness, but we're at least exercising the pathway. - (dolist (quil::*addresser-rewiring-swap-search-type* '(:greedy-path :greedy-qubit :a*)) - (format t "~& Testing addresser move type ~A~%" quil::*addresser-rewiring-swap-search-type*) + (dolist (cl-quil::*addresser-rewiring-swap-search-type* '(:greedy-path :greedy-qubit :a*)) + (format t "~& Testing addresser move type ~A~%" cl-quil::*addresser-rewiring-swap-search-type*) (finish-output) - (let* ((pp (quil::parse-quil " + (let* ((pp (cl-quil::parse-quil " LABEL @a CNOT 0 1 CNOT 1 2 CNOT 0 2 JUMP @a"))) - (not-signals error (quil::compiler-hook pp (quil::build-8Q-chip)))))) + (not-signals error (cl-quil::compiler-hook pp (cl-quil::build-8Q-chip)))))) (defun compare-compiled (file architecture) - (let* ((orig-prog (quil::transform 'quil::compress-qubits + (let* ((orig-prog (cl-quil::transform 'cl-quil::compress-qubits (cl-quil::read-quil-file file))) (proc-prog - (quil::compiler-hook (quil::transform 'quil::compress-qubits + (cl-quil::compiler-hook (cl-quil::transform 'cl-quil::compress-qubits (cl-quil::read-quil-file file)) - (quil::build-nQ-linear-chip 5 :architecture architecture) + (cl-quil::build-nQ-linear-chip 5 :architecture architecture) :protoquil t))) - (is (quil::matrix-equals-dwim (quil:parsed-program-to-logical-matrix orig-prog) - (quil:parsed-program-to-logical-matrix proc-prog))) + (is (cl-quil::matrix-equals-dwim (cl-quil:parsed-program-to-logical-matrix orig-prog) + (cl-quil:parsed-program-to-logical-matrix proc-prog))) (list - (quil::calculate-instructions-2q-depth (coerce (quil::parsed-program-executable-code proc-prog) + (cl-quil::calculate-instructions-2q-depth (coerce (cl-quil::parsed-program-executable-code proc-prog) 'list))))) (defmacro %with-loose-state-prep-compression (&body body) `(progn - (handler-bind ((quil::state-prep-compression-tolerance-error + (handler-bind ((cl-quil::state-prep-compression-tolerance-error (lambda (c) - (when (< (quil::state-prep-compression-tolerance-error-tolerance c) - (quil::state-prep-compression-tolerance-error-precision c) - quil::+double-comparison-threshold-loose+) + (when (< (cl-quil::state-prep-compression-tolerance-error-tolerance c) + (cl-quil::state-prep-compression-tolerance-error-precision c) + cl-quil::+double-comparison-threshold-loose+) (let ((r (find-restart 'continue c))) (when r (invoke-restart r))))))) ,@body))) @@ -137,7 +137,7 @@ JUMP @a"))) (ignore-errors (restart-case (%with-loose-state-prep-compression - (error 'quil::state-prep-compression-tolerance-error + (error 'cl-quil::state-prep-compression-tolerance-error :compilation-tolerance tolerance :compilation-precision precision)) (continue () @@ -153,9 +153,9 @@ JUMP @a"))) (is (not continue-happened)) (is (not (null condition))) (is (typep condition 'QUIL::STATE-PREP-COMPRESSION-TOLERANCE-ERROR)) - (is (= (quil::state-prep-compression-tolerance-error-tolerance condition) + (is (= (cl-quil::state-prep-compression-tolerance-error-tolerance condition) 2)) - (is (= (quil::state-prep-compression-tolerance-error-precision condition) + (is (= (cl-quil::state-prep-compression-tolerance-error-precision condition) 1))))) @@ -164,9 +164,9 @@ JUMP @a"))) some test programs." (finish-output) (dolist (state-prep '(t nil)) - (let ((quil::*enable-state-prep-compression* state-prep) - (quil::*compress-carefully* t)) - (format t "~& With *ENABLE-STATE-PREP-COMPRESSION* ~A~%" quil::*enable-state-prep-compression*) + (let ((cl-quil::*enable-state-prep-compression* state-prep) + (cl-quil::*compress-carefully* t)) + (format t "~& With *ENABLE-STATE-PREP-COMPRESSION* ~A~%" cl-quil::*enable-state-prep-compression*) (dolist (file (uiop:directory-files *compiler-hook-test-file-directory* #P"*.quil")) (format t " Testing file ~A:" (pathname-name file)) (dolist (architecture (list ':cz ':iswap ':cphase ':piswap ':cnot)) @@ -179,10 +179,10 @@ some test programs." (deftest test-compression-bug-QUILC-152 () "QUILC-152: A bug in state compression caused a failed assertion." - (let ((quil::*enable-state-prep-compression* t) - (quil::*compress-carefully* t) - (instructions (quil:parsed-program-executable-code - (quil:parse-quil " + (let ((cl-quil::*enable-state-prep-compression* t) + (cl-quil::*compress-carefully* t) + (instructions (cl-quil:parsed-program-executable-code + (cl-quil:parse-quil " RZ(0.9800157744729435) 2 RX(pi/2) 2 RZ(1.2991200310990418) 2 @@ -206,8 +206,8 @@ RX(pi) 2 (%with-loose-state-prep-compression (CL-QUIL::COMPRESS-INSTRUCTIONS-IN-CONTEXT (coerce instructions 'list) - (quil::build-nQ-linear-chip 4 :architecture ':cphase) - (quil::set-up-compilation-context :qubit-count 4 :simulate t))))) + (cl-quil::build-nQ-linear-chip 4 :architecture ':cphase) + (cl-quil::set-up-compilation-context :qubit-count 4 :simulate t))))) (defun shuffle-list (l &optional (k nil)) (let* ((elt (nth (random (length l)) l)) @@ -221,31 +221,31 @@ RX(pi) 2 (finish-output) (with-retries simple-error () (dolist (state-prep '(nil t)) - (let ((quil::*enable-state-prep-compression* state-prep)) - (format t "~& With *ENABLE-STATE-PREP-COMPRESSION* ~A~%" quil::*enable-state-prep-compression*) + (let ((cl-quil::*enable-state-prep-compression* state-prep)) + (format t "~& With *ENABLE-STATE-PREP-COMPRESSION* ~A~%" cl-quil::*enable-state-prep-compression*) (dolist (architecture '(:cz :iswap :cphase :piswap :cnot)) (format t " Working on architecture ~A.~%" architecture) (let* ((num-qubits 4) - (v (quil::random-special-unitary (expt 2 num-qubits))) + (v (cl-quil::random-special-unitary (expt 2 num-qubits))) (args (shuffle-list (a:iota num-qubits :start (1- num-qubits) :step -1))) (parsed-prog (make-instance - 'quil::parsed-program + 'cl-quil::parsed-program :executable-code (make-array 1 :initial-element (make-instance - 'quil::gate-application + 'cl-quil::gate-application :operator (named-operator "RANDO-GATE") :gate v :arguments (mapcar #'qubit args))))) (processed-program (%with-loose-state-prep-compression - (quil::compiler-hook parsed-prog (quil::build-nQ-linear-chip num-qubits + (cl-quil::compiler-hook parsed-prog (cl-quil::build-nQ-linear-chip num-qubits :architecture architecture))))) - (is (quil::matrix-equals-dwim (quil::kq-gate-on-lines v num-qubits args) - (quil:parsed-program-to-logical-matrix processed-program))))))))) + (is (cl-quil::matrix-equals-dwim (cl-quil::kq-gate-on-lines v num-qubits args) + (cl-quil:parsed-program-to-logical-matrix processed-program))))))))) (deftest test-compiler-hook-preserves-RESETs () - (let* ((pp (quil::parse-quil " + (let* ((pp (cl-quil::parse-quil " PRAGMA INITIAL_REWIRING \"PARTIAL\" RESET DECLARE ro BIT[2] @@ -255,10 +255,10 @@ RY(pi/3) 2 RY(pi/3) 3 H 0 MEASURE 0 ro[1]")) - (cpp (quil::compiler-hook pp (quil::build-8Q-chip)))) - (loop :for instr :across (quil::parsed-program-executable-code cpp) - :count (typep instr 'quil::reset) :into reset-count - :count (not (typep instr 'quil::gate-application)) :into non-application-count + (cpp (cl-quil::compiler-hook pp (cl-quil::build-8Q-chip)))) + (loop :for instr :across (cl-quil::parsed-program-executable-code cpp) + :count (typep instr 'cl-quil::reset) :into reset-count + :count (not (typep instr 'cl-quil::gate-application)) :into non-application-count :finally (progn (is (= 1 reset-count)) (is (= 4 non-application-count)))))) @@ -267,45 +267,45 @@ MEASURE 0 ro[1]")) (deftest test-compiler-hook-reset-naive-rewiring () ;; Note this numbering depends on the fact that the CZ gates are ;; native on the 8Q chip. - (let* ((pp (quil::parse-quil " + (let* ((pp (cl-quil::parse-quil " PRAGMA INITIAL_REWIRING \"NAIVE\" CZ 1 2 CZ 3 4 RESET CZ 5 6 ")) - (processed-program (quil::compiler-hook pp (quil::build-8Q-chip)))) + (processed-program (cl-quil::compiler-hook pp (cl-quil::build-8Q-chip)))) (is (= 3 - (loop :for instr :across (quil::parsed-program-executable-code processed-program) - :count (and (typep instr 'quil::gate-application) - (adt:match quil:operator-description (application-operator instr) + (loop :for instr :across (cl-quil::parsed-program-executable-code processed-program) + :count (and (typep instr 'cl-quil::gate-application) + (adt:match cl-quil:operator-description (application-operator instr) ((named-operator name) (string= "CZ" name)) (_ nil)))))))) (deftest test-compiler-hook-reset-partial-rewiring () - (let* ((pp (quil::parse-quil " + (let* ((pp (cl-quil::parse-quil " PRAGMA INITIAL_REWIRING \"PARTIAL\" CZ 1 2 CZ 7 6 RESET CZ 2 7 ")) - (processed-program (quil::compiler-hook pp (quil::build-8Q-chip)))) + (processed-program (cl-quil::compiler-hook pp (cl-quil::build-8Q-chip)))) (is (= 3 - (loop :for instr :across (quil::parsed-program-executable-code processed-program) - :count (and (typep instr 'quil::gate-application) - (adt:match quil:operator-description (application-operator instr) + (loop :for instr :across (cl-quil::parsed-program-executable-code processed-program) + :count (and (typep instr 'cl-quil::gate-application) + (adt:match cl-quil:operator-description (application-operator instr) ((named-operator name) (string= "CZ" name)) (_ nil)))))))) (deftest test-compiling-empty-program () "Test that an empty program goes through the pipes correctly." - (let* ((pp (quil::parse-quil "")) - (processed-program (quil::compiler-hook pp (quil::build-8Q-chip)))) + (let* ((pp (cl-quil::parse-quil "")) + (processed-program (cl-quil::compiler-hook pp (cl-quil::build-8Q-chip)))) (is (every (lambda (isn) - (or (typep isn 'quil:halt) - (typep isn 'quil:pragma) - (typep isn 'quil:no-operation))) + (or (typep isn 'cl-quil:halt) + (typep isn 'cl-quil:pragma) + (typep isn 'cl-quil:no-operation))) (parsed-program-executable-code processed-program))))) (defun parametric-compiler-test (program-string segment-table) @@ -315,9 +315,9 @@ CZ 2 7 :do (map-into (application-parameters instr) (lambda (p) (etypecase p - (quil::constant p) - (quil::delayed-expression - (quil::evaluate-delayed-expression + (cl-quil::constant p) + (cl-quil::delayed-expression + (cl-quil::evaluate-delayed-expression p (lambda (term) (let ((lookup (assoc term segment-table :test #'equalp))) @@ -326,17 +326,17 @@ CZ 2 7 p))))))) (application-parameters instr)))) - (make-pp () (quil::parse-quil program-string :transforms nil))) - (let* ((chip (quil::build-8Q-chip :architecture ':cz)) + (make-pp () (cl-quil::parse-quil program-string :transforms nil))) + (let* ((chip (cl-quil::build-8Q-chip :architecture ':cz)) (processed-pp (compiler-hook (make-pp) chip)) (orig-pp (make-pp))) (substitute-params orig-pp segment-table) (substitute-params processed-pp segment-table) - (is (quil::matrix-equals-dwim (quil:parsed-program-to-logical-matrix orig-pp :compress-qubits t) - (quil:parsed-program-to-logical-matrix processed-pp :compress-qubits t)))))) + (is (cl-quil::matrix-equals-dwim (cl-quil:parsed-program-to-logical-matrix orig-pp :compress-qubits t) + (cl-quil:parsed-program-to-logical-matrix processed-pp :compress-qubits t)))))) (deftest test-parametric-compiler-cphase () - (dolist (quil::*enable-state-prep-compression* '(nil t)) + (dolist (cl-quil::*enable-state-prep-compression* '(nil t)) (%with-loose-state-prep-compression (parametric-compiler-test " DECLARE angle REAL @@ -346,7 +346,7 @@ CPHASE(angle) 0 1 (list (cons (mref "angle" 0) (random 1d0))))))) (deftest test-daggered-parametric-compilation () - (dolist (quil::*enable-state-prep-compression* '(nil t)) + (dolist (cl-quil::*enable-state-prep-compression* '(nil t)) (%with-loose-state-prep-compression (parametric-compiler-test " DECLARE angle REAL @@ -359,7 +359,7 @@ DAGGER XY(angle) 0 1 (list (cons (mref "angle" 0) (random 1d0))))))) (deftest test-parametric-compiler-extended () - (dolist (quil::*enable-state-prep-compression* '(nil t)) + (dolist (cl-quil::*enable-state-prep-compression* '(nil t)) (%with-loose-state-prep-compression (parametric-compiler-test " DECLARE angle REAL @@ -379,22 +379,22 @@ RX(pi/3) 0 (deftest test-gapped-qpu () (dolist (state-prep '(nil)) ; TODO XXX compression disabled until QUILC-119 is resolved - (let ((quil::*enable-state-prep-compression* state-prep)) - (let* ((chip-spec (quil::qpu-hash-table-to-chip-specification (yason:parse "{\"isa\": {\"1Q\": {\"0\": {\"dead\": true}, + (let ((cl-quil::*enable-state-prep-compression* state-prep)) + (let* ((chip-spec (cl-quil::qpu-hash-table-to-chip-specification (yason:parse "{\"isa\": {\"1Q\": {\"0\": {\"dead\": true}, \"1\": {}, \"2\": {}}, \"2Q\": {\"1-2\": {}}}}"))) - (pp (quil::parse-quil " + (pp (cl-quil::parse-quil " H 1 CNOT 1 2")) - (old-matrix (quil:parsed-program-to-logical-matrix pp)) + (old-matrix (cl-quil:parsed-program-to-logical-matrix pp)) (cpp (%with-loose-state-prep-compression - (quil::compiler-hook pp chip-spec :protoquil t))) - (new-matrix (quil:parsed-program-to-logical-matrix cpp))) - (is (quil::matrix-equals-dwim old-matrix new-matrix)))))) + (cl-quil::compiler-hook pp chip-spec :protoquil t))) + (new-matrix (cl-quil:parsed-program-to-logical-matrix cpp))) + (is (cl-quil::matrix-equals-dwim old-matrix new-matrix)))))) (deftest test-rewiring-backfilling () - (let* ((pp (quil::parse-quil " + (let* ((pp (cl-quil::parse-quil " DECLARE beta REAL[1] DECLARE gamma REAL[1] DECLARE ro BIT[3] @@ -431,25 +431,25 @@ MEASURE 0 ro[0] MEASURE 1 ro[1] MEASURE 2 ro[2] ")) - (chip (quil::qpu-hash-table-to-chip-specification + (chip (cl-quil::qpu-hash-table-to-chip-specification (yason:parse " {\"isa\": {\"1Q\": {\"0\": {}, \"1\": {}, \"2\": {}, \"3\": {}, \"4\": {}, \"5\": {}, \"6\": {}, \"7\": {}, \"8\": {}}, \"2Q\": {\"0-3\": {}, \"0-1\": {}, \"1-4\": {}, \"1-2\": {}, \"2-5\": {}, \"3-6\": {}, \"3-4\": {}, \"4-7\": {}, \"4-5\": {}, \"5-8\": {}, \"6-7\": {}, \"7-8\": {}}}}")))) (multiple-value-bind (initial-rewiring l2p-components) - (quil::prog-initial-rewiring pp chip) + (cl-quil::prog-initial-rewiring pp chip) (multiple-value-bind (code initial final) - (quil::do-greedy-addressing - (make-instance quil::*default-addresser-state-class* + (cl-quil::do-greedy-addressing + (make-instance cl-quil::*default-addresser-state-class* :chip-spec chip :initial-l2p initial-rewiring :l2p-components l2p-components) (coerce (parsed-program-executable-code pp) 'list) :use-free-swaps t) (declare (ignore code)) - (is (every #'identity (quil::rewiring-l2p initial))) - (is (every #'identity (quil::rewiring-p2l initial))) - (is (every #'identity (quil::rewiring-l2p final))) - (is (every #'identity (quil::rewiring-p2l final))))))) + (is (every #'identity (cl-quil::rewiring-l2p initial))) + (is (every #'identity (cl-quil::rewiring-p2l initial))) + (is (every #'identity (cl-quil::rewiring-l2p final))) + (is (every #'identity (cl-quil::rewiring-p2l final))))))) (deftest test-pragma-preserve-block () (let* ((pp (parse-quil " @@ -524,10 +524,10 @@ H 0 PRAGMA END_PRESERVE_BLOCK MEASURE 1 "))) - (not-signals quil:not-protoquil (quil:check-protoquil-program valid-pp)) - (signals quil:not-protoquil (quil:check-protoquil-program invalid-pp-1in2)) - (signals quil:not-protoquil (quil:check-protoquil-program invalid-pp-1in3)) - (signals quil:not-protoquil (quil:check-protoquil-program invalid-pp-2in3)))) + (not-signals cl-quil:not-protoquil (cl-quil:check-protoquil-program valid-pp)) + (signals cl-quil:not-protoquil (cl-quil:check-protoquil-program invalid-pp-1in2)) + (signals cl-quil:not-protoquil (cl-quil:check-protoquil-program invalid-pp-1in3)) + (signals cl-quil:not-protoquil (cl-quil:check-protoquil-program invalid-pp-2in3)))) (deftest test-global-pragma-survives-compilation () "Test that a global pragma survives compilation." @@ -540,22 +540,22 @@ MEASURE 1 "X 1" "X 2" "X 3")) - (cp (quil:parsed-program-executable-code - (cl-quil::compiler-hook p (quil::build-8q-chip))))) - (is (= 1 (count-if (lambda (x) (typep x 'quil::pragma-initial-rewiring)) cp))) - (is (= 1 (count-if (lambda (x) (typep x 'quil::pragma-readout-povm)) cp))) - (is (= 2 (count-if (lambda (x) (typep x 'quil::pragma-add-kraus)) cp))))) + (cp (cl-quil:parsed-program-executable-code + (cl-quil::compiler-hook p (cl-quil::build-8q-chip))))) + (is (= 1 (count-if (lambda (x) (typep x 'cl-quil::pragma-initial-rewiring)) cp))) + (is (= 1 (count-if (lambda (x) (typep x 'cl-quil::pragma-readout-povm)) cp))) + (is (= 2 (count-if (lambda (x) (typep x 'cl-quil::pragma-add-kraus)) cp))))) (deftest test-clever-CCNOT-depth-reduction () "Test that the ':GREEDY-QUBIT swap selection strategy brings CZ depth down to optimal for CCNOT." - (let* ((quil::*default-addresser-state-class* 'quil::temporal-addresser-state) - (quil::*addresser-use-1q-queues* t) - (p (quil::compiler-hook (quil::parse-quil " + (let* ((cl-quil::*default-addresser-state-class* 'cl-quil::temporal-addresser-state) + (cl-quil::*addresser-use-1q-queues* t) + (p (cl-quil::compiler-hook (cl-quil::parse-quil " PRAGMA INITIAL_REWIRING \"GREEDY\" CCNOT 0 1 2") - (quil::build-8Q-chip))) - (ls (quil::make-lscheduler))) - (quil::append-instructions-to-lschedule ls (coerce (quil::parsed-program-executable-code p) + (cl-quil::build-8Q-chip))) + (ls (cl-quil::make-lscheduler))) + (cl-quil::append-instructions-to-lschedule ls (coerce (cl-quil::parsed-program-executable-code p) 'list)) (flet ((value-bumper (instr value) @@ -566,43 +566,43 @@ CCNOT 0 1 2") (string= "CZ" name)) (1+ value)) (t value)))) - (let ((CZ-depth (quil::lscheduler-walk-graph ls :bump-value #'value-bumper))) + (let ((CZ-depth (cl-quil::lscheduler-walk-graph ls :bump-value #'value-bumper))) (is (>= 7 CZ-depth)))))) (deftest test-resource-carving-basic () (let* ((chip (build-8Q-chip)) - (sched (quil::make-chip-schedule chip))) - (map nil (lambda (instr) (quil::chip-schedule-append sched instr)) - (list (quil::build-gate "CZ" () 0 1) - (quil::build-gate "CZ" () 2 3) - (quil::build-gate "CZ" () 1 2) - (quil::build-gate "CZ" () 0 3) - (quil::build-gate "RX" '(#.(/ pi 2)) 1))) + (sched (cl-quil::make-chip-schedule chip))) + (map nil (lambda (instr) (cl-quil::chip-schedule-append sched instr)) + (list (cl-quil::build-gate "CZ" () 0 1) + (cl-quil::build-gate "CZ" () 2 3) + (cl-quil::build-gate "CZ" () 1 2) + (cl-quil::build-gate "CZ" () 0 3) + (cl-quil::build-gate "RX" '(#.(/ pi 2)) 1))) (multiple-value-bind (order index obj) - (quil::lookup-hardware-address-by-qubits chip (list 1 2)) + (cl-quil::lookup-hardware-address-by-qubits chip (list 1 2)) (declare (ignore order index)) - (is (= (quil::hardware-object-native-instruction-p obj (quil::build-gate "CZ" () 1 2)) - (quil::chip-schedule-resource-carving-point sched (quil::make-qubit-resource 1 2))))))) + (is (= (cl-quil::hardware-object-native-instruction-p obj (cl-quil::build-gate "CZ" () 1 2)) + (cl-quil::chip-schedule-resource-carving-point sched (cl-quil::make-qubit-resource 1 2))))))) (deftest test-using-illegal-qubits-signals-error () - (let* ((chip (quil::build-nq-fully-connected-chip 4)) - (chip-hash (quil::chip-specification-to-qpu-hash-table chip))) + (let* ((chip (cl-quil::build-nq-fully-connected-chip 4)) + (chip-hash (cl-quil::chip-specification-to-qpu-hash-table chip))) (setf (gethash "dead" (gethash "2" (gethash "1Q" (gethash "isa" chip-hash)))) "true") - (let ((chip-bad (quil::qpu-hash-table-to-chip-specification chip-hash))) - (let ((good (quil::parse-quil "PRAGMA INITIAL_REWIRING \"PARTIAL\"; X 2")) + (let ((chip-bad (cl-quil::qpu-hash-table-to-chip-specification chip-hash))) + (let ((good (cl-quil::parse-quil "PRAGMA INITIAL_REWIRING \"PARTIAL\"; X 2")) (bad-naive (parse-quil "PRAGMA INITIAL_REWIRING \"NAIVE\"; X 2;")) (bad-naive-measure (parse-quil "PRAGMA INITIAL_REWIRING \"NAIVE\"; MEASURE 2;")) (bad-naive-reset (parse-quil "PRAGMA INITIAL_REWIRING \"NAIVE\"; RESET 2;")) (bad-preserve (parse-quil "PRAGMA PRESERVE_BLOCK; X 2; PRAGMA END_PRESERVE_BLOCK;")) (bad-preserve-measure (parse-quil "PRAGMA PRESERVE_BLOCK; MEASURE 2; PRAGMA END_PRESERVE_BLOCK;")) (bad-preserve-reset (parse-quil "PRAGMA PRESERVE_BLOCK; RESET 2; PRAGMA END_PRESERVE_BLOCK;"))) - (not-signals quil::illegal-qubits-used-error (compiler-hook good chip-bad)) - (signals quil::illegal-qubits-used-error (compiler-hook bad-naive chip-bad)) - (signals quil::illegal-qubits-used-error (compiler-hook bad-naive-measure chip-bad)) - (signals quil::illegal-qubits-used-error (compiler-hook bad-naive-reset chip-bad)) - (signals quil::illegal-qubits-used-in-preserved-block-error (compiler-hook bad-preserve chip-bad)) - (signals quil::illegal-qubits-used-in-preserved-block-error (compiler-hook bad-preserve-measure chip-bad)) - (signals quil::illegal-qubits-used-in-preserved-block-error (compiler-hook bad-preserve-reset chip-bad)))))) + (not-signals cl-quil::illegal-qubits-used-error (compiler-hook good chip-bad)) + (signals cl-quil::illegal-qubits-used-error (compiler-hook bad-naive chip-bad)) + (signals cl-quil::illegal-qubits-used-error (compiler-hook bad-naive-measure chip-bad)) + (signals cl-quil::illegal-qubits-used-error (compiler-hook bad-naive-reset chip-bad)) + (signals cl-quil::illegal-qubits-used-in-preserved-block-error (compiler-hook bad-preserve chip-bad)) + (signals cl-quil::illegal-qubits-used-in-preserved-block-error (compiler-hook bad-preserve-measure chip-bad)) + (signals cl-quil::illegal-qubits-used-in-preserved-block-error (compiler-hook bad-preserve-reset chip-bad)))))) (deftest test-compiler-accounts-for-readout-fidelity () "Test that the compiler includes readout fidelity when optimizing for program fidelity." @@ -613,12 +613,12 @@ CCNOT 0 1 2") ;; ;; Compiling an RZ on q0 should *not* produce a program using q1 because its ;; readout fidelity is so poor. - (let* ((chip (quil::read-chip-spec-file (asdf:system-relative-pathname ':cl-quil-tests "tests/qpu-test-files/readout-a.qpu"))) + (let* ((chip (cl-quil::read-chip-spec-file (asdf:system-relative-pathname ':cl-quil-tests "tests/qpu-test-files/readout-a.qpu"))) (program (parse "RZ(pi) 0; MEASURE 0")) (program-fidelity (program-fidelity program chip)) (compiled (compiler-hook program chip :rewiring-type ':partial)) (compiled-fidelity (program-fidelity compiled chip))) - (let* ((rz (quil::nth-instr 0 compiled)) + (let* ((rz (cl-quil::nth-instr 0 compiled)) (qubit (first (application-arguments rz)))) ;; Use q0 (is (= 0 (qubit-index qubit))) @@ -626,12 +626,12 @@ CCNOT 0 1 2") (is (>= compiled-fidelity program-fidelity)))) ;; Same chip as above, but with no MEASURE. Then we should use the qubit with ;; the best RZ (q1). - (let* ((chip (quil::read-chip-spec-file (asdf:system-relative-pathname ':cl-quil-tests "tests/qpu-test-files/readout-a.qpu"))) + (let* ((chip (cl-quil::read-chip-spec-file (asdf:system-relative-pathname ':cl-quil-tests "tests/qpu-test-files/readout-a.qpu"))) (program (parse "RZ(pi) 0")) (program-fidelity (program-fidelity program chip)) (compiled (compiler-hook program chip :rewiring-type ':partial)) (compiled-fidelity (program-fidelity compiled chip))) - (let* ((rz (quil::nth-instr 0 compiled)) + (let* ((rz (cl-quil::nth-instr 0 compiled)) (qubit (first (application-arguments rz)))) ;; Use q1 (is (= 1 (qubit-index qubit))) @@ -645,12 +645,12 @@ CCNOT 0 1 2") ;; ;; Compiling an RZ on q0 should produce a program using q1 because it has ;; great RZ and MEASURE fidelity. - (let* ((chip (quil::read-chip-spec-file (asdf:system-relative-pathname ':cl-quil-tests "tests/qpu-test-files/readout-b.qpu"))) + (let* ((chip (cl-quil::read-chip-spec-file (asdf:system-relative-pathname ':cl-quil-tests "tests/qpu-test-files/readout-b.qpu"))) (program (parse "RZ(pi) 0; MEASURE 0")) (program-fidelity (program-fidelity program chip)) (compiled (compiler-hook program chip :rewiring-type ':partial)) (compiled-fidelity (program-fidelity compiled chip))) - (let* ((rz (quil::nth-instr 0 compiled)) + (let* ((rz (cl-quil::nth-instr 0 compiled)) (qubit (first (application-arguments rz)))) ;; Use q1 (is (= 1 (qubit-index qubit))) diff --git a/tests/csd-tests.lisp b/tests/csd-tests.lisp index f082f3c52..ad9e26afc 100644 --- a/tests/csd-tests.lisp +++ b/tests/csd-tests.lisp @@ -4,7 +4,7 @@ (in-package #:cl-quil-tests) -(defun m= (a b &key (test #'quil::double=)) +(defun m= (a b &key (test #'cl-quil::double=)) "Returns T if matrices A and B are sufficiently close, NIL otherwise. The TEST function determines the tolerance for comparison." (flet ((norm-vec-inf (matrix) (reduce #'max (magicl::storage matrix) :key #'abs))) @@ -15,12 +15,12 @@ (deftest test-csd-2x1 () (let* ((m *csd-dim*) (n (floor m 2)) - (a (quil::random-unitary (list m m))) + (a (cl-quil::random-unitary (list m m))) (a3 (magicl:slice a (list 0 n) (list n m))) (a4 (magicl:slice a (list n n) (list m m))) - (id (quil::eye n))) + (id (cl-quil::eye n))) (multiple-value-bind (u1 u2 c s v2h) - (quil::csd-2x1 a3 a4) + (cl-quil::csd-2x1 a3 a4) (let ((u1h (magicl:conjugate-transpose u1)) (u2h (magicl:conjugate-transpose u2)) (v2 (magicl:conjugate-transpose v2h))) @@ -34,14 +34,14 @@ (deftest test-csd-equipartition () (let* ((m *csd-dim*) (n (/ m 2)) - (a (quil::random-unitary (list m m))) + (a (cl-quil::random-unitary (list m m))) (a1 (magicl:slice a '(0 0) (list n n))) (a2 (magicl:slice a (list n 0) (list m n))) (a3 (magicl:slice a (list 0 n) (list n m))) (a4 (magicl:slice a (list n n) (list m m))) - (id (quil::eye n))) + (id (cl-quil::eye n))) (multiple-value-bind (u1 u2 v1h v2h theta) - (quil::csd a n n) + (cl-quil::csd a n n) (let ((u1h (magicl:conjugate-transpose u1)) (u2h (magicl:conjugate-transpose u2)) (v1 (magicl:conjugate-transpose v1h)) @@ -50,8 +50,8 @@ (is (m= id (magicl:@ u2h u2))) (is (m= id (magicl:@ v1h v1))) (is (m= id (magicl:@ v2h v2))) - (let ((c (quil::from-diag (mapcar #'cos theta))) - (s (quil::from-diag (mapcar #'sin theta)))) + (let ((c (cl-quil::from-diag (mapcar #'cos theta))) + (s (cl-quil::from-diag (mapcar #'sin theta)))) (is (m= a1 (magicl:@ u1 c v1h))) (is (m= a2 (magicl:@ u2 s v1h))) (is (m= a3 (magicl:@ u1 (magicl:scale s -1) v2h))) @@ -60,15 +60,15 @@ (deftest test-csd-uneven-partition () (let* ((m *csd-dim*) (n 1) - (a (quil::random-unitary (list m m))) + (a (cl-quil::random-unitary (list m m))) (a1 (magicl:slice a '(0 0) (list n n))) (a2 (magicl:slice a (list n 0) (list m n))) (a3 (magicl:slice a (list 0 n) (list n m))) (a4 (magicl:slice a (list n n) (list m m))) - (id-n (quil::eye n)) - (id-m (quil::eye (- m n)))) + (id-n (cl-quil::eye n)) + (id-m (cl-quil::eye (- m n)))) (multiple-value-bind (u1 u2 v1h v2h theta) - (quil::csd a n n) + (cl-quil::csd a n n) (let ((c (cos (first theta))) (s (sin (first theta))) (u1h (magicl:conjugate-transpose u1)) @@ -80,12 +80,12 @@ (is (m= id-n (magicl:@ v1h v1))) (is (m= id-m (magicl:@ v2h v2))) (is (m= a1 (magicl:scale (magicl:@ u1 v1h) c))) - (let ((svec (let ((x (quil::zeros (list (1- m) 1)))) + (let ((svec (let ((x (cl-quil::zeros (list (1- m) 1)))) (setf (magicl:tref x (- m 2) 0) s) x))) (is (m= a2 (magicl:@ u2 svec v1h))) (is (m= a3 (magicl:@ u1 (magicl:conjugate-transpose (magicl:scale svec -1)) v2h)))) - (let ((cmat (let ((x (quil::eye (1- m)))) + (let ((cmat (let ((x (cl-quil::eye (1- m)))) (setf (magicl:tref x (- m 2) (- m 2)) c) x))) (is (m= a4 (magicl:@ u2 cmat v2h)))))))) diff --git a/tests/defcircuit-tests.lisp b/tests/defcircuit-tests.lisp index bf4bec1aa..4e9448bd3 100644 --- a/tests/defcircuit-tests.lisp +++ b/tests/defcircuit-tests.lisp @@ -7,23 +7,23 @@ (defun verify-h-cnot-code (code) (is (= 3 (length code))) (destructuring-bind (h cnot reset) (coerce code 'list) - (is (string= "H" (quil::application-operator-name h))) - (is (= 0 (quil:qubit-index (elt (quil:application-arguments h) 0)))) + (is (string= "H" (cl-quil::application-operator-name h))) + (is (= 0 (cl-quil:qubit-index (elt (cl-quil:application-arguments h) 0)))) - (is (string= "CNOT" (quil::application-operator-name cnot))) - (is (= 0 (quil:qubit-index (elt (quil:application-arguments cnot) 0)))) - (is (= 1 (quil:qubit-index (elt (quil:application-arguments cnot) 1)))) + (is (string= "CNOT" (cl-quil::application-operator-name cnot))) + (is (= 0 (cl-quil:qubit-index (elt (cl-quil:application-arguments cnot) 0)))) + (is (= 1 (cl-quil:qubit-index (elt (cl-quil:application-arguments cnot) 1)))) - (is (= 0 (quil::qubit-index (quil::reset-qubit-target reset)))))) + (is (= 0 (cl-quil::qubit-index (cl-quil::reset-qubit-target reset)))))) (defun verify-rx-code (code) (is (= 1 (length code))) (let ((rx (elt code 0))) - (is (string= "RX" (quil::application-operator-name rx))) - (is (= 1 (length (quil:application-parameters rx)))) - (is (= 1 (length (quil:application-arguments rx)))) - (is (= 0 (quil:qubit-index (elt (quil:application-arguments rx) 0)))) - (is (zerop (quil:constant-value (elt (quil:application-parameters rx) 0)))))) + (is (string= "RX" (cl-quil::application-operator-name rx))) + (is (= 1 (length (cl-quil:application-parameters rx)))) + (is (= 1 (length (cl-quil:application-arguments rx)))) + (is (= 0 (cl-quil:qubit-index (elt (cl-quil:application-arguments rx) 0)))) + (is (zerop (cl-quil:constant-value (elt (cl-quil:application-parameters rx) 0)))))) (deftest test-alias-defcircuit () "Test a simple parameter-less DEFCIRCUIT expansion." @@ -34,7 +34,7 @@ " RESET 0" "BELL" ))) - (verify-h-cnot-code (quil:parsed-program-executable-code p)))) + (verify-h-cnot-code (cl-quil:parsed-program-executable-code p)))) (deftest test-simple-defcircuit-with-arguments () "Test that arguments can be passed to DEFCIRCUIT." @@ -45,7 +45,7 @@ " RESET p" "BELL 0 1" ))) - (verify-h-cnot-code (quil:parsed-program-executable-code p)))) + (verify-h-cnot-code (cl-quil:parsed-program-executable-code p)))) (deftest test-simple-defcircuit-with-parameter () "Test that a parameter can be passed to a DEFCIRCUIT." @@ -54,7 +54,7 @@ " RX(%a) p" "ROT(0.0) 0" ))) - (verify-rx-code (quil:parsed-program-executable-code p)))) + (verify-rx-code (cl-quil:parsed-program-executable-code p)))) (deftest test-simple-defcircuit-with-simple-indirection () "Test that arguments can be passed from a DEFCIRCUIT to an inner one.." @@ -66,7 +66,7 @@ "DEFCIRCUIT INDIRECTION:" " BELL 0 1" "INDIRECTION"))) - (verify-h-cnot-code (quil:parsed-program-executable-code p)))) + (verify-h-cnot-code (cl-quil:parsed-program-executable-code p)))) (deftest test-simple-defcircuit-with-parameter-and-indirection () "Test that a parameter and argument can be passed from a parameter-less DEFCIRCUIT." @@ -76,7 +76,7 @@ "DEFCIRCUIT INDIRECTION:" " ROT(0.0) 0" "INDIRECTION"))) - (verify-rx-code (quil:parsed-program-executable-code p)))) + (verify-rx-code (cl-quil:parsed-program-executable-code p)))) (deftest test-simple-defcircuit-with-argument-passing () "Test that arguments get passed from outer DEFCIRCUITs to inner ones." @@ -88,7 +88,7 @@ "DEFCIRCUIT INDIRECTION r s:" " BELL s r" "INDIRECTION 1 0"))) - (verify-h-cnot-code (quil:parsed-program-executable-code p)))) + (verify-h-cnot-code (cl-quil:parsed-program-executable-code p)))) (deftest test-simple-defcircuit-with-parameter-passing () "Test that parameters get passed from outer DEFCIRCUITs to inner ones." @@ -98,7 +98,7 @@ "DEFCIRCUIT INDIRECTION(%b):" " ROT(%b) 0" "INDIRECTION(0.0)"))) - (verify-rx-code (quil:parsed-program-executable-code p)))) + (verify-rx-code (cl-quil:parsed-program-executable-code p)))) (deftest test-simple-defcircuit-with-mixed-parameter-passing () "Test that some parameters in a DEFCIRCUIT can be filled while others not." @@ -108,15 +108,15 @@ "DEFCIRCUIT INDIRECTION(%b):" " FOO(0.0, %b) 0" "INDIRECTION(1.0)"))) - (let ((code (quil:parsed-program-executable-code p))) + (let ((code (cl-quil:parsed-program-executable-code p))) (is (= 1 (length code))) (let ((rx (elt code 0))) - (is (string= "FOO" (quil::application-operator-name rx))) - (is (= 2 (length (quil:application-parameters rx)))) - (is (= 1 (length (quil:application-arguments rx)))) - (is (= 0 (quil:qubit-index (elt (quil:application-arguments rx) 0)))) - (is (zerop (quil:constant-value (elt (quil:application-parameters rx) 0)))) - (is (= 1 (quil:constant-value (elt (quil:application-parameters rx) 1)))))))) + (is (string= "FOO" (cl-quil::application-operator-name rx))) + (is (= 2 (length (cl-quil:application-parameters rx)))) + (is (= 1 (length (cl-quil:application-arguments rx)))) + (is (= 0 (cl-quil:qubit-index (elt (cl-quil:application-arguments rx) 0)))) + (is (zerop (cl-quil:constant-value (elt (cl-quil:application-parameters rx) 0)))) + (is (= 1 (cl-quil:constant-value (elt (cl-quil:application-parameters rx) 1)))))))) (deftest test-defcircuit-recursion-limit () "Test that unbounded recursion is detected." @@ -137,7 +137,7 @@ " LEVEL-2(%c - 1)" ;; 4 + (-2 * (3 - 1)) = 0 "LEVEL-3(3)"))) - (verify-rx-code (quil:parsed-program-executable-code p)))) + (verify-rx-code (cl-quil:parsed-program-executable-code p)))) (deftest test-chained-defcircuit-other-instructions () "Test recursive DEFCIRCUIT expansion with MEASUREs and JUMPs." @@ -157,7 +157,7 @@ " JUMP-UNLESS @start2 addr" " INNER(%p) qubit addr" "OUTER(0.0) 0 ro[0]"))) - (let ((code (quil:parsed-program-executable-code p))) + (let ((code (cl-quil:parsed-program-executable-code p))) (is (= 10 (length code))) (destructuring-bind (lbl1 meas-dis1 meas1 jw1 ju1 lbl2 meas-dis2 meas2 jw2 ju2) (coerce code 'list) @@ -187,14 +187,14 @@ " MOVE a b" " EXCHANGE b a" "CLASSICAL ro[0] ro[1]"))) - (let ((code (quil:parsed-program-executable-code p))) + (let ((code (cl-quil:parsed-program-executable-code p))) (is (= 5 (length code))) (destructuring-bind (not and ior move exchange) (coerce code 'list) - (is (typep not 'quil:classical-not)) - (is (typep and 'quil:classical-and)) - (is (typep ior 'quil:classical-inclusive-or)) - (is (typep move 'quil:classical-move)) - (is (typep exchange 'quil:classical-exchange)) + (is (typep not 'cl-quil:classical-not)) + (is (typep and 'cl-quil:classical-and)) + (is (typep ior 'cl-quil:classical-inclusive-or)) + (is (typep move 'cl-quil:classical-move)) + (is (typep exchange 'cl-quil:classical-exchange)) (is (= 0 (memory-ref-position (classical-target not)))) @@ -213,8 +213,8 @@ (deftest test-defcircuit-unique-labels () "Test that DEFCIRCUIT gets unique labels." (let* ((p (not-signals simple-error - (quil::transform - 'quil::patch-labels + (cl-quil::transform + 'cl-quil::patch-labels (with-output-to-quil "DECLARE ro BIT" "DEFCIRCUIT FOO:" @@ -224,7 +224,7 @@ " JUMP-UNLESS @INNER ro[0]" "FOO" "FOO")))) - (code (quil:parsed-program-executable-code p))) + (code (cl-quil:parsed-program-executable-code p))) (is (= 6 (length code))) (destructuring-bind (j1 jw1 ju1 j2 jw2 ju2) (coerce code 'list) (let ((label1 (jump-label j1)) @@ -242,10 +242,10 @@ " H 0" " CNOT 0 1" "DAGGER BELL")) - (code (quil:parsed-program-executable-code p))) + (code (cl-quil:parsed-program-executable-code p))) (destructuring-bind (instr-cnot instr-h) - (mapcar (a:compose #'quil::operator-description-string - #'quil:application-operator) + (mapcar (a:compose #'cl-quil::operator-description-string + #'cl-quil:application-operator) (coerce code 'list)) (is (string= "DAGGER CNOT" instr-cnot)) (is (string= "DAGGER H" instr-h)))) @@ -255,10 +255,10 @@ " X 0" "FOOBAR" "DAGGER FOOBAR")) - (code (quil:parsed-program-executable-code p))) + (code (cl-quil:parsed-program-executable-code p))) (destructuring-bind (instr-x instr-dagger-x) - (mapcar (a:compose #'quil::operator-description-string - #'quil:application-operator) + (mapcar (a:compose #'cl-quil::operator-description-string + #'cl-quil:application-operator) (coerce code 'list)) (is (string= "X" instr-x)) (is (string= "DAGGER X" instr-dagger-x))))) @@ -272,12 +272,12 @@ "DEFCIRCUIT B:" " DAGGER A" "DAGGER B")) - (code (quil:parsed-program-executable-code p))) + (code (cl-quil:parsed-program-executable-code p))) ;; Note that here the order of operations is reversed yet again, ;; so that the H 0 instruction is back on top. (destructuring-bind (instr-h instr-cnot) - (mapcar (a:compose #'quil::operator-description-string - #'quil:application-operator) + (mapcar (a:compose #'cl-quil::operator-description-string + #'cl-quil:application-operator) (coerce code 'list)) (is (string= "H" instr-h)) (is (string= "CNOT" instr-cnot))))) @@ -285,24 +285,24 @@ (deftest test-defcircuit-controlled () "Test application of CONTROLLED modifier on a circuit application." (signals simple-error - (quil:safely-parse-quil " + (cl-quil:safely-parse-quil " DEFCIRCUIT ZXZ q0 q1: Z q0; X q1; Z 2 CONTROLLED ZXZ")) (signals simple-error - (quil:safely-parse-quil " + (cl-quil:safely-parse-quil " DEFCIRCUIT ZXZ q0 q1: Z q0; X q1; Z 2 CONTROLLED ZXZ 2 0 1")) - (let ((a (quil:safely-parse-quil " + (let ((a (cl-quil:safely-parse-quil " DEFCIRCUIT ZX q0 q1: Z q0; X q1 CONTROLLED ZX 2 0 1")) - (b (quil:safely-parse-quil "CZ 2 0; CONTROLLED X 2 1"))) - (is (quil::matrix-equals-dwim (quil:parsed-program-to-logical-matrix a) - (quil:parsed-program-to-logical-matrix b))))) + (b (cl-quil:safely-parse-quil "CZ 2 0; CONTROLLED X 2 1"))) + (is (cl-quil::matrix-equals-dwim (cl-quil:parsed-program-to-logical-matrix a) + (cl-quil:parsed-program-to-logical-matrix b))))) diff --git a/tests/discrete/compilation-tests.lisp b/tests/discrete/compilation-tests.lisp index 4cf750687..e49fd4444 100644 --- a/tests/discrete/compilation-tests.lisp +++ b/tests/discrete/compilation-tests.lisp @@ -2,13 +2,13 @@ ;;;; ;;;; Author: A.J. Nyquist -(in-package #:cl-quil.discrete-tests) +(in-package #:cl-quil/discrete-tests) (deftest parse-tolerance () (cl-quil:parse-quil "PRAGMA TOLERANCE \"0.1234\"") - (is (<= (- cl-quil.discrete::*tolerance* 0.1234) 1d-16)) + (is (<= (- cl-quil/discrete::*tolerance* 0.1234) 1d-16)) (cl-quil:parse-quil "PRAGMA TOLERANCE \"2.0e-2\"") - (is (<= (- cl-quil.discrete::*tolerance* 2.0d-2) 1d-16)) + (is (<= (- cl-quil/discrete::*tolerance* 2.0d-2) 1d-16)) (signals type-error (cl-quil:parse-quil "PRAGMA TOLERANCE \"0\"")) (signals type-error @@ -19,5 +19,5 @@ ;; It at the very least assures it runs without errors. (q::compiler-hook (q:parse-quil "PRAGMA TOLERANCE \"1E-10\"; RZ(pi/3) 0") - (cl-quil.discrete:build-discrete-linear-chip + (cl-quil/discrete:build-discrete-linear-chip 1 :compile-fast t))) diff --git a/tests/discrete/package.lisp b/tests/discrete/package.lisp index 115b5d8b8..76b0b6054 100644 --- a/tests/discrete/package.lisp +++ b/tests/discrete/package.lisp @@ -2,30 +2,27 @@ ;;;; ;;;; Author: Robert Smith, A.J. Nyquist -(fiasco:define-test-package #:cl-quil.discrete-tests +(fiasco:define-test-package #:cl-quil/discrete-tests (:use #:cl - #:cl-quil.discrete - ) + #:cl-quil/discrete) (:local-nicknames - (#:q #:cl-quil) - ) + (#:q #:cl-quil)) + ;; suite.lisp (:export #:run-discrete-tests)) -(defpackage #:cl-quil.discrete-coalton-tests +(defpackage #:cl-quil/discrete-coalton-tests (:documentation "Tests for the Coalton componenents of clifford-t approx.") (:use #:coalton #:coalton-prelude #:coalton-testing #:coalton-library/math - #:cl-quil.discrete/numeric - #:cl-quil.discrete/operators - #:cl-quil.discrete/rz-approx - ) + #:cl-quil/discrete/numeric + #:cl-quil/discrete/operators + #:cl-quil/discrete/rz-approx) (:local-nicknames (#:list #:coalton-library/list) - (#:numeric #:cl-quil.discrete/numeric) - (#:operator #:cl-quil.discrete/operators) - (#:rz #:cl-quil.discrete/rz-approx) - )) + (#:numeric #:cl-quil/discrete/numeric) + (#:operator #:cl-quil/discrete/operators) + (#:rz #:cl-quil/discrete/rz-approx))) diff --git a/tests/discrete/rz-approx-tests.lisp b/tests/discrete/rz-approx-tests.lisp index c7fda2d81..74b575393 100644 --- a/tests/discrete/rz-approx-tests.lisp +++ b/tests/discrete/rz-approx-tests.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: A.J. Nyquist -(cl:in-package #:cl-quil.discrete-coalton-tests) +(cl:in-package #:cl-quil/discrete-coalton-tests) ;;; Tests solver found in src/discrete/rz-approx/ diff --git a/tests/discrete/suite.lisp b/tests/discrete/suite.lisp index 3fcc8657e..dcf9c074a 100644 --- a/tests/discrete/suite.lisp +++ b/tests/discrete/suite.lisp @@ -2,27 +2,27 @@ ;;;; ;;;; Author: Robert Smith -(in-package #:cl-quil.discrete-tests) +(in-package #:cl-quil/discrete-tests) (defun run-discrete-tests (&key (verbose nil) (headless nil)) "Run all CL-QUIL/DISCRETE tests. If VERBOSE is T, print out lots of test info. If HEADLESS is T, disable interactive debugging and quit on completion." ;; Bug in Fiasco commit fe89c0e924c22c667cc11c6fc6e79419fc7c1a8b (let ((fiasco::*test-run-standard-output* (make-broadcast-stream *standard-output*)) - (quil::*compress-carefully* t)) + (cl-quil::*compress-carefully* t)) (cond ((null headless) - (run-package-tests :package ':cl-quil.discrete-tests + (run-package-tests :package ':cl-quil/discrete-tests :verbose verbose :describe-failures t :interactive t)) (t - (let ((successp (run-package-tests :package ':cl-quil.discrete-tests + (let ((successp (run-package-tests :package ':cl-quil/discrete-tests :verbose t :describe-failures t :interactive nil))) (uiop:quit (if successp 0 1))))))) -(in-package #:cl-quil.discrete-coalton-tests) +(in-package #:cl-quil/discrete-coalton-tests) -(coalton-fiasco-init :cl-quil.discrete-tests) +(coalton-fiasco-init :cl-quil/discrete-tests) diff --git a/tests/discrete/tests.lisp b/tests/discrete/tests.lisp new file mode 100644 index 000000000..529438f06 --- /dev/null +++ b/tests/discrete/tests.lisp @@ -0,0 +1,9 @@ +;;;; tests/discrete/tests.lisp +;;;; +;;;; Author: + +(in-package #:cl-quil/discrete-tests) + +(deftest test-math () + (is (= 2 (+ 1 1)))) + diff --git a/tests/initial-rewiring-tests.lisp b/tests/initial-rewiring-tests.lisp index 299c757ef..ecf9a4fa7 100644 --- a/tests/initial-rewiring-tests.lisp +++ b/tests/initial-rewiring-tests.lisp @@ -5,36 +5,36 @@ (in-package #:cl-quil-tests) (deftest test-queue () - (let ((q (quil:make-queue))) - (is (quil:queue-empty-p q)) - (quil:enqueue q 1) - (is (not (quil:queue-empty-p q))) - (quil:enqueue q 2) - (quil:enqueue q 3) - (is (= 1 (quil:dequeue q))) - (is (= 2 (quil:dequeue q))) - (is (not (quil:queue-empty-p q))) - (quil:enqueue q 4) - (quil:enqueue q 5) - (is (= 3 (quil:dequeue q))) - (is (= 4 (quil:dequeue q))) - (is (= 5 (quil:dequeue q))) - (is (quil:queue-empty-p q)))) + (let ((q (cl-quil:make-queue))) + (is (cl-quil:queue-empty-p q)) + (cl-quil:enqueue q 1) + (is (not (cl-quil:queue-empty-p q))) + (cl-quil:enqueue q 2) + (cl-quil:enqueue q 3) + (is (= 1 (cl-quil:dequeue q))) + (is (= 2 (cl-quil:dequeue q))) + (is (not (cl-quil:queue-empty-p q))) + (cl-quil:enqueue q 4) + (cl-quil:enqueue q 5) + (is (= 3 (cl-quil:dequeue q))) + (is (= 4 (cl-quil:dequeue q))) + (is (= 5 (cl-quil:dequeue q))) + (is (cl-quil:queue-empty-p q)))) (deftest test-queue-make () - (let ((q (quil:make-queue))) - (quil:enqueue q 1) - (quil:enqueue q 2) - (quil:enqueue q 3) - (quil:enqueue q 4) - (is (not (quil:queue-empty-p q))) - (is (= 1 (quil:dequeue q))) - (is (= 2 (quil:dequeue q))) - (is (= 3 (quil:dequeue q))) - (quil:enqueue q 5) - (is (= 4 (quil:dequeue q))) - (is (= 5 (quil:dequeue q))) - (is (quil:queue-empty-p q)))) + (let ((q (cl-quil:make-queue))) + (cl-quil:enqueue q 1) + (cl-quil:enqueue q 2) + (cl-quil:enqueue q 3) + (cl-quil:enqueue q 4) + (is (not (cl-quil:queue-empty-p q))) + (is (= 1 (cl-quil:dequeue q))) + (is (= 2 (cl-quil:dequeue q))) + (is (= 3 (cl-quil:dequeue q))) + (cl-quil:enqueue q 5) + (is (= 4 (cl-quil:dequeue q))) + (is (= 5 (cl-quil:dequeue q))) + (is (cl-quil:queue-empty-p q)))) (deftest test-partial-rewiring-disconnected-components () "Test that partial rewiring behaves sensibly when presented with a @@ -44,28 +44,28 @@ Specifically, this is an issue then both PRAGMA INITIAL_REWIRING \"PARTIAL\" and PRAGMA EXPECTED_REWIRING are provided. See https://github.com/rigetti/quilc/pull/131 for colour." ;; This first case would cause an error due to the missing qubit 0. - (let ((progm (quil::parse-quil " + (let ((progm (cl-quil::parse-quil " PRAGMA INITIAL_REWIRING \"PARTIAL\" PRAGMA EXPECTED_REWIRING \"#(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)\" RX(pi) 1 PRAGMA CURRENT_REWIRING \"#(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)\" HALT ")) - (chip (quil::qpu-hash-table-to-chip-specification + (chip (cl-quil::qpu-hash-table-to-chip-specification (yason:parse "{\"isa\": {\"1Q\": {\"1\": {}, \"2\": {}, \"3\": {}}, \"2Q\": {\"1-2\": {}, \"2-3\": {}}}}")))) (not-signals error (compiler-hook progm chip))) ;; The second case would case an error due to the disconnected qubits 1 and 3 - (let ((progm (quil::parse-quil " + (let ((progm (cl-quil::parse-quil " PRAGMA INITIAL_REWIRING \"PARTIAL\" PRAGMA EXPECTED_REWIRING \"#(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)\" RX(pi) 1 PRAGMA CURRENT_REWIRING \"#(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)\" HALT ")) - (chip (quil::qpu-hash-table-to-chip-specification + (chip (cl-quil::qpu-hash-table-to-chip-specification (yason:parse "{\"isa\": {\"1Q\": {\"1\": {}, \"3\": {}}, @@ -73,19 +73,19 @@ HALT (not-signals error (compiler-hook progm chip))) ;; Just to be sure, let's test that a 2Q gate fails since the ;; largest connected component of the chip is length-1. - (let ((progm (quil::parse-quil " + (let ((progm (cl-quil::parse-quil " PRAGMA INITIAL_REWIRING \"PARTIAL\" PRAGMA EXPECTED_REWIRING \"#(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)\" CNOT 1 3 PRAGMA CURRENT_REWIRING \"#(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)\" HALT ")) - (chip (quil::qpu-hash-table-to-chip-specification + (chip (cl-quil::qpu-hash-table-to-chip-specification (yason:parse "{\"isa\": {\"1Q\": {\"1\": {}, \"3\": {}}, \"2Q\": {\"1-2\": {}, \"2-3\": {}}}}")))) - (signals quil::connected-components-incompatible (compiler-hook progm chip)))) + (signals cl-quil::connected-components-incompatible (compiler-hook progm chip)))) (deftest test-sohaib-gh-361-regression () "Regression test for github issue #361." @@ -131,41 +131,41 @@ HALT ;; Any PRAGMA INITIAL_REWIRING is respected. (dolist (init-rewiring '("NAIVE" "PARTIAL" "GREEDY" "RANDOM")) (is (eq (a:make-keyword init-rewiring) - (quil::prog-initial-rewiring-heuristic + (cl-quil::prog-initial-rewiring-heuristic (with-output-to-quil (format t "PRAGMA INITIAL_REWIRING ~S~%" init-rewiring) "X 0" "CZ 0 2" "CNOT 2 3") - (quil::build-nq-linear-chip 4))))) + (cl-quil::build-nq-linear-chip 4))))) (let ((pp-a (with-output-to-quil "X 0" "CZ 0 2" "CNOT 2 3")) (pp-b (with-output-to-quil "X 0" "CZ 1 2" "CNOT 2 3"))) - (dolist (quil::*initial-rewiring-default-type* '(:naive :partial :greedy :random)) + (dolist (cl-quil::*initial-rewiring-default-type* '(:naive :partial :greedy :random)) ;; Contains CZ on non-adjancent qubits: *INITIAL-REWIRING-DEFAULT-TYPE* - (is (eq quil::*initial-rewiring-default-type* - (quil::prog-initial-rewiring-heuristic pp-a (quil::build-nq-linear-chip 4)))) + (is (eq cl-quil::*initial-rewiring-default-type* + (cl-quil::prog-initial-rewiring-heuristic pp-a (cl-quil::build-nq-linear-chip 4)))) ;; Always :NAIVE for a fully-connected chip (is (eq ':naive - (quil::prog-initial-rewiring-heuristic pp-a (quil::build-nq-fully-connected-chip 4)))) + (cl-quil::prog-initial-rewiring-heuristic pp-a (cl-quil::build-nq-fully-connected-chip 4)))) ;; Always :NAIVE for PP-B on linear chip (is (eq ':naive - (quil::prog-initial-rewiring-heuristic pp-b (quil::build-nq-linear-chip 4)))))) + (cl-quil::prog-initial-rewiring-heuristic pp-b (cl-quil::build-nq-linear-chip 4)))))) ;; Test instructions operating on dead or non-existent qubit. (let ((pp-x (with-output-to-quil "X 0")) (pp-reset (with-output-to-quil "RESET 0")) (pp-measure (with-output-to-quil "DECLARE ro BIT" "MEASURE 0 ro")) (pp-r-and-m (with-output-to-quil "RESET" "DECLARE ro BIT" "MEASURE 0 ro")) - (chip-dead (quil::qpu-hash-table-to-chip-specification + (chip-dead (cl-quil::qpu-hash-table-to-chip-specification (yason:parse "{\"isa\": {\"1Q\": {\"0\": {\"dead\": \"true\"}, \"1\": {}}, \"2Q\": {}}}"))) - (chip-missing (quil::qpu-hash-table-to-chip-specification + (chip-missing (cl-quil::qpu-hash-table-to-chip-specification (yason:parse "{\"isa\": {\"1Q\": {\"1\": {}}}}")))) - (dolist (quil::*initial-rewiring-default-type* '(:naive :partial :greedy :random)) + (dolist (cl-quil::*initial-rewiring-default-type* '(:naive :partial :greedy :random)) (dolist (pp (list pp-x pp-reset pp-measure pp-r-and-m)) (dolist (chip (list chip-dead chip-missing)) - (is (eq quil::*initial-rewiring-default-type* - (quil::prog-initial-rewiring-heuristic pp chip)))))))) + (is (eq cl-quil::*initial-rewiring-default-type* + (cl-quil::prog-initial-rewiring-heuristic pp chip)))))))) diff --git a/tests/lexer-tests.lisp b/tests/lexer-tests.lisp index e2b84dbbb..5f6123e0a 100644 --- a/tests/lexer-tests.lisp +++ b/tests/lexer-tests.lisp @@ -79,7 +79,7 @@ "Test different combinations of lexical analysis." (declare (optimize (space 0) debug)) (loop :for (test-string . expected-types) :in *lexer-tests* - :for lexed := (cl-quil.frontend::tokenize-line #'cl-quil.frontend::line-lexer test-string) + :for lexed := (cl-quil/frontend::tokenize-line #'cl-quil/frontend::line-lexer test-string) :do (is (and (= (length expected-types) (length lexed)) (equal expected-types (mapcar #'token-type-or-newline lexed))) "Failed lex for ~S => ~A" diff --git a/tests/linear-reversible-circuit-tests.lisp b/tests/linear-reversible-circuit-tests.lisp index a07ce964d..964bdcfa0 100644 --- a/tests/linear-reversible-circuit-tests.lisp +++ b/tests/linear-reversible-circuit-tests.lisp @@ -30,7 +30,7 @@ (deftest test-linear-reversible-circuit-cnot-decomposition () (macrolet ((test (square-matrix) `(is (magicl:= (magicl:deep-copy-tensor ,square-matrix) - (quil::cnot-circuit-matrix (quil::cnot-synth! ,square-matrix) + (cl-quil::cnot-circuit-matrix (cl-quil::cnot-synth! ,square-matrix) (first (magicl:shape ,square-matrix))))))) (test *fig-2-matrix*) (test *fig-3-matrix*) diff --git a/tests/logical-matrix-sanity-tests.lisp b/tests/logical-matrix-sanity-tests.lisp index 002d435be..3e80e0fb4 100644 --- a/tests/logical-matrix-sanity-tests.lisp +++ b/tests/logical-matrix-sanity-tests.lisp @@ -20,22 +20,22 @@ (let* ((input (first testcase)) (entries (second testcase)) (n (length entries)) - (p (if (stringp input) (quil:parse-quil input) input)) - (actual (quil:parsed-program-to-logical-matrix p)) - (expected (quil::from-list (a:flatten entries) (list n n))) - (compiled (quil::matrix-rescale - (quil:parsed-program-to-logical-matrix - (quil:compiler-hook p (quil::build-nq-linear-chip - (quil:qubits-needed p)))) + (p (if (stringp input) (cl-quil:parse-quil input) input)) + (actual (cl-quil:parsed-program-to-logical-matrix p)) + (expected (cl-quil::from-list (a:flatten entries) (list n n))) + (compiled (cl-quil::matrix-rescale + (cl-quil:parsed-program-to-logical-matrix + (cl-quil:compiler-hook p (cl-quil::build-nq-linear-chip + (cl-quil:qubits-needed p)))) expected))) ;; FIASCO:IS always evaluates it's format arguments, even if the test assertion ;; succeeds. Formatting via MATRIX-MISMATCH-FMT will only compute the MATRIX-MISMATCH ;; when/if the associated test assertion actually fails. - (is (quil::matrix-equality actual expected) + (is (cl-quil::matrix-equality actual expected) "Checking input: ~S~%~/cl-quil-tests::matrix-mismatch-fmt/" input (list actual expected)) - (is (quil::operator= compiled expected) + (is (cl-quil::operator= compiled expected) "Checking compiled input: ~S~%~/cl-quil-tests::matrix-mismatch-fmt/" input (list compiled expected)))) @@ -43,19 +43,19 @@ ;; matching on them easier. Scroll down to the RY-gate tests to see where a,..,h are used. (let* ((i+ #C(0.0 1.0)) (i- #C(0.0 -1.0)) - (pi/6 (/ quil::pi 6)) + (pi/6 (/ cl-quil::pi 6)) (a+ (cos pi/6)) (b+ (sin pi/6)) (b- (- b+)) - (pi/12 (/ quil::pi 12)) + (pi/12 (/ cl-quil::pi 12)) (c+ (cos pi/12)) (d+ (sin pi/12)) (d- (- d+)) - (pi/16 (/ quil::pi 16)) + (pi/16 (/ cl-quil::pi 16)) (e+ (cos pi/16)) (f+ (sin pi/16)) (f- (- f+)) - (pi/20 (/ quil::pi 20)) + (pi/20 (/ cl-quil::pi 20)) (g+ (cos pi/20)) (h+ (sin pi/20)) (h- (- h+))) diff --git a/tests/misc-tests.lisp b/tests/misc-tests.lisp index 10ff4b62f..67216a19f 100644 --- a/tests/misc-tests.lisp +++ b/tests/misc-tests.lisp @@ -7,7 +7,7 @@ (deftest test-partition-sequence-into-segments () (flet ((test-it (expected-first expected-segments input-sequence) (multiple-value-bind (segments first?) - (cl-quil.frontend::partition-sequence-into-segments #'evenp input-sequence) + (cl-quil/frontend::partition-sequence-into-segments #'evenp input-sequence) (is (eq first? expected-first)) (is (equalp segments expected-segments))))) (test-it nil nil nil) @@ -22,17 +22,17 @@ (test-it t '((2) (1 1) (2 2 2) (1 1 1 1)) '(2 1 1 2 2 2 1 1 1 1)))) (deftest test-append-reduce () - (is (equal nil (quil::reduce-append nil))) - (is (equal nil (quil::reduce-append '(nil)))) - (is (equal nil (quil::reduce-append '(nil nil)))) - (is (equal '(a) (quil::reduce-append '(nil (a))))) - (is (equal '(a) (quil::reduce-append '((a) nil)))) - (is (equal '(a) (quil::reduce-append '((a) nil nil)))) - (is (equal '(a) (quil::reduce-append '(nil (a) nil)))) - (is (equal '(a) (quil::reduce-append '(nil nil (a))))) - (is (equal '(a b c) (quil::reduce-append '((a) nil (b) nil (c))))) - (is (equal '(a b c d) (quil::reduce-append '((a) (b c) nil (d))))) - (is (equal '(a b c d e f) (quil::reduce-append '((a) (b c) nil (d) (e f)))))) + (is (equal nil (cl-quil::reduce-append nil))) + (is (equal nil (cl-quil::reduce-append '(nil)))) + (is (equal nil (cl-quil::reduce-append '(nil nil)))) + (is (equal '(a) (cl-quil::reduce-append '(nil (a))))) + (is (equal '(a) (cl-quil::reduce-append '((a) nil)))) + (is (equal '(a) (cl-quil::reduce-append '((a) nil nil)))) + (is (equal '(a) (cl-quil::reduce-append '(nil (a) nil)))) + (is (equal '(a) (cl-quil::reduce-append '(nil nil (a))))) + (is (equal '(a b c) (cl-quil::reduce-append '((a) nil (b) nil (c))))) + (is (equal '(a b c d) (cl-quil::reduce-append '((a) (b c) nil (d))))) + (is (equal '(a b c d e f) (cl-quil::reduce-append '((a) (b c) nil (d) (e f)))))) (deftest test-big-defgate () (let* ((qubit-count 8) @@ -49,11 +49,11 @@ (format s ", "))) (format s "~%")) (format s "TEST ~{~D ~}" (a:iota qubit-count)))) - (parsed-prog (quil::parse-quil program-string))) - (is (quil::matrix-equality (quil::eye (expt 2 qubit-count)) - (quil::make-matrix-from-quil (coerce (parsed-program-executable-code parsed-prog) 'list)))))) + (parsed-prog (cl-quil::parse-quil program-string))) + (is (cl-quil::matrix-equality (cl-quil::eye (expt 2 qubit-count)) + (cl-quil::make-matrix-from-quil (coerce (parsed-program-executable-code parsed-prog) 'list)))))) -(defclass transformable-thing (quil::transformable) +(defclass transformable-thing (cl-quil::transformable) ((data :initarg :data :accessor data @@ -63,64 +63,64 @@ (setf (data thing) (mapcar (lambda (x) (* x x)) (data thing))) thing) -(quil::define-transform identity (identity)) +(cl-quil::define-transform identity (identity)) -(quil::define-transform double-data (double-data) +(cl-quil::define-transform double-data (double-data) "Double the data values in a thing." identity) (deftest test-transform-predecessor-checking () "Test that omitting a predecessor tranform signals an error." - (let ((transform (quil::find-transform 'double-data))) + (let ((transform (cl-quil::find-transform 'double-data))) (is (not (null transform))) - (is (member 'identity (quil::transform-description-predecessors transform)))) + (is (member 'identity (cl-quil::transform-description-predecessors transform)))) (signals unsatisfied-transform-dependency (let ((thing (make-instance 'transformable-thing))) ;; IDENTITY is a prerequisite transform but not ;; performed. - (setf thing (quil::transform 'double-data thing)) - (values thing (quil::transforms-performed thing))))) + (setf thing (cl-quil::transform 'double-data thing)) + (values thing (cl-quil::transforms-performed thing))))) (deftest test-peephole-splicing () (let ((code '(a b c d e)) (new '(x y))) (is (equalp '(x y c d e) - (quil::splice-instructions code '(a b) new 0))) + (cl-quil::splice-instructions code '(a b) new 0))) ;; Position is relative to the original code, not the output (is (equalp '(x y c d e) - (quil::splice-instructions code '(a b) new 1))) + (cl-quil::splice-instructions code '(a b) new 1))) (is (equalp '(x y c d e) - (quil::splice-instructions code '(a b) new 2))) + (cl-quil::splice-instructions code '(a b) new 2))) (is (equalp '(c x y d e) - (quil::splice-instructions code '(a b) new 3))) + (cl-quil::splice-instructions code '(a b) new 3))) (is (equalp '(c d x y e) - (quil::splice-instructions code '(a b) new 4))) + (cl-quil::splice-instructions code '(a b) new 4))) (is (equalp '(c d e x y) - (quil::splice-instructions code '(a b) new 5))) + (cl-quil::splice-instructions code '(a b) new 5))) ;; Position 6 is off the end of the original (signals simple-error - (quil::splice-instructions code '(a b) new 6)) + (cl-quil::splice-instructions code '(a b) new 6)) ;; (B A) is out of order (signals simple-error - (quil::splice-instructions code '(b a) new 0)) + (cl-quil::splice-instructions code '(b a) new 0)) ;; (J K) aren't in the original (signals simple-error - (quil::splice-instructions code '(j k) new 0)))) + (cl-quil::splice-instructions code '(j k) new 0)))) (deftest test-mref-equality () "Test MEMORY-REF equality and hash table creation." (let ((a0 (mref "a" 0)) (a0* (mref "a" 0)) - (a0! (mref "a" 0 (quil::make-memory-descriptor :name "hello" :type quil::quil-real))) + (a0! (mref "a" 0 (cl-quil::make-memory-descriptor :name "hello" :type cl-quil::quil-real))) (b0 (mref "b" 0)) (a1 (mref "a" 1))) - (is (quil::memory-ref= a0 a0)) - (is (quil::memory-ref= a0 a0*)) - (is (quil::memory-ref= a0 a0!)) - (is (not (quil::memory-ref= a0 a1))) - (is (not (quil::memory-ref= a0 b0))) - (let ((T-A-B-L-E (make-hash-table :test 'quil::memory-ref= - :hash-function 'quil::memory-ref-hash))) + (is (cl-quil::memory-ref= a0 a0)) + (is (cl-quil::memory-ref= a0 a0*)) + (is (cl-quil::memory-ref= a0 a0!)) + (is (not (cl-quil::memory-ref= a0 a1))) + (is (not (cl-quil::memory-ref= a0 b0))) + (let ((T-A-B-L-E (make-hash-table :test 'cl-quil::memory-ref= + :hash-function 'cl-quil::memory-ref-hash))) (setf (gethash a0 T-A-B-L-E) t (gethash a0* T-A-B-L-E) t (gethash a0! T-A-B-L-E) t @@ -136,72 +136,72 @@ (deftest test-power-of-two-p () "Test that POWER-OF-TWO-P and POSITIVE-POWER-OF-TWO-P do what they say on the tin." - (is (not (quil::power-of-two-p -2))) - (is (not (quil::power-of-two-p -1))) - (is (not (quil::power-of-two-p 0))) - (is (not (quil::positive-power-of-two-p -2))) - (is (not (quil::positive-power-of-two-p -1))) - (is (not (quil::positive-power-of-two-p 0))) + (is (not (cl-quil::power-of-two-p -2))) + (is (not (cl-quil::power-of-two-p -1))) + (is (not (cl-quil::power-of-two-p 0))) + (is (not (cl-quil::positive-power-of-two-p -2))) + (is (not (cl-quil::positive-power-of-two-p -1))) + (is (not (cl-quil::positive-power-of-two-p 0))) - (is (quil::power-of-two-p 1)) - (is (not (quil::positive-power-of-two-p 1))) + (is (cl-quil::power-of-two-p 1)) + (is (not (cl-quil::positive-power-of-two-p 1))) (loop :for power-of-two = 2 :then (* 2 power-of-two) :while (<= power-of-two 1024) :do (progn - (is (quil::power-of-two-p power-of-two)) - (is (not (quil::power-of-two-p (1+ power-of-two)))) - (is (quil::positive-power-of-two-p power-of-two)) - (is (not (quil::positive-power-of-two-p (1+ power-of-two))))))) + (is (cl-quil::power-of-two-p power-of-two)) + (is (not (cl-quil::power-of-two-p (1+ power-of-two)))) + (is (cl-quil::positive-power-of-two-p power-of-two)) + (is (not (cl-quil::positive-power-of-two-p (1+ power-of-two))))))) (deftest test-check-permutation () "Test that CHECK-PERMUTATION signals error iff input is not valid." ;; Duplicates - (signals simple-error (cl-quil.frontend::check-permutation '(0 0))) - (signals simple-error (cl-quil.frontend::check-permutation '(0 0 1))) - (signals simple-error (cl-quil.frontend::check-permutation '(0 1 0))) - (signals simple-error (cl-quil.frontend::check-permutation '(1 0 0))) - (signals simple-error (cl-quil.frontend::check-permutation '(0 1 2 3 4 5 2))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 0))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 0 1))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 1 0))) + (signals simple-error (cl-quil/frontend::check-permutation '(1 0 0))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 1 2 3 4 5 2))) ;; Out of range values - (signals simple-error (cl-quil.frontend::check-permutation '(1))) - (signals simple-error (cl-quil.frontend::check-permutation '(-1))) - (signals simple-error (cl-quil.frontend::check-permutation '(0 2))) - (signals simple-error (cl-quil.frontend::check-permutation '(2 0))) - (signals simple-error (cl-quil.frontend::check-permutation '(0 1 3))) - (signals simple-error (cl-quil.frontend::check-permutation '(0 3 1))) - (signals simple-error (cl-quil.frontend::check-permutation '(3 1 0))) - (signals simple-error (cl-quil.frontend::check-permutation '(0 1 2 5 3))) + (signals simple-error (cl-quil/frontend::check-permutation '(1))) + (signals simple-error (cl-quil/frontend::check-permutation '(-1))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 2))) + (signals simple-error (cl-quil/frontend::check-permutation '(2 0))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 1 3))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 3 1))) + (signals simple-error (cl-quil/frontend::check-permutation '(3 1 0))) + (signals simple-error (cl-quil/frontend::check-permutation '(0 1 2 5 3))) ;; Valid permutations. Grows as n!, so don't get too crazy here. (dotimes (n 6) (a:map-permutations (lambda (permutation) - (not-signals simple-error (cl-quil.frontend::check-permutation permutation))) + (not-signals simple-error (cl-quil/frontend::check-permutation permutation))) (a:iota n)))) (deftest test-quil<->lisp-bridge () "Test that the functions for mapping between quil<->lisp work." - (loop :for (quil-string . lisp-symbol) :in cl-quil.frontend::+quil<->lisp-prefix-arithmetic-operators+ :do + (loop :for (quil-string . lisp-symbol) :in cl-quil/frontend::+quil<->lisp-prefix-arithmetic-operators+ :do (progn - (is (cl-quil.frontend::valid-quil-function-or-operator-p lisp-symbol)) - (is (eq lisp-symbol (cl-quil.frontend::quil-prefix-operator->lisp-symbol quil-string))) - (is (string= quil-string (cl-quil.frontend::lisp-symbol->quil-prefix-operator lisp-symbol))) - (is (string= quil-string (cl-quil.frontend::lisp-symbol->quil-function-or-prefix-operator lisp-symbol))))) + (is (cl-quil/frontend::valid-quil-function-or-operator-p lisp-symbol)) + (is (eq lisp-symbol (cl-quil/frontend::quil-prefix-operator->lisp-symbol quil-string))) + (is (string= quil-string (cl-quil/frontend::lisp-symbol->quil-prefix-operator lisp-symbol))) + (is (string= quil-string (cl-quil/frontend::lisp-symbol->quil-function-or-prefix-operator lisp-symbol))))) - (loop :for (quil-string . lisp-symbol) :in cl-quil.frontend::+quil<->lisp-infix-arithmetic-operators+ :do + (loop :for (quil-string . lisp-symbol) :in cl-quil/frontend::+quil<->lisp-infix-arithmetic-operators+ :do (progn - (is (cl-quil.frontend::valid-quil-function-or-operator-p lisp-symbol)) - (is (eq lisp-symbol (cl-quil.frontend::quil-infix-operator->lisp-symbol quil-string))) - (is (string= quil-string (cl-quil.frontend::lisp-symbol->quil-infix-operator lisp-symbol))))) + (is (cl-quil/frontend::valid-quil-function-or-operator-p lisp-symbol)) + (is (eq lisp-symbol (cl-quil/frontend::quil-infix-operator->lisp-symbol quil-string))) + (is (string= quil-string (cl-quil/frontend::lisp-symbol->quil-infix-operator lisp-symbol))))) - (loop :for (quil-string . lisp-symbol) :in cl-quil.frontend::+quil<->lisp-functions+ :do + (loop :for (quil-string . lisp-symbol) :in cl-quil/frontend::+quil<->lisp-functions+ :do (progn - (is (cl-quil.frontend::valid-quil-function-or-operator-p lisp-symbol)) - (is (eq lisp-symbol (cl-quil.frontend::quil-function->lisp-symbol quil-string))) - (is (string= quil-string (cl-quil.frontend::lisp-symbol->quil-function lisp-symbol))) - (is (string= quil-string (cl-quil.frontend::lisp-symbol->quil-function-or-prefix-operator lisp-symbol)))))) + (is (cl-quil/frontend::valid-quil-function-or-operator-p lisp-symbol)) + (is (eq lisp-symbol (cl-quil/frontend::quil-function->lisp-symbol quil-string))) + (is (string= quil-string (cl-quil/frontend::lisp-symbol->quil-function lisp-symbol))) + (is (string= quil-string (cl-quil/frontend::lisp-symbol->quil-function-or-prefix-operator lisp-symbol)))))) (deftest test-nth-instr () - (dolist (pp (list (quil:parse-quil "") + (dolist (pp (list (cl-quil:parse-quil "") (with-output-to-quil "RESET") (with-output-to-quil @@ -214,64 +214,64 @@ (let* ((code (parsed-program-executable-code pp)) (length (length code))) ;; Index out-of-bounds checks - (signals error (quil::nth-instr length pp :from-end nil)) - (signals error (quil::nth-instr length pp :from-end t)) - (signals error (quil::nth-instr -1 pp :from-end nil)) - (signals error (quil::nth-instr -1 pp :from-end t)) + (signals error (cl-quil::nth-instr length pp :from-end nil)) + (signals error (cl-quil::nth-instr length pp :from-end t)) + (signals error (cl-quil::nth-instr -1 pp :from-end nil)) + (signals error (cl-quil::nth-instr -1 pp :from-end t)) ;; Test all valid indices (dotimes (i length) - (is (eq (quil::nth-instr i pp) (aref code i))) - (is (eq (quil::nth-instr (- length i 1) pp :from-end t) (aref code i))) - (let ((no-op1 (make-instance 'quil::no-operation)) - (no-op2 (make-instance 'quil::no-operation))) + (is (eq (cl-quil::nth-instr i pp) (aref code i))) + (is (eq (cl-quil::nth-instr (- length i 1) pp :from-end t) (aref code i))) + (let ((no-op1 (make-instance 'cl-quil::no-operation)) + (no-op2 (make-instance 'cl-quil::no-operation))) ;; These two SETFs set the same location, hence the need for two distinct no-op ;; instructions to compare against. - (setf (quil::nth-instr i pp) no-op1) + (setf (cl-quil::nth-instr i pp) no-op1) (is (eq no-op1 (aref code i))) - (setf (quil::nth-instr (- length i 1) pp :from-end t) no-op2) + (setf (cl-quil::nth-instr (- length i 1) pp :from-end t) no-op2) (is (eq no-op2 (aref code i)))))))) (deftest test-make-rewiring-from-string () - (signals error (quil::make-rewiring-from-string "")) - (signals error (quil::make-rewiring-from-string "foobar")) - (signals error (quil::make-rewiring-from-string "(0 1 2)")) - (signals error (quil::make-rewiring-from-string "#(0 1 2")) - (signals error (quil::make-rewiring-from-string "#(1)")) - (signals error (quil::make-rewiring-from-string "#(0 3 2)")) - (signals error (quil::make-rewiring-pair-from-string "")) - (signals error (quil::make-rewiring-pair-from-string "()")) - (signals error (quil::make-rewiring-pair-from-string "(1 . 2)")) - (signals error (quil::make-rewiring-pair-from-string "(#(0 . #())")) - (signals error (quil::make-rewiring-pair-from-string "(#(0) . #())")) - (signals error (quil::make-rewiring-pair-from-string "( #(0) . #(0) )")) - (signals error (quil::make-rewiring-pair-from-string "(#(0) #(0))")) - (signals error (quil::make-rewiring-pair-from-string "#(0) #(0)")) + (signals error (cl-quil::make-rewiring-from-string "")) + (signals error (cl-quil::make-rewiring-from-string "foobar")) + (signals error (cl-quil::make-rewiring-from-string "(0 1 2)")) + (signals error (cl-quil::make-rewiring-from-string "#(0 1 2")) + (signals error (cl-quil::make-rewiring-from-string "#(1)")) + (signals error (cl-quil::make-rewiring-from-string "#(0 3 2)")) + (signals error (cl-quil::make-rewiring-pair-from-string "")) + (signals error (cl-quil::make-rewiring-pair-from-string "()")) + (signals error (cl-quil::make-rewiring-pair-from-string "(1 . 2)")) + (signals error (cl-quil::make-rewiring-pair-from-string "(#(0 . #())")) + (signals error (cl-quil::make-rewiring-pair-from-string "(#(0) . #())")) + (signals error (cl-quil::make-rewiring-pair-from-string "( #(0) . #(0) )")) + (signals error (cl-quil::make-rewiring-pair-from-string "(#(0) #(0))")) + (signals error (cl-quil::make-rewiring-pair-from-string "#(0) #(0)")) (dolist (input '("#()" "#(0)" "#(0 1 2)" "#(2 1 0)" "#(1 0 3 4 2 5 6)")) - (is (equalp (quil::rewiring-l2p (quil::make-rewiring-from-string input)) + (is (equalp (cl-quil::rewiring-l2p (cl-quil::make-rewiring-from-string input)) (read-from-string input)))) (dolist (input '("(#() . #())" "(#(0) . #(0))" "(#(0 2 1 4 3) . #(3 2 0 1 4))")) (multiple-value-bind (actual-first-rewiring actual-second-rewiring) - (quil::make-rewiring-pair-from-string input) + (cl-quil::make-rewiring-pair-from-string input) (destructuring-bind (expected-first-rewiring . expected-second-rewiring) (read-from-string input) - (is (equalp (quil::rewiring-l2p actual-first-rewiring) expected-first-rewiring)) - (is (equalp (quil::rewiring-l2p actual-second-rewiring) expected-second-rewiring)))))) + (is (equalp (cl-quil::rewiring-l2p actual-first-rewiring) expected-first-rewiring)) + (is (equalp (cl-quil::rewiring-l2p actual-second-rewiring) expected-second-rewiring)))))) (deftest test-extract-final-exit-rewiring-vector () - (is (null (quil::extract-final-exit-rewiring-vector (quil:parse-quil "")))) + (is (null (cl-quil::extract-final-exit-rewiring-vector (cl-quil:parse-quil "")))) ;; test that the *final* rewiring is extracted (let ((pp (with-output-to-quil "RESET" "MEASURE 0"))) - (setf (quil::comment (quil::nth-instr 0 pp)) - (quil::make-rewiring-comment :exiting #(0 1 2))) - (setf (quil::comment (quil::nth-instr 1 pp)) - (quil::make-rewiring-comment :exiting #(1 0 2))) - (is (equalp #(1 0 2) (quil::extract-final-exit-rewiring-vector pp)))) + (setf (cl-quil::comment (cl-quil::nth-instr 0 pp)) + (cl-quil::make-rewiring-comment :exiting #(0 1 2))) + (setf (cl-quil::comment (cl-quil::nth-instr 1 pp)) + (cl-quil::make-rewiring-comment :exiting #(1 0 2))) + (is (equalp #(1 0 2) (cl-quil::extract-final-exit-rewiring-vector pp)))) ;; Each test in the loop should allocate to a fresh PARSED-PROGRAM; otherwise, comments attached ;; earlier in the loop persist for later tests. @@ -279,19 +279,19 @@ (format nil "RESET~%MEASURE 0") (format nil "RESET~%MEASURE 0~%HALT"))) ;; no rewirings - (is (null (quil::extract-final-exit-rewiring-vector (quil:parse-quil quil)))) + (is (null (cl-quil::extract-final-exit-rewiring-vector (cl-quil:parse-quil quil)))) ;; only enter rewiring - (is (null (quil::extract-final-exit-rewiring-vector - (attach-rewirings-to-program (quil:parse-quil quil) #(0 1 2) nil)))) + (is (null (cl-quil::extract-final-exit-rewiring-vector + (attach-rewirings-to-program (cl-quil:parse-quil quil) #(0 1 2) nil)))) ;; only exit rewiring - (is (equalp #(2 1 0) (quil::extract-final-exit-rewiring-vector - (attach-rewirings-to-program (quil:parse-quil quil) nil #(2 1 0))))) + (is (equalp #(2 1 0) (cl-quil::extract-final-exit-rewiring-vector + (attach-rewirings-to-program (cl-quil:parse-quil quil) nil #(2 1 0))))) ;; both enter and exiting rewirings - (is (equalp #(2 1 0) (quil::extract-final-exit-rewiring-vector - (attach-rewirings-to-program (quil:parse-quil quil) #(0 1 2) #(2 1 0))))))) + (is (equalp #(2 1 0) (cl-quil::extract-final-exit-rewiring-vector + (attach-rewirings-to-program (cl-quil:parse-quil quil) #(0 1 2) #(2 1 0))))))) (defun %make-density-qvm-initialized-in-basis (num-qubits basis-index) "Make a DENSITY-QVM that is initialized in the basis state described by BASIS-INDEX. @@ -329,19 +329,19 @@ To put the density matrix into the basis state, e.g., |01><11|, we would choose ;; - ecp (defun %test-measure-semantics (p-str) (let* ((p (parse-quil p-str)) - (p-comp (quil:compiler-hook (parse-quil p-str) (quil::build-nq-linear-chip 3) :protoquil nil)) - (rewiring (cl-quil.frontend::qubit-relabeler (quil::extract-final-exit-rewiring-vector p-comp)))) + (p-comp (cl-quil:compiler-hook (parse-quil p-str) (cl-quil::build-nq-linear-chip 3) :protoquil nil)) + (rewiring (cl-quil/frontend::qubit-relabeler (cl-quil::extract-final-exit-rewiring-vector p-comp)))) (loop :for i :below (expt 2 6) :do (let* ((qvm (%make-density-qvm-initialized-in-basis 3 i)) (qvm-comp (%make-density-qvm-initialized-in-basis 3 i))) (qvm:load-program qvm p :supersede-memory-subsystem t) ;; relabeling is a side-effect - (map nil (a:rcurry #'cl-quil.frontend::%relabel-qubits rewiring) + (map nil (a:rcurry #'cl-quil/frontend::%relabel-qubits rewiring) (parsed-program-executable-code p-comp)) (qvm:load-program qvm-comp p-comp :supersede-memory-subsystem t) (qvm:run qvm) (qvm:run qvm-comp) - (is (every #'quil::double= + (is (every #'cl-quil::double= (qvm::amplitudes qvm) (qvm::amplitudes qvm-comp))))))) @@ -356,11 +356,11 @@ To put the density matrix into the basis state, e.g., |01><11|, we would choose ((word->program (word) (let ((code (make-array (+ len n) :fill-pointer 0)) (orig-code (coerce (parsed-program-executable-code p) 'list)) - (new-prog (quil:copy-instance p))) + (new-prog (cl-quil:copy-instance p))) (loop :for char :across word :do (vector-push (if (zerop char) (pop orig-code) - (make-instance 'quil:measure-discard :qubit (quil:qubit (1- char)))) + (make-instance 'cl-quil:measure-discard :qubit (cl-quil:qubit (1- char)))) code)) (setf (parsed-program-executable-code new-prog) code) new-prog))) @@ -374,7 +374,7 @@ To put the density matrix into the basis state, e.g., |01><11|, we would choose (map-measure-combinations (lambda (p) (%test-measure-semantics (with-output-to-string (s) - (quil::print-parsed-program p s)))) + (cl-quil::print-parsed-program p s)))) (parse-quil "RX(pi/3) 0 CNOT 0 2 RX(7*pi/3) 2") diff --git a/tests/package.lisp b/tests/package.lisp index e2ed5cd05..2ffc43f2a 100644 --- a/tests/package.lisp +++ b/tests/package.lisp @@ -2,15 +2,10 @@ ;;;; ;;;; Author: Robert Smith -;;; Allegro (and other Lisps) don't support the non-standard "package -;;; local nicknames". -#-(or sbcl ecl ccl) -(rename-package :alexandria :alexandria '(:a)) - (fiasco:define-test-package #:cl-quil-tests - #+(or sbcl ecl ccl) - (:local-nicknames (:a :alexandria)) - (:use #:cl-quil #:cl-quil.clifford) + (:local-nicknames (#:a #:alexandria) + (#:quil #:cl-quil)) + (:use #:cl-quil #:cl-quil/clifford) ;; suite.lisp (:export diff --git a/tests/parser-tests.lisp b/tests/parser-tests.lisp index c7ad0ee66..f4c41a52b 100644 --- a/tests/parser-tests.lisp +++ b/tests/parser-tests.lisp @@ -27,26 +27,26 @@ (dolist (file (uiop:directory-files *bad-test-file-directory* #P"*.quil")) (format t "~& Testing bad file ~A~%" (pathname-name file)) (let ((cl-quil:*allow-unresolved-applications* t)) - (signals quil:quil-parse-error + (signals cl-quil:quil-parse-error (handler-case (cl-quil:read-quil-file file) ;; Re-signal all of the following errors as ;; QUIL-PARSE-ERRORs. - (quil:quil-type-error (c) + (cl-quil:quil-type-error (c) (declare (ignore c)) - (error 'quil:quil-parse-error)) + (error 'cl-quil:quil-parse-error)) (yacc:yacc-parse-error (c) (declare (ignore c)) - (error 'quil:quil-parse-error)) + (error 'cl-quil:quil-parse-error)) (alexa:lexer-match-error (c) (declare (ignore c)) - (error 'quil:quil-parse-error))))))) + (error 'cl-quil:quil-parse-error))))))) (deftest test-semicolon-parsing () (let ((pp1 (parse-quil "H 0 ; X 1")) (pp2 (parse-quil "DEFCIRCUIT foo: X 0 ; H 0"))) (is (= 2 (length (parsed-program-executable-code pp1)))) - (is (= 2 (length (quil::circuit-definition-body + (is (= 2 (length (cl-quil::circuit-definition-body (first (parsed-program-circuit-definitions pp2)))))))) (deftest test-pragma-parsing () @@ -85,40 +85,40 @@ ;; first pragma (let ((instr (aref code 0))) - (is (typep instr 'quil::pragma-expected-rewiring)) - (is (and (typep (quil::pragma-rewiring instr) 'quil::rewiring)))) + (is (typep instr 'cl-quil::pragma-expected-rewiring)) + (is (and (typep (cl-quil::pragma-rewiring instr) 'cl-quil::rewiring)))) ;; second pragma (let ((instr (aref code 1))) - (is (typep instr 'quil::pragma-readout-povm)) - (is (typep (quil::pragma-qubit-index instr) 'integer)) - (is (and (typep (quil::pragma-matrix-entries instr) 'list) + (is (typep instr 'cl-quil::pragma-readout-povm)) + (is (typep (cl-quil::pragma-qubit-index instr) 'integer)) + (is (and (typep (cl-quil::pragma-matrix-entries instr) 'list) (every (lambda (e) (typep e 'double-float)) - (quil::pragma-matrix-entries instr))))) + (cl-quil::pragma-matrix-entries instr))))) ;; third pragma (let ((instr (aref code 2))) - (is (typep instr 'quil::pragma-add-kraus)) - (is (typep (quil::pragma-operator-name instr) 'string)) - (is (and (typep (quil::pragma-qubit-arguments instr) 'list) - (every #'integerp (quil::pragma-qubit-arguments instr)))) - (is (and (typep (quil::pragma-matrix-entries instr) 'list) + (is (typep instr 'cl-quil::pragma-add-kraus)) + (is (typep (cl-quil::pragma-operator-name instr) 'string)) + (is (and (typep (cl-quil::pragma-qubit-arguments instr) 'list) + (every #'integerp (cl-quil::pragma-qubit-arguments instr)))) + (is (and (typep (cl-quil::pragma-matrix-entries instr) 'list) (every (lambda (e) (typep e '(complex double-float))) - (quil::pragma-matrix-entries instr))))) + (cl-quil::pragma-matrix-entries instr))))) ;; fourth pragma (let ((instr (aref code 3))) - (is (typep instr 'quil::pragma-add-kraus)) - (is (typep (quil::pragma-operator-name instr) 'string)) - (is (and (typep (quil::pragma-qubit-arguments instr) 'list) - (every #'integerp (quil::pragma-qubit-arguments instr)))) - (is (and (typep (quil::pragma-matrix-entries instr) 'list) + (is (typep instr 'cl-quil::pragma-add-kraus)) + (is (typep (cl-quil::pragma-operator-name instr) 'string)) + (is (and (typep (cl-quil::pragma-qubit-arguments instr) 'list) + (every #'integerp (cl-quil::pragma-qubit-arguments instr)))) + (is (and (typep (cl-quil::pragma-matrix-entries instr) 'list) (every (lambda (e) (typep e '(complex double-float))) - (quil::pragma-matrix-entries instr))))))) + (cl-quil::pragma-matrix-entries instr))))))) (deftest test-parse-element-list () (let* ((element-list "(1 2.0 3.0e3 4.0i 5+6i 7+8.0i 9.0E-10i -i i pi -pi)") - (parsed-list (cl-quil.frontend::parse-element-list element-list 11))) + (parsed-list (cl-quil/frontend::parse-element-list element-list 11))) (is (equalp parsed-list (list @@ -156,7 +156,7 @@ TEST 0") (quil-parsed (not-signals quil-parse-error (parse-quil quil)))) (let ((gates (parsed-program-gate-definitions quil-parsed))) (is (= 1 (length gates))) - (is (typep (first gates) 'quil::static-gate-definition))))) + (is (typep (first gates) 'cl-quil::static-gate-definition))))) (deftest test-defgate-as-permutation () (let ((quil " @@ -169,10 +169,10 @@ DEFGATE TEST AS PERMUTATION: 0, 1, 2, 3, 4, 5, 7, 6, 8 TEST 0 1 2")) - (let* ((quil-parsed (not-signals quil-parse-error (quil::parse-quil quil))) + (let* ((quil-parsed (not-signals quil-parse-error (cl-quil::parse-quil quil))) (gates (parsed-program-gate-definitions quil-parsed))) (is (= 1 (length gates))) - (is (typep (first gates) 'quil::permutation-gate-definition))) + (is (typep (first gates) 'cl-quil::permutation-gate-definition))) (signals quil-parse-error (parse-quil quil-bad)))) (deftest test-parsing-process-include () @@ -220,7 +220,7 @@ DEFGATE FOO(%a): DEFCIRCUIT FOO(%a) q: X q ")) - (signals quil::ambiguous-definition-condition + (signals cl-quil::ambiguous-definition-condition (parse-quil test-quil :ambiguous-definition-handler #'identity)))) (deftest test-parsing-multiple-includes-good () @@ -378,7 +378,7 @@ DEFGATE FOO(%a) q AS PAULI-SUM: (deftest test-split-lines (&optional verbose) (loop :for (tokens expect) :in *test-cases-for-split-lines* :as actual ; split-lines mutates list structure, so copy list - := (cl-quil.frontend::split-lines (copy-list tokens)) + := (cl-quil/frontend::split-lines (copy-list tokens)) :as i :from 1 :do (when verbose (let ((*print-circle* nil)) ; don't print #1#, say diff --git a/tests/permutation-tests.lisp b/tests/permutation-tests.lisp index e8887463c..b952eabd5 100644 --- a/tests/permutation-tests.lisp +++ b/tests/permutation-tests.lisp @@ -18,17 +18,17 @@ (nreverse (coerce (a:iota n) 'vector))) (defun permutation-synthesis-as-parsed-program (permutation) - (make-instance 'quil::parsed-program - :executable-code (coerce (quil::synthesize-permutation + (make-instance 'cl-quil::parsed-program + :executable-code (coerce (cl-quil::synthesize-permutation permutation - (qubits-in-computational-order (cl-quil.frontend::ilog2 (length permutation)))) + (qubits-in-computational-order (cl-quil/frontend::ilog2 (length permutation)))) 'vector))) ;;; Test that the synthesized permutation when simulated performs the ;;; action of the permutation. (defun synthesize-and-check-permutation (permutation) - (quil::operator= - (quil:parsed-program-to-logical-matrix + (cl-quil::operator= + (cl-quil:parsed-program-to-logical-matrix (permutation-synthesis-as-parsed-program permutation) :compress-qubits nil) (matrix-from-permutation permutation))) @@ -60,19 +60,19 @@ internal-time-units-per-second)))) (deftest test-perm-compilation-gh805 () - (let* ((chip (quil::build-nq-linear-chip 3 :architecture ':cnot)) - (orig-prog (quil::parse-quil " + (let* ((chip (cl-quil::build-nq-linear-chip 3 :architecture ':cnot)) + (orig-prog (cl-quil::parse-quil " DEFGATE PERM AS PERMUTATION: 5, 1, 2, 6, 7, 0, 4, 3 X 0 PERM 0 1 2 ")) - (orig-matrix (quil:parsed-program-to-logical-matrix orig-prog)) - (proc-prog (quil::compiler-hook orig-prog chip)) - (proc-matrix (quil:parsed-program-to-logical-matrix proc-prog)) + (orig-matrix (cl-quil:parsed-program-to-logical-matrix orig-prog)) + (proc-prog (cl-quil::compiler-hook orig-prog chip)) + (proc-matrix (cl-quil:parsed-program-to-logical-matrix proc-prog)) (2q-code (program-2q-instructions proc-prog))) - (is (quil::matrix-equals-dwim orig-matrix proc-matrix)) + (is (cl-quil::matrix-equals-dwim orig-matrix proc-matrix)) (is (every (link-nativep chip) 2q-code)))) (deftest test-random-3q-perm-compilations () @@ -85,16 +85,16 @@ X 0 PERM 0 1 2 " perm))) - (let ((chip (quil::build-nq-linear-chip 3 :architecture ':cnot)) + (let ((chip (cl-quil::build-nq-linear-chip 3 :architecture ':cnot)) (*print-pretty* nil)) (loop :repeat 16 :do (let* ((perm (alexandria:shuffle (alexandria:iota 8))) - (orig-prog (quil::parse-quil (perm->prog perm))) - (orig-matrix (quil:parsed-program-to-logical-matrix orig-prog)) - (proc-prog (quil::compiler-hook orig-prog chip)) - (proc-matrix (quil:parsed-program-to-logical-matrix proc-prog)) + (orig-prog (cl-quil::parse-quil (perm->prog perm))) + (orig-matrix (cl-quil:parsed-program-to-logical-matrix orig-prog)) + (proc-prog (cl-quil::compiler-hook orig-prog chip)) + (proc-matrix (cl-quil:parsed-program-to-logical-matrix proc-prog)) (2q-code (program-2q-instructions proc-prog))) (format t " Testing compiling perm ~A...~%" perm) - (is (quil::matrix-equals-dwim orig-matrix proc-matrix)) + (is (cl-quil::matrix-equals-dwim orig-matrix proc-matrix)) (is (every (link-nativep chip) 2q-code))))))) diff --git a/tests/printer-tests.lisp b/tests/printer-tests.lisp index 3f54662dd..2be66d1fe 100644 --- a/tests/printer-tests.lisp +++ b/tests/printer-tests.lisp @@ -19,8 +19,8 @@ "Path to directory containing golden files whose expected output sections must be compared via regex.") (defun parse-and-print-quil-to-string (input - &key (parser #'quil:parse-quil) - (printer #'quil::print-parsed-program)) + &key (parser #'cl-quil:parse-quil) + (printer #'cl-quil::print-parsed-program)) (with-output-to-string (s) (funcall printer (funcall parser input) s))) @@ -49,7 +49,7 @@ See the documentation string for UPDATE-GOLDEN-FILE-OUTPUT-SECTIONS for more inf ;; This SETF is ugly, but guarding this in a NOT-SIGNALS aids debugging in case ;; PARSE-AND-PRINT-QUIL-TO-STRING chokes on INPUT. (not-signals error (setf actual-output (parse-and-print-quil-to-string input))) - (not-signals error (quil:parse-quil actual-output)) + (not-signals error (cl-quil:parse-quil actual-output)) (is (funcall check-output expected-output actual-output) golden-error-message) ;; Ensure expected-output is a fixed point of parse -> print. In rare cases, this check @@ -80,7 +80,7 @@ See the documentation string for UPDATE-GOLDEN-FILE-OUTPUT-SECTIONS for more inf (deftest test-instruction-fmt () (is (string= "PRAGMA gate_time CNOT \"50 ns\"" (format nil "~/cl-quil:instruction-fmt/" - (make-instance 'quil::pragma + (make-instance 'cl-quil::pragma :words '("gate_time" "CNOT") :freeform-string "50 ns")))) ;; try a operand-free instruction @@ -88,11 +88,11 @@ See the documentation string for UPDATE-GOLDEN-FILE-OUTPUT-SECTIONS for more inf ;; try a unary instruction (is (string= "NEG ro[3]" (format nil "~/cl-quil:instruction-fmt/" - (make-instance 'quil::classical-negate + (make-instance 'cl-quil::classical-negate :target (mref "ro" 3))))) ;; try a binary instruction (is (string= "MEASURE 1 ro[3]" (format nil "~/cl-quil:instruction-fmt/" - (make-instance 'quil::measure + (make-instance 'cl-quil::measure :address (mref "ro" 3) :qubit (qubit 1))))) ;; try something fancy @@ -117,7 +117,7 @@ See the documentation string for UPDATE-GOLDEN-FILE-OUTPUT-SECTIONS for more inf R 0")) (let ((after (parse-and-print-quil-to-string before))) - (not-signals error (quil::parse-quil after))))) + (not-signals error (cl-quil::parse-quil after))))) (deftest test-circuit-and-declare-printing () ;; This test relies on not applying the EXPAND-CIRCUITS transform, @@ -132,26 +132,26 @@ DEFCIRCUIT TEST(%a) b c: TEST(0.5) 0 1 ") (after (parse-and-print-quil-to-string before :parser (lambda (string) - (quil::parse-quil string :transforms nil))))) + (cl-quil::parse-quil string :transforms nil))))) (is (string= before after)))) (deftest test-jump-to-integer-label-printing () "Ensure that JUMP instructions with integer LABELs are printed correctly." - (is (string= (quil::print-instruction-to-string - (quil::make-instance 'quil::unconditional-jump :label 42)) + (is (string= (cl-quil::print-instruction-to-string + (cl-quil::make-instance 'cl-quil::unconditional-jump :label 42)) "JUMP {absolute address 42}")) - (is (string= (quil::print-instruction-to-string - (quil::make-instance 'quil::jump-when :label 0 :address (quil::mref "ro" 0))) + (is (string= (cl-quil::print-instruction-to-string + (cl-quil::make-instance 'cl-quil::jump-when :label 0 :address (cl-quil::mref "ro" 0))) "JUMP-WHEN {absolute address 0} ro[0]")) - (is (string= (quil::print-instruction-to-string - (quil::make-instance 'quil::jump-unless :label 1 :address (quil::mref "ro" 2))) + (is (string= (cl-quil::print-instruction-to-string + (cl-quil::make-instance 'cl-quil::jump-unless :label 1 :address (cl-quil::mref "ro" 2))) "JUMP-UNLESS {absolute address 1} ro[2]"))) (defun %check-format-single (test-function format-control input expected-output &key print-fractional-radians print-polar-form) - (let ((quil::*print-fractional-radians* print-fractional-radians) - (quil::*print-polar-form* print-polar-form)) + (let ((cl-quil::*print-fractional-radians* print-fractional-radians) + (cl-quil::*print-polar-form* print-polar-form)) (is (funcall test-function expected-output (format nil format-control input))))) (defun %check-format (test-function format-control testcases @@ -188,8 +188,8 @@ Used as a helper function in TEST-REAL-FMT." (42.42 . "42.42") (42.42d0 . "42.42") (#C(4.2 0) . "4.2")))) - (%check-format #'string= "~/quil:complex-fmt/" simple-cases :print-polar-form t) - (%check-format #'string= "~/quil:complex-fmt/" simple-cases :print-polar-form nil)) + (%check-format #'string= "~/cl-quil:complex-fmt/" simple-cases :print-polar-form t) + (%check-format #'string= "~/cl-quil:complex-fmt/" simple-cases :print-polar-form nil)) ;; Test some cases with non-zero IMAGPART with *PRINT-POLAR-FORM* = NIL. (let ((complex-cases '((#C(0.0 1.0) . "1.0i") @@ -198,20 +198,20 @@ Used as a helper function in TEST-REAL-FMT." (#C(-1.0 -1.0) . "-1.0-1.0i") (#C(42.42 123.45) . "42.42+123.45i") (#C(42.42d0 123.45d0) . "42.42+123.45i")))) - (%check-format #'string= "~/quil:complex-fmt/" complex-cases + (%check-format #'string= "~/cl-quil:complex-fmt/" complex-cases :print-polar-form nil :print-fractional-radians t) - (%check-format #'string= "~/quil:complex-fmt/" complex-cases + (%check-format #'string= "~/cl-quil:complex-fmt/" complex-cases :print-polar-form nil :print-fractional-radians nil)) ;; Test *PRINT-POLAR-FORM* = T and *PRINT-FRACTIONAL-RADIANS* = T. (%check-format #'string= - "~/quil:complex-fmt/" + "~/cl-quil:complex-fmt/" `((#C(0.0 1.0) . "1.0∠pi/2") (#C(0.0 -1.0) . "1.0∠3*pi/2") - (,(cis quil::pi) . "1.0∠pi") - (,(cis (- quil::pi)) . "1.0∠pi") - (,(cis (/ quil::pi 2)) . "1.0∠pi/2") - (,(cis (/ quil::pi 4)) . "1.0∠pi/4")) + (,(cis cl-quil::pi) . "1.0∠pi") + (,(cis (- cl-quil::pi)) . "1.0∠pi") + (,(cis (/ cl-quil::pi 2)) . "1.0∠pi/2") + (,(cis (/ cl-quil::pi 4)) . "1.0∠pi/4")) :print-polar-form t :print-fractional-radians t)) @@ -234,23 +234,23 @@ Used as a helper function in TEST-REAL-FMT." (1234.1234 . "1234.1234") #-allegro (2e10 . "20000000000.0") ))) - (%check-format #'string= "~/quil:real-fmt/" simple-cases :print-fractional-radians t) - (%check-format #'string= "~/quil:real-fmt/" simple-cases :print-fractional-radians nil)) + (%check-format #'string= "~/cl-quil:real-fmt/" simple-cases :print-fractional-radians t) + (%check-format #'string= "~/cl-quil:real-fmt/" simple-cases :print-fractional-radians nil)) ;; Test *PRINT-FRACTIONAL-RADIANS* = NIL. (%check-format #'uiop:string-prefix-p - "~/quil:real-fmt/" - `((,(- quil::pi) . "-3.1415") - (,quil::pi . "3.1415") - (,(* (- 1) (/ quil::pi 2)) . "-1.5707") - (,(* (- 3) (/ quil::pi 2)) . "-4.7123") - (,(* (- 1) (/ quil::pi 3)) . "-1.0471") - (,(* 1 (/ quil::pi 4)) . "0.7853") - (,(* 5 (/ quil::pi 6)) . "2.6179")) + "~/cl-quil:real-fmt/" + `((,(- cl-quil::pi) . "-3.1415") + (,cl-quil::pi . "3.1415") + (,(* (- 1) (/ cl-quil::pi 2)) . "-1.5707") + (,(* (- 3) (/ cl-quil::pi 2)) . "-4.7123") + (,(* (- 1) (/ cl-quil::pi 3)) . "-1.0471") + (,(* 1 (/ cl-quil::pi 4)) . "0.7853") + (,(* 5 (/ cl-quil::pi 6)) . "2.6179")) :print-fractional-radians nil) ;; Test *PRINT-FRACTIONAL-RADIANS* = T. - (let ((loose-threshold quil::+double-comparison-threshold-loose+) + (let ((loose-threshold cl-quil::+double-comparison-threshold-loose+) ;; fudge-factor of 20x because numerical analysis is hard (let's go shopping) (epsilon (* 20 double-float-epsilon))) (flet ((in-bounds- (r) @@ -262,9 +262,9 @@ Used as a helper function in TEST-REAL-FMT." (out-of-bounds+ (r) (+ r loose-threshold epsilon)) (check (pred r expected) - (%check-format-single pred "~/quil:real-fmt/" r expected :print-fractional-radians t))) - (loop :for rr :across cl-quil.frontend::**reasonable-rationals** - :for rr-pi := (* rr quil::pi) + (%check-format-single pred "~/cl-quil:real-fmt/" r expected :print-fractional-radians t))) + (loop :for rr :across cl-quil/frontend::**reasonable-rationals** + :for rr-pi := (* rr cl-quil::pi) :for minus-rr-pi := (- rr-pi) :for rr-pi-expected := (%pprint-rational-as-pi-multiple rr) :for minus-rr-pi-expected := (concatenate 'string "-" rr-pi-expected) :do diff --git a/tests/qasm-tests.lisp b/tests/qasm-tests.lisp index 03bb2765f..d8b830c55 100644 --- a/tests/qasm-tests.lisp +++ b/tests/qasm-tests.lisp @@ -16,32 +16,32 @@ "tests/qasm-files/qelib1.inc")) (deftest test-qasm-openqasm () - (is (quil.qasm::parse-qasm "OPENQASM 2.0"))) + (is (cl-quil/qasm::parse-qasm "OPENQASM 2.0"))) (deftest test-qasm-creg/qreg-declaration () (let* ((qasm "creg c1[1]; creg c2[1]; qreg q[1]; measure q[0] -> c1[0]; measure q[0] -> c2[0];") - (quil (quil.qasm::parse-qasm qasm)) - (mems (quil:parsed-program-memory-definitions quil)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (mems (cl-quil:parsed-program-memory-definitions quil)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 2 (length mems))) (is (= 2 (length code))) ;; Can't guarantee the ordering of the memory regions, so gotta ;; look up the region by name. - (let* ((mem (find "c1" mems :key #'quil:memory-descriptor-name :test #'equalp)) + (let* ((mem (find "c1" mems :key #'cl-quil:memory-descriptor-name :test #'equalp)) (cod (elt code 0)) - (des (quil::memory-ref-descriptor (quil:measure-address cod)))) + (des (cl-quil::memory-ref-descriptor (cl-quil:measure-address cod)))) (is (not (null mem))) - (is (eql quil::quil-bit (quil:memory-descriptor-type mem))) - (is (= 1 (quil:memory-descriptor-length mem))) + (is (eql cl-quil::quil-bit (cl-quil:memory-descriptor-type mem))) + (is (= 1 (cl-quil:memory-descriptor-length mem))) (is (equalp mem des))) ;; c2 - (let* ((mem (find "c2" mems :key #'quil:memory-descriptor-name :test #'equalp)) + (let* ((mem (find "c2" mems :key #'cl-quil:memory-descriptor-name :test #'equalp)) (cod (elt code 1)) - (des (quil::memory-ref-descriptor (quil:measure-address cod)))) + (des (cl-quil::memory-ref-descriptor (cl-quil:measure-address cod)))) (is (not (null mem))) - (is (eql quil::quil-bit (quil:memory-descriptor-type mem))) - (is (= 1 (quil:memory-descriptor-length mem))) + (is (eql cl-quil::quil-bit (cl-quil:memory-descriptor-type mem))) + (is (= 1 (cl-quil:memory-descriptor-length mem))) (is (equalp mem des))))) (deftest test-qasm-include () @@ -49,70 +49,70 @@ (format stream "creg c[1]; qreg q[2]; measure q[1] -> c[0];") (force-output stream) (let* ((qasm (format nil "include \"~A\";" path)) - (quil (quil.qasm::parse-qasm qasm)) - (mems (quil:parsed-program-memory-definitions quil)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (mems (cl-quil:parsed-program-memory-definitions quil)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 1 (length mems))) - (is (find "c" mems :key #'quil:memory-descriptor-name :test #'equalp)) - (is (typep (elt code 0) 'quil:measure))))) + (is (find "c" mems :key #'cl-quil:memory-descriptor-name :test #'equalp)) + (is (typep (elt code 0) 'cl-quil:measure))))) (deftest test-qasm-gate-definition-and-application () (let* ((qasm (format nil "include ~S; qreg a[2]; qreg b[2]; gate bell q, r { h q; cx q, r; }; bell a[0], b[1];" (namestring *qasm-qelib.inc-path*))) - (quil (quil.qasm::parse-qasm qasm)) - (circ (quil:parsed-program-circuit-definitions quil)) - (bell (find (quil.qasm::%qasm-gate-name "bell") + (quil (cl-quil/qasm::parse-qasm qasm)) + (circ (cl-quil:parsed-program-circuit-definitions quil)) + (bell (find (cl-quil/qasm::%qasm-gate-name "bell") circ - :key #'quil:circuit-definition-name + :key #'cl-quil:circuit-definition-name :test #'string=))) (is bell) - (is (= 2 (length (quil:circuit-definition-body bell)))) - (is (quil::matrix-equals-dwim - (quil:parsed-program-to-logical-matrix quil) - (quil:parsed-program-to-logical-matrix - (quil:parse-quil "H 0; CNOT 0 3;")))))) + (is (= 2 (length (cl-quil:circuit-definition-body bell)))) + (is (cl-quil::matrix-equals-dwim + (cl-quil:parsed-program-to-logical-matrix quil) + (cl-quil:parsed-program-to-logical-matrix + (cl-quil:parse-quil "H 0; CNOT 0 3;")))))) (deftest test-qasm-gate-definition-and-application-on-qreg () (let* ((qasm (format nil "include ~S; qreg a[2]; qreg b[2]; gate bell q, r { h q; cx q, r; }; bell a, b;" (namestring *qasm-qelib.inc-path*))) - (quil (quil.qasm::parse-qasm qasm)) - (circ (quil:parsed-program-circuit-definitions quil)) - (bell (find (quil.qasm::%qasm-gate-name "bell") + (quil (cl-quil/qasm::parse-qasm qasm)) + (circ (cl-quil:parsed-program-circuit-definitions quil)) + (bell (find (cl-quil/qasm::%qasm-gate-name "bell") circ - :key #'quil:circuit-definition-name + :key #'cl-quil:circuit-definition-name :test #'string=))) (is bell) - (is (= 2 (length (quil:circuit-definition-body bell)))) - (is (quil::matrix-equals-dwim - (quil:parsed-program-to-logical-matrix quil) - (quil:parsed-program-to-logical-matrix - (quil:parse-quil "H 0; CNOT 0 2; H 1; CNOT 1 3;")))))) + (is (= 2 (length (cl-quil:circuit-definition-body bell)))) + (is (cl-quil::matrix-equals-dwim + (cl-quil:parsed-program-to-logical-matrix quil) + (cl-quil:parsed-program-to-logical-matrix + (cl-quil:parse-quil "H 0; CNOT 0 2; H 1; CNOT 1 3;")))))) (deftest test-qasm-opaque-gate-definition-and-application () ;; opaque definitions and applications produce pragmas, rather than ;; a circuit definition + application. (let* ((qasm "qreg q[2]; opaque gate bell q, r; bell q[0], q[1];") - (quil (quil.qasm::parse-qasm qasm)) - (circ (quil:parsed-program-circuit-definitions quil)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (circ (cl-quil:parsed-program-circuit-definitions quil)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 0 (length circ))) (is (= 2 (length code))) (map nil (lambda (a b) - (is (typep a 'quil:pragma)) - (is (equal (quil:pragma-words a) - (quil:pragma-words b))) - (is (equal (quil:pragma-freeform-string a) - (quil:pragma-freeform-string a)))) + (is (typep a 'cl-quil:pragma)) + (is (equal (cl-quil:pragma-words a) + (cl-quil:pragma-words b))) + (is (equal (cl-quil:pragma-freeform-string a) + (cl-quil:pragma-freeform-string a)))) code - (list (quil:make-pragma '("QASM_OPAQUE_DEFINITION" "bell") "() q, r") - (quil:make-pragma '("QASM_OPAQUE_APPLICATION" "bell") "() 0, 1"))))) + (list (cl-quil:make-pragma '("QASM_OPAQUE_DEFINITION" "bell") "() q, r") + (cl-quil:make-pragma '("QASM_OPAQUE_APPLICATION" "bell") "() 0, 1"))))) (deftest test-qasm-comment () ;; Comments are stripped. (let* ((qasm "// hi qreg q[2]; CX q[0], q[1]; // bye") - (quil (quil.qasm::parse-qasm qasm)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 1 (length code))))) (deftest test-qasm-single-qubit-u () @@ -120,148 +120,148 @@ qreg q[2]; CX q[0], q[1]; // bye") (dolist (qasm (list "qreg q[1]; U(0, 0, 1.0) q[0];" (format nil "include ~S; qreg q[1]; u1(1.0) q[0];" (namestring *qasm-qelib.inc-path*)))) - (let* ((quil (quil.qasm::parse-qasm qasm)) - (code (quil:parsed-program-executable-code quil))) + (let* ((quil (cl-quil/qasm::parse-qasm qasm)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 3 (length code))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 0)))) - (is (= 1 (quil:constant-value (first (quil:application-parameters (elt code 0)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 0)))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 0)))) + (is (= 1 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 0)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 0)))))) - (is (equal "RY" (quil::application-operator-root-name (elt code 1)))) - (is (= 0 (quil:constant-value (first (quil:application-parameters (elt code 1)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 1)))))) + (is (equal "RY" (cl-quil::application-operator-root-name (elt code 1)))) + (is (= 0 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 1)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 1)))))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 2)))) - (is (= 0 (quil:constant-value (first (quil:application-parameters (elt code 2)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 2)))))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 2)))) + (is (= 0 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 2)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 2)))))))) ;; u2(phi, lambda) = U(pi/2, phi, lambda) (dolist (qasm (list "qreg q[1]; U(pi/2, 0.5, 1) q[0];" (format nil "include ~S; qreg q[1]; u2(0.5, 1) q[0];" (namestring *qasm-qelib.inc-path*)))) - (let* ((quil (quil.qasm::parse-qasm qasm)) - (code (quil:parsed-program-executable-code quil))) + (let* ((quil (cl-quil/qasm::parse-qasm qasm)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 3 (length code))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 0)))) - (is (= 1 (quil:constant-value (first (quil:application-parameters (elt code 0)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 0)))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 0)))) + (is (= 1 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 0)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 0)))))) - (is (equal "RY" (quil::application-operator-root-name (elt code 1)))) - (is (= quil:pi/2 (quil:constant-value (first (quil:application-parameters (elt code 1)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 1)))))) + (is (equal "RY" (cl-quil::application-operator-root-name (elt code 1)))) + (is (= cl-quil:pi/2 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 1)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 1)))))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 2)))) - (is (= 0.5 (quil:constant-value (first (quil:application-parameters (elt code 2)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 2)))))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 2)))) + (is (= 0.5 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 2)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 2)))))))) ;; u3(theta, phi, lambda) = U(theta, phi, lambda) = RZ(phi) RY(theta) RZ(lambda) (dolist (qasm (list "qreg q[1]; U(-0.5, 0.5, 1) q[0];" (format nil "include ~S; qreg q[1]; u3(-0.5, 0.5, 1) q[0];" (namestring *qasm-qelib.inc-path*)))) - (let* ((quil (quil.qasm::parse-qasm qasm)) - (code (quil:parsed-program-executable-code quil))) + (let* ((quil (cl-quil/qasm::parse-qasm qasm)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 3 (length code))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 0)))) - (is (= 1 (quil:constant-value (first (quil:application-parameters (elt code 0)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 0)))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 0)))) + (is (= 1 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 0)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 0)))))) - (is (equal "RY" (quil::application-operator-root-name (elt code 1)))) - (is (= -0.5 (quil:constant-value (first (quil:application-parameters (elt code 1)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 1)))))) + (is (equal "RY" (cl-quil::application-operator-root-name (elt code 1)))) + (is (= -0.5 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 1)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 1)))))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 2)))) - (is (= 0.5 (quil:constant-value (first (quil:application-parameters (elt code 2)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 2)))))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 2)))) + (is (= 0.5 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 2)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 2)))))))) ;; U(0,0,0) is compiled into the appropriate sequence (let* ((qasm "qreg q[1]; U(0, 0, 0) q[0];") - (quil (quil.qasm::parse-qasm qasm)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 3 (length code))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 0)))) - (is (= 0 (quil:constant-value (first (quil:application-parameters (elt code 0)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 0)))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 0)))) + (is (= 0 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 0)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 0)))))) - (is (equal "RY" (quil::application-operator-root-name (elt code 1)))) - (is (= 0 (quil:constant-value (first (quil:application-parameters (elt code 1)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 1)))))) + (is (equal "RY" (cl-quil::application-operator-root-name (elt code 1)))) + (is (= 0 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 1)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 1)))))) - (is (equal "RZ" (quil::application-operator-root-name (elt code 2)))) - (is (= 0 (quil:constant-value (first (quil:application-parameters (elt code 2)))))) - (is (= 0 (quil:qubit-index (first (quil:application-arguments (elt code 2)))))))) + (is (equal "RZ" (cl-quil::application-operator-root-name (elt code 2)))) + (is (= 0 (cl-quil:constant-value (first (cl-quil:application-parameters (elt code 2)))))) + (is (= 0 (cl-quil:qubit-index (first (cl-quil:application-arguments (elt code 2)))))))) (deftest test-qasm-measure () (let* ((qasm "qreg q[1]; creg c[1]; measure q[0] -> c[0];") - (quil (quil.qasm::parse-qasm qasm)) - (cmem (quil:parsed-program-memory-definitions quil)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (cmem (cl-quil:parsed-program-memory-definitions quil)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 1 (length cmem))) (is (= 1 (length code))) - (is (typep (elt code 0) 'quil:measure)) - (is (= 0 (quil:qubit-index (quil:measurement-qubit (elt code 0))))))) + (is (typep (elt code 0) 'cl-quil:measure)) + (is (= 0 (cl-quil:qubit-index (cl-quil:measurement-qubit (elt code 0))))))) (deftest test-qasm-measure-on-qreg () (let* ((qasm "qreg q[2]; creg c[1]; measure q -> c[0];") - (quil (quil.qasm::parse-qasm qasm)) - (cmem (quil:parsed-program-memory-definitions quil)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (cmem (cl-quil:parsed-program-memory-definitions quil)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 1 (length cmem))) (is (= 2 (length code))) - (is (typep (elt code 0) 'quil:measure)) - (is (typep (elt code 1) 'quil:measure)) - (is (= 0 (quil:qubit-index (quil:measurement-qubit (elt code 0))))) - (is (= 1 (quil:qubit-index (quil:measurement-qubit (elt code 1))))) + (is (typep (elt code 0) 'cl-quil:measure)) + (is (typep (elt code 1) 'cl-quil:measure)) + (is (= 0 (cl-quil:qubit-index (cl-quil:measurement-qubit (elt code 0))))) + (is (= 1 (cl-quil:qubit-index (cl-quil:measurement-qubit (elt code 1))))) ;; Should expand into same memory destination - (is (= 0 (quil:memory-ref-position (quil:measure-address (elt code 0))))) - (is (= 0 (quil:memory-ref-position (quil:measure-address (elt code 1))))) - (is (= 1 (quil:memory-descriptor-length (first cmem))))) + (is (= 0 (cl-quil:memory-ref-position (cl-quil:measure-address (elt code 0))))) + (is (= 0 (cl-quil:memory-ref-position (cl-quil:measure-address (elt code 1))))) + (is (= 1 (cl-quil:memory-descriptor-length (first cmem))))) (let* ((qasm "qreg q[2]; creg c[2]; measure q -> c;") - (quil (quil.qasm::parse-qasm qasm)) - (cmem (quil:parsed-program-memory-definitions quil)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (cmem (cl-quil:parsed-program-memory-definitions quil)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 1 (length cmem))) (is (= 2 (length code))) - (is (typep (elt code 0) 'quil:measure)) - (is (typep (elt code 1) 'quil:measure)) - (is (= 0 (quil:qubit-index (quil:measurement-qubit (elt code 0))))) - (is (= 1 (quil:qubit-index (quil:measurement-qubit (elt code 1))))) + (is (typep (elt code 0) 'cl-quil:measure)) + (is (typep (elt code 1) 'cl-quil:measure)) + (is (= 0 (cl-quil:qubit-index (cl-quil:measurement-qubit (elt code 0))))) + (is (= 1 (cl-quil:qubit-index (cl-quil:measurement-qubit (elt code 1))))) ;; Should expand into distinct memory destinations - (is (= 0 (quil:memory-ref-position (quil:measure-address (elt code 0))))) - (is (= 1 (quil:memory-ref-position (quil:measure-address (elt code 1))))) - (is (= 2 (quil:memory-descriptor-length (first cmem)))))) + (is (= 0 (cl-quil:memory-ref-position (cl-quil:measure-address (elt code 0))))) + (is (= 1 (cl-quil:memory-ref-position (cl-quil:measure-address (elt code 1))))) + (is (= 2 (cl-quil:memory-descriptor-length (first cmem)))))) (deftest test-qasm-reset () (let* ((qasm "qreg q[1]; reset q[0];") - (quil (quil.qasm::parse-qasm qasm)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 1 (length code))) - (is (typep (elt code 0) 'quil:reset-qubit)) - (is (= 0 (quil:qubit-index (quil:reset-qubit-target (elt code 0))))))) + (is (typep (elt code 0) 'cl-quil:reset-qubit)) + (is (= 0 (cl-quil:qubit-index (cl-quil:reset-qubit-target (elt code 0))))))) (deftest test-qasm-reset-on-qreg () (let* ((qasm "qreg q[2]; reset q;") - (quil (quil.qasm::parse-qasm qasm)) - (code (quil:parsed-program-executable-code quil))) + (quil (cl-quil/qasm::parse-qasm qasm)) + (code (cl-quil:parsed-program-executable-code quil))) (is (= 2 (length code))) - (is (typep (elt code 0) 'quil:reset-qubit)) - (is (typep (elt code 1) 'quil:reset-qubit)) - (is (= 0 (quil:qubit-index (quil:reset-qubit-target (elt code 0))))) - (is (= 1 (quil:qubit-index (quil:reset-qubit-target (elt code 1))))))) + (is (typep (elt code 0) 'cl-quil:reset-qubit)) + (is (typep (elt code 1) 'cl-quil:reset-qubit)) + (is (= 0 (cl-quil:qubit-index (cl-quil:reset-qubit-target (elt code 0))))) + (is (= 1 (cl-quil:qubit-index (cl-quil:reset-qubit-target (elt code 1))))))) (defun %probs (qvm) (map 'vector 'qvm:probability (qvm::amplitudes qvm))) (defun %probs= (probs-a probs-b) - (every #'quil::double= probs-a probs-b)) + (every #'cl-quil::double= probs-a probs-b)) (deftest test-qasm-if () (let* ((qasm (format nil "include ~S; qreg q[1]; creg c[1]; x q[0]; measure q[0] -> c[0]; if(c==1) x q[0];" (namestring *qasm-qelib.inc-path*))) - (quil (quil.qasm::parse-qasm qasm)) + (quil (cl-quil/qasm::parse-qasm qasm)) (qvm (qvm:run-program 1 quil)) (mem (qvm::classical-memories (qvm:classical-memory-subsystem qvm)))) (is (%probs= '(1 0) (%probs qvm))) @@ -270,7 +270,7 @@ qreg q[2]; CX q[0], q[1]; // bye") (let* ((qasm (format nil "include ~S; qreg q[2]; creg c[3]; x q; measure q -> c; if(c==3) x q;" (namestring *qasm-qelib.inc-path*))) - (quil (quil.qasm::parse-qasm qasm)) + (quil (cl-quil/qasm::parse-qasm qasm)) (qvm (qvm:run-program 2 quil)) (mem (qvm::classical-memories (qvm:classical-memory-subsystem qvm)))) (is (%probs= '(1 0 0 0) (%probs qvm))) @@ -280,7 +280,7 @@ qreg q[2]; CX q[0], q[1]; // bye") ;; Test that the if branch is not executed (and we're left in |11>). (let* ((qasm (format nil "include ~S; qreg q[2]; creg c[3]; x q; measure q -> c; if(c==4) x q;" (namestring *qasm-qelib.inc-path*))) - (quil (quil.qasm::parse-qasm qasm)) + (quil (cl-quil/qasm::parse-qasm qasm)) (qvm (qvm:run-program 2 quil)) (mem (qvm::classical-memories (qvm:classical-memory-subsystem qvm)))) (is (%probs= '(0 0 0 1) (%probs qvm))) @@ -288,15 +288,15 @@ qreg q[2]; CX q[0], q[1]; // bye") (is (= 1 (qvm::memory-view-ref (gethash "c" mem) 0))))) (deftest test-qasm-header () - (is (cl-quil.frontend::%check-for-qasm-header "OPENQASM 2.0")) - (is (cl-quil.frontend::%check-for-qasm-header "OPENQASM 2.0; creg c[0];")) - (is (cl-quil.frontend::%check-for-qasm-header "// this is a comment + (is (cl-quil/frontend::%check-for-qasm-header "OPENQASM 2.0")) + (is (cl-quil/frontend::%check-for-qasm-header "OPENQASM 2.0; creg c[0];")) + (is (cl-quil/frontend::%check-for-qasm-header "// this is a comment OPENQASM 2.0;")) - (is (cl-quil.frontend::%check-for-qasm-header "// this is a comment + (is (cl-quil/frontend::%check-for-qasm-header "// this is a comment // this is also a comment, and the next line is indented lightly // but that should be ok. OPENQASM 2.0;")) - (is (cl-quil.frontend::%check-for-qasm-header "// this is a comment + (is (cl-quil/frontend::%check-for-qasm-header "// this is a comment // this is also a comment, and the next line is empty // and this a comment, and that should be ok @@ -304,13 +304,13 @@ OPENQASM 2.0;")) OPENQASM 2.0;")) - (is (not (cl-quil.frontend::%check-for-qasm-header ""))) - (is (not (cl-quil.frontend::%check-for-qasm-header " "))) - (is (not (cl-quil.frontend::%check-for-qasm-header " + (is (not (cl-quil/frontend::%check-for-qasm-header ""))) + (is (not (cl-quil/frontend::%check-for-qasm-header " "))) + (is (not (cl-quil/frontend::%check-for-qasm-header " "))) - (is (not (cl-quil.frontend::%check-for-qasm-header " "))) ; tab char - (is (not (cl-quil.frontend::%check-for-qasm-header "X 0; OPENQASM 2.0"))) - (is (not (cl-quil.frontend::%check-for-qasm-header "# This is a Quil comment, + (is (not (cl-quil/frontend::%check-for-qasm-header " "))) ; tab char + (is (not (cl-quil/frontend::%check-for-qasm-header "X 0; OPENQASM 2.0"))) + (is (not (cl-quil/frontend::%check-for-qasm-header "# This is a Quil comment, # and thus cannot be a qasm program OPENQASM 2.0")))) @@ -341,12 +341,12 @@ cz q[0], q[1]; (partial-2q (program-2q-instructions compiled-program-partial))) (is (= 1 (length naive-2q))) (let ((2q (elt naive-2q 0))) - (is (string= "CZ" (quil::application-operator-root-name 2q))) + (is (string= "CZ" (cl-quil::application-operator-root-name 2q))) (is (subsetp (mapcar #'qubit-index (application-arguments 2q)) '(0 1)))) (is (= 1 (length partial-2q))) (let ((2q (elt partial-2q 0))) - (is (string= "CZ" (quil::application-operator-root-name 2q))) + (is (string= "CZ" (cl-quil::application-operator-root-name 2q))) (is (subsetp (mapcar #'qubit-index (application-arguments 2q)) '(1 2))))))) diff --git a/tests/quilec/cleve-gottesman-tests.lisp b/tests/quilec/cleve-gottesman-tests.lisp index 8d81c162c..263c19d6d 100644 --- a/tests/quilec/cleve-gottesman-tests.lisp +++ b/tests/quilec/cleve-gottesman-tests.lisp @@ -2,20 +2,20 @@ ;;;; ;;;; Author: Juan M. Bello-Rivas -(in-package #:cl-quil.quilec-tests) +(in-package #:cl-quil/quilec-tests) (defun pauli-to-program (pauli) "Return parsed program that applies PAULI to the current wavefunction." - (quil:with-output-to-quil + (cl-quil:with-output-to-quil (loop :for d :from 0 - :with components := (subseq (cl-quil.clifford::pauli-components pauli) 1) + :with components := (subseq (cl-quil/clifford::pauli-components pauli) 1) :for l :across components :do (format t "~[I~;X~;Z~;RY(pi)~] ~D~%" l d) :finally (terpri)))) (defun pauli-to-matrix (pauli) "Return matrix corresponding to PAULI (i.e., a Kronecker product of I, X, Z, and Y gates)." - (quil:parsed-program-to-logical-matrix (pauli-to-program pauli))) + (cl-quil:parsed-program-to-logical-matrix (pauli-to-program pauli))) (defun dist (u v) "Return $\ell_\infty$ distance between vectors U and V." @@ -39,7 +39,7 @@ (defun get-amplitudes (qvm) (declare (type qvm:pure-state-qvm qvm)) (let ((amplitudes (qvm::amplitudes (qvm::state qvm)))) - (quil::from-list (coerce amplitudes 'list) (list (length amplitudes) 1)))) + (cl-quil::from-list (coerce amplitudes 'list) (list (length amplitudes) 1)))) (defun encode-linear-algebra (stabilizer-group bits) "Use STABILIZER-GROUP to encode BITS. Return a vector of amplitudes and a QVM with the corresponding wavefunction." @@ -47,7 +47,7 @@ (2^n (expt 2 n))) (flet ((make-zero-ket () - (let ((vector (quil::zeros (list 2^n 1)))) + (let ((vector (cl-quil::zeros (list 2^n 1)))) (setf (magicl:tref vector 0 0) #c(1.0d0 0.0d0)) vector)) @@ -68,7 +68,7 @@ (setf ket (magicl:@ matrix ket)))) (loop :with b := (length primary-generators) - :with result := (quil::zeros (list 2^n 1)) + :with result := (cl-quil::zeros (list 2^n 1)) :for z :below (expt 2 b) :do (loop :with term := (magicl::copy-matrix/complex-double-float ket) :for x :below b @@ -112,9 +112,9 @@ (let ((value (dot-product (encode-linear-algebra stabilizer-group c1) (encode-linear-algebra stabilizer-group c2)))) (is (if (= c1 c2) - (and (quil::double~ (realpart value) 1.0d0) - (quil::double~ (imagpart value) 0.0d0)) - (quil::double~ (abs value) 0.0d0))))))) + (and (cl-quil::double~ (realpart value) 1.0d0) + (cl-quil::double~ (imagpart value) 0.0d0)) + (cl-quil::double~ (abs value) 0.0d0))))))) (defun test-idempotence (stabilizer-group) "Ensure that all the codewords are idempotent." @@ -140,8 +140,8 @@ (loop :for x :from 0 :for matrix :in matrices :for rq := (rayleigh-quotient matrix (magicl:slice vector '(0 0) (list 2^n 1))) - :do (is (and (quil::double~ 1.0d0 (realpart rq)) - (quil::double~ 0.0d0 (imagpart rq)))))))) + :do (is (and (cl-quil::double~ 1.0d0 (realpart rq)) + (cl-quil::double~ 0.0d0 (imagpart rq)))))))) (defun test-eigenspace-linear-algebra (stabilizer-group) "Verify that every codeword is in the +1 eigenspace of the generators using linear algebra to create the relevant codewords." @@ -149,14 +149,14 @@ (secondary-generators (qec::secondary-generators stabilizer-group))) (labels ((make-zero-ket (n &optional (value #c(1.0d0 0.0d0))) - (let ((vector (quil::zeros (list (expt 2 n))))) + (let ((vector (cl-quil::zeros (list (expt 2 n))))) (setf (magicl:tref vector 0) value) vector)) (make-state () (loop :with n := (qec::number-of-physical-qubits stabilizer-group) :with b := (length primary-generators) - :with psi := (quil::zeros (list (expt 2 n))) + :with psi := (cl-quil::zeros (list (expt 2 n))) :for a :below (expt 2 b) :do (loop :with vector := (make-zero-ket n (/ (sqrt (expt 2 b)))) :for i :below b @@ -171,8 +171,8 @@ :for matrix := (pauli-to-matrix generator) :for vector := (make-state) :do (let ((rq (rayleigh-quotient matrix vector))) - (is (and (quil::double~ 1.0d0 (realpart rq)) - (quil::double~ 0.0d0 (imagpart rq))))))))) + (is (and (cl-quil::double~ 1.0d0 (realpart rq)) + (cl-quil::double~ 0.0d0 (imagpart rq))))))))) (defun test-commutation (stabilizer-group) "Ensure all generators commute." @@ -188,7 +188,7 @@ (is (qec::commutes-p new-stabilizer-group)))) (defun make-error-program (gate qubit) - (quil:parse-quil (format nil "~A ~D~%" gate qubit))) + (cl-quil:parse-quil (format nil "~A ~D~%" gate qubit))) (defun test-syndromes (stabilizer-group) "Verify that the errors lie in the orthogonal complement of the code space and that every error anticommutes with at least one generator." @@ -230,7 +230,7 @@ (loop :for j :below n :do (loop :with should-break-p := nil :for generator :in (concatenate 'list primary-generators secondary-generators) - :for matrix := (quil:parsed-program-to-logical-matrix (pauli-to-program generator)) + :for matrix := (cl-quil:parsed-program-to-logical-matrix (pauli-to-program generator)) :unless should-break-p :do (let ((qvm (nth-value 1 (encode-linear-algebra stabilizer-group i)))) (load-program-and-run qvm (make-error-program gate j)) diff --git a/tests/quilec/package.lisp b/tests/quilec/package.lisp index 5533b8656..c2ff612a9 100644 --- a/tests/quilec/package.lisp +++ b/tests/quilec/package.lisp @@ -2,16 +2,9 @@ ;;;; ;;;; Author: Juan M. Bello-Rivas -;;; Allegro (and other Lisps) don't support the non-standard "package -;;; local nicknames". -#-(or sbcl ecl ccl) -(rename-package :alexandria :alexandria '(:a)) - -(fiasco:define-test-package #:cl-quil.quilec-tests - (:nicknames #:qec-tests) - #+(or sbcl ecl ccl) +(fiasco:define-test-package #:cl-quil/quilec-tests (:local-nicknames (:a :alexandria)) - (:use #:common-lisp #:cl-quil.quilec) + (:use #:common-lisp #:cl-quil/quilec) ;; suite.lisp (:export diff --git a/tests/quilec/stabilizer-group-tests.lisp b/tests/quilec/stabilizer-group-tests.lisp index b7b5c3ef2..d1297383a 100644 --- a/tests/quilec/stabilizer-group-tests.lisp +++ b/tests/quilec/stabilizer-group-tests.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Juan M. Bello-Rivas -(in-package #:cl-quil.quilec-tests) +(in-package #:cl-quil/quilec-tests) (deftest test-make-group () (let* ((symbols '((i x y z) @@ -14,7 +14,7 @@ (is (= (length generators) (length symbols))) (loop :for generator :across generators :for symbol :in symbols :do - (is (equalp generator (cl-quil.clifford::pauli-from-symbols symbol))))))) + (is (equalp generator (cl-quil/clifford::pauli-from-symbols symbol))))))) (deftest test-group-matrices () (let ((input-code (make-group '((i x y z i x x i) diff --git a/tests/quilec/suite.lisp b/tests/quilec/suite.lisp index 32930117f..6ccd8eb55 100644 --- a/tests/quilec/suite.lisp +++ b/tests/quilec/suite.lisp @@ -2,22 +2,22 @@ ;;;; ;;;; Author: Robert Smith, Juan M. Bello-Rivas -(in-package #:cl-quil.quilec-tests) +(in-package #:cl-quil/quilec-tests) (defun run-quilec-tests (&key (verbose nil) (headless nil)) "Run all QUILEC tests. If VERBOSE is T, print out lots of test info. If HEADLESS is T, disable interactive debugging and quit on completion." ;; Bug in Fiasco commit fe89c0e924c22c667cc11c6fc6e79419fc7c1a8b (let ((fiasco::*test-run-standard-output* (make-broadcast-stream *standard-output*)) - (quil::*compress-carefully* t)) + (cl-quil::*compress-carefully* t)) (cond ((null headless) - (run-package-tests :package ':cl-quil.quilec-tests + (run-package-tests :package ':cl-quil/quilec-tests :verbose verbose :describe-failures t :interactive t)) (t - (let ((successp (run-package-tests :package ':cl-quil.quilec-tests + (let ((successp (run-package-tests :package ':cl-quil/quilec-tests :verbose t :describe-failures t :interactive nil))) diff --git a/tests/quilt/analysis-tests.lisp b/tests/quilt/analysis-tests.lisp index 8a2b1d34d..22f0ba1bc 100644 --- a/tests/quilt/analysis-tests.lisp +++ b/tests/quilt/analysis-tests.lisp @@ -1,4 +1,4 @@ -(in-package #:cl-quil.quilt-tests) +(in-package #:cl-quil/quilt-tests) (deftest test-quilt-circuit-expansion () (let ((pp (parse-quilt " @@ -19,7 +19,7 @@ DEFCIRCUIT FOO(%theta) q: FENCE q FOO(1.0) 0" - :transforms '(quil::expand-circuits))) + :transforms '(cl-quil::expand-circuits))) (expected-instrs (list "SET-PHASE 0 \"xy\" 1.0" @@ -36,7 +36,7 @@ FOO(1.0) 0" :for expected :in expected-instrs :do (is (string= expected - (quil::print-instruction-to-string instr)))))) + (cl-quil::print-instruction-to-string instr)))))) (deftest test-quilt-name-resolution () (let ((pp (parse-quilt " @@ -135,7 +135,7 @@ RAW-CAPTURE 0 \"xy\" 1.0 iqs")) :transforms nil))) (= duration (quilt::quilt-instruction-duration - (quil::nth-instr 0 pp)))))) + (cl-quil::nth-instr 0 pp)))))) (is (duration= 1.5 "PULSE 0 \"xy\" flat(duration: 1.5, iq: 1)")) (is (duration= 1.5 "CAPTURE 0 \"xy\" flat(duration: 1.5, iq: 1) iq")) (is (duration= 1.5 "RAW-CAPTURE 0 \"xy\" 1.5 iq")) @@ -186,7 +186,7 @@ CAPTURE 1 \"xy\" flat(duration: 1, iq: 1) iq (lambda (instr) (is (not (typep instr 'fence)))) (parsed-program-executable-code pp)) - (let ((instr (quil::nth-instr 1 pp))) + (let ((instr (cl-quil::nth-instr 1 pp))) (is (and (typep instr 'delay) (= 1.0 (constant-value (delay-duration instr))) ;; we can't say which kind of delay is inserted, diff --git a/tests/quilt/calibration-tests.lisp b/tests/quilt/calibration-tests.lisp index 1f1aad563..2219a1133 100644 --- a/tests/quilt/calibration-tests.lisp +++ b/tests/quilt/calibration-tests.lisp @@ -1,4 +1,4 @@ -(in-package #:cl-quil.quilt-tests) +(in-package #:cl-quil/quilt-tests) (deftest test-gate-calibration-matching () (let ((pp (parse-quilt " @@ -76,7 +76,7 @@ DEFCAL RX(%theta) q: X 0"))) (quilt::expand-calibrations pp) (is (= 1 (length (parsed-program-executable-code pp)))) - (is (typep (elt (parsed-program-executable-code pp) 0) 'quil::no-operation)))) + (is (typep (elt (parsed-program-executable-code pp) 0) 'cl-quil::no-operation)))) (deftest test-infinitely-recursive-calibrations () (let ((pp (parse-quilt " diff --git a/tests/quilt/package.lisp b/tests/quilt/package.lisp index 5e420ffcf..4ff72e0b9 100644 --- a/tests/quilt/package.lisp +++ b/tests/quilt/package.lisp @@ -2,15 +2,9 @@ ;;;; ;;;; Author: Erik Davis -;;; Allegro (and other Lisps) don't support the non-standard "package -;;; local nicknames". -#-(or sbcl ecl ccl) -(rename-package :alexandria :alexandria '(:a)) - -(fiasco:define-test-package #:cl-quil.quilt-tests - #+(or sbcl ecl ccl) - (:local-nicknames (:a :alexandria)) - (:use #:cl-quil #:cl-quil.quilt) +(fiasco:define-test-package #:cl-quil/quilt-tests + (:use #:cl-quil #:cl-quil/quilt) + (:local-nicknames (#:quilt #:cl-quil/quilt)) ;; suite.lisp (:export diff --git a/tests/quilt/parser-tests.lisp b/tests/quilt/parser-tests.lisp index dc589bb0d..15bc1957e 100644 --- a/tests/quilt/parser-tests.lisp +++ b/tests/quilt/parser-tests.lisp @@ -1,4 +1,4 @@ -(in-package #:cl-quil.quilt-tests) +(in-package #:cl-quil/quilt-tests) (defparameter *good-quilt-test-file-directory* (asdf:system-relative-pathname @@ -23,23 +23,23 @@ (dolist (file (uiop:directory-files *bad-quilt-test-file-directory* #P"*.quil")) (format t "~& Testing bad file ~A~%" (pathname-name file)) (let ((cl-quil:*allow-unresolved-applications* t)) - (signals quil:quil-parse-error + (signals cl-quil:quil-parse-error (handler-case (read-quilt-file file) ;; Re-signal all of the following errors as ;; QUIL-PARSE-ERRORs. - (quil:quil-type-error (c) + (cl-quil:quil-type-error (c) (declare (ignore c)) - (error 'quil:quil-parse-error)) + (error 'cl-quil:quil-parse-error)) (yacc:yacc-parse-error (c) (declare (ignore c)) - (error 'quil:quil-parse-error)) + (error 'cl-quil:quil-parse-error)) (alexa:lexer-match-error (c) (declare (ignore c)) - (error 'quil:quil-parse-error))))))) + (error 'cl-quil:quil-parse-error))))))) (deftest test-parser-fail-without-extensions () "Test that Quilt parsing fails with PARSE-QUIL." - (signals quil::quil-parse-error + (signals cl-quil::quil-parse-error (parse-quil "DEFFRAME 0 \"foo\""))) (deftest test-quilt-defwaveform-sample-rate () @@ -59,7 +59,7 @@ DEFWAVEFORM foo 4.0: (waveform-definition-sample-rate (first (parsed-program-waveform-definitions pp)))))))) -(defun prints-as (expected obj &key (accessor #'quil:parsed-program-executable-code)) +(defun prints-as (expected obj &key (accessor #'cl-quil:parsed-program-executable-code)) "Checks whether OBJ prints as the EXPECTED string. If OBJ is a string, parses OBJ and then checks that the first instruction prints as EXPECTED." (typecase obj (string @@ -69,7 +69,7 @@ DEFWAVEFORM foo 4.0: 0))) (otherwise (is (string= expected - (quil::print-instruction-to-string obj)))))) + (cl-quil::print-instruction-to-string obj)))))) (deftest test-print-quilt-objects () (prints-as "0 \"xy\"" @@ -157,7 +157,7 @@ DEFWAVEFORM wf 1.0: (deftest test-definition-signature () (flet ((signature (raw-quil &rest args) (let ((pp (parse-quilt (apply #'format nil raw-quil args)))) - (cl-quil.frontend::definition-signature + (cl-quil/frontend::definition-signature (first (append (parsed-program-gate-definitions pp) (parsed-program-circuit-definitions pp) (parsed-program-waveform-definitions pp) diff --git a/tests/quilt/suite.lisp b/tests/quilt/suite.lisp index 75ae4e254..3f51a3dff 100644 --- a/tests/quilt/suite.lisp +++ b/tests/quilt/suite.lisp @@ -2,22 +2,22 @@ ;;;; ;;;; Author: Erik Davis -(in-package #:cl-quil.quilt-tests) +(in-package #:cl-quil/quilt-tests) (defun run-quilt-tests (&key (verbose nil) (headless nil)) "Run all CL-QUIL/QUILT tests. If VERBOSE is T, print out lots of test info. If HEADLESS is T, disable interactive debugging and quit on completion." ;; Bug in Fiasco commit fe89c0e924c22c667cc11c6fc6e79419fc7c1a8b (setf fiasco::*test-run-standard-output* (make-broadcast-stream *standard-output*)) - (let ((quil::*compress-carefully* t)) + (let ((cl-quil::*compress-carefully* t)) (cond ((null headless) - (run-package-tests :package ':cl-quil.quilt-tests + (run-package-tests :package ':cl-quil/quilt-tests :verbose verbose :describe-failures t :interactive t)) (t - (let ((successp (run-package-tests :package ':cl-quil.quilt-tests + (let ((successp (run-package-tests :package ':cl-quil/quilt-tests :verbose t :describe-failures t :interactive nil))) diff --git a/tests/resource-tests.lisp b/tests/resource-tests.lisp index 7d6084a30..9c9f909f8 100644 --- a/tests/resource-tests.lisp +++ b/tests/resource-tests.lisp @@ -4,18 +4,18 @@ (in-package #:cl-quil-tests) -(defun qr (idx) (quil::make-qubit-resource idx)) +(defun qr (idx) (cl-quil::make-qubit-resource idx)) (defun make-qubit-resources (indices) - (reduce #'quil::resource-union (mapcar #'qr indices))) + (reduce #'cl-quil::resource-union (mapcar #'qr indices))) (defun mk-ranges (ranges &optional names) (unless names (setf names (make-list (length ranges) :initial-element ""))) - (reduce #'quil::resource-union + (reduce #'cl-quil::resource-union (mapcar (lambda (range name) - (quil::make-resource-range name (car range) (cdr range))) + (cl-quil::make-resource-range name (car range) (cdr range))) ranges names) - :initial-value (quil::make-null-resource))) + :initial-value (cl-quil::make-null-resource))) (defparameter *test-ranges-cases* ;; first-arg second-arg intersect union difference @@ -29,13 +29,13 @@ (loop :for case :in *test-ranges-cases* :for (s1 s2 intersect union difference) := (mapcar #'mk-ranges case) - :for intersect-p := (not (quil::resource-null-p intersect)) - :for subset-p := (quil::resource-null-p difference) - :do (is (eql intersect-p (quil::resources-intersect-p s1 s2))) - (is (eql subset-p (quil::resource-subsetp s1 s2))) - (is (quil::resource= intersect (quil::resource-intersection s1 s2))) - (is (quil::resource= union (quil::resource-union s1 s2))) - (is (quil::resource= difference (quil::resource-difference s1 s2))))) + :for intersect-p := (not (cl-quil::resource-null-p intersect)) + :for subset-p := (cl-quil::resource-null-p difference) + :do (is (eql intersect-p (cl-quil::resources-intersect-p s1 s2))) + (is (eql subset-p (cl-quil::resource-subsetp s1 s2))) + (is (cl-quil::resource= intersect (cl-quil::resource-intersection s1 s2))) + (is (cl-quil::resource= union (cl-quil::resource-union s1 s2))) + (is (cl-quil::resource= difference (cl-quil::resource-difference s1 s2))))) (defparameter *test-ranges-subset-p-cases* '((((1 . 2)) ((1 . 2)) T) @@ -52,13 +52,13 @@ (deftest test-ranges-subset-p () (loop :for (s1 s2 result) :in *test-ranges-subset-p-cases* - :do (is (eql result (quil::resource-subsetp (mk-ranges s1) (mk-ranges s2)))))) + :do (is (eql result (cl-quil::resource-subsetp (mk-ranges s1) (mk-ranges s2)))))) (defun resource-eq-check (resource indices) - (is (quil::resource= resource (make-qubit-resources indices))) + (is (cl-quil::resource= resource (make-qubit-resources indices))) (dolist (i indices) - (is (quil::resource-subsetp (qr i) resource)) - (is (quil::resources-intersect-p (qr i) resource)))) + (is (cl-quil::resource-subsetp (qr i) resource)) + (is (cl-quil::resources-intersect-p (qr i) resource)))) (deftest test-resource-operations () (loop @@ -67,11 +67,11 @@ :for l2 := (sort (delete-duplicates (loop :repeat 20 :collect (random 30))) #'<) :for r1 := (make-qubit-resources l1) :for r2 := (make-qubit-resources l2) - :do (resource-eq-check (quil::resource-intersection r1 r2) (intersection l1 l2)) - (resource-eq-check (quil::resource-union r1 r2) (union l1 l2)) - (resource-eq-check (quil::resource-difference r1 r2) (set-difference l1 l2)) - (is (eql (quil::resources-intersect-p r1 r2) (if (intersection l1 l2) t nil))) - (is (eql (quil::resource-subsetp r1 r2) (subsetp l1 l2))))) + :do (resource-eq-check (cl-quil::resource-intersection r1 r2) (intersection l1 l2)) + (resource-eq-check (cl-quil::resource-union r1 r2) (union l1 l2)) + (resource-eq-check (cl-quil::resource-difference r1 r2) (set-difference l1 l2)) + (is (eql (cl-quil::resources-intersect-p r1 r2) (if (intersection l1 l2) t nil))) + (is (eql (cl-quil::resource-subsetp r1 r2) (subsetp l1 l2))))) (deftest test-resource-difference () @@ -79,47 +79,47 @@ (loop :repeat 20 :for l := (loop :repeat 20 :collect (random 30)) - :for r := (quil::resource-difference universe (make-qubit-resources l)) + :for r := (cl-quil::resource-difference universe (make-qubit-resources l)) :do (dolist (i l) - (is (not (quil::resource-subsetp (qr i) r))))))) + (is (not (cl-quil::resource-subsetp (qr i) r))))))) (defun check-identities (r1 r2 r3 universe) ;; A ∩ B = A - Bᶜ - (is (quil::resource= (quil::resource-intersection r1 r2) - (quil::resource-difference r1 (quil::resource-difference universe r2)))) + (is (cl-quil::resource= (cl-quil::resource-intersection r1 r2) + (cl-quil::resource-difference r1 (cl-quil::resource-difference universe r2)))) ;; (A - B)ᶜ = A or Bᶜ - (is (quil::resource= (quil::resource-difference universe (quil::resource-difference r1 r2)) - (quil::resource-union r2 (quil::resource-difference universe r1)))) + (is (cl-quil::resource= (cl-quil::resource-difference universe (cl-quil::resource-difference r1 r2)) + (cl-quil::resource-union r2 (cl-quil::resource-difference universe r1)))) ;; A or B = (Aᶜ ∩ Bᶜ)ᶜ - (is (quil::resource= (quil::resource-union r1 r2) - (quil::resource-difference universe - (quil::resource-intersection - (quil::resource-difference universe r1) - (quil::resource-difference universe r2))))) + (is (cl-quil::resource= (cl-quil::resource-union r1 r2) + (cl-quil::resource-difference universe + (cl-quil::resource-intersection + (cl-quil::resource-difference universe r1) + (cl-quil::resource-difference universe r2))))) ;; A - ∅ = A - (is (quil::resource= (quil::resource-difference r1 (quil::make-null-resource)) r1)) + (is (cl-quil::resource= (cl-quil::resource-difference r1 (cl-quil::make-null-resource)) r1)) ;; (B - A) or C = (B or C) - (A - C) - (is (quil::resource= (quil::resource-union - (quil::resource-difference r2 r1) r3) - (quil::resource-difference - (quil::resource-union r2 r3) - (quil::resource-difference r1 r3))))) + (is (cl-quil::resource= (cl-quil::resource-union + (cl-quil::resource-difference r2 r1) r3) + (cl-quil::resource-difference + (cl-quil::resource-union r2 r3) + (cl-quil::resource-difference r1 r3))))) (defun random-resource (range-names) "Constructs a random resource, where named ranges have names selected from RANGE-NAMES." (reduce - #'quil::resource-union + #'cl-quil::resource-union (list* (make-qubit-resources (remove-duplicates (loop :repeat (1+ (random 20)) :collect (random 30)))) (loop :repeat (1+ (random 10)) :for size := (random 10) :for lo := (random (- 50 size)) - :collect (quil::make-resource-range (format nil "~D" (a:random-elt range-names)) lo (+ lo size)))))) + :collect (cl-quil::make-resource-range (format nil "~D" (a:random-elt range-names)) lo (+ lo size)))))) (deftest test-resource-identities () (let* ((names (list "a" "b" "c")) - (universe (cl-quil.resource::make-resource-collection - :qubits cl-quil.resource::+full+ + (universe (cl-quil/resource::make-resource-collection + :qubits cl-quil/resource::+full+ :memory-regions (mapcar (lambda (name) (cons name (list (cons most-negative-fixnum most-positive-fixnum)))) names)))) diff --git a/tests/rewrite-tests.lisp b/tests/rewrite-tests.lisp index 08db4a6e1..50af3ec93 100644 --- a/tests/rewrite-tests.lisp +++ b/tests/rewrite-tests.lisp @@ -1,28 +1,28 @@ (in-package #:cl-quil-tests) (defun %filter-halt (pp) - (remove-if #'quil::haltp + (remove-if #'cl-quil::haltp (parsed-program-executable-code pp))) (deftest test-rz-full-rotation-elimination () ;; Test the compiler directly. - (is (null (quil::eliminate-full-rz-rotations (quil::build-gate "RZ" (list 0d0) 0)))) - (is (null (quil::eliminate-full-rz-rotations (quil::build-gate "RZ" (list (quil::constant 0d0)) 0)))) + (is (null (cl-quil::eliminate-full-rz-rotations (cl-quil::build-gate "RZ" (list 0d0) 0)))) + (is (null (cl-quil::eliminate-full-rz-rotations (cl-quil::build-gate "RZ" (list (cl-quil::constant 0d0)) 0)))) ;; Test that the compiler takes effect via compiler-hook. - (let ((chip (quil::build-nq-fully-connected-chip 2)) - (pps (list (quil::parse-quil "DECLARE theta REAL[1]; RZ(0.0) 0;") - (quil::parse-quil "DECLARE theta REAL[1]; RZ(2*pi) 0;") - (quil::parse-quil "DECLARE theta REAL[1]; RZ(-2*pi) 0;")))) + (let ((chip (cl-quil::build-nq-fully-connected-chip 2)) + (pps (list (cl-quil::parse-quil "DECLARE theta REAL[1]; RZ(0.0) 0;") + (cl-quil::parse-quil "DECLARE theta REAL[1]; RZ(2*pi) 0;") + (cl-quil::parse-quil "DECLARE theta REAL[1]; RZ(-2*pi) 0;")))) (dolist (pp pps) - (is (zerop (length (%filter-halt (quil::compiler-hook pp chip)))))))) + (is (zerop (length (%filter-halt (cl-quil::compiler-hook pp chip)))))))) (deftest test-rz-agglutination-elimination () - (let ((chip (quil::build-nq-fully-connected-chip 2)) + (let ((chip (cl-quil::build-nq-fully-connected-chip 2)) (pps (list (parse-quil "RZ(1) 0; RZ(-1) 0;") (parse-quil "DECLARE theta REAL[1]; RZ(theta) 0; RZ(-theta) 0")))) (dolist (pp pps) - (is (zerop (length (%filter-halt (quil::compiler-hook pp chip)))))))) + (is (zerop (length (%filter-halt (cl-quil::compiler-hook pp chip)))))))) diff --git a/tests/state-prep-tests.lisp b/tests/state-prep-tests.lisp index 362a6f194..5957a03a1 100644 --- a/tests/state-prep-tests.lisp +++ b/tests/state-prep-tests.lisp @@ -6,7 +6,7 @@ (defun wf-to-matrix (wf) "Convert a sequence WF to a corresponding column vector." - (quil::from-array (copy-seq wf) + (cl-quil::from-array (copy-seq wf) (list (length wf) 1))) (defun check-state-prep (source-wf target-wf matrix) @@ -14,52 +14,52 @@ (let* ((result (magicl:@ matrix (wf-to-matrix source-wf))) (prefactor (/ (aref target-wf 0) (magicl:tref result 0 0)))) - (is (quil::matrix-equality (magicl:scale result prefactor) + (is (cl-quil::matrix-equality (magicl:scale result prefactor) (wf-to-matrix target-wf))))) (deftest test-state-prep-formation () "Checks that STATE-PREP-APPLICATION (with SOURCE-WF in the ground state) correctly compiles into native instructions." - (let* ((qubits (mapcar #'quil:qubit (list 0 1 2 3))) - (target-wf (quil::random-wavefunction (length qubits))) - (source-wf (quil::build-ground-state (length qubits))) - (instr (make-instance 'quil::state-prep-application + (let* ((qubits (mapcar #'cl-quil:qubit (list 0 1 2 3))) + (target-wf (cl-quil::random-wavefunction (length qubits))) + (source-wf (cl-quil::build-ground-state (length qubits))) + (instr (make-instance 'cl-quil::state-prep-application :arguments qubits :target-wf target-wf :source-wf source-wf))) - (let* ((output-matrix (quil::make-matrix-from-quil - (quil::expand-to-native-instructions + (let* ((output-matrix (cl-quil::make-matrix-from-quil + (cl-quil::expand-to-native-instructions (list instr) - (quil::build-8Q-chip))))) + (cl-quil::build-8Q-chip))))) (check-state-prep source-wf target-wf output-matrix)))) (deftest test-aqvm-unlink-refuses-large-GHZ-state () "Checks that an AQVM correctly assembles a GHZ state and then correctly disables itself." - (let ((aqvm (quil::build-aqvm 8)) - (quil (quil::parse-quil " + (let ((aqvm (cl-quil::build-aqvm 8)) + (quil (cl-quil::parse-quil " H 0 CNOT 0 1 CNOT 1 2 CNOT 2 3 "))) - (dolist (instr (coerce (quil::parsed-program-executable-code quil) 'list)) - (quil::aqvm-apply-instruction aqvm instr)) + (dolist (instr (coerce (cl-quil::parsed-program-executable-code quil) 'list)) + (cl-quil::aqvm-apply-instruction aqvm instr)) ;; check that the correct state was constructed (destructuring-bind (wf qc-complex) - (quil::aqvm-extract-single-wf-component aqvm 0) + (cl-quil::aqvm-extract-single-wf-component aqvm 0) (declare (ignore qc-complex)) - (is (and (quil::double~ (/ (sqrt 2)) (aref wf 0)) - (quil::double~ (/ (sqrt 2)) (aref wf 15))))) + (is (and (cl-quil::double~ (/ (sqrt 2)) (aref wf 0)) + (cl-quil::double~ (/ (sqrt 2)) (aref wf 15))))) ;; now check that unlinking the AQVM kills this state, since it is too entangled - (quil::aqvm-unlink aqvm) + (cl-quil::aqvm-unlink aqvm) (loop :for i :below 4 :do (destructuring-bind (wf qc-complex) - (quil::aqvm-extract-single-wf-component aqvm i) + (cl-quil::aqvm-extract-single-wf-component aqvm i) (declare (ignore qc-complex)) (is (eql ':not-simulated wf)))) (destructuring-bind (wf qc-complex) - (quil::aqvm-extract-single-wf-component aqvm 4) + (cl-quil::aqvm-extract-single-wf-component aqvm 4) (declare (ignore qc-complex)) - (every #'quil::double~ wf (quil::build-ground-state 1))))) + (every #'cl-quil::double~ wf (cl-quil::build-ground-state 1))))) (deftest test-state-prep-2Q-source-and-target () "Checks that STATE-PREP-APPLICATION (both with arbitrary and with adversarial SOURCE-WF and TARGET-WF) correctly compiles into native instructions." @@ -69,17 +69,17 @@ CNOT 2 3 :initial-contents (loop :for i :below 4 :collect (magicl:tref m i j)))) (build-state-prep (source-wf target-wf) - (make-instance 'quil::state-prep-application + (make-instance 'cl-quil::state-prep-application :operator (named-operator "STATE-PREP") :arguments (list (qubit 1) (qubit 0)) :source-wf source-wf :target-wf target-wf))) - (let ((chip (quil::build-8q-chip))) + (let ((chip (cl-quil::build-8q-chip))) (dotimes (j 10) - (let* ((unentangled-matrix (quil::make-matrix-from-quil - (list (quil::anon-gate "U0" (quil::random-special-unitary 2) 0) - (quil::anon-gate "U1" (quil::random-special-unitary 2) 1)))) - (entangled-matrix (quil::random-special-unitary 4))) + (let* ((unentangled-matrix (cl-quil::make-matrix-from-quil + (list (cl-quil::anon-gate "U0" (cl-quil::random-special-unitary 2) 0) + (cl-quil::anon-gate "U1" (cl-quil::random-special-unitary 2) 1)))) + (entangled-matrix (cl-quil::random-special-unitary 4))) (loop :for (source-wf target-wf) :in (list ;; entangled-entangled (list (grab-row entangled-matrix 0) (grab-row entangled-matrix 1)) @@ -93,39 +93,39 @@ CNOT 2 3 (list (grab-row unentangled-matrix 2) (grab-row unentangled-matrix 3))) :for state-instr := (build-state-prep source-wf target-wf) - :for state-circuit := (quil::expand-to-native-instructions - (quil::state-prep-2Q-compiler state-instr) chip) - :for circuit-result := (quil::nondestructively-apply-instrs-to-wf state-circuit source-wf + :for state-circuit := (cl-quil::expand-to-native-instructions + (cl-quil::state-prep-2Q-compiler state-instr) chip) + :for circuit-result := (cl-quil::nondestructively-apply-instrs-to-wf state-circuit source-wf (list 0 1)) - :do (is (quil::collinearp target-wf circuit-result)))))))) + :do (is (cl-quil::collinearp target-wf circuit-result)))))))) (deftest test-state-prep-1q-source-and-target () "Checks that STATE-PREP-APPLICATION (with arbitrary SOURCE-WF and TARGET-WF) correctly compiles into native instructions." - (let* ((source-wf (quil::random-wavefunction 1)) - (target-wf (quil::random-wavefunction 1)) - (instr (make-instance 'quil::state-prep-application - :arguments (mapcar #'quil::qubit (list 0)) + (let* ((source-wf (cl-quil::random-wavefunction 1)) + (target-wf (cl-quil::random-wavefunction 1)) + (instr (make-instance 'cl-quil::state-prep-application + :arguments (mapcar #'cl-quil::qubit (list 0)) :target-wf target-wf :source-wf source-wf))) - (let* ((output-matrix (quil::make-matrix-from-quil - (quil::expand-to-native-instructions + (let* ((output-matrix (cl-quil::make-matrix-from-quil + (cl-quil::expand-to-native-instructions (list instr) - (quil::build-8Q-chip))))) + (cl-quil::build-8Q-chip))))) (check-state-prep source-wf target-wf output-matrix)))) (deftest test-state-prep-4q-compiler () "Check that STATE-PREP-4Q-COMPILER (with arbitrary SOURCE-WF and TARGET-WF) correctly compiles into native instructions." - (let* ((qubits (mapcar #'quil::qubit (list 0 1 2 3))) - (source-wf (quil::random-wavefunction 4)) - (target-wf (quil::random-wavefunction 4)) - (instr (make-instance 'quil::state-prep-application + (let* ((qubits (mapcar #'cl-quil::qubit (list 0 1 2 3))) + (source-wf (cl-quil::random-wavefunction 4)) + (target-wf (cl-quil::random-wavefunction 4)) + (instr (make-instance 'cl-quil::state-prep-application :arguments qubits :target-wf target-wf :source-wf source-wf)) - (output-matrix (quil::make-matrix-from-quil - (quil::expand-to-native-instructions - (quil::state-prep-4q-compiler instr) - (quil::build-8Q-chip))))) + (output-matrix (cl-quil::make-matrix-from-quil + (cl-quil::expand-to-native-instructions + (cl-quil::state-prep-4q-compiler instr) + (cl-quil::build-8Q-chip))))) (check-state-prep source-wf target-wf output-matrix))) (deftest test-schmidt-decomposition () @@ -134,21 +134,21 @@ CNOT 2 3 (magicl::slice m (list 0 i) (list (magicl:nrows m) (1+ i))))) - (let* ((random-wf (quil::random-wavefunction 4))) - (multiple-value-bind (c U V) (quil::schmidt-decomposition random-wf 2 2) + (let* ((random-wf (cl-quil::random-wavefunction 4))) + (multiple-value-bind (c U V) (cl-quil::schmidt-decomposition random-wf 2 2) (let* ((schmidt-terms (loop :for i :from 0 :below 4 :collect (magicl:scale (magicl::kron (matrix-column U i) (matrix-column V i)) (aref c i)))) (reconstructed-wf (reduce #'magicl:.+ schmidt-terms))) - (is (quil::matrix-equality reconstructed-wf + (is (cl-quil::matrix-equality reconstructed-wf (wf-to-matrix random-wf)))))))) (deftest test-aqvm-unlink-on-10Q () - (let ((quil::*aqvm-correlation-threshold* 4) - (aqvm (quil::build-aqvm 11)) - (pp (quil::parse-quil " + (let ((cl-quil::*aqvm-correlation-threshold* 4) + (aqvm (cl-quil::build-aqvm 11)) + (pp (cl-quil::parse-quil " # set up wf RX(1.0) 3 RX(1.3) 1 @@ -175,14 +175,14 @@ CNOT 3 5 CNOT 3 5 "))) (dolist (instr (coerce (parsed-program-executable-code pp) 'list)) - (quil::aqvm-apply-instruction aqvm instr)) - (quil::aqvm-stop-simulating aqvm 10) + (cl-quil::aqvm-apply-instruction aqvm instr)) + (cl-quil::aqvm-stop-simulating aqvm 10) (destructuring-bind (wf qubit-list) - (quil::aqvm-extract-state aqvm (list 0 1 2 3 4 5 6 7 8 9) + (cl-quil::aqvm-extract-state aqvm (list 0 1 2 3 4 5 6 7 8 9) :destructive-update nil) - (quil::aqvm-unlink aqvm) + (cl-quil::aqvm-unlink aqvm) (destructuring-bind (new-wf new-qubit-list) - (quil::aqvm-extract-state aqvm (list 0 1 2 3 4 5 6 7 8 9)) + (cl-quil::aqvm-extract-state aqvm (list 0 1 2 3 4 5 6 7 8 9)) ;; check wf against new-wf (is (loop :for j :below (ash 1 10) :always (let ((wf-index (loop :for i :from 0 @@ -191,10 +191,10 @@ CNOT 3 5 (new-wf-index (loop :for i :from 0 :for idx :in new-qubit-list :sum (ash (ldb (byte 1 idx) j) (- 9 i))))) - (quil::double= (aref wf wf-index) + (cl-quil::double= (aref wf wf-index) (aref new-wf new-wf-index))))) ;; check new-wf has small components - (is (loop :for wf :across (quil::antisocial-qvm-wfs aqvm) + (is (loop :for wf :across (cl-quil::antisocial-qvm-wfs aqvm) :for expected-size :in (list 4 8 8 2 4 8 16 16 16 16 ':not-simulated) :always (if (eql ':not-simulated wf) (eql ':not-simulated expected-size) @@ -203,12 +203,12 @@ CNOT 3 5 (deftest test-canonicalize-wf () (dotimes (n 100) - (let ((wf (quil::random-wavefunction 2))) + (let ((wf (cl-quil::random-wavefunction 2))) (multiple-value-bind (m v) - (quil::canonicalize-wf wf) - (is (every #'quil::double= + (cl-quil::canonicalize-wf wf) + (is (every #'cl-quil::double= v - (quil::nondestructively-apply-matrix-to-vector m wf))) - (is (quil::double= 0d0 (imagpart (aref v 1)))) - (is (quil::double= 0d0 (aref v 2))) - (is (quil::double= 0d0 (aref v 3))))))) + (cl-quil::nondestructively-apply-matrix-to-vector m wf))) + (is (cl-quil::double= 0d0 (imagpart (aref v 1)))) + (is (cl-quil::double= 0d0 (aref v 2))) + (is (cl-quil::double= 0d0 (aref v 3))))))) diff --git a/tests/suite.lisp b/tests/suite.lisp index a26349af4..76a69494b 100644 --- a/tests/suite.lisp +++ b/tests/suite.lisp @@ -9,7 +9,7 @@ ;; Bug in Fiasco commit fe89c0e924c22c667cc11c6fc6e79419fc7c1a8b (setf fiasco::*test-run-standard-output* (make-broadcast-stream *standard-output*)) - (let ((quil::*compress-carefully* t)) + (let ((cl-quil::*compress-carefully* t)) (cond ((null headless) (run-package-tests :package ':cl-quil-tests diff --git a/tests/tools/circuit-diagram-tests.lisp b/tests/tools/circuit-diagram-tests.lisp index f7f168d8a..66dd3549c 100644 --- a/tests/tools/circuit-diagram-tests.lisp +++ b/tests/tools/circuit-diagram-tests.lisp @@ -2,13 +2,13 @@ ;;; ;;; Author: Erik Davis -(in-package #:cl-quil.tools-tests) +(in-package #:cl-quil/tools-tests) ;;; We don't actually test the pdflatex calls, but we can ensure that ;;; we generate reasonable-looking latex source. (deftest test-plot-circuit-raw-latex-example () - (let ((pp (quil:parse-quil "DECLARE ro BIT[2]; H 0; CNOT 0 1; RX(pi) 1; CNOT 1 2; MEASURE 0 ro[0]; MEASURE 2 ro[1]")) + (let ((pp (cl-quil:parse-quil "DECLARE ro BIT[2]; H 0; CNOT 0 1; RX(pi) 1; CNOT 1 2; MEASURE 0 ro[0]; MEASURE 2 ro[1]")) ;; the following has been validated by hand.... ;; we will need to update this after any changes to latex codegen. (expected "\\documentclass[convert={density=300,outext=.png}]{standalone} @@ -25,12 +25,12 @@ \\end{document} ")) (is (string= expected - (cl-quil.tools:plot-circuit pp + (cl-quil/tools:plot-circuit pp :backend :latex :right-align-measurements t))))) (deftest test-plot-circuit-loose-measure-sanity-check () - (let ((pp (quil:parse-quil "H 0; MEASURE 3")) + (let ((pp (cl-quil:parse-quil "H 0; MEASURE 3")) (expected "\\documentclass[convert={density=300,outext=.png}]{standalone} \\usepackage[margin=1in]{geometry} @@ -45,12 +45,12 @@ \\end{document} ")) (is (string= expected - (cl-quil.tools:plot-circuit pp + (cl-quil/tools:plot-circuit pp :backend :latex :right-align-measurements t))))) (deftest test-plot-circuit-nq-gate-layout () - (let ((pp (quil:parse-quil " + (let ((pp (cl-quil:parse-quil " DEFGATE FOO p q r AS PAULI-SUM: X(pi) p Y(pi) q @@ -72,6 +72,6 @@ FOO 3 2 1")) \\end{document} ")) (is (string= expected - (cl-quil.tools:plot-circuit pp + (cl-quil/tools:plot-circuit pp :backend :latex :layout-strategy ':increasing))))) diff --git a/tests/tools/hasse-diagram-tests.lisp b/tests/tools/hasse-diagram-tests.lisp index bb061cb25..7c53be14b 100644 --- a/tests/tools/hasse-diagram-tests.lisp +++ b/tests/tools/hasse-diagram-tests.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Mark David -(in-package #:cl-quil.tools-tests) +(in-package #:cl-quil/tools-tests) ;;; For now, this tests module provides both an demo/example as well diff --git a/tests/tools/package.lisp b/tests/tools/package.lisp index 1b9d4cdc7..c52bee87b 100644 --- a/tests/tools/package.lisp +++ b/tests/tools/package.lisp @@ -2,13 +2,7 @@ ;;;; ;;;; Author: Mark David -;;; Allegro (and other Lisps) don't support the non-standard "package -;;; local nicknames". -#-(or sbcl ecl ccl) -(rename-package :alexandria :alexandria '(:a)) - -(fiasco:define-test-package #:cl-quil.tools-tests - #+(or sbcl ecl ccl) +(fiasco:define-test-package #:cl-quil/tools-tests (:local-nicknames (:a :alexandria)) (:use #:cl) diff --git a/tests/tools/suite.lisp b/tests/tools/suite.lisp index 5e8d7d394..961615008 100644 --- a/tests/tools/suite.lisp +++ b/tests/tools/suite.lisp @@ -2,7 +2,7 @@ ;;;; ;;;; Author: Mark David -(in-package #:cl-quil.tools-tests) +(in-package #:cl-quil/tools-tests) (defun run-tools-tests (&key (verbose nil) (headless nil)) "Run all CL-QUIL/TOOLS tests. If VERBOSE is T, print out lots of test info. If HEADLESS is T, disable interactive debugging and quit on completion." @@ -11,12 +11,12 @@ *standard-output*)) (cond ((null headless) - (run-package-tests :package ':cl-quil.tools-tests + (run-package-tests :package ':cl-quil/tools-tests :verbose verbose :describe-failures t :interactive t)) (t - (let ((successp (run-package-tests :package ':cl-quil.tools-tests + (let ((successp (run-package-tests :package ':cl-quil/tools-tests :verbose t :describe-failures t :interactive nil))) diff --git a/tests/translator-tests.lisp b/tests/translator-tests.lisp index c3e5e7246..98655cf0f 100644 --- a/tests/translator-tests.lisp +++ b/tests/translator-tests.lisp @@ -27,17 +27,17 @@ (deftest test-euler-translations () "Ensures that the different Euler decompositions all work." - (let ((master-matrix (quil::random-special-unitary 2))) - (dolist (compiler '(quil::euler-zyz-compiler - quil::euler-zxz-compiler - quil::euler-yzy-compiler - quil::euler-yxy-compiler - quil::euler-xyx-compiler - quil::euler-xzx-compiler)) + (let ((master-matrix (cl-quil::random-special-unitary 2))) + (dolist (compiler '(cl-quil::euler-zyz-compiler + cl-quil::euler-zxz-compiler + cl-quil::euler-yzy-compiler + cl-quil::euler-yxy-compiler + cl-quil::euler-xyx-compiler + cl-quil::euler-xzx-compiler)) (let* ((compiled-program (funcall compiler (build-anonymous-gate master-matrix 0))) - (compiled-matrix (quil::make-matrix-from-quil compiled-program))) - (is (quil::matrix-equals-dwim master-matrix compiled-matrix) + (compiled-matrix (cl-quil::make-matrix-from-quil compiled-program))) + (is (cl-quil::matrix-equals-dwim master-matrix compiled-matrix) "Euler translation test failed: ~A~%" compiler))))) (global-vars:define-global-var **compiler-fuzzers-available** @@ -50,24 +50,24 @@ ,@body)))) (define-fuzzer cl-quil::qs-compiler () - (inst "QS-FUZZ" (quil::random-special-unitary 8) 2 1 0)) + (inst "QS-FUZZ" (cl-quil::random-special-unitary 8) 2 1 0)) (define-fuzzer cl-quil::recognize-ucr () - (let ((m (quil::make-matrix-from-quil - (list (build-gate (quil::forked-operator (quil::forked-operator (quil::named-operator "RZ"))) + (let ((m (cl-quil::make-matrix-from-quil + (list (build-gate (cl-quil::forked-operator (cl-quil::forked-operator (cl-quil::named-operator "RZ"))) (loop :repeat 4 :collect (random (* 2 pi))) 2 1 0))))) (inst "UCR-FUZZ" m 2 1 0))) (define-fuzzer cl-quil::ucr-compiler-to-iswap () - (inst (quil::forked-operator (quil::forked-operator (quil::named-operator "RZ"))) + (inst (cl-quil::forked-operator (cl-quil::forked-operator (cl-quil::named-operator "RZ"))) (loop :repeat 4 :collect (random (* 2 pi))) 2 1 0)) (define-fuzzer cl-quil::ucr-compiler-to-cz () - (inst (quil::forked-operator (quil::forked-operator (quil::named-operator "RZ"))) + (inst (cl-quil::forked-operator (cl-quil::forked-operator (cl-quil::named-operator "RZ"))) (loop :repeat 4 :collect (random (* 2 pi))) 2 1 0)) @@ -120,7 +120,7 @@ DEFGATE U(%alpha) p q AS PAULI-SUM: Z(3*%alpha) q U(time) 1 0")) - (inst (quil::vnth 0 (parsed-program-executable-code pp)))) + (inst (cl-quil::vnth 0 (parsed-program-executable-code pp)))) (setf (application-parameters inst) (list (mref "fuzz" 0))) (finish-compiler (list inst)))) @@ -135,7 +135,7 @@ DEFGATE U(%alpha) p q r AS PAULI-SUM: Z(%alpha) q U(time) 2 1 0")) - (inst (quil::vnth 0 (parsed-program-executable-code pp)))) + (inst (cl-quil::vnth 0 (parsed-program-executable-code pp)))) (setf (application-parameters inst) (list (mref "fuzz" 0))) (finish-compiler (list inst)))) @@ -173,26 +173,26 @@ U(time) 2 1 0")) (add-clique (rest qubits)))))) (dolist (binding bindings) (etypecase binding - (quil::wildcard-binding + (cl-quil::wildcard-binding (error 'test-case-too-complicated :reason "I don't know how to make tests for permissive compilers.")) - (quil::measure-binding + (cl-quil::measure-binding (error 'test-case-too-complicated :reason "I don't know how to make tests for MEASURE compilers.")) - (quil::gate-binding - (when (quil::gate-binding-options binding) + (cl-quil::gate-binding + (when (cl-quil::gate-binding-options binding) (error 'test-case-too-complicated :reason "I don't know how to make test cases for guarded compilers.")) - (add-clique (quil::gate-binding-arguments binding)) - (when (listp (quil::gate-binding-parameters binding)) + (add-clique (cl-quil::gate-binding-arguments binding)) + (when (listp (cl-quil::gate-binding-parameters binding)) (setf parameter-names (union parameter-names - (loop :for param :in (quil::gate-binding-parameters binding) + (loop :for param :in (cl-quil::gate-binding-parameters binding) :when (and (typep param 'symbol) (not (eql '_ param))) :collect param))))))) ;; color the graph with qubit indices. it'd be :cool: if this were randomized. - (quil::dohash ((qubit collision-names) adjacency-table) + (cl-quil::dohash ((qubit collision-names) adjacency-table) (let ((collision-qubits (mapcar (lambda (name) (gethash name adjacency-table)) collision-names))) (loop :for j :from 0 @@ -201,7 +201,7 @@ U(time) 2 1 0")) (return)))) ;; save the max of the largest instruction qubit number & the k in the k-coloring (setf qubit-bound (max (loop :for binding :in bindings - :maximize (1+ (length (quil::gate-binding-arguments binding)))) + :maximize (1+ (length (cl-quil::gate-binding-arguments binding)))) (loop :for name :being :the :hash-keys :of adjacency-table :using (hash-value qubit-assignment) :maximize (1+ qubit-assignment)))) @@ -213,7 +213,7 @@ U(time) 2 1 0")) ;; walk the instructions, doing parameter/argument instantiation (values (loop :for binding :in bindings :collect - (let* ((params (when (listp (quil::gate-binding-parameters binding)) + (let* ((params (when (listp (cl-quil::gate-binding-parameters binding)) (mapcar (lambda (param) (cond ((numberp param) @@ -223,7 +223,7 @@ U(time) 2 1 0")) (t (error 'test-case-too-complicated :reason "I don't know how to generate this parameter.")))) - (quil::gate-binding-parameters binding)))) + (cl-quil::gate-binding-parameters binding)))) (qubits (mapcar (lambda (qubit) (cond ((numberp qubit) @@ -232,7 +232,7 @@ U(time) 2 1 0")) nil) ((symbolp qubit) (gethash qubit adjacency-table)))) - (quil::gate-binding-arguments binding))) + (cl-quil::gate-binding-arguments binding))) (occupied-qubits (remove-if #'symbolp qubits)) (qubits (let ((output-qubits nil)) @@ -245,44 +245,44 @@ U(time) 2 1 0")) (append output-qubits occupied-qubits)) output-qubits))))))) (cond - ((symbolp (quil::gate-binding-operator binding)) - (apply #'quil::anon-gate "ANONYMOUS-INPUT" - (quil::random-special-unitary (ash 1 (length qubits))) + ((symbolp (cl-quil::gate-binding-operator binding)) + (apply #'cl-quil::anon-gate "ANONYMOUS-INPUT" + (cl-quil::random-special-unitary (ash 1 (length qubits))) qubits)) (t - (apply #'quil::build-gate (quil::gate-binding-operator binding) params qubits))))) + (apply #'cl-quil::build-gate (cl-quil::gate-binding-operator binding) params qubits))))) parameter-assignments)))) (defun %patch-mref-values (instr table) (unless (and (typep instr 'gate-application) - (quil::application-parameters instr)) + (cl-quil::application-parameters instr)) (return-from %patch-mref-values instr)) - (let ((instr-new (quil::copy-instance instr))) - (setf (quil::application-parameters instr-new) - (mapcar #'quil::copy-instance - (quil::application-parameters instr-new))) + (let ((instr-new (cl-quil::copy-instance instr))) + (setf (cl-quil::application-parameters instr-new) + (mapcar #'cl-quil::copy-instance + (cl-quil::application-parameters instr-new))) (labels ((treesplore (expression) (cond ((listp expression) (mapcar #'treesplore expression)) - ((quil::delayed-expression-p expression) - (quil::make-delayed-expression - nil nil (treesplore (quil::delayed-expression-expression expression)))) - ((typep expression 'quil::memory-ref) - (let* ((name (quil::memory-ref-name expression))) + ((cl-quil::delayed-expression-p expression) + (cl-quil::make-delayed-expression + nil nil (treesplore (cl-quil::delayed-expression-expression expression)))) + ((typep expression 'cl-quil::memory-ref) + (let* ((name (cl-quil::memory-ref-name expression))) (gethash name table))) (t expression)))) - (map-into (quil::application-parameters instr-new) + (map-into (cl-quil::application-parameters instr-new) (lambda (param) (typecase param - (quil::delayed-expression + (cl-quil::delayed-expression (let ((res (treesplore param))) - (quil::evaluate-delayed-expression res))) - (quil::memory-ref + (cl-quil::evaluate-delayed-expression res))) + (cl-quil::memory-ref (constant (gethash (memory-ref-name param) table))) (otherwise param))) - (quil::application-parameters instr-new)) + (cl-quil::application-parameters instr-new)) instr-new))) (defun %make-de-value-table (quil) @@ -291,11 +291,11 @@ U(time) 2 1 0")) :for params := (application-parameters instr) :do (dolist (param (application-parameters instr)) (typecase param - (quil::delayed-expression - (let ((name (quil::memory-ref-name (quil::delayed-expression-expression param)))) + (cl-quil::delayed-expression + (let ((name (cl-quil::memory-ref-name (cl-quil::delayed-expression-expression param)))) (setf (gethash name table) (random (* 2 pi))))) - (quil::memory-ref - (let ((name (quil::memory-ref-name param))) + (cl-quil::memory-ref + (let ((name (cl-quil::memory-ref-name param))) (setf (gethash name table) (random (* 2 pi))))))) :finally (return table))) @@ -303,32 +303,32 @@ U(time) 2 1 0")) (deftest test-translators () (declare (optimize (debug 3) (speed 0))) (labels ((do-compilation (compiler) - (unless (quil::compiler-gateset-reducer-p compiler) + (unless (cl-quil::compiler-gateset-reducer-p compiler) (return-from do-compilation nil)) (let (test-case test-case-patched input-matrix compiled-output output-matrix table) ;; building the test case can throw an error if the compiler itself is ;; too complicated. we don't intend for that to break the tests. (handler-case (setf test-case (or (alexandria:when-let* - ((name (quil::compiler-name compiler)) + ((name (cl-quil::compiler-name compiler)) (fuzzer (gethash name **compiler-fuzzers-available**))) (funcall fuzzer)) (generate-translator-test-case-for-simple-compiler - (quil::compiler-bindings compiler)))) + (cl-quil::compiler-bindings compiler)))) (test-case-too-complicated (c) - (format t "~&Compiler ~A not tested because ~A" (quil::compiler-name compiler) (test-case-too-complicated-reason c)) + (format t "~&Compiler ~A not tested because ~A" (cl-quil::compiler-name compiler) (test-case-too-complicated-reason c)) (return-from do-compilation nil))) (setf table (%make-de-value-table test-case)) (setf test-case-patched (mapcar (a:rcurry #'%patch-mref-values table) test-case)) - (setf input-matrix (quil::make-matrix-from-quil test-case-patched)) + (setf input-matrix (cl-quil::make-matrix-from-quil test-case-patched)) (setf compiled-output (mapcar (a:rcurry #'%patch-mref-values table) (apply compiler test-case))) - (setf output-matrix (quil::make-matrix-from-quil compiled-output)) - (format t "~& Testing compiler ~A" (quil::compiler-name compiler)) - (is (quil::matrix-equals-dwim input-matrix output-matrix)) + (setf output-matrix (cl-quil::make-matrix-from-quil compiled-output)) + (format t "~& Testing compiler ~A" (cl-quil::compiler-name compiler)) + (is (cl-quil::matrix-equals-dwim input-matrix output-matrix)) t))) - (loop :for compiler :in (remove-if (a:rcurry #'typep 'quil::approximate-compiler) - quil::**compilers-available**) + (loop :for compiler :in (remove-if (a:rcurry #'typep 'cl-quil::approximate-compiler) + cl-quil::**compilers-available**) :count t :into compiler-count :count (do-compilation compiler) :into hit-count :finally (let ((hit-rate (/ hit-count compiler-count))) @@ -365,17 +365,17 @@ U(time)~{ ~a~}" (patch-table (alexandria:plist-hash-table (list "time" (random 2pi)) :test #'equalp)) (pp (parse-quil program)) - (original-output (quil::make-matrix-from-quil + (original-output (cl-quil::make-matrix-from-quil (mapcar (a:rcurry #'%patch-mref-values patch-table) (coerce (parsed-program-executable-code pp) 'list)))) - (cpp (compiler-hook pp (quil::build-nq-fully-connected-chip qubit-count))) - (compiled-output (quil::make-matrix-from-quil + (cpp (compiler-hook pp (cl-quil::build-nq-fully-connected-chip qubit-count))) + (compiled-output (cl-quil::make-matrix-from-quil (mapcar (a:rcurry #'%patch-mref-values patch-table) (coerce (parsed-program-executable-code cpp) 'list))))) - (is (quil::matrix-equals-dwim original-output compiled-output)))) + (is (cl-quil::matrix-equals-dwim original-output compiled-output)))) (deftest test-simple-defexpis () - (let ((chip (quil::build-nq-fully-connected-chip 2))) + (let ((chip (cl-quil::build-nq-fully-connected-chip 2))) (dolist (prog-text (list " PRAGMA INITIAL_REWIRING \"NAIVE\" DEFGATE EXPI(%beta) p q AS PAULI-SUM: @@ -393,10 +393,10 @@ DEFGATE EXPI(%beta) p AS PAULI-SUM: EXPI(2.0) 0 RZ(-2.0) 0")) (let* ((cpp (compiler-hook (parse-quil prog-text) chip)) - (m (quil:parsed-program-to-logical-matrix cpp))) - (is (quil::double= 1d0 (abs (magicl:tref m 0 0)))) + (m (cl-quil:parsed-program-to-logical-matrix cpp))) + (is (cl-quil::double= 1d0 (abs (magicl:tref m 0 0)))) (loop :for j :below (magicl:nrows m) - :do (is (quil::double= (magicl:tref m 0 0) + :do (is (cl-quil::double= (magicl:tref m 0 0) (magicl:tref m j j)))))))) (deftest test-parametric-simple-defexpi () @@ -409,12 +409,12 @@ DECLARE t REAL f(t) 0"))) (is (compiler-hook progm - (quil::build-nq-fully-connected-chip 2))))) + (cl-quil::build-nq-fully-connected-chip 2))))) (deftest test-horizontal-composition-of-pauli-term->matrix () (flet ((word->matrix (word) - (quil::pauli-term->matrix - (quil::make-pauli-term :pauli-word word + (cl-quil::pauli-term->matrix + (cl-quil::make-pauli-term :pauli-word word :prefactor 1 :arguments (a:iota (length word))) (a:iota (length word)) nil nil))) @@ -424,7 +424,7 @@ f(t) 0"))) (I (word->matrix "I")) (word-size 4) (word (random-pauli-word word-size)) - (m (quil::eye 1))) + (m (cl-quil::eye 1))) (loop :for char :across word :for p := (ecase char (#\X X) @@ -432,7 +432,7 @@ f(t) 0"))) (#\Z Z) (#\I I)) :do (setf m (magicl:kron m p))) - (is (quil::operator= m (word->matrix word)))))) + (is (cl-quil::operator= m (word->matrix word)))))) (defun random-permutation (list) (unless (null list) @@ -448,14 +448,14 @@ f(t) 0"))) (declare (ignore x)) (constant (random (* 2 pi)))) (make-list (expt 2 (1- qubit-count))))) - (ucr-instruction (apply #'quil::build-UCR roll-type angle-list argument-list)) - (ucr-matrix (quil::make-matrix-from-quil (list ucr-instruction))) - (anonymous-instr (make-instance 'quil::gate-application + (ucr-instruction (apply #'cl-quil::build-UCR roll-type angle-list argument-list)) + (ucr-matrix (cl-quil::make-matrix-from-quil (list ucr-instruction))) + (anonymous-instr (make-instance 'cl-quil::gate-application :operator #.(named-operator "ANONYMOUS-UCR") :arguments (mapcar #'qubit (nreverse (a:iota qubit-count))) :gate ucr-matrix)) - (recognized-instruction (quil::recognize-ucr anonymous-instr)) - (recognized-matrix (quil::make-matrix-from-quil recognized-instruction))) + (recognized-instruction (cl-quil::recognize-ucr anonymous-instr)) + (recognized-matrix (cl-quil::make-matrix-from-quil recognized-instruction))) (fiasco-assert-matrices-are-equal ucr-matrix recognized-matrix)))) @@ -472,10 +472,10 @@ f(t) 0"))) (list "PISWAP" (list (random 1.0d0)) #'cl-quil::PISWAP-to-native-PISWAPs))) (destructuring-bind (operator params expander) instr-type (format t "~& Testing global-to-local ~A expansion~%" operator) - (let* ((instr (quil::build-gate operator params 0 3)) + (let* ((instr (cl-quil::build-gate operator params 0 3)) (ref-mat (cl-quil::make-matrix-from-quil (list instr))) (mat (cl-quil::make-matrix-from-quil (funcall expander instr - :context (quil::make-compilation-context + :context (cl-quil::make-compilation-context :chip-specification chip-spec))))) (is (cl-quil::matrix-equality ref-mat (cl-quil::scale-out-matrix-phases mat ref-mat)))))))) @@ -507,32 +507,32 @@ f(t) 0"))) (deftest test-phase-compiles-to-rz () "A PHASE gate should trivially compile to a RZ gate, preserving parameters." - (let* ((cphase (quil::parse-quil "PHASE(0) 0")) - (cphase-compiled (quil::compiler-hook cphase (quil::build-8q-chip))) - (cphase-parametric (quil::parse-quil "DECLARE gamma REAL[1] + (let* ((cphase (cl-quil::parse-quil "PHASE(0) 0")) + (cphase-compiled (cl-quil::compiler-hook cphase (cl-quil::build-8q-chip))) + (cphase-parametric (cl-quil::parse-quil "DECLARE gamma REAL[1] PHASE(2*gamma[0]) 0")) - (cphase-parametric-compiled (quil::compiler-hook cphase-parametric (build-8q-chip))) - (rz (quil::compiler-hook (quil::parse-quil "RZ(0) 0") (build-8q-chip))) - (rz-parametric (quil::compiler-hook (quil::parse-quil "DECLARE gamma REAL[1] -RZ(2*gamma[0]) 0") (quil::build-8q-chip)))) + (cphase-parametric-compiled (cl-quil::compiler-hook cphase-parametric (build-8q-chip))) + (rz (cl-quil::compiler-hook (cl-quil::parse-quil "RZ(0) 0") (build-8q-chip))) + (rz-parametric (cl-quil::compiler-hook (cl-quil::parse-quil "DECLARE gamma REAL[1] +RZ(2*gamma[0]) 0") (cl-quil::build-8q-chip)))) (fiasco-assert-matrices-are-equal - (quil::make-matrix-from-quil (coerce (quil::parsed-program-executable-code cphase-compiled) 'list)) - (quil::make-matrix-from-quil (coerce (quil::parsed-program-executable-code rz) 'list))) + (cl-quil::make-matrix-from-quil (coerce (cl-quil::parsed-program-executable-code cphase-compiled) 'list)) + (cl-quil::make-matrix-from-quil (coerce (cl-quil::parsed-program-executable-code rz) 'list))) ;; one phase should compile to one rz - (is (= (length (quil::parsed-program-executable-code cphase-parametric-compiled)) - (length (quil::parsed-program-executable-code rz-parametric)))))) + (is (= (length (cl-quil::parsed-program-executable-code cphase-parametric-compiled)) + (length (cl-quil::parsed-program-executable-code rz-parametric)))))) (deftest test-modifier-compilers () (let ((text "DECLARE theta REAL ; DAGGER CONTROLLED FORKED RZ(1*theta, 2*theta) 1 0 2")) (dolist (architecture '(:cz :iswap)) - (let* ((quil::*compress-carefully* nil) - (orig (coerce (parsed-program-executable-code (quil::parse-quil text)) 'list)) - (cpp (quil::expand-to-native-instructions (coerce (parsed-program-executable-code (quil::parse-quil text)) 'list) - (quil::build-nq-fully-connected-chip 3 :architecture architecture))) + (let* ((cl-quil::*compress-carefully* nil) + (orig (coerce (parsed-program-executable-code (cl-quil::parse-quil text)) 'list)) + (cpp (cl-quil::expand-to-native-instructions (coerce (parsed-program-executable-code (cl-quil::parse-quil text)) 'list) + (cl-quil::build-nq-fully-connected-chip 3 :architecture architecture))) (table (a:plist-hash-table (list "theta" (random 2pi)) :test #'equalp))) - (is (quil::operator= - (quil::make-matrix-from-quil (mapcar (a:rcurry #'%patch-mref-values table) + (is (cl-quil::operator= + (cl-quil::make-matrix-from-quil (mapcar (a:rcurry #'%patch-mref-values table) orig)) - (quil::make-matrix-from-quil (mapcar (a:rcurry #'%patch-mref-values table) + (cl-quil::make-matrix-from-quil (mapcar (a:rcurry #'%patch-mref-values table) cpp)))))))) diff --git a/tests/typed-memory-tests.lisp b/tests/typed-memory-tests.lisp index 3c60ca3c1..f53120c79 100644 --- a/tests/typed-memory-tests.lisp +++ b/tests/typed-memory-tests.lisp @@ -8,7 +8,7 @@ (in-package #:cl-quil-tests) (deftest test-typed-circuit-expansion () - (let ((pp (quil::parse-quil " + (let ((pp (cl-quil::parse-quil " DECLARE a BIT DEFCIRCUIT CLEAR q scratch-bit: @@ -18,14 +18,14 @@ DEFCIRCUIT CLEAR q scratch-bit: LABEL @end CLEAR 0 a"))) - (let ((instr (aref (quil::parsed-program-executable-code pp) 0))) - (is (typep instr 'quil::measure)) - (is (= (quil::qubit-index (quil::measurement-qubit instr)) 0)) - (is (equalp (quil::measure-address instr) - (quil::mref "a" 0 (first (quil::parsed-program-memory-definitions pp)))))))) + (let ((instr (aref (cl-quil::parsed-program-executable-code pp) 0))) + (is (typep instr 'cl-quil::measure)) + (is (= (cl-quil::qubit-index (cl-quil::measurement-qubit instr)) 0)) + (is (equalp (cl-quil::measure-address instr) + (cl-quil::mref "a" 0 (first (cl-quil::parsed-program-memory-definitions pp)))))))) (deftest test-constant-coercion () - (let ((pp (quil::parse-quil " + (let ((pp (cl-quil::parse-quil " DECLARE stats INTEGER DECLARE angle REAL @@ -35,15 +35,15 @@ MOVE angle 0 RX(-2.0*angle) 0"))) (let ((code (parsed-program-executable-code pp))) - (is (equalp quil::quil-integer (quil::constant-value-type - (quil::classical-right-operand (aref code 0))))) - (is (equalp quil::quil-real (quil::constant-value-type - (quil::classical-right-operand (aref code 1))))) + (is (equalp cl-quil::quil-integer (cl-quil::constant-value-type + (cl-quil::classical-right-operand (aref code 0))))) + (is (equalp cl-quil::quil-real (cl-quil::constant-value-type + (cl-quil::classical-right-operand (aref code 1))))) (let ((param (first (application-parameters (aref code 2))))) - (is (typep param 'quil::delayed-expression)))))) + (is (typep param 'cl-quil::delayed-expression)))))) (deftest test-compression-with-classical-angles () - (let ((pp (quil::parse-quil " + (let ((pp (cl-quil::parse-quil " DECLARE val REAL[8] DECLARE ro BIT DECLARE int INTEGER @@ -52,11 +52,11 @@ RZ(val[2]) 0 RZ(val[0]+val[1]) 0 RZ(val[1]) 0 RZ(val[3]) 1"))) - (let ((cpp (quil::compiler-hook pp (quil::build-8Q-chip)))) - (is (= 3 (length (quil::parsed-program-executable-code cpp))))))) + (let ((cpp (cl-quil::compiler-hook pp (cl-quil::build-8Q-chip)))) + (is (= 3 (length (cl-quil::parsed-program-executable-code cpp))))))) (deftest test-compression-with-classical-angles-+-resource-usage () - (let ((pp (quil::parse-quil " + (let ((pp (cl-quil::parse-quil " DECLARE val REAL[8] DECLARE ro BIT DECLARE int INTEGER @@ -66,13 +66,13 @@ STORE val int[0] val[1] RZ(val[0]+val[1]) 0 RZ(val[1]) 0 RZ(val[3]) 1"))) - (let ((cpp (quil::compiler-hook pp (quil::build-8Q-chip)))) - (is (= 5 (length (quil::parsed-program-executable-code cpp))))))) + (let ((cpp (cl-quil::compiler-hook pp (cl-quil::build-8Q-chip)))) + (is (= 5 (length (cl-quil::parsed-program-executable-code cpp))))))) (deftest test-paltry-type-conversions () "Test that we convert classical base classes into specialized classes correctly." - (let ((code (quil:parsed-program-executable-code - (quil:parse-quil " + (let ((code (cl-quil:parsed-program-executable-code + (cl-quil:parse-quil " DECLARE w BIT DECLARE x OCTET DECLARE y INTEGER @@ -85,13 +85,13 @@ XOR x x LOAD z z y STORE w y w ")))) - (is (every #'typep code '(quil:classical-not-bit - quil:classical-addition-real/real - quil:classical-addition-real/immediate - quil:classical-convert-real/bit - quil:classical-exclusive-or-octet/octet - quil:classical-load-real/real*/integer - quil:classical-store-bit*/integer/bit))))) + (is (every #'typep code '(cl-quil:classical-not-bit + cl-quil:classical-addition-real/real + cl-quil:classical-addition-real/immediate + cl-quil:classical-convert-real/bit + cl-quil:classical-exclusive-or-octet/octet + cl-quil:classical-load-real/real*/integer + cl-quil:classical-store-bit*/integer/bit))))) (deftest test-classical-equality-immediate-types () (signals quil-type-error (parse-quil "DECLARE r BIT; DECLARE a BIT; EQ r a 1.0")) diff --git a/tests/utilities.lisp b/tests/utilities.lisp index 558742fba..55a0fefcd 100644 --- a/tests/utilities.lisp +++ b/tests/utilities.lisp @@ -43,7 +43,7 @@ is still being signalled." (decf ,retries-left) (go ,TRY-AGAIN)))))))))) -(defun matrix-mismatch (m u &key (test #'quil::double~)) +(defun matrix-mismatch (m u &key (test #'cl-quil::double~)) "Return a LIST of the (ROW COL) indices of the first mismatch between M and U. If M and U are equal under TEST, return NIL." @@ -56,7 +56,7 @@ If M and U are equal under TEST, return NIL." (unless (funcall test (magicl:tref m r c) (magicl:tref u r c)) (return-from matrix-mismatch (list r c)))))) -(defun %print-matrix-mismatch (m u &key (test #'quil::double~) +(defun %print-matrix-mismatch (m u &key (test #'cl-quil::double~) stream) (a:if-let (mismatch-position (matrix-mismatch m u :test test)) (format stream @@ -89,7 +89,7 @@ For example, (defun fiasco-assert-matrices-are-equal (m u) (is (= (magicl:nrows u) (magicl:nrows m))) (is (= (magicl:ncols u) (magicl:ncols m))) - (setf u (quil::scale-out-matrix-phases u m)) + (setf u (cl-quil::scale-out-matrix-phases u m)) (flet ((test~ (a b) (< (abs (- a b)) 0.01))) (is (loop :for i :below (magicl:nrows m) :always @@ -113,7 +113,7 @@ For example, If PREFIX-P is non-nil, prefix the returned string with DELIMITER. If SUFFIX-P is non-nil, suffix the returned string with DELIMITER." - (check-type strings quil::string-sequence) + (check-type strings cl-quil::string-sequence) (check-type delimiter (or string character)) (with-output-to-string (stream) (loop :with last := (length strings)