code: def _load_experiment(
      experiment_name: str,
      decoder: Decoder,
      reduced_state: bool = False,
      load_trials_in_batches_of_size: Optional[int] = None,
      ax_object_field_overrides: Optional[Dict[str, Any]] = None,
      skip_runners_and_metrics: bool = False,
  ) -> Experiment:
      """Load experiment by name, using given Decoder instance.
  
      1) Get SQLAlchemy object from DB.
      2) Convert to corresponding Ax object.
  
      Args:
          experiment_name: Name of the experiment
          decoder: Decoder used to convert SQAlchemy objects into Ax objects
          reduced_state: Whether to load experiment and generation strategy
          load_trials_in_batches_of_size: Number of trials to be fetched from database
              per batch
          ax_object_field_overrides: Mapping of object types to mapping of fields
              to override values loaded objects will all be instantiated with fields
              set to override value
              current valid object types are: "runner"
  
      """
  
      # pyre-ignore Incompatible variable type [9]: exp_sqa_class is declared to have type
      # `Type[SQAExperiment]` but is used as type `Type[ax.storage.sqa_store.db.SQABase]`
      exp_sqa_class: Type[
          SQAExperiment
      ] = decoder.config.class_to_sqa_class[Experiment]
      # pyre-ignore Incompatible variable type [9]: trial_sqa_class is decl. to have type
      # `Type[SQATrial]` but is used as type `Type[ax.storage.sqa_store.db.SQABase]`
      trial_sqa_class: Type[
          SQATrial
      ] = decoder.config.class_to_sqa_class[Trial]
      imm_OC_and_SS = (
          _get_experiment_immutable_opt_config_and_search_space(
              experiment_name=experiment_name,
              exp_sqa_class=exp_sqa_class,
          )
      )
  
      if reduced_state:
          _get_experiment_sqa_func = _get_experiment_sqa_reduced_state
  
      else:
          _get_experiment_sqa_func = (
              _get_experiment_sqa_immutable_opt_config_and_search_space
              if imm_OC_and_SS
              else _get_experiment_sqa
          )
  
      experiment_sqa = _get_experiment_sqa_func(
          experiment_name=experiment_name,
          exp_sqa_class=exp_sqa_class,
          trial_sqa_class=trial_sqa_class,
          load_trials_in_batches_of_size=load_trials_in_batches_of_size,
          skip_runners_and_metrics=skip_runners_and_metrics,
      )
  
      # If skip_runners_and_metrics is True, override metric types to
      # base metric type of 0 (to load them with minimum base properties).
      # This includes metrics attached to the experiment, and ones
      # attached to the trials.
      #
      # NOTE: Currently, we load metrics and then convert mostly go get
      # "lower_is_better". Alternatively, we can "nolod" all attributes except
      # "lower_is_better" or any other attribute we want to include. This can be
      # implemented in the future if we need to.
      if skip_runners_and_metrics:
          base_metric_type_int = decoder.config.metric_registry[Metric]
          for sqa_metric in experiment_sqa.metrics:
              sqa_metric.metric_type = base_metric_type_int
          assign_metric_on_gr = not reduced_state and not imm_OC_and_SS
          if assign_metric_on_gr:
              try:
                  for sqa_trial in experiment_sqa.trials:
                      for sqa_generator_run in sqa_trial.generator_runs:
                          for sqa_metric in sqa_generator_run.metrics:
                              sqa_metric.metric_type = (
                                  base_metric_type_int
                              )
              except DetachedInstanceError as e:
                  raise DetachedInstanceError(
                      "Unable to retrieve metric from SQA generator run, possibly due "
                      "to parts of the experiment being lazy-loaded. This is not "
                      f"expected state, please contact Ax support. Original error: {e}"
                  )
  
      return decoder.experiment_from_sqa(
          experiment_sqa=experiment_sqa,
          reduced_state=reduced_state,
          ax_object_field_overrides=ax_object_field_overrides,
      )
  
imports: from math import ceil
  from typing import Any, cast, Dict, List, Optional, Type
  from ax.core.experiment import Experiment
  from ax.core.generator_run import GeneratorRun
  from ax.core.metric import Metric
  from ax.core.trial import Trial
  from ax.exceptions.core import ExperimentNotFoundError, ObjectNotFoundError
  from ax.modelbridge.generation_strategy import GenerationStrategy
  from ax.storage.sqa_store.db import session_scope
  from ax.storage.sqa_store.decoder import Decoder
  from ax.storage.sqa_store.reduced_state import get_query_options_to_defer_immutable_duplicates, get_query_options_to_defer_large_model_cols
  from ax.storage.sqa_store.sqa_classes import SQAExperiment, SQAGenerationStrategy, SQAGeneratorRun, SQATrial
  from ax.storage.sqa_store.sqa_config import SQAConfig
  from ax.utils.common.constants import Keys
  from ax.utils.common.typeutils import checked_cast, not_none
  from sqlalchemy.orm import defaultload, lazyload, noload
  from sqlalchemy.orm.exc import DetachedInstanceError
label_desc: Use image node_id 2 for calling a global function with example usage: _load_experiment(experiment_name, decoder, reduced_state, load_trials_in_batches_of_size, ax_object_field_overrides, skip_runners_and_metrics) and returns: decoder