-
Notifications
You must be signed in to change notification settings - Fork 1
/
02b_run_benchmark_with_slurminade.py
91 lines (73 loc) · 3.16 KB
/
02b_run_benchmark_with_slurminade.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
This is a slightly modified version of `02_run_benchmark.py` that
uses slurminade to distribute the execution in a slurm environment.
This script will also work without a slurm environment.
THIS IS JUST FOR COMPARISON AND NOT AN ACTUAL PART OF THE EXAMPLE STUDY.
"""
import networkx as nx
# ---------------------
import slurminade
from _utils import InstanceDb
from algbench import Benchmark
# ---------------------
benchmark = Benchmark("03_benchmark_data")
instances = InstanceDb("./01_instances.zip")
# ---------------------
# this is just my slurm configuration, you would have to change it.
# Your admin will probably tell you what to insert here.
slurminade.update_default_configuration(
partition="alg",
constraint="alggen03",
mail_user="[email protected]",
mail_type="ALL", # or "FAIL" if you only want to be notified about failures.
)
slurminade.set_dispatch_limit(200)
# ----------------------
# ----------------------
# distribute the following function
@slurminade.slurmify()
# ----------------------
def load_instance_and_run(instance_name: str, alg_params):
# load the instance outside the actual measurement
g = instances[instance_name]
def eval_greedy_alg(instance_name: str, alg_params, _instance: nx.Graph):
# arguments starting with `_` are not saved.
coloring = nx.coloring.greedy_coloring.greedy_color(_instance, **alg_params)
return { # the returned values are saved to the database
"num_vertices": _instance.number_of_nodes(),
"num_edges": _instance.number_of_edges(),
"coloring": coloring,
"n_colors": max(coloring.values()) + 1,
}
benchmark.add(eval_greedy_alg, instance_name, alg_params, g)
# --------------------------
# Compression is not thread-safe so we make it a separate function
# if you only notify about failures, you may want to do
# ``@slurminade.slurmify(mail_type="ALL)`` to be notified after completion.
@slurminade.slurmify()
def compress():
benchmark.compress()
# --------------------------
alg_params_to_evaluate = [
{"strategy": "largest_first", "interchange": True},
{"strategy": "largest_first", "interchange": False},
{"strategy": "random_sequential", "interchange": True},
{"strategy": "random_sequential", "interchange": False},
{"strategy": "smallest_last", "interchange": True},
{"strategy": "smallest_last", "interchange": False},
{"strategy": "independent_set"},
{"strategy": "connected_sequential_bfs", "interchange": True},
{"strategy": "connected_sequential_bfs", "interchange": False},
{"strategy": "connected_sequential_dfs", "interchange": True},
{"strategy": "connected_sequential_dfs", "interchange": False},
{"strategy": "saturation_largest_first"},
]
if __name__ == "__main__":
# ------------------------
# tiny changes here
with slurminade.Batch(100) as batch: # combine up to 100 calls into one task
for instance_name in instances:
for conf in alg_params_to_evaluate:
load_instance_and_run.distribute(instance_name, conf)
compress.wait_for(batch.flush()).distribute() # after all runs finished
# ----------------------