diff --git a/performance/scaling_circuits.py b/performance/generate_data_scaling_circuits.py similarity index 69% rename from performance/scaling_circuits.py rename to performance/generate_data_scaling_circuits.py index 5b4a807..88ce816 100644 --- a/performance/scaling_circuits.py +++ b/performance/generate_data_scaling_circuits.py @@ -1,6 +1,7 @@ from collections import deque import matplotlib.pyplot as plt import numpy as np +import json from pyqcs import State, H, X, S, CZ from pyqcs.graph.state import GraphState @@ -35,13 +36,14 @@ def test_scaling_circuits(state_factory if __name__ == "__main__": nstart = 400 - nstop = 1600 + nstop = 800 step = 50 - ncircuits = 250 + ncircuits = 50 nqbits0 = 100 nqbits1 = 50 + seed = 0xdeadbeef - np.random.seed(0xdeadbeef) + np.random.seed(seed) results_graph0 = test_scaling_circuits(GraphState.new_zero_state , nstart , nstop @@ -49,7 +51,7 @@ if __name__ == "__main__": , nqbits0 , ncircuits , repeat=10) - np.random.seed(0xdeadbeef) + np.random.seed(seed) results_graph1 = test_scaling_circuits(GraphState.new_zero_state , nstart , nstop @@ -58,19 +60,21 @@ if __name__ == "__main__": , ncircuits , repeat=10) - h0 = plt.errorbar(results_graph0[:, 0], results_graph0[:, 2], results_graph0[:, 3] - , label=f"Graphical Simulator $N_q={nqbits0}$ Qbits" - , marker="^" - , color="black") - h1 = plt.errorbar(results_graph1[:, 0], results_graph1[:, 2], results_graph1[:, 3] - , label=f"Graphical Simulator $N_q={nqbits1}$ Qbits" - , marker="o" - , color="black") + np.savetxt("circuit_scaling_graph0.csv", results_graph0) + print("saved results0 to circuit_scaling_graph0.csv") + np.savetxt("circuit_scaling_graph1.csv", results_graph1) + print("saved results1 to circuit_scaling_graph1.csv") - plt.legend(handles=[h0, h1]) - plt.xlabel("Number of gates in circuit") - plt.ylabel("Execution time per circuit [s]") - plt.title(f"Execution Time for random Circuits") + meta = { + "nstart": 400 + , "nstop": 1800 + , "step": 50 + , "ncircuits": 50 + , "nqbits0": 100 + , "nqbits1": 50 + , "seed": 0xdeadbeef} + + with open("circuit_scaling_meta.json", "w") as fout: + json.dump(meta, fout) + print("saved meta to circuit_scaling_meta.json") - #plt.show() - plt.savefig("scaling_circuits.png", dpi=400) diff --git a/performance/scaling_qbits.py b/performance/generate_data_scaling_qbits.py similarity index 65% rename from performance/scaling_qbits.py rename to performance/generate_data_scaling_qbits.py index c63c87e..3afd270 100644 --- a/performance/scaling_qbits.py +++ b/performance/generate_data_scaling_qbits.py @@ -1,6 +1,7 @@ from collections import deque import matplotlib.pyplot as plt import numpy as np +import json from pyqcs import State, H, X, S, CZ from pyqcs.graph.state import GraphState @@ -31,18 +32,19 @@ def test_scaling_qbits(state_factory if __name__ == "__main__": nstart = 4 - nstop = 19 - ncircuits = 250 + nstop = 16 + ncircuits = 50 ngates_per_qbit = 100 + seed = 0xdeadbeef - np.random.seed(0xdeadbeef) + np.random.seed(seed) results_naive = test_scaling_qbits(State.new_zero_state , nstart , nstop , ngates_per_qbit , ncircuits , repeat=10) - np.random.seed(0xdeadbeef) + np.random.seed(seed) results_graph = test_scaling_qbits(GraphState.new_zero_state , nstart , nstop @@ -50,19 +52,18 @@ if __name__ == "__main__": , ncircuits , repeat=10) - h0 = plt.errorbar(results_naive[:, 0], results_naive[:, 2], results_naive[:, 3] - , label=f"Dense Vector Simulator $N_c={int(results_naive[:, 1][0])}$ circuits" - , marker="o" - , color="black") - h1 = plt.errorbar(results_graph[:, 0], results_graph[:, 2], results_graph[:, 3] - , label=f"Graphical Simulator $N_c={int(results_graph[:, 1][0])}$ circuits" - , marker="^" - , color="black") + np.savetxt("qbit_scaling_naive.csv", results_naive) + print("saved naive results to qbit_scaling_naive.csv") + np.savetxt("qbit_scaling_graph.csv", results_graph) + print("saved graph results to qbit_scaling_graph.csv") - plt.legend(handles=[h0, h1]) - plt.xlabel("Number of Qbits $N_q$") - plt.ylabel("Execution time per circuit [s]") - plt.title(f"Execution Time for ${ngates_per_qbit}\\times N_q$ Gates with random Circuits (rescaled)") + meta = {"nstart": nstart + , "nstop": nstop + , "ncircuits": ncircuits + , "ngates_per_qbit": ngates_per_qbit + , "seed": seed} + + with open("qbit_scaling_meta.json", "w") as fout: + json.dump(meta, fout) + print("saved meta data to qbit_scaling_meta.json") - #plt.show() - plt.savefig("Figure_1.png", dpi=400) diff --git a/performance/plot_scaling_circuits_linear.py b/performance/plot_scaling_circuits_linear.py new file mode 100644 index 0000000..d6b8005 --- /dev/null +++ b/performance/plot_scaling_circuits_linear.py @@ -0,0 +1,29 @@ +from collections import deque +import matplotlib +import matplotlib.pyplot as plt +import numpy as np +import json + +matplotlib.rcParams.update({'errorbar.capsize': 2}) + +results_graph0 = np.genfromtxt("circuit_scaling_graph0.csv") +results_graph1 = np.genfromtxt("circuit_scaling_graph1.csv") +with open("circuit_scaling_meta.json") as fin: + meta = json.load(fin) + +h0 = plt.errorbar(results_graph0[:, 0], results_graph0[:, 2], results_graph0[:, 3] + , label=f"Graphical Simulator $N_q={meta['nqbits0']}$ Qbits" + , marker="^" + , color="black") +h1 = plt.errorbar(results_graph1[:, 0], results_graph1[:, 2], results_graph1[:, 3] + , label=f"Graphical Simulator $N_q={meta['nqbits1']}$ Qbits" + , marker="o" + , color="black") + +plt.legend(handles=[h0, h1]) +plt.xlabel("Number of gates in circuit") +plt.ylabel("Execution time per circuit [s]") +plt.title(f"Execution Time for random Circuits") + +plt.show() +#plt.savefig("scaling_circuits_linear.png", dpi=400) diff --git a/performance/plot_scaling_qbits_linear.py b/performance/plot_scaling_qbits_linear.py new file mode 100644 index 0000000..e051a9b --- /dev/null +++ b/performance/plot_scaling_qbits_linear.py @@ -0,0 +1,29 @@ +import matplotlib.pyplot as plt +import matplotlib +import numpy as np +import json + +matplotlib.rcParams.update({'errorbar.capsize': 2}) + +results_naive = np.genfromtxt("qbit_scaling_naive.csv") +results_graph = np.genfromtxt("qbit_scaling_graph.csv") +with open("qbit_scaling_meta.json") as fin: + meta = json.load(fin) + + +h0 = plt.errorbar(results_naive[:, 0], results_naive[:, 2], results_naive[:, 3] + , label=f"Dense Vector Simulator $N_c={int(results_naive[:, 1][0])}$ circuits" + , marker="o" + , color="black") +h1 = plt.errorbar(results_graph[:, 0], results_graph[:, 2], results_graph[:, 3] + , label=f"Graphical Simulator $N_c={int(results_graph[:, 1][0])}$ circuits" + , marker="^" + , color="black") + +plt.legend(handles=[h0, h1]) +plt.xlabel("Number of Qbits $N_q$") +plt.ylabel("Execution time per circuit [s]") +plt.title(f"Execution Time for ${meta['ngates_per_qbit']}\\times N_q$ Gates with random Circuits (rescaled)") + +plt.show() +#plt.savefig("scaling_qbits_linear.png", dpi=400) diff --git a/performance/plot_scaling_qbits_log.py b/performance/plot_scaling_qbits_log.py new file mode 100644 index 0000000..6bffa45 --- /dev/null +++ b/performance/plot_scaling_qbits_log.py @@ -0,0 +1,31 @@ +import matplotlib.pyplot as plt +import matplotlib +import numpy as np +import json + +matplotlib.rcParams.update({'errorbar.capsize': 2}) + +results_naive = np.genfromtxt("qbit_scaling_naive.csv") +results_graph = np.genfromtxt("qbit_scaling_graph.csv") +with open("qbit_scaling_meta.json") as fin: + meta = json.load(fin) + + +h0 = plt.errorbar(results_naive[:, 0], results_naive[:, 2], results_naive[:, 3] + , label=f"Dense Vector Simulator $N_c={int(results_naive[:, 1][0])}$ circuits" + , marker="o" + , color="black") +h1 = plt.errorbar(results_graph[:, 0], results_graph[:, 2], results_graph[:, 3] + , label=f"Graphical Simulator $N_c={int(results_graph[:, 1][0])}$ circuits" + , marker="^" + , color="black") + +plt.yscale("log") +plt.legend(handles=[h0, h1]) +plt.xlabel("Number of Qbits $N_q$") +plt.ylabel("Execution time per circuit [s]") +plt.title(f"Execution Time for ${meta['ngates_per_qbit']}\\times N_q$ Gates with random Circuits (rescaled)") + +plt.show() +#plt.savefig("scaling_qbits_log.png", dpi=400) + diff --git a/performance/scaling_circuits.png b/performance/scaling_circuits.png index dfbe67f..7e4938b 100644 Binary files a/performance/scaling_circuits.png and b/performance/scaling_circuits.png differ