forked from nkpro2000/IVyearProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantum.py
More file actions
43 lines (30 loc) · 854 Bytes
/
quantum.py
File metadata and controls
43 lines (30 loc) · 854 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
import qiskit_
from bits_nums import *
import matplotlib.pyplot as plt
N = 5 # max no. of qbits we have in IBMQ free
def get_qcir(n=None):
if n is None:
n = N
q, c = QuantumRegister(n), ClassicalRegister(n)
qcir = QuantumCircuit(q, c)
qcir.h(q)
# insert qbit manipulate circuit
qcir.measure(q, c)
return qcir
def show(qcir):
qcir.draw(output='mpl').show()
def output(qcir, backend=None):
if backend == 1:
backend = qiskit_.qbackend1
elif backend == 2:
backend = qiskit_.qbackend2
else:
backend = qiskit_.sbackend
job = execute(qcir, backend)
return result(job, 0)
def plot(counts):
if type(counts) is not dict:
counts = counts.get_counts()
plt.figure("Result")
plt.plot(counts.keys(), counts.values(), 'X')
plt.show(block=False)