forked from iQuHACK/2023_IonQ_Remote
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_encoder_part1.py
66 lines (51 loc) · 1.04 KB
/
test_encoder_part1.py
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
import qiskit as qk
from qiskit import QuantumCircuit, Aer, IBMQ
from qiskit import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import plot_histogram
from math import pi
import matplotlib.pyplot as plt
theta = [0, pi / 8, pi / 4, 3 * pi / 8]
qc = QuantumCircuit(3)
qc.h(0)
qc.h(1)
qc.barrier()
# Pixel 1
qc.cry(theta[0], 0, 2)
qc.cx(0, 1)
qc.cry(-theta[0], 1, 2)
qc.cx(0, 1)
qc.cry(theta[0], 1, 2)
qc.barrier()
# Pixel 2
qc.x(1)
qc.cry(theta[1], 0, 2)
qc.cx(0, 1)
qc.cry(-theta[1], 1, 2)
qc.cx(0, 1)
qc.cry(theta[1], 1, 2)
qc.barrier()
qc.x(1)
qc.x(0)
qc.cry(theta[2], 0, 2)
qc.cx(0, 1)
qc.cry(-theta[2], 1, 2)
qc.cx(0, 1)
qc.cry(theta[2], 1, 2)
qc.barrier()
qc.x(1)
qc.cry(theta[3], 0, 2)
qc.cx(0, 1)
qc.cry(-theta[3], 1, 2)
qc.cx(0, 1)
qc.cry(theta[3], 1, 2)
qc.measure_all()
print(qc.draw())
aer_sim = Aer.get_backend('aer_simulator')
t_qc = transpile(qc, aer_sim)
qobj = assemble(t_qc, shots=4096)
result = aer_sim.run(qobj).result()
counts = result.get_counts(qc)
print(counts)
plot_histogram(counts)
plt.show()