-
Notifications
You must be signed in to change notification settings - Fork 59
/
ch02_04_spy_hunter.qasm
65 lines (56 loc) · 1.54 KB
/
ch02_04_spy_hunter.qasm
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
// Programming Quantum Computers
// by Eric Johnston, Nic Harrigan and Mercedes Gimeno-Segovia
// O'Reilly Media
//
// More samples like this can be found at http://oreilly-qc.github.io
//
// A complete set of all OpenQASM samples (including this one) can be found at
// https://github.com/oreilly-qc/oreilly-qc.github.io/tree/master/samples/OpenQASM
//
// OpenQASM code was generated with the help of Qiskit (http://qiskit.org)
// A complete set of all Qiskit samples (including this one) can be found at
// https://github.com/oreilly-qc/oreilly-qc.github.io/tree/master/samples/Qiskit
//
// Run this sample in the IBM Q Experience Circuit Composer
// at https://quantum-computing.ibm.com
// Example 2-4: Quasntum Spy Hunter
OPENQASM 2.0;
include "qelib1.inc";
// Set up the program
qreg alice[1];
qreg fiber[1];
qreg bob[1];
creg ahad[1];
creg aval[1];
creg fval[1];
creg bhad[1];
creg bval[1];
// Use Alice's QPU to generate two random bits
reset alice[0];
h alice[0];
measure alice[0] -> ahad[0];
reset alice[0];
h alice[0];
measure alice[0] -> aval[0];
// Prepare Alice's qubit
reset alice[0];
if(aval==1) x alice[0];
if(ahad==1) h alice[0];
// Send the qubit!
swap alice[0],fiber[0];
// Activate the spy
barrier alice[0],fiber[0],bob[0];
h fiber[0];
measure fiber[0] -> fval[0];
reset fiber[0];
if(fval==1) x fiber[0];
h fiber[0];
barrier alice[0],fiber[0],bob[0];
// Use Bob's QPU to generate a random bit
reset bob[0];
h bob[0];
measure bob[0] -> bhad[0];
// Receive the qubit!
swap fiber[0],bob[0];
if(bhad==1) h bob[0];
measure bob[0] -> bval[0];