Fix #4: Fix wandb generate_id crash — use string directly instead of int(id, 36)
Browse files
itt_solver/wandb_runner.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import wandb
|
| 6 |
|
| 7 |
-
from typing import Any, Dict
|
| 8 |
from itt_solver import experiment_driver as ed
|
| 9 |
|
| 10 |
def _save_phi_image(phi: np.ndarray, path: str):
|
|
@@ -20,8 +20,8 @@ def run_and_log_wandb(task: Dict[str, Any],
|
|
| 20 |
params: Dict[str, Any],
|
| 21 |
out_dir: str = "experiments",
|
| 22 |
wandb_project: str = "itt_solver",
|
| 23 |
-
wandb_entity: str
|
| 24 |
-
resume: bool
|
| 25 |
"""
|
| 26 |
Run a single experiment via experiment_driver.run_single and log results to W&B
|
| 27 |
using a context manager (with wandb.init(...) as run: ...).
|
|
@@ -32,7 +32,7 @@ def run_and_log_wandb(task: Dict[str, Any],
|
|
| 32 |
- out_dir: local directory where run_single writes artifacts (result.json, logs.json, phi_best.npy).
|
| 33 |
- wandb_project: W&B project name.
|
| 34 |
- wandb_entity: optional W&B entity (team/user).
|
| 35 |
-
-
|
| 36 |
"""
|
| 37 |
# Run the experiment locally first (this writes files under out_dir)
|
| 38 |
result = ed.run_single(task, atomic_library, params, out_dir)
|
|
@@ -54,11 +54,14 @@ def run_and_log_wandb(task: Dict[str, Any],
|
|
| 54 |
result_path = os.path.join(out_dir, base + "_result.json") if base else None
|
| 55 |
logs_path = os.path.join(out_dir, base + "_logs.json") if base else None
|
| 56 |
|
|
|
|
|
|
|
|
|
|
| 57 |
# Start W&B run using context manager
|
| 58 |
with wandb.init(project=wandb_project,
|
| 59 |
entity=wandb_entity,
|
| 60 |
config=params,
|
| 61 |
-
name=f"{task.get('name','task')}_{
|
| 62 |
reinit=True,
|
| 63 |
resume=resume) as run:
|
| 64 |
|
|
|
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import wandb
|
| 6 |
|
| 7 |
+
from typing import Any, Dict, Optional, Union
|
| 8 |
from itt_solver import experiment_driver as ed
|
| 9 |
|
| 10 |
def _save_phi_image(phi: np.ndarray, path: str):
|
|
|
|
| 20 |
params: Dict[str, Any],
|
| 21 |
out_dir: str = "experiments",
|
| 22 |
wandb_project: str = "itt_solver",
|
| 23 |
+
wandb_entity: Optional[str] = None,
|
| 24 |
+
resume: Union[bool, str] = "allow"):
|
| 25 |
"""
|
| 26 |
Run a single experiment via experiment_driver.run_single and log results to W&B
|
| 27 |
using a context manager (with wandb.init(...) as run: ...).
|
|
|
|
| 32 |
- out_dir: local directory where run_single writes artifacts (result.json, logs.json, phi_best.npy).
|
| 33 |
- wandb_project: W&B project name.
|
| 34 |
- wandb_entity: optional W&B entity (team/user).
|
| 35 |
+
- resume: "allow" to log anonymously if no API key is set, or False/None to require login.
|
| 36 |
"""
|
| 37 |
# Run the experiment locally first (this writes files under out_dir)
|
| 38 |
result = ed.run_single(task, atomic_library, params, out_dir)
|
|
|
|
| 54 |
result_path = os.path.join(out_dir, base + "_result.json") if base else None
|
| 55 |
logs_path = os.path.join(out_dir, base + "_logs.json") if base else None
|
| 56 |
|
| 57 |
+
# Generate a safe run name using wandb's built-in ID generator
|
| 58 |
+
run_id = wandb.util.generate_id()
|
| 59 |
+
|
| 60 |
# Start W&B run using context manager
|
| 61 |
with wandb.init(project=wandb_project,
|
| 62 |
entity=wandb_entity,
|
| 63 |
config=params,
|
| 64 |
+
name=f"{task.get('name','task')}_{run_id}",
|
| 65 |
reinit=True,
|
| 66 |
resume=resume) as run:
|
| 67 |
|