-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantum-sim.py
More file actions
67 lines (42 loc) · 992 Bytes
/
quantum-sim.py
File metadata and controls
67 lines (42 loc) · 992 Bytes
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
from qiskit import QuantumCircuit
from qiskit_aer import Aer
import matplotlib.pyplot as plt
import numpy as np
backend = Aer.get_backend('qasm_simulator')
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
qc.draw('mpl')
plt.figure()
job = backend.run(qc, shots=1000)
result = job.result()
counts = result.get_counts(qc)
print(counts)
plt.bar(counts.keys(), counts.values())
plt.show()
########################################
qc = QuantumCircuit(1, 1)
qc.ry(np.pi/3, 0)
qc.measure(0, 0)
qc.draw('mpl')
plt.figure()
job = backend.run(qc, shots=1000)
result = job.result()
counts = result.get_counts(qc)
print(counts)
plt.bar(counts.keys(), counts.values())
plt.show()
########################################
qc = QuantumCircuit(1, 1)
qc.ry(np.pi/3, 0)
qc.x(0)
qc.measure(0, 0)
qc.draw('mpl')
plt.figure()
job = backend.run(qc, shots=1000)
result = job.result()
counts = result.get_counts(qc)
print(counts)
plt.bar(counts.keys(), counts.values())
plt.show()