code: def run_experiments(
      job_mode: c.JobMode,
      run_args: Optional[List[str]] = None,
      script_args: Optional[List[str]] = None,
      image_id: Optional[str] = None,
      dry_run: bool = False,
      experiment_config: Optional[ce.ExpConf] = None,
      xgroup: Optional[str] = None,
      **build_image_kwargs,
  ) -> None:
      """Builds an image using the supplied **build_image_kwargs and calls `docker
      run` on the resulting image using sensible defaults.
  
      Keyword args:
  
      - job_mode: c.JobMode.
  
      - run_args: extra arguments to supply to `docker run` after our defaults.
      - script_args: extra arguments to supply to the entrypoint. (You can
      - override the default container entrypoint by supplying a new one inside
        run_args.)
      - image_id: ID of the image to run. Supplying this will skip an image build.
      - experiment_config: dict of string to list, boolean, string or int. Any
        lists will trigger a cartesian product out with the rest of the config. A
        job will be executed for every combination of parameters in the experiment
        config.
      - dry_run: if True, no actual jobs will be executed and docker won't
        actually build; logging side effects will show the user what will happen
        without dry_run=True.
  
      any extra kwargs supplied are passed through to build_image.
      """
      if run_args is None:
          run_args = []
  
      if script_args is None:
          script_args = []
  
      if experiment_config is None:
          experiment_config = {}
  
      docker_args = {k: v for k, v in build_image_kwargs.items()}
      docker_args["job_mode"] = job_mode
      caliban_config = docker_args.get("caliban_config", {})
  
      engine = get_mem_engine() if dry_run else get_sql_engine()
  
      with session_scope(engine) as session:
          container_spec = generate_container_spec(
              session, docker_args, image_id
          )
  
          if image_id is None:
              if dry_run:
                  logging.info(
                      "Dry run - skipping actual 'docker build'."
                  )
                  image_id = "dry_run_tag"
              else:
                  image_id = b.build_image(**docker_args)
  
          experiments = create_experiments(
              session=session,
              container_spec=container_spec,
              script_args=script_args,
              experiment_config=experiment_config,
              xgroup=xgroup,
          )
  
          job_specs = [
              JobSpec.get_or_create(
                  experiment=x,
                  spec=_create_job_spec_dict(
                      experiment=x,
                      job_mode=job_mode,
                      run_args=run_args,
                      image_id=image_id,
                      index=i,
                      caliban_config=caliban_config,
                  ),
                  platform=Platform.LOCAL,
              )
              for i, x in enumerate(experiments)
          ]
  
          try:
              execute_jobs(
                  job_specs=job_specs,
                  dry_run=dry_run,
                  caliban_config=caliban_config,
              )
          except Exception as e:
              logging.error(f"exception: {e}")
              logging.error(f"{traceback.format_exc()}")
              session.commit()
  
imports: from __future__ import absolute_import, division, print_function
  from datetime import datetime
  import json
  import os
  import subprocess
  import sys
  import traceback
  from typing import Any, Dict, Iterable, List, Optional
  import tqdm
  from absl import logging
  from blessings import Terminal
  from tqdm.utils import _screen_shape_wrapper
  import caliban.config
  import caliban.config.experiment
  import caliban.docker.build
  import caliban.util
  import caliban.util.fs
  import caliban.util.metrics
  import caliban.util.tqdm
  from caliban.history.types import Experiment, Job, JobSpec, JobStatus, Platform
  from caliban.history.util import create_experiments, generate_container_spec, get_mem_engine, get_sql_engine, session_scope
label_desc: Use image node_id 9 for calling a global function with example usage: run_experiments(job_mode, run_args, script_args, image_id, dry_run, experiment_config, xgroup) without return types