-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
302 lines (212 loc) · 6.06 KB
/
index.Rmd
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
---
title: "Quantum FlyTrap Demo"
description: |
Welcome to the demo. I hope you enjoy it!
site: distill::distill_website
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
# Learn more about creating websites with Distill at:
# https://rstudio.github.io/distill/website.html
# Learn more about publishing to GitHub Pages at:
# https://rstudio.github.io/distill/publish_website.html#github-pages
```
```{r, results='asis', echo=FALSE, message=FALSE}
cat(
"<script src='https://cdn.jsdelivr.net/npm/vue@2.6.12'></script>",
"<script src='https://unpkg.com/quantum-tensors@0.4.10/dist/quantum-tensors.min.js'></script>",
"<script src='https://unpkg.com/bra-ket-vue@0.3.1/dist/bra-ket-vue.min.js'></script>"
)
```
Author: **Deep Lokhande**
---
## Example 0 Test Examples.
- This section is included just to test if everthing loads properly.
- Proceed to next section for actual submission.
#### Test adding user defined vector.
<div id='qtest'></div>
#### Test adding gates/operators.
<div id='op-h'></div>
---
## Example 1
- In this example we will look at the simple case of effect of pauli gates ($H$ and $X$) on initial state.
<div id='ex1'></div>
---
## Example 2
- In this example we will look at matrix multiplication and tensor products of operators.
### Input Matrix
- This is a user defined operator using `Operator.fromArray()` function.
- For simplicity I have considered Hadamard Matrix, but an other matrix will work.
<div id='uin'></div>
### Example of matrix multiplication $H \cdot H = I$
- Here, we look at matrix multiplication between 2 Hadamard matrices.
- As we know that Hadamard matrix is unitary matrix, multiplying this matrix with itself will result in Identity matrix.
<div id='ex2mul'></div>
### Example of tensor multiplication $H \otimes I$
- Here, we look at tensor product of one Hadamard and Identity matrix.
- We will observe the dimensionality increase in the output matrix, where tensor product between two $2 \times 2$ matrices, result in a $4 \times 4$ matrix.
<div id='ex2ten'></div>
---
## Quantum Teleportation
- In this section, we will look at and example of Quantum Teleportation.
- The initial state can be chosen by user as $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$.
- For simplicity here I chose $|\psi\rangle = |1\rangle$
- The steps in the teleportation are explained briefly in the value column of Ketlistviewer.
<div id='qtp'></div>
---
Hope the reviewer of this site will approve my work.
Looking forward for working with you.
Let me know if you need anything else regarding this project.
- Contact Details:
- Phone: +1-(848)-252-0653
- Email: [deep.lokhande@rutgers.edu](mailto:deep.lokhande@rutgers.edu)
- Webpage: [deeplokhande.github.io](https://deeplokhande.github.io)
# THANK YOU
```{js,results='asis', echo=FALSE, message=FALSE}
const { Circuit,Gates, Vector, Dimension, Cx, Operator } = QuantumTensors;
const { MatrixViewer, KetListViewer, KetViewer } = BraKetVue;
const rt2 = 1 / Math.sqrt(2);
function showKet(elName, vector) {
new Vue({
el: elName,
template: "<ket-viewer :vector='vector' :dark-mode='false'/>",
components: {
KetViewer,
},
data() {
return { vector }
}
})
}
function showMatrix(elName, operator) {
return new Vue({
el: elName,
template: "<matrix-viewer :operator-raw='operator' :dark-mode='false'/>",
components: {
MatrixViewer,
},
data() {
return { operator }
}
})
}
function showKetList(elName, list) {
return new Vue({
el: elName,
template: "<ket-list-viewer :steps='list' :dark-mode='false'/>",
components: {
KetListViewer,
},
data() {
return { list }
}
})
}
// Example 0 Code
const qtest = Vector.fromArray(
[Cx(1), Cx(0), Cx(2, 1), Cx(0, -1)],
[Dimension.qubit(), Dimension.qubit()]
).normalize();
showKet('#qtest',qtest);
showMatrix('#op-h',Gates.H());
// Example 1 Code
const qex1 = Vector.fromArray([Cx(1), Cx(0)], [Dimension.qubit()]).normalize();
let ex1=[
{
value: "Initial State",
vector: qex1,
},
{
value: "After applying H gate on initial state",
vector: Gates.H().mulVec(qex1),
},
{
value: "After applying X gate on initial state",
vector: Gates.X().mulVec(qex1),
},
];
showKetList('#ex1',ex1);
// Example 2 Code
const uin = Operator.fromArray(
[
[Cx(rt2), Cx(rt2)],
[Cx(rt2), Cx(-rt2)],
],
[Dimension.qubit()]
);
let ex2mul = uin.mulOp(uin);
let ex2ten = uin.outer(Gates.I());
showMatrix('#uin',uin);
showMatrix('#ex2mul',ex2mul);
showMatrix('#ex2ten', ex2ten);
// Example 3 Code (TODO)
// Quantum Teleportation
const circh = [];
let circ = Circuit.qubits(1)
// .applyGate(uin,0)
.X(0)
.saveTo(circh)
.addQubit()
.addQubit()
.H(1)
.CNOT(1, 2)
.saveTo(circh)
.CNOT(0, 1)
.H(0)
.saveTo(circh)
.CNOT(1,2)
.saveTo(circh)
.SWAP(0,2)
.saveTo(circh);
// Following conditional statements could be used, but I choose different method to find the final answer.
// if (circh[2].measureQubit(1)[1]["probability"] === 1) {
// circ.X(2);
// circ.saveTo(circh);
// }
// if (circh[2].measureQubit(0)[1]["probability"] === 1) {
// circ.Z(2);
// circ.saveTo(circh);
// }
let a = circh[4].measureQubit(0)[0]['probability'];
let b = circh[4].measureQubit(0)[1]['probability'];
let outState = Vector.fromArray(
[Cx(a),Cx(b)],
[Dimension.qubit()],
removeZeros = 'false',
).normalize();
let qtp = [
{
value: "Initial state to be teleported on 0th qubit",
vector: circh[0].vector
},
{
value: "Adding 2 more qubits and creating Bell Pair on 1st and 2nd qubit",
vector: circh[1].vector,
},
{
value: "Alice does operations on 0th and 1st qubit",
vector: circh[2].vector,
},
{
value: "Bob does corrective operations",
vector: circh[3].vector,
},
{
value: "Bob does corrective operations",
vector: circh[4].vector,
},
{
value: "The teleported state is",
vector: outState,
},
];
showKetList('#qtp',qtp);
```
```{css, echo=FALSE}
.matrix-viewer {
margin: auto;
}
a {
color: #42b983;
}
```