Skip to content

Commit

Permalink
Draft script for extracting/plotting results
Browse files Browse the repository at this point in the history
  • Loading branch information
chmwzc committed May 10, 2024
1 parent f25f229 commit c3fa31b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# def circuit_benchmark(nqubits, backend, circuit_name, circuit_options=None,
def circuit_benchmark(
n_hydrogens,
backend, # circuit_name, circuit_options=None,
backend,
nreps=1,
nshots=None,
transfer=False,
Expand Down
Binary file added benchmarks/data/benchmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions benchmarks/data/plot-graphs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Parse the .dat files from running main.py to get and plot the dry_run_times
"""

import json
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np


def parse_dat_files(dat_glob, directory=None):
"""
Read all the .dat files found with dat_glob. .dat files should be in .json format
"""
if directory is None:
directory = "."

result = {}
for dat_file in Path(directory).glob(dat_glob):
_h_n, backend = dat_file.stem.split("_")
h_n = int(_h_n[1:])
if result.get(h_n) is None:
result[h_n] = {}
with open(dat_file) as file_handler:
result[h_n][backend] = json.load(file_handler)
return result


def main():
dat_glob = "*.dat"
json_data = parse_dat_files(dat_glob)
# Plot results
x_vals = sorted(json_data.keys())
# print(x_vals)
qibojit_vals = [json_data[_i]["qibojit"][0]["dry_run_time"] for _i in x_vals]
# print(qibojit_vals)
numpy_vals = [json_data[_i]["numpy"][0]["dry_run_time"] for _i in x_vals]
# print(numpy_vals)

plt.plot(x_vals, qibojit_vals, label="Qibojit")
plt.plot(x_vals, numpy_vals, label="Numpy")
plt.legend()
plt.ylabel("Time (s)")
plt.xlabel(r"Length of hydrogen chain, $H_n$")
plt.savefig("benchmark.svg")


if __name__ == "__main__":
main()
20 changes: 20 additions & 0 deletions benchmarks/run-benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash


nreps=10

# Run main.py with various command-line arguments/options
for n_hydrogen in 2 4 6 8; do
for backend in numpy qibojit; do
filename="h${n_hydrogen}_${backend}"
for precision in single double; do
python main.py --n_hydrogens ${n_hydrogen} --backend ${backend} --nreps ${nreps} --precision ${precision} --filename ${filename}.dat &>> ${filename}.log
echo &>> ${filename}.log
done

# Move the .log and .dat file into data/ folder
if [ -d "data" ]; then
mv ${filename}.dat ${filename}.log
fi
done
done

0 comments on commit c3fa31b

Please sign in to comment.