Skip to content

Commit

Permalink
Fix up whitespace and typos (#234)
Browse files Browse the repository at this point in the history
* Fix up whitespace and typos

* Remove trailing whitespace
  • Loading branch information
jlapeyre authored and Robert Smith committed Jan 13, 2020
1 parent 1b3d43a commit 684ba3d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
22 changes: 11 additions & 11 deletions src/basic-noise-qvm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
;;; (setf (qubit-depolarization qvm 0) depolarization-prob-q0)
;;; (setf (qubit-depolarization qvm 1) depolarization-prob-q1)
;;;
;;; If we later wanted to add T1 noise, we can continue by doing the following:
;;; If we later wanted to add T1 noise, we can continue by doing the following:
;;;
;;; (setf (qubit-t1 qvm 0) t1-for-q0)
;;; (setf (qubit-t1 qvm 1) t1-for-q1)
Expand Down Expand Up @@ -108,7 +108,7 @@
(check-allocate-computation-space (state qvm))))

(defun %check-depol-entry (qubit kraus-map)
"Check that a key value pair in the DEPOLARIZATION-OPS slot is valid. The QUBIT must be a non-negative integer, and the KRAUS-MAP must be a valid kraus map. "
"Check that a key value pair in the DEPOLARIZATION-OPS slot is valid. The QUBIT must be a non-negative integer, and the KRAUS-MAP must be a valid kraus map."
(check-type qubit nat-tuple-element)
(check-kraus-ops kraus-map))

Expand Down Expand Up @@ -136,7 +136,7 @@

(defun (setf qubit-tphi) (tphi qvm qubit)
"Evaluate that TPHI is valid and save it for the specified QUBIT in the QVM."
(check-type tphi valid-noise-value)
(check-type tphi valid-noise-value)
(check-allocate-computation-space (state qvm))
(setf (gethash qubit (tphi-vals qvm)) tphi))

Expand All @@ -160,7 +160,7 @@
;; instruction involves more than one qubit, we need to tensor the
;; kraus operators for each qubit's error sources.
(loop :for noise-operators :in kraus-ops
:when noise-operators
:when noise-operators
:do (let ((simplified-kraus-ops (reduce #'kraus-kron noise-operators))
(qubits (mapcar #'quil:qubit-index (quil:application-arguments instr))))
(when simplified-kraus-ops
Expand Down Expand Up @@ -191,9 +191,9 @@
:for q-tphi := (gethash q (tphi-vals qvm))
:for q-t1 := (gethash q (t1-vals qvm))
:for q-t2 := (gethash q (t2-vals qvm))
:when (calculate-dephasing-map q-tphi q-t1 q-t2 curr-time)
:when (calculate-dephasing-map q-tphi q-t1 q-t2 curr-time)
:collect it))
(depol-ops (loop :for q :in qubits
(depol-ops (loop :for q :in qubits
:collect (gethash q (depolarization-ops qvm)))))
(apply-all-kraus-maps qvm instr (list damping-ops dephasing-ops depol-ops))
(setf (elapsed-time qvm) curr-time)))
Expand All @@ -205,21 +205,21 @@

(defun calculate-dephasing-map (qubit-tphi qubit-t1 qubit-t2 elapsed-time)
"Build the dephasing map. If TPHI is not null, use that to calculate the dephasing map. In the absence of a TPHI value, use T1 and T2 to calculate TPHI if those values exist. T2 is upper bounded by 2 * T1."
(cond
(cond
;; First, try to use T-PHI to calculate the dephasing operators
(qubit-tphi
(qubit-tphi
(dephasing-kraus-map qubit-tphi elapsed-time))
;; Next, if there are values for QUBIT-T1 and QUBIT-T2,
;; calculate T-PHI
((and qubit-t2 qubit-t1)
((and qubit-t2 qubit-t1)
(dephasing-kraus-map (tphi qubit-t1 qubit-t2) elapsed-time))
;; If either T1 or T2 is missing, an no T-PHI, return no kraus
;; operators.
(t nil)))

(defun tphi (t1 t2)
"Calculate t_phi from T1 and T2. T-PHI = (2*T1*T2) / (2*T1 + T2). T2 must be strictly less than 2 * T1."
(assert (< t2 (* 2.0d0 t1))
(assert (< t2 (* 2.0d0 t1))
(t1 t2)
"T2 must be upper bounded by 2*T1")
(check-type t1 valid-noise-value)
Expand Down Expand Up @@ -258,7 +258,7 @@
:collect (magicl:kron identity-matrix k)))
((endp k2s) (loop :for k :in k1s
:collect (magicl:kron k identity-matrix)))
(t (loop :for k1 :in k1s
(t (loop :for k1 :in k1s
:append (loop :for k2 :in k2s
:collect (magicl:kron k1 k2)))))))

Expand Down
6 changes: 3 additions & 3 deletions src/channel-qvm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
(null (slot-value qvm 'state)))
(%set-state (make-pure-state (number-of-qubits qvm))
qvm))
;; The the NOISE-MODEL is not empty, allocate space for
;; The NOISE-MODEL is not empty, allocate space for
;; TRIAL-AMPLITUDES in a PURE-STATE state. (This method is not
;; defined for a DMS)
(when (or (noise-rules (noise-model qvm))
Expand Down Expand Up @@ -131,7 +131,7 @@
(magicl:identityp kraus-sum)
(kraus-sum)
"The Kraus map must preserve trace or equivalently this matrix ~
~S must be equal to the identity"
~S must be equal to the identity"
kraus-sum))) t)

(defun check-all-kraus-ops (seq)
Expand All @@ -141,7 +141,7 @@
;;; Measurement

(defmethod measure-all-state ((state pure-state) (qvm channel-qvm))
;; Measure all QUBITS in PURE-STATE state of the the CHANNEL-QVM QVM
;; Measure all QUBITS in PURE-STATE state of the CHANNEL-QVM QVM
;; and apply readout noise if necessary.
(declare (ignore qvm))
(multiple-value-bind (qvm-ret measured-bits)
Expand Down
6 changes: 3 additions & 3 deletions src/mixed-state-qvm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
(defun make-mixed-state-qvm (num-qubits &key (allocation nil) &allow-other-keys)
"Build a MIXED-STATE-QVM with a DENSITY-MATRIX-STATE representing NUM-QUBITS qubits."
(check-type num-qubits unsigned-byte)
(make-instance 'mixed-state-qvm :number-of-qubits num-qubits
:state (make-density-matrix-state
num-qubits
(make-instance 'mixed-state-qvm :number-of-qubits num-qubits
:state (make-density-matrix-state
num-qubits
:allocation allocation)))

(defun full-density-number-of-qubits (vec-density)
Expand Down
28 changes: 14 additions & 14 deletions src/noise-models.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
;;; of NOISE-RULES, where each NOISE-RULE is a NOISE-PREDICATE and a
;;; list of OPERATION-ELEMENTS. The NOISE-PREDICATE defines how to
;;; match QUIL instructions around which to apply the kraus operators
;;; defined by the OPERATION-ELEMENTS.
;;; defined by the OPERATION-ELEMENTS.
;;;
;;; Example: A common noise model is the depolarization channel. To
;;; model depolarization on a qubit, inject depolarization operators
Expand Down Expand Up @@ -46,7 +46,7 @@
(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?"
"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))

;;; A NOISE-PREDICATE describes how and when to match instructions in
Expand Down Expand Up @@ -100,7 +100,7 @@
(defun predicate-and (noise-predicate1 noise-predicate2)
"Logical AND of 2 noise predicates. The NOISE-POSITION is taken from NOISE-PREDICATE1 and the priority is taken to be the max PRIORITY between the two predicates."
(let* ((new-name (and-predicate-names (name noise-predicate1) (name noise-predicate2)))
(conjunction (alexandria:conjoin (predicate-function noise-predicate1)
(conjunction (alexandria:conjoin (predicate-function noise-predicate1)
(predicate-function noise-predicate2)))
(priority (max (priority noise-predicate1) (priority noise-predicate2)))
(noise-position (noise-position noise-predicate1)))
Expand All @@ -109,7 +109,7 @@
(defun predicate-or (noise-predicate1 noise-predicate2)
"Logical OR of 2 noise predicates. The NOISE-POSITION is taken from NOISE-PREDICATE1 and the priority is taken to be the max PRIORITY between the two predicates."
(let* ((new-name (or-predicate-names (name noise-predicate1) (name noise-predicate2)))
(disjunction (alexandria:disjoin (predicate-function noise-predicate1)
(disjunction (alexandria:disjoin (predicate-function noise-predicate1)
(predicate-function noise-predicate2)))
(priority (max (priority noise-predicate1) (priority noise-predicate2)))
(noise-position (noise-position noise-predicate1)))
Expand Down Expand Up @@ -208,11 +208,11 @@
(append (operation-elements r1)
(operation-elements r2)))
:collect (apply #'make-noise-rule
(predicate-and (noise-predicate r1)
(predicate-and (noise-predicate r1)
(predicate-not (noise-predicate r2)))
(operation-elements r1))
:collect (apply #'make-noise-rule
(predicate-and (noise-predicate r2)
(predicate-and (noise-predicate r2)
(predicate-not (noise-predicate r1)))
(operation-elements r2))))))

Expand All @@ -227,50 +227,50 @@

(defun match-any-n-qubits (n qubit-list)
"The returned function is true if there is any intersection between the instruction's qubits and the QUBIT-LIST for an N-qubit operation. We need to specify N in the rule because a 2 qubit gate CNOT 0 1 could match a rule with qubits that has operation elements for a 1q gate. We want to prevent this, so we require the user to specify the number of qubits expected in the gate."
(lambda (instr)
(lambda (instr)
(and (typep instr 'quil:gate-application)
(= n (length (mapcar #'quil:qubit-index (quil:application-arguments instr))))
(intersection qubit-list (mapcar #'quil:qubit-index (quil:application-arguments instr))))))

(defun match-strict-gate (gate)
"The returned function is true if the instruction is a GATE-APPLICATION that is exactly equal to GATE."
(lambda (instr)
(lambda (instr)
(and (typep instr 'quil:gate-application)
(quil::plain-operator-p (quil:application-operator instr))
(string= gate (cl-quil::application-operator-root-name instr)))))

(defun match-any-gates (&rest gates)
"The returned function is true if there is any intersection between the instruction's gate and GATES."
(lambda (instr)
(lambda (instr)
(and (typep instr 'quil:gate-application)
(quil::plain-operator-p (quil:application-operator instr))
(member (cl-quil::application-operator-root-name instr) gates :test #'string=))))

(defun match-all-nq-gates (n)
"The returned function is true if the instruction operates on N qubits."
(lambda (instr)
(lambda (instr)
(and (typep instr 'quil:gate-application)
(= n (length (quil:application-arguments instr))))))

(defun match-all-gates ()
"The returned function is true if the instruction contains a gate (not a MEASURE)."
(lambda (instr)
(lambda (instr)
(typep instr 'quil:gate-application)))

(defun match-measure ()
"The returned function is true if the instruction is a MEASURE."
(lambda (instr)
(lambda (instr)
(typep instr 'quil:measurement)))

(defun match-measure-at-strict (qubit)
"The returned function is true if the instruciton is a MEASURE on the specified QUBIT."
(lambda (instr)
(lambda (instr)
(and (typep instr 'quil:measurement)
(= qubit (quil:qubit-index (quil:measurement-qubit instr))))))

(defun match-measure-at-any (&rest qubits)
"The returned function is true if the instruciton is a MEASURE on any of the specified QUBITS."
(lambda (instr)
(lambda (instr)
(and (typep instr 'quil:measurement)
(member (quil:qubit-index (quil:measurement-qubit instr)) qubits))))

Expand Down
10 changes: 5 additions & 5 deletions src/qvm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
;;; via the ADD-KRAUS PRAGMA.

(defclass base-qvm (classical-memory-mixin)
((number-of-qubits ; XXX: Should we just compute the number of qubits from the STATE?
((number-of-qubits ; XXX: Should we just compute the number of qubits from the STATE?
:reader number-of-qubits
:initarg :number-of-qubits
:type alexandria:non-negative-fixnum
:initform (error ":NUMBER-OF-QUBITS is a required initarg to BASE-QVM.")
:documentation "Number of qubits being simulated by the QVM.")
(state
(state
:reader state
:writer %set-state
:initarg :state
:documentation "The state of the quantum system simulated by the QVM.")
(program-compiled-p
(program-compiled-p
:accessor program-compiled-p
:initform nil
:documentation "Has the loaded program been compiled?")
(superoperator-definitions
(superoperator-definitions
:initarg :superoperator-definitions
:accessor superoperator-definitions
:initform (make-hash-table :test 'equalp)
Expand Down Expand Up @@ -90,7 +90,7 @@
;; Wrap a gate defined by GATE-NAME and QUBITS in a superoperator
;; defined by KRAUS-OPS. When the QVM reads an instruction with
;; GATE-NAME on QUBITS, the superoperator made from the KRAUS-OPS
;; will be applied to the state of the QVM.
;; will be applied to the state of the QVM.
;;
;; Note: if we are applying superoperators, we do not want to
;; compile the QVM program before running it.
Expand Down

0 comments on commit 684ba3d

Please sign in to comment.