# Buggy code
def launch(self, job_overrides):
    import submitit

    num_jobs = len(job_overrides)
    assert num_jobs > 0
    self.config.hydra.job.num_jobs = num_jobs
    if self.queue == "auto":
        executor = submitit.AutoExecutor(folder=self.folder, conda_file=self.conda_file)
    elif self.queue == "slurm":
        executor = submitit.SlurmExecutor(folder=self.folder)
    elif self.queue == "chronos":
        executor = submitit.ChronosExecutor(
            folder=self.folder, conda_file=self.conda_file
        )
    elif self.queue == "local":
        executor = submitit.LocalExecutor(folder=self.folder)
    else:
        raise RuntimeError("Unsupported queue type {}".format(self.queue))

    executor.update_parameters(**self.queue_parameters[self.queue])

    log.info("Sweep output dir : {}".format(self.config.hydra.sweep.dir))
    path_str = str(self.config.hydra.sweep.dir)
    os.makedirs(path_str, exist_ok=True)
    if self.config.hydra.sweep.mode is not None:
        mode = int(str(self.config.hydra.sweep.mode), 8)
        os.chmod(path_str, mode=mode)

    jobs = []
    for job_num in range(num_jobs):
        sweep_override = list(job_overrides[job_num])
        log.info(
            "\t#{} : {}".format(
                job_num,
                " ".join(hydra.plugins.common.utils.filter_overrides(sweep_override)),
            )
        )
        job = executor.submit(
            self.launch_job, sweep_override, "hydra.sweep.dir", job_num
        )
        jobs.append(job)

    return [j.results() for j in jobs]


# Traceback (KeyError)
6_sweep(master*)$ python3 experiment.py -m
Traceback (most recent call last):
File "experiment.py", line 15, in <module>
experiment()
File "/private/home/bda/repos/hydra/hydra/main.py", line 62, in decorated_main
run_hydra(get_args(), task_function, config_path, strict)
File "/private/home/bda/repos/hydra/hydra/_internal/utils.py", line 57, in run_hydra
hydra.multirun(overrides=args.overrides)
File "/private/home/bda/repos/hydra/hydra/_internal/hydra.py", line 124, in multirun
return sweeper.sweep(arguments=task_overrides)
File "/private/home/bda/repos/hydra/hydra/plugins/step_sweeper.py", line 63, in sweep
results = self.launcher.launch(batch)
File "/private/home/bda/repos/hydra/plugins/submitit/hydra_plugins/submitit/submitit_launcher.py", line 67, in launch
self.config.hydra.job.num_jobs = num_jobs
File "/private/home/bda/anaconda3/lib/python3.7/site-packages/omegaconf-1.3.0-py3.7.egg/omegaconf/dictconfig.py", line 59, in __setattr__
self.__setitem__(key, value)
File "/private/home/bda/anaconda3/lib/python3.7/site-packages/omegaconf-1.3.0-py3.7.egg/omegaconf/dictconfig.py", line 28, in __setitem__
raise KeyError("Accessing unknown key in a struct : {}".format(self.get_full_key(key)))
KeyError: 'Accessing unknown key in a struct : hydra.job.num_jobs'

# Fixed code
def launch(self, job_overrides):
    # lazy import to ensurue plugin discovery remains fast
    import submitit

    num_jobs = len(job_overrides)
    assert num_jobs > 0
    with open_dict(self.config):
        self.config.hydra.job.num_jobs = num_jobs

    if self.queue == "auto":
        executor = submitit.AutoExecutor(folder=self.folder, conda_file=self.conda_file)
    elif self.queue == "slurm":
        executor = submitit.SlurmExecutor(folder=self.folder)
    elif self.queue == "chronos":
        executor = submitit.ChronosExecutor(
            folder=self.folder, conda_file=self.conda_file
        )
    elif self.queue == "local":
        executor = submitit.LocalExecutor(folder=self.folder)
    else:
        raise RuntimeError("Unsupported queue type {}".format(self.queue))

    executor.update_parameters(**self.queue_parameters[self.queue])

    log.info("Sweep output dir : {}".format(self.config.hydra.sweep.dir))
    path_str = str(self.config.hydra.sweep.dir)
    os.makedirs(path_str, exist_ok=True)
    if "mode" in self.config.hydra.sweep:
        mode = int(str(self.config.hydra.sweep.mode), 8)
        os.chmod(path_str, mode=mode)

    jobs = []
    for job_num in range(num_jobs):
        sweep_override = list(job_overrides[job_num])
        log.info(
            "\t#{} : {}".format(
                job_num,
                " ".join(hydra.plugins.common.utils.filter_overrides(sweep_override)),
            )
        )
        job = executor.submit(
            self.launch_job, sweep_override, "hydra.sweep.dir", job_num
        )
        jobs.append(job)

    return [j.results() for j in jobs]