When debugging qvm:measure, I find that qvm yields the incorrect result.
Here are the source code of qvm:measure:
(defmethod measure ((qvm base-qvm) q)
(check-type q nat-tuple-element)
(assert (< q (number-of-qubits qvm)) (qvm q)
"Trying to measure qubit ~D on a QVM with only ~D qubit~:P."
q
(number-of-qubits qvm))
(let* ((r (random 1.0d0))
(excited-probability (get-excited-state-probability (state qvm) q))
(cbit (if (<= r excited-probability)
1
0)))
;; Force the non-deterministic measurement.
(force-measurement cbit q (state qvm) excited-probability)
;; Return the qvm.
(values qvm cbit)))
The following is the flowchart drawn according to the above code snippet.
According to the above flowchart, if we set excited-probablity = 0.0d0 and r=0.0d0, the value of cbit is 1, while in fact the correct value of cbit is 0 because the probability of |1> is 0.0d0.
This exception can be triggered as the following steps:
Step 1:Replace the statement (let* ((r (random 1.0d0)) on line 7 with the statement (let* ((r (random 1)) to ensure the value of r to be 0;
Step 2: Run the following test case:
(setq *aqvm* (qvm:run-program 1 (cl-quil:parse-quil "I 0")))
(qvm:measure *aqvm* 0)
Note that gate I is used to make sure the value of excited-probability to be 0.0d0.
We think it is likely to be a logical problem of qvm.
When debugging
qvm:measure
, I find that qvm yields the incorrect result.Here are the source code of
qvm:measure
:The following is the flowchart drawn according to the above code snippet.
According to the above flowchart, if we set
excited-probablity = 0.0d0
andr=0.0d0
, the value ofcbit
is1
, while in fact the correct value ofcbit
is0
because the probability of |1> is0.0d0
.This exception can be triggered as the following steps: Step 1:Replace the statement
(let* ((r (random 1.0d0))
on line 7 with the statement(let* ((r (random 1))
to ensure the value ofr
to be0
; Step 2: Run the following test case:Note that
gate I
is used to make sure the value ofexcited-probability
to be0.0d0
.We think it is likely to be a logical problem of qvm.