/
ch04_teleport_cloud.js
60 lines (49 loc) · 1021 Bytes
/
ch04_teleport_cloud.js
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
// Programming Quantum Computers
// by Eric Johnston, Nic Harrigan and Mercedes Gimeno-Segovia
// O'Reilly Media
// To run this online, go to http://oreilly-qc.github.io?p=4-3
// An example of quantum cloud computation, achieved through teleportation
qc.reset(3);
var alice = qint.new(1, 'alice');
var ep = qint.new(1, 'ep');
var bob = qint.new(1, 'bob');
ep.write(0);
bob.write(0);
qc.label('entangle');
ep.had();
bob.cnot(ep);
qc.label('');
alice.write(0);
qc.label('prep payload');
alice.had();
alice.phase(45);
alice.had();
qc.label('');
qc.nop();
qc.print('alice prob:' + alice.peekProbability(1));
qc.label('send');
ep.cnot(alice);
alice.had();
alice.read();
ep.read();
qc.label('');
qc.nop();
// ej TODO: Check code order issue
qc.label('apply gate');
bob.had();
//bob.phase(30);
bob.had();
qc.label('');
qc.label('receive');
bob.cnot(ep);
bob.cz(alice);
qc.label('');
qc.nop();
qc.label('verify');
bob.had();
//bob.phase(-45-30);
bob.phase(-45);
bob.had();
bob.read();
qc.label('');
qc.nop();