Skip to content

Commit 2779538

Browse files
committed
add scripts/update_wandb_runs.py
1 parent 5860a5e commit 2779538

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

scripts/update_wandb_runs.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# %%
2+
import pandas as pd
3+
import wandb
4+
from wandb.wandb_run import Run
5+
6+
"""
7+
Update run metadata recorded on Weights and Biases
8+
https://wandb.ai/janosh/matbench-discovery.
9+
"""
10+
11+
__author__ = "Janosh Riebesell"
12+
__date__ = "2022-09-21"
13+
14+
15+
# %%
16+
filters = dict(display_name={"$regex": "voronoi-featurize"})
17+
runs = wandb.Api().runs("janosh/matbench-discovery", filters=filters)
18+
19+
print(f"matching runs: {len(runs)}")
20+
21+
22+
# %%
23+
df = pd.DataFrame([run.config | dict(run.summary) for run in runs])
24+
df["display_name"] = [run.display_name for run in runs]
25+
26+
27+
# %%
28+
df.isna().sum()
29+
30+
31+
# %% --- Update run metadata ---
32+
updated_runs: list[Run] = []
33+
wet_run = input("Wet run or dry run? [w/d] ").lower().startswith("w")
34+
35+
for idx, run in enumerate(runs, 1):
36+
old_config, new_config = run.config.copy(), run.config.copy()
37+
38+
new_display_name = run.display_name.replace("featurize", "features")
39+
40+
for x in ("IS2RE", "ES2RE"):
41+
if x in run.display_name:
42+
new_config["task_type"] = x
43+
44+
if "SLURM_JOB_ID" in new_config:
45+
new_config["slurm_job_id"] = new_config.pop("SLURM_JOB_ID")
46+
47+
if "SLURM_ARRAY_TASK_ID" in new_config:
48+
new_config["slurm_array_task_id"] = new_config.pop("SLURM_ARRAY_TASK_ID")
49+
50+
if old_config != new_config or new_display_name != run.display_name:
51+
print(f"\nrun {idx}/{len(runs)}: {run.display_name}")
52+
53+
if new_display_name != run.display_name:
54+
print(f"{new_display_name=}")
55+
56+
for key in set(old_config) | set(new_config):
57+
old_val = old_config.get(key)
58+
new_val = new_config.get(key)
59+
if new_val != old_val:
60+
print(f"{key}: {old_val} => {new_val}")
61+
62+
updated_runs.append(run)
63+
64+
if wet_run:
65+
run.display_name = new_display_name
66+
run.config = new_config
67+
run.update()
68+
69+
print(f"\n{'' if wet_run else 'dry run: would have'} updated {len(updated_runs)} runs")

0 commit comments

Comments
 (0)