Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing the default :initarg of channel-qvm to be valid #211

Merged
merged 1 commit into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/channel-qvm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
:initarg :noise-model
:accessor noise-model))
(:default-initargs
:noise-model nil)
:noise-model (make-noise-model nil))
(:documentation "The CHANNEL-QVM is a QVM that supports a fully explicit NOISE-MODEL. The NOISE-MODEL is an explicit definition of where and how different channels should be applied to a program running in the CHANNEL-QVM."))

(defmethod initialize-instance :after ((qvm channel-qvm) &rest args)
;; Initializes an instance of a CHANNEL-QVM.
(declare (ignore args))
(check-type (noise-model qvm) noise-model)
(setf
;; Initialize the TRIAL-AMPLITUDES to an empty array of the correct
;; size
Expand Down
3 changes: 2 additions & 1 deletion src/noise-models.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
;;; instructions.
(defconstant +maxpriority+ 20)
(defconstant +minpriority+ 0)
(deftype noise-priority () `(integer ,+minpriority+ ,+maxpriority+))
(alexandria:define-constant +default-noise-predicate-name+ "NOISE-NAME" :test #'string=)

(deftype noise-priority () `(integer ,+minpriority+ ,+maxpriority+))

(deftype noise-position ()
"Describes the position of a noise rule relative to an instruction. Should the noise be applied :BEFORE or :AFTER the instruction is executed?"
'(member :before :after))
Expand Down
24 changes: 18 additions & 6 deletions tests/channel-qvm-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@
(q (make-instance 'qvm::channel-qvm :number-of-qubits 2 :noise-model nm)))
(is (= 3 (length (qvm::noise-rules (qvm::noise-model q)))))
;; Check noise rules are ordered by priority
(is (>= (qvm::priority (qvm::noise-predicate (nth 0 (qvm::noise-rules (qvm::noise-model q)))))
(qvm::priority (qvm::noise-predicate (nth 1 (qvm::noise-rules (qvm::noise-model q)))))
(qvm::priority (qvm::noise-predicate (nth 2 (qvm::noise-rules (qvm::noise-model q)))))))
(is (>= (qvm::priority (qvm::noise-predicate
(nth 0 (qvm::noise-rules (qvm::noise-model q)))))
(qvm::priority (qvm::noise-predicate
(nth 1 (qvm::noise-rules (qvm::noise-model q)))))
(qvm::priority (qvm::noise-predicate
(nth 2 (qvm::noise-rules (qvm::noise-model q)))))))
;; Check that each noise rule has the correct number of operation elements.
(is (= 2 (length (qvm::operation-elements (nth 0 (qvm::noise-rules (qvm::noise-model q)))))))
(is (= 3 (length (qvm::operation-elements (nth 1 (qvm::noise-rules (qvm::noise-model q)))))))
(is (= 1 (length (qvm::operation-elements (nth 2 (qvm::noise-rules (qvm::noise-model q)))))))))
(is (= 2 (length (qvm::operation-elements
(nth 0 (qvm::noise-rules (qvm::noise-model q)))))))
(is (= 3 (length (qvm::operation-elements
(nth 1 (qvm::noise-rules (qvm::noise-model q)))))))
(is (= 1 (length (qvm::operation-elements
(nth 2 (qvm::noise-rules (qvm::noise-model q))))))))
;; Test channel-qvm with no noise-model
(let ((channel-qvm (make-instance 'channel-qvm :number-of-qubits 2))
(program (quil:parse-quil "DECLARE R0 BIT; H 0; CNOT 0 1")))
(load-program channel-qvm program :supersede-memory-subsystem t)
(run channel-qvm))
(signals error (make-instance 'channel-qvm :number-of-qubits 2 :noise-model nil)))

(deftest test-rule-matches-instr-p ()
;; Test that RULE-MATCHES-INSTR-P correctly finds matches between
Expand Down