-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.py
127 lines (102 loc) · 3.25 KB
/
field.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# import numpy as np
# from numpy import pi
# import ipywidgets as widgets
# from IPython.display import display
# from qutip import Bloch
# import matplotlib as plt
# import time
# from qiskit import QuantumCircuit
# from qiskit import Aer, execute
# from qiskit.visualization import plot_histogram
# # makes quantum curcuit for the hieght
# blockHeightCircuit=QuantumCircuit(3)
# blockHeightCircuit.h(1)
# blockHeightCircuit.z(1)
# blockHeightCircuit.h(0)
# blockHeightCircuit.h(2)
# backend_sim = Aer.get_backend('statevector_simulator')
# sim = execute(blockHeightCircuit, backend_sim, shots=5000)
# sim_result = sim.result()
# counts = sim_result.get_counts(blockHeightCircuit)
# print(counts)
# blockHeightCircuit.measure
# boardspace =[[0, 0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 0]]
# plot_histogram(counts)
# def x_measurement(blockHeightCircuit,qubit,cbit):
# blockHeightCircuit.measure(qubit, cbit)
# blockHeightCircuit.h(qubit)
# return blockHeightCircuit
# print(x_measurement)
#----------------------------------------------------------------
import numpy as np
from numpy import pi
# import ipywidgets as widgets
# from IPython.display import display
# from qutip import Bloch
import matplotlib
# import time
from qiskit import *
# from qiskit import Aer, execute
from qiskit.tools.visualization import plot_histogram
# makes quantum curcuit for the height, bhcircuit = blockHeightCircuit
bhCircuit=QuantumCircuit(3, 3)
bhCircuit.h(1)
bhCircuit.z(1)
bhCircuit.h(0)
bhCircuit.h(2)
backend_sim = Aer.get_backend('statevector_simulator')
sim = execute(bhCircuit, backend_sim, shots=5000)
sim_result = sim.result()
statevector = sim_result.get_statevector()
print(statevector)
bhCircuit.draw(output='mpl')
bhCircuit.measure([0,1,2], [0,1,2])
backend = Aer.get_backend('qasm_simulator')
result = execute(bhCircuit, backend = backend, shots = 5000).result()
counts = result.get_counts()
print(counts)
boardspace =[[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]]
plot_histogram(counts)
import random
total = 0
for (key, value) in counts.items():
total += value
poss_q_states = ['000',
'001',
'010',
'011',
'100',
'101',
'110',
'111']
q_probs = []
for q_state in poss_q_states:
prob = int(counts[q_state])/5000
q_probs.append(prob)
# print(q_probs) prints list of q state probabilities
# k = random.choices(poss_q_states, weights = q_probs, k=1)
# print(k) just a test
qubit_state = []
num_qubits = 48
for i in range(num_qubits):
k = random.choices(poss_q_states, weights = q_probs, k=1)
qubit_state.append(k)
print(qubit_state)
# for i in boardspace:
# for j in i:
# with np.nditer(boardspace, op_flags=['readwrite']) as i:
# for i in j:
# i = random.choices(poss_q_states, weights = q_probs, k=1)
# print(boardspace)