quil-lang / qvm

The high-performance and featureful Quil simulator.
Other
413 stars 57 forks source link

Noise models #195

Closed sophiaponte closed 4 years ago

sophiaponte commented 5 years ago

175

channel-qvm.lisp is an implementation of a qvm that requires the user to explicitly define a noise model. The noise model is a set of noise rules. The noise rules describe where different types of noise should be injected in a program. Each rule is made up of a noise-predicate (describes the 'where' part) and operation-elements (kraus operators describing the noise). During each transition, the channel-qvm checks to see if the current instruction matches any of the noise-rules. If there is a match, the channel-qvm applies the noise-rule's operation elems either before or after the instruction is applied.

(defun build-noise-model ()
  (let* ((pred1 (make-noise-predicate (match-strict-qubits (list 0 1)) 1 "after"))
          (pred2 (make-noise-predicate (match-strict-gates (list "X" "Z")) 1 "after"))
          (kraus-elems1 (list (generate-damping-kraus-ops 2 1)))
          (kraus-elems2 (list (generate-damping-dephasing-kraus-ops 3 1)))
          (rule1 (make-noise-rule pred1 kraus-elems1))
          (rule2 (make-noise-rule pred2 kraus-elems2)))
    (make-noise-model (list rule1 rule2))))

approx-qvm.lisp Is an implementation of a qubit level noise model qvm. The noise model for this qvm is specified by adding T1, T2 and fReadout values for each qubit. The approx-qvm will generate the kraus operators for these values (or assignment probabilities in the case of fRo) and save them. Then, after each gate application instruction, this qvm searches for kraus operators belonging to the current qubit for either T1 or T2 and will apply them.

(defun make-noisy-approx-qvm ()
  (let* ((qvm (make-instance 'approx-qvm :number-of-qubits 2 :avg-gate-time 1)))
    (set-qubit-t1 qvm 0 5)
    (set-qubit-t2 qvm 0 4)
    (set-qubit-t1 qvm 1 2)
    (set-qubit-t2 qvm 1 3)))
braised-babbage commented 5 years ago

Overall this is good progress. Most of the things I mentioned are just minor stylistic tweaks to make this look more "idiomatic". The only more substantial issue is the predicate stuff. Here I think predicates should be basically any boolean function of a quil:instruction. This will take a bit more writing to get working at once, but is more powerful and more sustainable than the previous pyquil approach.

ecpeterson commented 5 years ago

I gave this a once-over, and it looks like it's headed very much in the right direction. Please ping me to check back again after you've knocked out Erik's and Appleby's comments.

Exciting changes ahead for noise in the QVM!

sophiaponte commented 4 years ago

Recent updates:

EDIT:

sophiaponte commented 4 years ago

In this last review I mostly made changes to documentation and a few smaller stylistic things. However, I did have to make a pretty big change in BASIC-NOISE-QVM to more accurately generate the Kraus operators for damping and dephasing noise. I'll summarize the changes here:

sophiaponte commented 4 years ago

I went through the src files again to catch any formatting issues, and I think I've cleaned everything up at this point. The last thing that I need to do is squash my commits, and then I think this should be good to go unless anyone thinks otherwise :)