code: def run_job(
      task_function: TaskFunction,
      config: DictConfig,
      job_dir_key: str,
      job_subdir_key: Optional[str],
      hydra_context: HydraContext,
      configure_logging: bool = True,
  ) -> "JobReturn":
      _check_hydra_context(hydra_context)
      callbacks = hydra_context.callbacks
  
      old_cwd = os.getcwd()
      orig_hydra_cfg = HydraConfig.instance().cfg
  
      # init Hydra config for config evaluation
      HydraConfig.instance().set_config(config)
  
      output_dir = str(OmegaConf.select(config, job_dir_key))
      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
          # are only available there.
          subdir = str(OmegaConf.select(config, job_subdir_key))
          output_dir = os.path.join(output_dir, subdir)
  
      with read_write(config.hydra.runtime):
          with open_dict(config.hydra.runtime):
              config.hydra.runtime.output_dir = os.path.abspath(
                  output_dir
              )
  
      # update Hydra config
      HydraConfig.instance().set_config(config)
      _chdir = None
      try:
          ret = JobReturn()
          task_cfg = copy.deepcopy(config)
          with read_write(task_cfg):
              with open_dict(task_cfg):
                  del task_cfg["hydra"]
  
          ret.cfg = task_cfg
          hydra_cfg = copy.deepcopy(HydraConfig.instance().cfg)
          assert isinstance(hydra_cfg, DictConfig)
          ret.hydra_cfg = hydra_cfg
          overrides = OmegaConf.to_container(
              config.hydra.overrides.task
          )
          assert isinstance(overrides, list)
          ret.overrides = overrides
          # handle output directories here
          Path(str(output_dir)).mkdir(parents=True, exist_ok=True)
  
          _chdir = hydra_cfg.hydra.job.chdir
  
          if _chdir is None:
              if version.base_at_least("1.2"):
                  _chdir = False
  
          if _chdir is None:
              url = "https://hydra.cc/docs/1.2/upgrades/1.1_to_1.2/changes_to_job_working_dir/"
              deprecation_warning(
                  message=dedent(
                      f"""\
                      Future Hydra versions will no longer change working directory at job runtime by default.
                      See {url} for more information."""
                  ),
                  stacklevel=2,
              )
              _chdir = True
  
          if _chdir:
              os.chdir(output_dir)
              ret.working_dir = output_dir
          else:
              ret.working_dir = os.getcwd()
  
          if configure_logging:
              configure_log(
                  config.hydra.job_logging, config.hydra.verbose
              )
  
          if config.hydra.output_subdir is not None:
              hydra_output = Path(
                  config.hydra.runtime.output_dir
              ) / Path(config.hydra.output_subdir)
              _save_config(task_cfg, "config.yaml", hydra_output)
              _save_config(hydra_cfg, "hydra.yaml", hydra_output)
              _save_config(
                  config.hydra.overrides.task,
                  "overrides.yaml",
                  hydra_output,
              )
  
          with env_override(hydra_cfg.hydra.job.env_set):
              callbacks.on_job_start(
                  config=config, task_function=task_function
              )
              try:
                  ret.return_value = task_function(task_cfg)
                  ret.status = JobStatus.COMPLETED
              except Exception as e:
                  ret.return_value = e
                  ret.status = JobStatus.FAILED
  
          ret.task_name = JobRuntime.instance().get("name")
  
          _flush_loggers()
  
          callbacks.on_job_end(config=config, job_return=ret)
  
          return ret
      finally:
          HydraConfig.instance().cfg = orig_hydra_cfg
          if _chdir:
              os.chdir(old_cwd)
  
imports: import copy
  import logging
  import os
  import re
  import sys
  from contextlib import contextmanager
  from dataclasses import dataclass
  from datetime import datetime
  from enum import Enum
  from os.path import splitext
  from pathlib import Path
  from textwrap import dedent
  from typing import Any, Dict, Optional, Sequence, Union, cast
  from omegaconf import DictConfig, OmegaConf, open_dict, read_write
  from hydra import version
  from hydra._internal.deprecation_warning import deprecation_warning
  from hydra.core.hydra_config import HydraConfig
  from hydra.core.singleton import Singleton
  from hydra.types import HydraContext, TaskFunction
label_desc: Use image node_id 6 for calling a global function with example usage: run_job(task_function, config, job_dir_key, job_subdir_key, hydra_context, configure_logging) and returns: ret