-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathrun_experiments.py
More file actions
65 lines (55 loc) · 2.02 KB
/
Copy pathrun_experiments.py
File metadata and controls
65 lines (55 loc) · 2.02 KB
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
import json
import sys
import subprocess
from pathlib import Path
def build_test_command(cfg):
# Mandatory arguments
cmd = [
"pnpm", "-w", "cli", "start", "--",
"--testID", cfg["testID"],
"--task", cfg["task"],
"--numberOfUsers", str(cfg["numberOfUsers"]),
"--epochs", str(cfg["epochs"]),
"--roundDuration", str(cfg["roundDuration"]),
"--batchSize", str(cfg["batchSize"]),
"--validationSplit", str(cfg["validationSplit"]),
"--aggregator", cfg["aggregator"],
"--host", cfg["host"],
]
if cfg.get("save", False): # If no "save" argument, default is False
cmd += ["--save"]
if "epsilon" in cfg:
cmd += ["--epsilon", str(cfg["epsilon"])]
if "delta" in cfg:
cmd += ["--delta", str(cfg["delta"])]
if "dpDefaultClippingRadius" in cfg:
cmd += ["--dpDefaultClippingRadius", str(cfg["dpDefaultClippingRadius"])]
if "clippingRadius" in cfg:
cmd += ["--clippingRadius", str(cfg["clippingRadius"])]
if "maxIterations" in cfg:
cmd += ["--maxIterations", str(cfg["maxIterations"])]
if "beta" in cfg:
cmd += ["--beta", str(cfg["beta"])]
if "maxShareValue" in cfg:
cmd += ["--maxShareValue", str(cfg["maxShareValue"])]
return cmd
def main():
# path of configuration file for experiments
# default path is "./experiments/basic_tests.json"
default_path = Path("./experiments/basic_tests.json")
if len(sys.argv) > 1 and Path(sys.argv[1]).exists():
config_path = Path(sys.argv[1])
else:
config_path = default_path
with config_path.open("r", encoding="utf-8") as f:
test_suite = json.load(f)
defaults = test_suite.get("defaults", {})
experiments = test_suite["experiments"]
for exp in experiments:
cfg = {**defaults, **exp}
cmd = build_test_command(cfg)
print(f"Running {cfg['testID']}...")
print(" ".join(cmd))
subprocess.run(cmd, text=True)
if __name__ == "__main__":
main()