code: def _load_generation_strategy_by_id(
      gs_id: int,
      decoder: Decoder,
      experiment: Optional[Experiment] = None,
      reduced_state: bool = False,
  ) -> GenerationStrategy:
      """Finds a generation strategy stored by a given ID and restores it."""
      if reduced_state:
          return decoder.generation_strategy_from_sqa(
              gs_sqa=get_generation_strategy_sqa_reduced_state(
                  gs_id=gs_id, decoder=decoder
              ),
              experiment=experiment,
              reduced_state=reduced_state,
          )
  
      exp_sqa_class = decoder.config.class_to_sqa_class[Experiment]
      immutable_opt_config_and_search_space = (
          (
              _get_experiment_immutable_opt_config_and_search_space(
                  experiment_name=experiment.name,
                  # pyre-ignore Incompatible parameter type [6]: Expected
                  # `Type[SQAExperiment]` for 2nd parameter `exp_sqa_class`
                  # to call `_get_experiment_immutable_opt_config_and_search_space`
                  # but got `Type[ax.storage.sqa_store.db.SQABase]`.
                  exp_sqa_class=exp_sqa_class,
              )
          )
          if experiment is not None
          else False
      )
      if immutable_opt_config_and_search_space:
          gs_sqa = _get_generation_strategy_sqa_immutable_opt_config_and_search_space(
              gs_id=gs_id, decoder=decoder
          )
      else:
          gs_sqa = get_generation_strategy_sqa(
              gs_id=gs_id, decoder=decoder
          )
  
      return decoder.generation_strategy_from_sqa(
          gs_sqa=gs_sqa,
          experiment=experiment,
          reduced_state=reduced_state,
      )
  
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 12 for calling a global function with example usage: _load_generation_strategy_by_id(gs_id, decoder, experiment, reduced_state) and returns: decoder, decoder