code: def _get_trials_sqa(
      experiment_id: int,
      trial_sqa_class: Type[SQATrial],
      load_trials_in_batches_of_size: Optional[int] = None,
      # pyre-fixme[2]: Parameter annotation cannot contain `Any`.
      trials_query_options: Optional[List[Any]] = None,
      skip_runners_and_metrics: bool = False,
  ) -> List[SQATrial]:
      """Obtains SQLAlchemy trial objects for given experiment ID from DB,
      optionally in mini-batches and with specified query options.
      """
      with session_scope() as session:
          query = session.query(trial_sqa_class.id).filter_by(
              experiment_id=experiment_id
          )
          trial_db_ids = query.all()
          trial_db_ids = [
              db_id_tuple[0] for db_id_tuple in trial_db_ids
          ]
  
      if len(trial_db_ids) == 0:
          return []
  
      batch_size = (
          len(trial_db_ids)
          if load_trials_in_batches_of_size is None
          else load_trials_in_batches_of_size
      )
  
      sqa_trials = []
      for i in range(ceil(len(trial_db_ids) / batch_size)):
          mini_batch_db_ids = trial_db_ids[
              batch_size * i : batch_size * (i + 1)
          ]
          with session_scope() as session:
              query = session.query(trial_sqa_class).filter(
                  trial_sqa_class.id.in_(
                      mini_batch_db_ids
                  )  # pyre-ignore[16]
              )
  
              if trials_query_options is not None:
                  query = query.options(*trials_query_options)
  
              if skip_runners_and_metrics:
                  query = query.options(noload("runner"))
  
              sqa_trials.extend(query.all())
  
      return sqa_trials
  
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 4 for calling a global function with example usage: _get_trials_sqa(experiment_id, trial_sqa_class, load_trials_in_batches_of_size, trials_query_options, skip_runners_and_metrics) and returns: sqa_trials, list