This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Adding Bar Graph Visualization for games/applications #24
Open
danielleodigie
wants to merge
10
commits into
Qiskit:main
Choose a base branch
from
danielleodigie:visualization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c5ceb54
adding dj
danielleodigie ac22583
fixing deustch jozsa
danielleodigie b296c82
fixing lint stuff
danielleodigie 1d7acae
fixing lint issues again
danielleodigie 07e7a9a
adding bar graph visualization
danielleodigie a924195
fixing files
danielleodigie 5621b4b
Merge branch 'Qiskit:main' into visualization
danielleodigie 6f0fb64
adding dual file comparison
danielleodigie e1d38ed
adding doc
danielleodigie 1baee45
fixing labels
danielleodigie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,153 @@ | ||||||||||||||||||||||
import sys | ||||||||||||||||||||||
import json | ||||||||||||||||||||||
from turtle import color | ||||||||||||||||||||||
import matplotlib.pyplot as plt | ||||||||||||||||||||||
from numpy import mean | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def fidelity(contents, contents2 = None): | ||||||||||||||||||||||
if not contents2: | ||||||||||||||||||||||
try: | ||||||||||||||||||||||
bench_name = {} | ||||||||||||||||||||||
bench_fid= {} | ||||||||||||||||||||||
for i,bench in enumerate(contents["benchmarks"]): | ||||||||||||||||||||||
bench_name[bench["name"]] = i + 1 | ||||||||||||||||||||||
if bench_fid.get(bench["name"]): | ||||||||||||||||||||||
bench_fid[bench["name"]] = bench_fid.get(bench["name"]) + bench["stats"]["quality"]["fidelity"] | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
bench_fid[bench["name"]] = bench["stats"]["quality"]["fidelity"] | ||||||||||||||||||||||
fidavg = [] | ||||||||||||||||||||||
for i in bench_fid: | ||||||||||||||||||||||
fidavg.append(bench_fid[i]/bench_name[i]) | ||||||||||||||||||||||
return bench_name.keys(), fidavg | ||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||
print("Uh, Oh! Something went wrong") | ||||||||||||||||||||||
print(e) | ||||||||||||||||||||||
Comment on lines
+10
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to just not have the exception here raise? |
||||||||||||||||||||||
else: | ||||||||||||||||||||||
#try: | ||||||||||||||||||||||
bench_names = ["Benchmark #1", "Benchmark #2"] | ||||||||||||||||||||||
bench_fid = {"Benchmark #1" : 0 , "Benchmark #2" : 0} | ||||||||||||||||||||||
count1 = 0 | ||||||||||||||||||||||
count2 = 0 | ||||||||||||||||||||||
avgs = [] | ||||||||||||||||||||||
for i, bench in enumerate(contents["benchmarks"]): | ||||||||||||||||||||||
count1+=1 | ||||||||||||||||||||||
bench_fid["Benchmark #1"] = bench_fid.get("Benchmark #1") + bench["stats"]["quality"]["fidelity"] | ||||||||||||||||||||||
|
||||||||||||||||||||||
for i, bench in enumerate(contents2["benchmarks"]): | ||||||||||||||||||||||
count2+=1 | ||||||||||||||||||||||
bench_fid["Benchmark #2"] = bench_fid.get("Benchmark #2") + bench["stats"]["quality"]["fidelity"] | ||||||||||||||||||||||
|
||||||||||||||||||||||
avgs.append(bench_fid["Benchmark #1"]/count1) | ||||||||||||||||||||||
avgs.append(bench_fid["Benchmark #2"]/count2) | ||||||||||||||||||||||
print(avgs) | ||||||||||||||||||||||
return bench_names, avgs | ||||||||||||||||||||||
#except Exception as e: | ||||||||||||||||||||||
#print("Uh, Oh! Something went wrong") | ||||||||||||||||||||||
#print(e) | ||||||||||||||||||||||
|
||||||||||||||||||||||
def meantime(contents, contents2 = None): | ||||||||||||||||||||||
if not contents2: | ||||||||||||||||||||||
try: | ||||||||||||||||||||||
bench_name = {} | ||||||||||||||||||||||
bench_mean= {} | ||||||||||||||||||||||
for i,bench in enumerate(contents["benchmarks"]): | ||||||||||||||||||||||
bench_name[bench["name"]] = i + 1 | ||||||||||||||||||||||
if bench_mean.get(bench["name"]): | ||||||||||||||||||||||
bench_mean[bench["name"]] = bench_mean.get(bench["name"]) + bench["stats"]["timing"]["mean"] | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
bench_mean[bench["name"]] = bench["stats"]["timing"]["mean"] | ||||||||||||||||||||||
timeavg = [] | ||||||||||||||||||||||
for i in bench_mean: | ||||||||||||||||||||||
timeavg.append(bench_mean[i]/bench_name[i]) | ||||||||||||||||||||||
return bench_name.keys(), timeavg | ||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||
print("Uh, Oh! Something went wrong") | ||||||||||||||||||||||
print(e) | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
try: | ||||||||||||||||||||||
bench_names = ["Benchmark #1", "Benchmark #2"] | ||||||||||||||||||||||
bench_times = {"Benchmark #1" : 0, "Benchmark #2" : 0} | ||||||||||||||||||||||
count1 = 0 | ||||||||||||||||||||||
count2 = 0 | ||||||||||||||||||||||
avgs = [] | ||||||||||||||||||||||
for bench in enumerate(contents["benchmarks"]): | ||||||||||||||||||||||
count1+=1 | ||||||||||||||||||||||
bench_times["Benchmark #1"] += bench["stats"]["timing"]["mean"] | ||||||||||||||||||||||
|
||||||||||||||||||||||
for bench in enumerate(contents2["benchmarks"]): | ||||||||||||||||||||||
count2+=1 | ||||||||||||||||||||||
bench_times["Benchmark #1"] += bench["stats"]["timing"]["mean"] | ||||||||||||||||||||||
|
||||||||||||||||||||||
avgs.append(bench_times["Benchmark #1"]/count1) | ||||||||||||||||||||||
avgs.append(bench_times["Benchmark #2"]/count2) | ||||||||||||||||||||||
return bench_names, avgs | ||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||
print("Uh, Oh! Something went wrong") | ||||||||||||||||||||||
print(e) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def main(args): | ||||||||||||||||||||||
#arg parsing | ||||||||||||||||||||||
if len(args) == 4: | ||||||||||||||||||||||
viewtype = args[1] | ||||||||||||||||||||||
file = args[2] | ||||||||||||||||||||||
datatype = args[3] | ||||||||||||||||||||||
if len(args) == 5: | ||||||||||||||||||||||
viewtype = args[1] | ||||||||||||||||||||||
file = args[2] | ||||||||||||||||||||||
file2 = args[3] | ||||||||||||||||||||||
datatype = args[4] | ||||||||||||||||||||||
Comment on lines
+94
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you leverage argparse for this so we have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If need be, I could help you with this @danielleodigie. |
||||||||||||||||||||||
if viewtype == "view": | ||||||||||||||||||||||
results_file = file | ||||||||||||||||||||||
with open(results_file, 'r') as f: | ||||||||||||||||||||||
contents = json.load(f) | ||||||||||||||||||||||
if datatype == "fidelity": | ||||||||||||||||||||||
x_axis, y_axis = fidelity(contents) | ||||||||||||||||||||||
ax = plt.subplot() | ||||||||||||||||||||||
plt.bar(x_axis, y_axis, color="darkolivegreen") | ||||||||||||||||||||||
plt.xlabel("Benchmark Name") | ||||||||||||||||||||||
plt.ylabel("Fidelity") | ||||||||||||||||||||||
plt.setp(ax.get_xticklabels(), rotation=30, ha='right') | ||||||||||||||||||||||
plt.show() | ||||||||||||||||||||||
elif datatype == "meantime": | ||||||||||||||||||||||
x_axis, y_axis = meantime(contents) | ||||||||||||||||||||||
ax = plt.subplot() | ||||||||||||||||||||||
plt.bar(x_axis, y_axis, color="darkolivegreen") | ||||||||||||||||||||||
plt.xlabel("Benchmark Name") | ||||||||||||||||||||||
plt.ylabel("Mean Time") | ||||||||||||||||||||||
plt.setp(ax.get_xticklabels(), rotation=30, ha='right') | ||||||||||||||||||||||
plt.show() | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
print("Invalid Data Type! Allowed parameters are: 'fidelity' and 'meantime'") | ||||||||||||||||||||||
if viewtype == "compare": | ||||||||||||||||||||||
with open(file, 'r') as f: | ||||||||||||||||||||||
contents1 = json.load(f) | ||||||||||||||||||||||
with open(file2, 'r') as f: | ||||||||||||||||||||||
contents2 = json.load(f) | ||||||||||||||||||||||
if datatype == "fidelity": | ||||||||||||||||||||||
x_axis, y_axis = fidelity(contents1, contents2) | ||||||||||||||||||||||
ax = plt.subplot() | ||||||||||||||||||||||
plt.bar(x_axis, y_axis, color="darkolivegreen") | ||||||||||||||||||||||
plt.xlabel("Benchmark Name") | ||||||||||||||||||||||
plt.ylabel("Fidelity") | ||||||||||||||||||||||
plt.setp(ax.get_xticklabels(), rotation=30, ha='right') | ||||||||||||||||||||||
plt.show() | ||||||||||||||||||||||
elif datatype == "meantime": | ||||||||||||||||||||||
x_axis, y_axis = meantime(contents1, contents2) | ||||||||||||||||||||||
ax = plt.subplot() | ||||||||||||||||||||||
plt.bar(x_axis, y_axis, color="darkolivegreen") | ||||||||||||||||||||||
plt.xlabel("Benchmark Name") | ||||||||||||||||||||||
plt.ylabel("Mean Time") | ||||||||||||||||||||||
plt.setp(ax.get_xticklabels(), rotation=30, ha='right') | ||||||||||||||||||||||
plt.show() | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
print("Invalid Data Type! Allowed parameters are: 'fidelity' and 'meantime'") | ||||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||
main(sys.argv) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
Comment on lines
+147
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is turtle in the requirements list? I think this will fail unless people manually install turtle so we should add it to the requirements list https://github.com/Qiskit/red-queen/blob/main/requirements.txt so that it gets installed with red queen. That being said I don;t think anything is actually using this.