Skip to content

Commit

Permalink
Fixed hydra.job.id and hydra.job.num not getting passed to jobs in mu…
Browse files Browse the repository at this point in the history
…ltirun
  • Loading branch information
omry committed Jan 5, 2021
1 parent e49b697 commit 8404d7f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hydra/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def run_job(
) -> "JobReturn":
old_cwd = os.getcwd()
working_dir = str(OmegaConf.select(config, job_dir_key))
orig_hydra_cfg = HydraConfig.instance().cfg
if job_subdir_key is not None:
# evaluate job_subdir_key lazily.
# this is running on the client side in sweep and contains things such as job:id which
Expand All @@ -97,11 +98,16 @@ def run_job(
ret = JobReturn()
ret.working_dir = working_dir
task_cfg = copy.deepcopy(config)
hydra_cfg = OmegaConf.masked_copy(task_cfg, "hydra")
# maintain parent to preserve interpolation links from hydra_cfg to job_cfg
hydra_cfg._set_parent(task_cfg)
with read_write(task_cfg):
with open_dict(task_cfg):
del task_cfg["hydra"]
HydraConfig.instance().cfg = hydra_cfg # type: ignore

ret.cfg = task_cfg
ret.hydra_cfg = OmegaConf.create({"hydra": HydraConfig.get()})
ret.hydra_cfg = hydra_cfg
overrides = OmegaConf.to_container(config.hydra.overrides.task)
assert isinstance(overrides, list)
ret.overrides = overrides
Expand All @@ -112,9 +118,6 @@ def run_job(
if configure_logging:
configure_log(config.hydra.job_logging, config.hydra.verbose)

hydra_cfg = OmegaConf.masked_copy(config, "hydra")
assert isinstance(hydra_cfg, DictConfig)

if config.hydra.output_subdir is not None:
hydra_output = Path(config.hydra.output_subdir)
_save_config(task_cfg, "config.yaml", hydra_output)
Expand All @@ -129,6 +132,7 @@ def run_job(

return ret
finally:
HydraConfig.instance().cfg = orig_hydra_cfg
os.chdir(old_cwd)


Expand Down
5 changes: 5 additions & 0 deletions hydra/test_utils/launcher_common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def sweep_1_job(
assert job_ret[0].hydra_cfg.hydra.job.name == "a_module", (
"Unexpected job name: " + job_ret[0].hydra_cfg.hydra.job.name
)
assert job_ret[0].hydra_cfg.hydra.job.id is not None
assert job_ret[0].hydra_cfg.hydra.job.num is not None
verify_dir_outputs(sweep.returns[0][0])


Expand Down Expand Up @@ -388,6 +390,9 @@ def sweep_2_jobs(
assert job_ret.hydra_cfg.hydra.job.name == "a_module", (
"Unexpected job name: " + job_ret.hydra_cfg.hydra.job.name
)
assert job_ret.hydra_cfg.hydra.job.id is not None
assert job_ret.hydra_cfg.hydra.job.num is not None

verify_dir_outputs(job_ret, job_ret.overrides)
path = temp_dir / str(i)
lst = [x for x in temp_dir.iterdir() if x.is_dir()]
Expand Down
1 change: 1 addition & 0 deletions news/1270.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed hydra.job.id and hydra.job.num not getting passed to jobs in multirun

0 comments on commit 8404d7f

Please sign in to comment.