Skip to content

Commit 59b2b79

Browse files
committed
feat: config= parameter for formatting job names
1 parent 69c2d1d commit 59b2b79

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,13 @@ easy_slurm.submit_job(
9797

9898
The job names can be formatted using a config dictionary:
9999
```python
100-
job_name = easy_slurm.format.format_with_config(
101-
"bs={hp.batch_size:04},lr={hp.lr:.1e}",
102-
config={"hp": {"batch_size": 32, "lr": 1e-2}},
103-
)
104-
105100
easy_slurm.submit_job(
106-
job_dir="$HOME/jobs/{date:%Y-%m-%d}-{job_name}",
107101
sbatch_options={
108-
"job-name": job_name, # equals "bs=0032,lr=1.0e-02"
109-
...
102+
"job-name": "bs={hp.batch_size:04},lr={hp.lr:.1e}",
103+
# Equivalent to:
104+
# "job-name": "bs=0032,lr=1.0e-02"
110105
},
111-
...
106+
config={"hp": {"batch_size": 32, "lr": 1e-2}},
112107
)
113108
```
114109

easy_slurm/jobs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def submit_job(
3737
submit: bool = True,
3838
interactive: bool = False,
3939
resubmit_limit: int = 64,
40+
config: dict[str, Any] = {},
4041
) -> str:
4142
"""Submits job.
4243
@@ -87,12 +88,17 @@ def submit_job(
8788
Maximum number of times to auto-submit a job for "resume".
8889
(Not entirely unlike submitting a resume for a job.)
8990
Default is 64 resubmissions.
91+
config (dict[str, Any]):
92+
A dictionary of configuration values to use for formatting.
9093
9194
Returns:
9295
Path to the newly created job directory.
9396
"""
9497
job_name = sbatch_options.get("job-name", "untitled")
95-
job_dir = _expand_path(format_with_config(job_dir, {"job_name": job_name}))
98+
job_name = format_with_config(job_name, config)
99+
job_dir = _expand_path(
100+
format_with_config(job_dir, {**config, "job_name": job_name})
101+
)
96102
create_job_dir(job_dir, src)
97103

98104
_write_script(

0 commit comments

Comments
 (0)