-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqcLec08-meas.R
67 lines (52 loc) · 1.85 KB
/
qcLec08-meas.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# ----------------------
# ---------- AD S. Aaronson, Introduction to Quantum Information Science Lecture Notes
# ---------- https://www.scottaaronson.com/qclec.pdf
# ----------------------
#
# This script is designed to run line by line --> RStudio and Ctrl + Enter
#
# Author: Mariusz Krej
#
# ----------------------
if("rstudioapi" %in% rownames(installed.packages()) && rstudioapi::isAvailable())
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
getwd()
if (FALSE)
rm(list=ls())
source("quSimLib.R")
source("modpow.R")
#------------------------
# Nimish Mishra, Understanding the basics of measurements in Quantum Computation
# https://towardsdatascience.com/understanding-basics-of-measurements-in-quantum-computation-4c885879eba0
M0 = q0 %*% t(Conj(q0))
M00 = q00 %*% t(Conj(q00))
M01 = q01 %*% t(Conj(q01))
M10 = q10 %*% t(Conj(q10))
M11 = q11 %*% t(Conj(q11))
N = 10
step1_dud = kronecker(ROT(pi/2/N) %*% q0, q0)
step1_bomb = CNOT %*% step1_dud
state = step1_bomb
state = step1_dud
meas = M00 + M10
meas %*% state / sqrt(Conj(t(state)) %*% meas %*% state)[1,1]
postmeas2 = function(state, measBasis)
{
meas = 0
for (it in measBasis)
meas = meas + it %*% t(Conj(it))
meas %*% state / sqrt(Conj(t(state)) %*% meas %*% state)[1,1]
}
round(postmeas2(step1_bomb, list(q00, q10)), 3)
round(postmeas2(step1_dud, list(q00, q10)), 3)
qmm %*% t(Conj(qmm)) + qpm %*% t(Conj(qpm)) + qmp %*% t(Conj(qmp)) + qpp %*% t(Conj(qpp))
state = CNOT %*% kronecker(ROT(pi/2/N) %*% q0, qm)
postmeas(state , list(qmm, qpm))
meas = qmm %*% t(Conj(qmm)) + qpm %*% t(Conj(qpm))
meas %*% state / sqrt(Conj(t(state)) %*% meas %*% state)[1,1]
postmeas(state , list(qmm, qpm))
# ad flip does nothing to |+〉
NOT %*% qp == qp
CNOT %*% qpp == qpp
# CNOT*CNOT == I, no tak --> crypto: c ⊕ k = m ⊕ k ⊕ k = m
all(CNOT %*% CNOT == diag(1,4))