class_docstr: Class that contains methods for storing an Ax experiment to SQLAlchemy.
  
  Instantiate with an instance of Config to customize the functionality.
  For even more flexibility, create a subclass.
  
  Attributes:
      config: Metadata needed to save and load an experiment to SQLAlchemy.
class_docstr_tok: ["Class","that","contains","methods","for","storing","an","Ax","experiment","to","SQLAlchemy",".","Instantiate","with","an","instance","of","Config","to","customize","the","functionality",".","For","even","more","flexibility",",","create","a","subclass",".","Attributes",":","config",":","Metadata","needed","to","save","and","load","an","experiment","to","SQLAlchemy","."]
docstr: Convert Ax Trial to SQLAlchemy.
  
  In addition to creating and storing a new Trial object, we need to
  create and store the GeneratorRuns and Runner that it owns.
code: def trial_to_sqa(
      self, trial: BaseTrial, generator_run_reduced_state: bool = False
  ) -> SQATrial:
      """Convert Ax Trial to SQLAlchemy.
  
      In addition to creating and storing a new Trial object, we need to
      create and store the GeneratorRuns and Runner that it owns.
      """
  
      runner = None
      if trial.runner:
          runner = self.runner_to_sqa(runner=not_none(trial.runner))
  
      abandoned_arms = []
      generator_runs = []
      status_quo_name = None
      optimize_for_power = None
      lifecycle_stage = None
  
      if isinstance(trial, Trial) and trial.generator_run:
          gr_sqa = self.generator_run_to_sqa(
              generator_run=not_none(trial.generator_run),
              reduced_state=generator_run_reduced_state,
          )
          generator_runs.append(gr_sqa)
  
      elif isinstance(trial, BatchTrial):
          for abandoned_arm in trial.abandoned_arms_metadata:
              abandoned_arms.append(
                  self.abandoned_arm_to_sqa(abandoned_arm=abandoned_arm)
              )
          for struct in trial.generator_run_structs:
              gr_sqa = self.generator_run_to_sqa(
                  generator_run=struct.generator_run,
                  weight=struct.weight,
              )
              generator_runs.append(gr_sqa)
  
          trial_status_quo = trial.status_quo
          trial_status_quo_weight_override = (
              trial._status_quo_weight_override
          )
          lifecycle_stage = trial.lifecycle_stage
  
          if (
              trial_status_quo is not None
              and trial_status_quo_weight_override is not None
          ):
              status_quo_generator_run = GeneratorRun(
                  arms=[trial_status_quo],
                  weights=[trial_status_quo_weight_override],
                  type=GeneratorRunType.STATUS_QUO.name,
              )
              # This is a hack necessary to get equality tests passing;
              # otherwise you can encode same object and get two different results.
              status_quo_generator_run._time_created = (
                  trial.time_created
              )
              gr_sqa = self.generator_run_to_sqa(
                  generator_run=status_quo_generator_run
              )
  
              # pyre-ignore Attribute `id` declared in class `SQAGeneratorRun`
              # has type `int` but is used as type `Optional[int]`.
              gr_sqa.id = trial._status_quo_generator_run_db_id
              # pyre-ignore Attribute `id` declared in class `SQAArm`
              # has type `int` but is used as type `Optional[int]`.
              gr_sqa.arms[0].id = trial._status_quo_arm_db_id
  
              generator_runs.append(gr_sqa)
              status_quo_name = trial_status_quo.name
  
          optimize_for_power = getattr(
              trial, "optimize_for_power", None
          )
          if optimize_for_power is None:
              logger.warning(
                  f"optimize_for_power not present in BatchTrial: {trial.__dict__}"
              )
  
      # pyre-ignore[9]: Expected `Base` for 1st...ot `typing.Type[Trial]`.
      trial_class: SQATrial = self.config.class_to_sqa_class[Trial]
      trial_sqa = (
          trial_class(  # pyre-fixme[29]: `SQATrial` is not a function.
              id=trial.db_id,
              abandoned_reason=trial.abandoned_reason,
              failed_reason=trial.failed_reason,
              deployed_name=trial.deployed_name,
              index=trial.index,
              is_batch=isinstance(trial, BatchTrial),
              num_arms_created=trial._num_arms_created,
              optimize_for_power=optimize_for_power,
              ttl_seconds=trial.ttl_seconds,
              run_metadata=trial.run_metadata,
              stop_metadata=trial.stop_metadata,
              status=trial.status,
              status_quo_name=status_quo_name,
              time_completed=trial.time_completed,
              time_created=trial.time_created,
              time_staged=trial.time_staged,
              time_run_started=trial.time_run_started,
              trial_type=trial.trial_type,
              abandoned_arms=abandoned_arms,
              generator_runs=generator_runs,
              runner=runner,
              generation_step_index=trial._generation_step_index,
              properties=trial._properties,
              lifecycle_stage=lifecycle_stage,
          )
      )
      return trial_sqa
  
imports: from enum import Enum
  from logging import Logger
  from typing import Any, cast, Dict, List, Optional, Tuple, Type
  from ax.core.arm import Arm
  from ax.core.base_trial import BaseTrial
  from ax.core.batch_trial import AbandonedArm, BatchTrial
  from ax.core.data import Data
  from ax.core.experiment import Experiment
  from ax.core.generator_run import GeneratorRun, GeneratorRunType
  from ax.core.metric import Metric
  from ax.core.multi_type_experiment import MultiTypeExperiment
  from ax.core.objective import MultiObjective, Objective, ScalarizedObjective
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig, OptimizationConfig
  from ax.core.outcome_constraint import ObjectiveThreshold, OutcomeConstraint, ScalarizedOutcomeConstraint
  from ax.core.parameter import ChoiceParameter, FixedParameter, Parameter, RangeParameter
  from ax.core.parameter_constraint import OrderConstraint, ParameterConstraint, SumConstraint
  from ax.core.parameter_distribution import ParameterDistribution
  from ax.core.risk_measures import RiskMeasure
  from ax.core.runner import Runner
  from ax.core.search_space import RobustSearchSpace, SearchSpace
  from ax.core.trial import Trial
  from ax.exceptions.storage import SQAEncodeError
  from ax.modelbridge.generation_strategy import GenerationStrategy
  from ax.storage.json_store.encoder import object_to_json
  from ax.storage.sqa_store.sqa_classes import SQAAbandonedArm, SQAArm, SQAData, SQAExperiment, SQAGenerationStrategy, SQAGeneratorRun, SQAMetric, SQAParameter, SQAParameterConstraint, SQARunner, SQATrial
  from ax.storage.sqa_store.sqa_config import SQAConfig
  from ax.storage.utils import DomainType, MetricIntent, ParameterConstraintType
  from ax.utils.common.base import Base
  from ax.utils.common.constants import Keys
  from ax.utils.common.logger import get_logger
  from ax.utils.common.serialization import serialize_init_args
  from ax.utils.common.typeutils import checked_cast, not_none
label_desc: Use image node_id 27 for calling the Encoder obj's underlying member method code with example usage: obj.trial_to_sqa(trial, generator_run_reduced_state) and returns: trial_sqa