plot-benchmarks.py (5502B)
1 import matplotlib.pyplot as plt 2 import results_h48 3 import results_vcube 4 5 # Table sizes in bytes 6 7 sizes_h48 = { 8 6: 1897951528, 9 7: 3793842344, 10 8: 7585624040, 11 9: 15169187432, 12 10: 30336314216, 13 11: 60670567784, 14 } 15 16 sizes_vcube = { 17 112: 2603089920, 18 208: 7809269760, 19 308: 22777036800, 20 404: 34165555200, 21 212: 62474158080, 22 } 23 24 # Printing tables in markdown format 25 26 def print_row(solver_name, solver_size, dict, mul_by_size, superflip_star): 27 if dict is None: 28 return 29 solver_gib = solver_size / (2**30) 30 m = solver_gib if mul_by_size else 1 31 s = " (a) " if superflip_star else " " 32 cols = [f"{solver_name: <10}", f"{solver_gib:>4.1f} GiB"] + [ 33 f"{dict[key]*m/25:>8.2f}" if key in dict else " " 34 for key in [17, 18, 19, 20] 35 ] + [ 36 f"{dict["superflip"]*m:>9.2f}" if "superflip" in dict else s 37 ] 38 sep = "|" 39 print(sep + sep.join(cols) + sep) 40 41 def print_table(h48, vcube, ms, st): 42 vcube = vcube or {} 43 print("| Solver | Size |17 moves|18 moves|19 moves|20 moves|Superflip|") 44 print("|:---------|:-------|-------:|-------:|-------:|-------:|--------:|") 45 print_row("vcube 212", sizes_vcube[212], vcube.get(212), ms, not st) 46 print_row("H48 h11", sizes_h48[11], h48[11], ms, False) 47 print_row("vcube 404", sizes_vcube[404], vcube.get(404), ms, not st) 48 print_row("H48 h10", sizes_h48[10], h48[10], ms, False) 49 print_row("vcube 308", sizes_vcube[308], vcube.get(308), ms, not st) 50 print_row("H48 h9", sizes_h48[9], h48[9], ms, False) 51 print_row("vcube 208", sizes_vcube[208], vcube.get(208), ms, not st) 52 print_row("H48 h8", sizes_h48[8], h48[8], ms, False) 53 print_row("H48 h7", sizes_h48[7], h48[7], ms, False) 54 print_row("vcube 112", sizes_vcube[112], vcube.get(112), ms, not st) 55 print_row("H48 h6", sizes_h48[6], h48[6], ms, False) 56 57 print("<details><summary>Single solution, single thread</summary>") 58 print() 59 print("Time per cube (in seconds, lower is better).") 60 print() 61 print_table(results_h48.h48_single_thread, results_vcube.vcube_single_thread, False, True) 62 print() 63 print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") 64 print() 65 print_table(results_h48.h48_single_thread, results_vcube.vcube_single_thread, True, True) 66 print() 67 print( 68 '<img src="img/17moves1thread.png">\n' 69 '<img src="img/18moves1thread.png">\n' 70 '<img src="img/19moves1thread.png">\n' 71 '<img src="img/20moves1thread.png">' 72 ) 73 print("</details>") 74 75 print() 76 print("<details><summary>Single solution, 4 threads</summary>") 77 print() 78 print("Time per cube (in seconds, lower is better).") 79 print() 80 print_table(results_h48.h48_4_threads, results_vcube.vcube_4_threads, False, False) 81 print() 82 print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") 83 print() 84 print_table(results_h48.h48_4_threads, results_vcube.vcube_4_threads, True, False) 85 print() 86 print("(a) vcube cannot parallelize on a single scramble, the results for the") 87 print("superflip are going to be the same as in the single thread case.") 88 print() 89 print( 90 '<img src="img/17moves4threads.png">\n' 91 '<img src="img/18moves4threads.png">\n' 92 '<img src="img/19moves4threads.png">\n' 93 '<img src="img/20moves4threads.png">' 94 ) 95 print("</details>") 96 97 print() 98 print("<details><summary>Single solution, 16 threads</summary>") 99 print() 100 print("Time per cube (in seconds, lower is better).") 101 print() 102 print_table(results_h48.h48_16_threads, results_vcube.vcube_16_threads, False, False) 103 print() 104 print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") 105 print() 106 print_table(results_h48.h48_16_threads, results_vcube.vcube_16_threads, True, False) 107 print() 108 print("(a) vcube cannot parallelize on a single scramble, the results for the") 109 print("superflip are going to be the same as in the single thread case.") 110 print() 111 print( 112 '<img src="img/17moves16threads.png">\n' 113 '<img src="img/18moves16threads.png">\n' 114 '<img src="img/19moves16threads.png">\n' 115 '<img src="img/20moves16threads.png">' 116 ) 117 print("</details>") 118 119 print() 120 print("<details><summary>All solutions, 16 threads</summary>") 121 print() 122 print("*Note: vcube does not have an option for finding multiple solutions.*") 123 print() 124 print("Time per cube (in seconds, lower is better).") 125 print() 126 print_table(results_h48.h48_all_solutions, None, False, False) 127 print() 128 print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") 129 print() 130 print_table(results_h48.h48_all_solutions, None, True, False) 131 print() 132 print("</details>") 133 134 # Plotting 135 136 def plot(title, hd, vd, key): 137 d = 1 if key == "superflip" else 25 138 h48x = [sizes_h48[m]/(2**30) for m in hd.keys() if key in hd[m]] 139 vcubex = [sizes_vcube[m]/(2**30) for m in vd.keys() if key in vd[m]] 140 h48y = [d[key] for _, d in hd.items() if key in d] 141 vcubey = [d[key] for _, d in vd.items() if key in d] 142 143 plt.clf() 144 plt.title(title) 145 plt.xlabel("Table size (GiB)") 146 plt.ylabel("Time to solve (s / cube)") 147 plt.plot(h48x, h48y, "o--", label = "H48") 148 plt.plot(vcubex, vcubey, "o--", label = "vcube") 149 plt.legend(loc = "right") 150 filename = title.replace(" ", "").replace(",", "") + ".png" 151 plt.savefig("benchmarks/img/" + filename, dpi=300) 152 #plt.show() 153 154 rh, rv = results_h48.h48_single_thread, results_vcube.vcube_single_thread 155 for m in [17, 18, 19, 20]: 156 plot(f"{m} moves 1 thread", rh, rv, m) 157 158 rh, rv = results_h48.h48_4_threads, results_vcube.vcube_4_threads 159 for m in [17, 18, 19, 20]: 160 plot(f"{m} moves 4 threads", rh, rv, m) 161 162 rh, rv = results_h48.h48_16_threads, results_vcube.vcube_16_threads 163 for m in [17, 18, 19, 20]: 164 plot(f"{m} moves 16 threads", rh, rv, m)