-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add logging of numerical results in experiments
- Loading branch information
1 parent
cfd3cb9
commit 2a9ce77
Showing
4 changed files
with
60 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,4 +148,6 @@ figures/ | |
|
||
.idea/ | ||
|
||
secrets.py | ||
secrets.py | ||
|
||
results/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
exp_log_name: "default" # optional but recommended | ||
data: "random" | ||
experiments: ["ScaleDimKL"] | ||
n: 10000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,61 @@ | ||
|
||
from labproject.utils import set_seed, get_cfg | ||
from labproject.data import get_dataset | ||
from labproject.experiments import * | ||
|
||
|
||
import time | ||
import datetime | ||
import os | ||
|
||
|
||
def get_log_path(cfg): | ||
""" | ||
Get the log path for the current experiment run. | ||
This log path is then used to save the numerical results of the experiment. | ||
Import this function in the run_{name}.py file and call it to get the log path. | ||
""" | ||
|
||
# get datetime string | ||
now = datetime.datetime.now() | ||
if "exp_log_name" not in cfg: | ||
exp_log_name = now.strftime("%Y-%m-%d_%H-%M-%S") | ||
else: | ||
exp_log_name = cfg.exp_log_name | ||
# add datetime to the name | ||
exp_log_name = exp_log_name + "_" + now.strftime("%Y-%m-%d_%H-%M-%S") | ||
log_path = os.path.join(f"results/{cfg.running_user}/{exp_log_name}.pkl") | ||
return log_path | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
|
||
|
||
print("Running experiments...") | ||
cfg = get_cfg() | ||
seed = cfg.seed | ||
|
||
set_seed(seed) | ||
print(f"Seed: {seed}") | ||
print(f"Experiments: {cfg.experiments}") | ||
print(f"Data: {cfg.data}") | ||
|
||
dataset_fn = get_dataset(cfg.data) | ||
|
||
|
||
|
||
for exp_name in cfg.experiments: | ||
experiment = globals()[exp_name]() | ||
time_start = time.time() | ||
dataset1 = dataset_fn(cfg.n, cfg.d) | ||
dataset2 = dataset_fn(cfg.n, cfg.d) | ||
|
||
output = experiment.run_experiment( | ||
dataset1=dataset1, dataset2=dataset2 | ||
) | ||
output = experiment.run_experiment(dataset1=dataset1, dataset2=dataset2) | ||
time_end = time.time() | ||
print(f"Experiment {exp_name} finished in {time_end - time_start}") | ||
experiment.plot_experiment(*output, cfg.data) | ||
|
||
|
||
log_path = get_log_path(cfg) | ||
os.makedirs(os.path.dirname(log_path), exist_ok=True) | ||
experiment.log_results(output, log_path) | ||
print(f"Numerical results saved to {log_path}") | ||
|
||
experiment.plot_experiment(*output, cfg.data) | ||
print(f"Plots saved to {cfg.data}.png") | ||
|
||
print("Finished running experiments.") |