-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphing_tools.py
More file actions
47 lines (39 loc) · 1.13 KB
/
graphing_tools.py
File metadata and controls
47 lines (39 loc) · 1.13 KB
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
# Automate generation of a histogram
def state_histogram(states, buckets):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
xpos = list(range(len(states)))
ax.bar(xpos, buckets, alpha=0.4)
ax.set_xticks(xpos)
ax.set_xticklabels(states)
ax.yaxis.grid(True)
ax.set_xlabel("State")
ax.set_ylabel("Probability")
plt.show()
# Generate the input lists for our histogram function from a braket counts object.
def braket_unpack(counts):
raw_states = counts.keys()
states = []
buckets = []
nsamples = 0
for a in raw_states:
nsamples += counts[a]
states.append("|"+a+">")
for a in raw_states:
buckets.append(counts[a]/nsamples)
return states,buckets
# Generate the input lists for our histogram function from a MyQLM results object.
def myqlm_unpack(result):
buckets = []
states = []
for sample in result:
buckets.append(sample.probability)
states.append(sample.state)
return states,buckets
# Generate the input lists for our histogram function from a qsharp_utils dict:
def qsharp_unpack(results):
states = list(results.keys())
buckets = []
for a in states:
buckets.append(results[a])
return states,buckets