-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptim_val.py
More file actions
45 lines (37 loc) · 1.78 KB
/
optim_val.py
File metadata and controls
45 lines (37 loc) · 1.78 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
import os, json, pickle
import optuna # needed only to read the study
from pathlib import Path
OUTDIR = "optuna_out_VAF" # same as in the optimisation script
DECODERS = ["GRU", "LSTM", "Linear", "LiGRU"]
TOP_K = 5 # how many best trials you want
best_cfgs = {} # decoder → [ {params…}, … ]
best_full = {} # same but includes seed & param‑count
for dec in DECODERS:
study_pkl = Path(OUTDIR) / f"{dec}_study.pkl"
if not study_pkl.exists():
print(f"[WARN] {study_pkl} not found – skipped.") ; continue
with study_pkl.open("rb") as f:
study = pickle.load(f)
# keep only completed trials, sort by objective (ascending)
completed = [t for t in study.trials if t.state == optuna.trial.TrialState.COMPLETE]
top = sorted(completed, key=lambda t: t.value)[:TOP_K]
best_cfgs[dec] = [t.params for t in top]
best_full[dec] = [
{
"params" : t.params,
"objective" : t.value,
"param_count" : t.user_attrs.get("param_count"),
"trial_seed" : t.user_attrs.get("trial_seed"),
"run_id" : t.user_attrs.get("run_id"),
}
for t in top
]
# -------- pretty print to console -------------------------------------------
print("\n# ========= COPY/PASTE BELOW INTO YOUR TRAIN SCRIPT ========== #")
print("BEST_HPARAMS = ")
print(json.dumps(best_cfgs, indent=2))
print("# ============================================================= #\n")
# -------- save full details --------------------------------------
with open(Path(OUTDIR) / "top_trials_summary.json", "w") as f:
json.dump(best_full, f, indent=2)
print(f"[INFO] Wrote detailed summary to {OUTDIR}/top_trials_summary.json")