diff options
Diffstat (limited to '')
| -rw-r--r-- | benchmarks/plot-benchmarks.py | 218 |
1 files changed, 175 insertions, 43 deletions
diff --git a/benchmarks/plot-benchmarks.py b/benchmarks/plot-benchmarks.py index 1a6fc39..dfd1f90 100644 --- a/benchmarks/plot-benchmarks.py +++ b/benchmarks/plot-benchmarks.py | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | import matplotlib.pyplot as plt | 1 | import matplotlib.pyplot as plt |
| 2 | import results_h48 | 2 | import results_h48 |
| 3 | import results_vcube | 3 | import results_vcube |
| 4 | import results_egg | ||
| 4 | from pathlib import Path | 5 | from pathlib import Path |
| 5 | 6 | ||
| 6 | benchmarks_dir = Path("benchmarks") | 7 | benchmarks_dir = Path("benchmarks") |
| @@ -29,6 +30,15 @@ sizes_vcube = { | |||
| 29 | 212: 62474158080, | 30 | 212: 62474158080, |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 33 | sizes_egg = { | ||
| 34 | 6: 1945686016, | ||
| 35 | 7: 3891367936, | ||
| 36 | 8: 7782731776, | ||
| 37 | 9: 15565459456, | ||
| 38 | 10: 31130914816, | ||
| 39 | 11: 62261825536, | ||
| 40 | } | ||
| 41 | |||
| 32 | # Printing tables in markdown format | 42 | # Printing tables in markdown format |
| 33 | 43 | ||
| 34 | def print_row(f, solver_name, solver_size, dict, mul_by_size, superflip_star): | 44 | def print_row(f, solver_name, solver_size, dict, mul_by_size, superflip_star): |
| @@ -46,48 +56,94 @@ def print_row(f, solver_name, solver_size, dict, mul_by_size, superflip_star): | |||
| 46 | sep = "|" | 56 | sep = "|" |
| 47 | f.write(sep + sep.join(cols) + sep + "\n") | 57 | f.write(sep + sep.join(cols) + sep + "\n") |
| 48 | 58 | ||
| 49 | def print_table(f, h48, vcube, ms, st): | 59 | def print_table(f, h48, vcube, egg, ms, st): |
| 50 | vcube = vcube or {} | 60 | vcube = vcube or {} |
| 51 | f.write("| Solver | Size |17 moves|18 moves|19 moves|20 moves|Superflip|\n") | 61 | egg = egg or {} |
| 52 | f.write("|:---------|:-------|-------:|-------:|-------:|-------:|--------:|\n") | 62 | f.write("|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|\n") |
| 63 | f.write("|:-----|:---|-------:|-------:|-------:|-------:|--------:|\n") | ||
| 53 | print_row(f, "vcube 212", sizes_vcube[212], vcube.get(212), ms, not st) | 64 | print_row(f, "vcube 212", sizes_vcube[212], vcube.get(212), ms, not st) |
| 65 | print_row(f, "egg h11", sizes_egg[11], egg.get(11), ms, False) | ||
| 54 | print_row(f, "H48 h11", sizes_h48[11], h48[11], ms, False) | 66 | print_row(f, "H48 h11", sizes_h48[11], h48[11], ms, False) |
| 55 | print_row(f, "vcube 404", sizes_vcube[404], vcube.get(404), ms, not st) | 67 | print_row(f, "vcube 404", sizes_vcube[404], vcube.get(404), ms, not st) |
| 68 | print_row(f, "egg h10", sizes_egg[10], egg.get(10), ms, False) | ||
| 56 | print_row(f, "H48 h10", sizes_h48[10], h48[10], ms, False) | 69 | print_row(f, "H48 h10", sizes_h48[10], h48[10], ms, False) |
| 57 | print_row(f, "vcube 308", sizes_vcube[308], vcube.get(308), ms, not st) | 70 | print_row(f, "vcube 308", sizes_vcube[308], vcube.get(308), ms, not st) |
| 71 | print_row(f, "egg h9", sizes_egg[9], egg.get(9), ms, False) | ||
| 58 | print_row(f, "H48 h9", sizes_h48[9], h48[9], ms, False) | 72 | print_row(f, "H48 h9", sizes_h48[9], h48[9], ms, False) |
| 59 | print_row(f, "vcube 208", sizes_vcube[208], vcube.get(208), ms, not st) | 73 | print_row(f, "vcube 208", sizes_vcube[208], vcube.get(208), ms, not st) |
| 74 | print_row(f, "egg h8", sizes_egg[8], egg.get(8), ms, False) | ||
| 60 | print_row(f, "H48 h8", sizes_h48[8], h48[8], ms, False) | 75 | print_row(f, "H48 h8", sizes_h48[8], h48[8], ms, False) |
| 76 | print_row(f, "egg h7", sizes_egg[7], egg.get(7), ms, False) | ||
| 61 | print_row(f, "H48 h7", sizes_h48[7], h48[7], ms, False) | 77 | print_row(f, "H48 h7", sizes_h48[7], h48[7], ms, False) |
| 62 | print_row(f, "vcube 112", sizes_vcube[112], vcube.get(112), ms, not st) | 78 | print_row(f, "vcube 112", sizes_vcube[112], vcube.get(112), ms, not st) |
| 79 | print_row(f, "egg h6", sizes_egg[6], egg.get(6), ms, False) | ||
| 63 | print_row(f, "H48 h6", sizes_h48[6], h48[6], ms, False) | 80 | print_row(f, "H48 h6", sizes_h48[6], h48[6], ms, False) |
| 64 | 81 | ||
| 65 | def print_factor_table(f, slow, fast): | 82 | def print_factor_table(f, slow_h48, fast_h48, slow_egg, fast_egg): |
| 66 | ratio = {} | 83 | ratio_h48 = {} |
| 84 | ratio_egg = {} | ||
| 67 | for m in [6, 7, 8, 9, 10, 11]: | 85 | for m in [6, 7, 8, 9, 10, 11]: |
| 68 | ratio[m] = {} | 86 | ratio_h48[m] = {} |
| 69 | for k in slow[m]: | 87 | ratio_egg[m] = {} |
| 70 | ratio[m][k] = (slow[m][k] / fast[m][k]) * (25 if k != "superflip" else 1) | 88 | for k in slow_h48[m]: |
| 71 | f.write("| Solver | Size |17 moves|18 moves|19 moves|20 moves|Superflip|\n") | 89 | ratio_h48[m][k] = ( |
| 72 | f.write("|:---------|:-------|-------:|-------:|-------:|-------:|--------:|\n") | 90 | (slow_h48[m][k] / fast_h48[m][k]) * |
| 73 | print_row(f, "H48 h11", sizes_h48[11], ratio[11], False, False) | 91 | (25 if k != "superflip" else 1) |
| 74 | print_row(f, "H48 h10", sizes_h48[10], ratio[10], False, False) | 92 | ) |
| 75 | print_row(f, "H48 h9", sizes_h48[9], ratio[9], False, False) | 93 | for k in slow_egg[m]: |
| 76 | print_row(f, "H48 h8", sizes_h48[8], ratio[8], False, False) | 94 | ratio_egg[m][k] = ( |
| 77 | print_row(f, "H48 h7", sizes_h48[7], ratio[7], False, False) | 95 | (slow_egg[m][k] / fast_egg[m][k]) * |
| 78 | print_row(f, "H48 h6", sizes_h48[6], ratio[6], False, False) | 96 | (25 if k != "superflip" else 1) |
| 97 | ) | ||
| 98 | f.write("|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|\n") | ||
| 99 | f.write("|:-----|:---|-------:|-------:|-------:|-------:|--------:|\n") | ||
| 100 | print_row(f, "egg h11", sizes_egg[11], ratio_egg[11], False, False) | ||
| 101 | print_row(f, "H48 h11", sizes_h48[11], ratio_h48[11], False, False) | ||
| 102 | print_row(f, "egg h10", sizes_egg[10], ratio_egg[10], False, False) | ||
| 103 | print_row(f, "H48 h10", sizes_h48[10], ratio_h48[10], False, False) | ||
| 104 | print_row(f, "egg h9", sizes_egg[9], ratio_egg[9], False, False) | ||
| 105 | print_row(f, "H48 h9", sizes_h48[9], ratio_h48[9], False, False) | ||
| 106 | print_row(f, "egg h8", sizes_egg[8], ratio_egg[8], False, False) | ||
| 107 | print_row(f, "H48 h8", sizes_h48[8], ratio_h48[8], False, False) | ||
| 108 | print_row(f, "egg h7", sizes_egg[7], ratio_egg[7], False, False) | ||
| 109 | print_row(f, "H48 h7", sizes_h48[7], ratio_h48[7], False, False) | ||
| 110 | print_row(f, "egg h6", sizes_egg[6], ratio_egg[6], False, False) | ||
| 111 | print_row(f, "H48 h6", sizes_h48[6], ratio_h48[6], False, False) | ||
| 79 | 112 | ||
| 80 | with open(benchmarks_single_thread, "w") as f: | 113 | with open(benchmarks_single_thread, "w") as f: |
| 81 | f.write(f"<!-- The following details block can be found in {benchmarks_single_thread} -->\n") | 114 | f.write( |
| 82 | f.write("<details><summary>Results: Single solution, single thread</summary>\n") | 115 | "<!-- The following details block can " |
| 116 | f"be found in {benchmarks_single_thread} -->\n" | ||
| 117 | ) | ||
| 118 | f.write( | ||
| 119 | "<details><summary>Results: Single solution, " | ||
| 120 | "single thread</summary>\n" | ||
| 121 | ) | ||
| 83 | f.write("\n") | 122 | f.write("\n") |
| 84 | f.write("Time per cube (in seconds, lower is better).\n") | 123 | f.write("Time per cube (in seconds, lower is better).\n") |
| 85 | f.write("\n") | 124 | f.write("\n") |
| 86 | print_table(f, results_h48.h48_single_thread, results_vcube.vcube_single_thread, False, True) | 125 | print_table( |
| 126 | f, | ||
| 127 | results_h48.h48_single_thread, | ||
| 128 | results_vcube.vcube_single_thread, | ||
| 129 | results_egg.egg_single_thread, | ||
| 130 | False, | ||
| 131 | True, | ||
| 132 | ) | ||
| 87 | f.write("\n") | 133 | f.write("\n") |
| 88 | f.write("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).\n") | 134 | f.write( |
| 135 | "Time per cube adjusted for table size " | ||
| 136 | "(in seconds \\* GiB, lower is better).\n" | ||
| 137 | ) | ||
| 89 | f.write("\n") | 138 | f.write("\n") |
| 90 | print_table(f, results_h48.h48_single_thread, results_vcube.vcube_single_thread, True, True) | 139 | print_table( |
| 140 | f, | ||
| 141 | results_h48.h48_single_thread, | ||
| 142 | results_vcube.vcube_single_thread, | ||
| 143 | results_egg.egg_single_thread, | ||
| 144 | True, | ||
| 145 | True, | ||
| 146 | ) | ||
| 91 | f.write("\n") | 147 | f.write("\n") |
| 92 | f.write( | 148 | f.write( |
| 93 | '<img src="img/17moves1thread.png">\n' | 149 | '<img src="img/17moves1thread.png">\n' |
| @@ -98,59 +154,114 @@ with open(benchmarks_single_thread, "w") as f: | |||
| 98 | f.write("</details>\n") | 154 | f.write("</details>\n") |
| 99 | 155 | ||
| 100 | with open(benchmarks_4_threads, "w") as f: | 156 | with open(benchmarks_4_threads, "w") as f: |
| 101 | f.write(f"<!-- The following details block can be found in {benchmarks_4_threads} -->\n") | 157 | f.write( |
| 102 | f.write("<details><summary>Results: Single solution, 4 threads</summary>\n") | 158 | "<!-- The following details block can " |
| 159 | f"be found in {benchmarks_4_threads} -->\n" | ||
| 160 | ) | ||
| 161 | f.write( | ||
| 162 | "<details><summary>Results: Single solution, " | ||
| 163 | "4 threads</summary>\n" | ||
| 164 | ) | ||
| 103 | f.write("\n") | 165 | f.write("\n") |
| 104 | f.write("Time per cube (in seconds, lower is better).\n") | 166 | f.write("Time per cube (in seconds, lower is better).\n") |
| 105 | f.write("\n") | 167 | f.write("\n") |
| 106 | print_table(f, results_h48.h48_4_threads, None, False, False) | 168 | print_table( |
| 169 | f, | ||
| 170 | results_h48.h48_4_threads, | ||
| 171 | None, | ||
| 172 | results_egg.egg_4_threads, | ||
| 173 | False, | ||
| 174 | False, | ||
| 175 | ) | ||
| 107 | f.write("\n") | 176 | f.write("\n") |
| 108 | f.write("Speed-up factor (higher is better).\n") | 177 | f.write("Speed-up factor (higher is better).\n") |
| 109 | f.write("\n") | 178 | f.write("\n") |
| 110 | print_factor_table(f, results_h48.h48_single_thread, results_h48.h48_4_threads) | 179 | print_factor_table( |
| 180 | f, | ||
| 181 | results_h48.h48_single_thread, | ||
| 182 | results_h48.h48_4_threads, | ||
| 183 | results_egg.egg_single_thread, | ||
| 184 | results_egg.egg_4_threads, | ||
| 185 | ) | ||
| 111 | f.write("\n") | 186 | f.write("\n") |
| 112 | f.write('<img src="img/4threadsspeedupfactor.png">\n') | 187 | f.write( |
| 188 | '<img src="img/H48_4_threads_speedup_factor.png">\n' | ||
| 189 | '<img src="img/egg_4_threads_speedup_factor.png">\n' | ||
| 190 | ) | ||
| 113 | f.write("\n") | 191 | f.write("\n") |
| 114 | f.write("</details>\n") | 192 | f.write("</details>\n") |
| 115 | 193 | ||
| 116 | with open(benchmarks_16_threads, "w") as f: | 194 | with open(benchmarks_16_threads, "w") as f: |
| 117 | f.write(f"<!-- The following details block can be found in {benchmarks_16_threads} -->\n") | 195 | f.write( |
| 118 | f.write("<details><summary>Results: Single solution, 16 threads</summary>\n") | 196 | "<!-- The following details block can " |
| 197 | f"be found in {benchmarks_16_threads} -->\n" | ||
| 198 | ) | ||
| 199 | f.write( | ||
| 200 | "<details><summary>Results: Single solution, " | ||
| 201 | "16 threads</summary>\n" | ||
| 202 | ) | ||
| 119 | f.write("\n") | 203 | f.write("\n") |
| 120 | f.write("Time per cube (in seconds, lower is better).\n") | 204 | f.write("Time per cube (in seconds, lower is better).\n") |
| 121 | f.write("\n") | 205 | f.write("\n") |
| 122 | print_table(f, results_h48.h48_16_threads, None, False, False) | 206 | print_table( |
| 207 | f, | ||
| 208 | results_h48.h48_16_threads, | ||
| 209 | None, | ||
| 210 | results_egg.egg_16_threads, | ||
| 211 | False, | ||
| 212 | False, | ||
| 213 | ) | ||
| 123 | f.write("\n") | 214 | f.write("\n") |
| 124 | f.write("Speed-up factor (higher is better).\n") | 215 | f.write("Speed-up factor (higher is better).\n") |
| 125 | f.write("\n") | 216 | f.write("\n") |
| 126 | print_factor_table(f, results_h48.h48_single_thread, results_h48.h48_16_threads) | 217 | print_factor_table( |
| 218 | f, | ||
| 219 | results_h48.h48_single_thread, | ||
| 220 | results_h48.h48_16_threads, | ||
| 221 | results_egg.egg_single_thread, | ||
| 222 | results_egg.egg_16_threads, | ||
| 223 | ) | ||
| 127 | f.write("\n") | 224 | f.write("\n") |
| 128 | f.write('<img src="img/16threadsspeedupfactor.png">\n') | 225 | f.write( |
| 226 | '<img src="img/H48_16_threads_speedup_factor.png">\n' | ||
| 227 | '<img src="img/egg_16_threads_speedup_factor.png">\n' | ||
| 228 | ) | ||
| 129 | f.write("\n") | 229 | f.write("\n") |
| 130 | f.write("</details>\n") | 230 | f.write("</details>\n") |
| 131 | 231 | ||
| 132 | with open(benchmarks_all_solutions, "w") as f: | 232 | with open(benchmarks_all_solutions, "w") as f: |
| 133 | f.write(f"<!-- The following details block can be found in {benchmarks_all_solutions} -->\n") | 233 | f.write( |
| 134 | f.write("<details><summary>Results: All solutions, 16 threads</summary>\n") | 234 | "<!-- The following details block can " |
| 235 | f"be found in {benchmarks_all_solutions} -->\n" | ||
| 236 | ) | ||
| 237 | f.write( | ||
| 238 | "<details><summary>Results: All solutions, " | ||
| 239 | "16 threads</summary>\n" | ||
| 240 | ) | ||
| 135 | f.write("\n") | 241 | f.write("\n") |
| 136 | f.write("Time per cube (in seconds, lower is better).\n") | 242 | f.write("Time per cube (in seconds, lower is better).\n") |
| 137 | f.write("\n") | 243 | f.write("\n") |
| 138 | print_table(f, results_h48.h48_all_solutions, None, False, False) | 244 | print_table(f, results_h48.h48_all_solutions, None, None, False, False) |
| 139 | f.write("\n") | 245 | f.write("\n") |
| 140 | f.write("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).\n") | 246 | f.write( |
| 247 | "Time per cube adjusted for table size " | ||
| 248 | "(in seconds \\* GiB, lower is better).\n" | ||
| 249 | ) | ||
| 141 | f.write("\n") | 250 | f.write("\n") |
| 142 | print_table(f, results_h48.h48_all_solutions, None, True, False) | 251 | print_table(f, results_h48.h48_all_solutions, None, None, True, False) |
| 143 | f.write("\n") | 252 | f.write("\n") |
| 144 | f.write("</details>\n") | 253 | f.write("</details>\n") |
| 145 | 254 | ||
| 146 | # Plotting | 255 | # Plotting |
| 147 | 256 | ||
| 148 | def plot_comparison(title, hd, vd, key): | 257 | def plot_comparison(title, hd, vd, ed, key): |
| 149 | d = 1 if key == "superflip" else 25 | 258 | d = 1 if key == "superflip" else 25 |
| 150 | h48x = [sizes_h48[m]/(2**30) for m in hd.keys() if key in hd[m]] | 259 | h48x = [sizes_h48[m]/(2**30) for m in hd.keys() if key in hd[m]] |
| 151 | vcubex = [sizes_vcube[m]/(2**30) for m in vd.keys() if key in vd[m]] | 260 | vcubex = [sizes_vcube[m]/(2**30) for m in vd.keys() if key in vd[m]] |
| 261 | eggx = [sizes_egg[m]/(2**30) for m in ed.keys() if key in ed[m]] | ||
| 152 | h48y = [d[key] for _, d in hd.items() if key in d] | 262 | h48y = [d[key] for _, d in hd.items() if key in d] |
| 153 | vcubey = [d[key] for _, d in vd.items() if key in d] | 263 | vcubey = [d[key] for _, d in vd.items() if key in d] |
| 264 | eggy = [d[key] for _, d in ed.items() if key in d] | ||
| 154 | 265 | ||
| 155 | plt.clf() | 266 | plt.clf() |
| 156 | plt.title(title) | 267 | plt.title(title) |
| @@ -158,14 +269,17 @@ def plot_comparison(title, hd, vd, key): | |||
| 158 | plt.ylabel("Time to solve (s / cube)") | 269 | plt.ylabel("Time to solve (s / cube)") |
| 159 | plt.plot(h48x, h48y, "o--", label = "H48") | 270 | plt.plot(h48x, h48y, "o--", label = "H48") |
| 160 | plt.plot(vcubex, vcubey, "o--", label = "vcube") | 271 | plt.plot(vcubex, vcubey, "o--", label = "vcube") |
| 272 | plt.plot(eggx, eggy, "o--", label = "egg") | ||
| 161 | plt.legend(loc = "right") | 273 | plt.legend(loc = "right") |
| 162 | filename = title.replace(" ", "").replace(",", "") + ".png" | 274 | filename = title.replace(" ", "").replace(",", "") + ".png" |
| 163 | plt.savefig(benchmarks_img_dir / filename, dpi=300) | 275 | plt.savefig(benchmarks_img_dir / filename, dpi=300) |
| 164 | #plt.show() | 276 | #plt.show() |
| 165 | 277 | ||
| 166 | rh, rv = results_h48.h48_single_thread, results_vcube.vcube_single_thread | 278 | rh = results_h48.h48_single_thread |
| 279 | rv = results_vcube.vcube_single_thread | ||
| 280 | re = results_egg.egg_single_thread | ||
| 167 | for m in [17, 18, 19, 20]: | 281 | for m in [17, 18, 19, 20]: |
| 168 | plot_comparison(f"{m} moves 1 thread", rh, rv, m) | 282 | plot_comparison(f"{m} moves 1 thread", rh, rv, re, m) |
| 169 | 283 | ||
| 170 | def plot_multithread_scatter(title, slow, fast): | 284 | def plot_multithread_scatter(title, slow, fast): |
| 171 | plt.clf() | 285 | plt.clf() |
| @@ -176,11 +290,29 @@ def plot_multithread_scatter(title, slow, fast): | |||
| 176 | plt.xticks(x) | 290 | plt.xticks(x) |
| 177 | for h in [11, 10, 9, 8, 7, 6]: | 291 | for h in [11, 10, 9, 8, 7, 6]: |
| 178 | y = [slow[h][i] / fast[h][i] for i in x] | 292 | y = [slow[h][i] / fast[h][i] for i in x] |
| 179 | plt.scatter(x, y, label=f"H48 h{h}") | 293 | plt.scatter(x, y, label=f"h{h}") |
| 180 | plt.legend(loc = "right") | 294 | plt.legend(loc = "right") |
| 181 | filename = title.replace(" ", "").replace(",", "") + ".png" | 295 | filename = title.replace(" ", "_") + ".png" |
| 182 | plt.savefig(benchmarks_img_dir / filename, dpi=300) | 296 | plt.savefig(benchmarks_img_dir / filename, dpi=300) |
| 183 | #plt.show() | 297 | #plt.show() |
| 184 | 298 | ||
| 185 | plot_multithread_scatter("4 threads speedup factor", results_h48.h48_single_thread, results_h48.h48_4_threads) | 299 | plot_multithread_scatter( |
| 186 | plot_multithread_scatter("16 threads speedup factor", results_h48.h48_single_thread, results_h48.h48_16_threads) | 300 | "H48 4 threads speedup factor", |
| 301 | results_h48.h48_single_thread, | ||
| 302 | results_h48.h48_4_threads, | ||
| 303 | ) | ||
| 304 | plot_multithread_scatter( | ||
| 305 | "H48 16 threads speedup factor", | ||
| 306 | results_h48.h48_single_thread, | ||
| 307 | results_h48.h48_16_threads, | ||
| 308 | ) | ||
| 309 | plot_multithread_scatter( | ||
| 310 | "egg 4 threads speedup factor", | ||
| 311 | results_egg.egg_single_thread, | ||
| 312 | results_egg.egg_4_threads, | ||
| 313 | ) | ||
| 314 | plot_multithread_scatter( | ||
| 315 | "egg 16 threads speedup factor", | ||
| 316 | results_egg.egg_single_thread, | ||
| 317 | results_egg.egg_16_threads, | ||
| 318 | ) | ||
