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 GeneratorRun to SQLAlchemy.
  
  In addition to creating and storing a new GeneratorRun object, we need to
  create and store copies of the Arms, Metrics, Parameters, and
  ParameterConstraints owned by this GeneratorRun.
code: def generator_run_to_sqa(
      self,
      generator_run: GeneratorRun,
      weight: Optional[float] = None,
      reduced_state: bool = False,
  ) -> SQAGeneratorRun:
      """Convert Ax GeneratorRun to SQLAlchemy.
  
      In addition to creating and storing a new GeneratorRun object, we need to
      create and store copies of the Arms, Metrics, Parameters, and
      ParameterConstraints owned by this GeneratorRun.
      """
  
      arms = []
      for arm, arm_weight in generator_run.arm_weights.items():
          arms.append(self.arm_to_sqa(arm=arm, weight=arm_weight))
  
      metrics = self.optimization_config_to_sqa(
          generator_run.optimization_config
      )
      parameters, parameter_constraints = self.search_space_to_sqa(
          generator_run.search_space
      )
  
      best_arm_name = None
      best_arm_parameters = None
      best_arm_predictions = None
      if generator_run.best_arm_predictions is not None:
          best_arm = generator_run.best_arm_predictions[0]
          # pyre-fixme[16]: `Optional` has no attribute `__getitem__`.
          best_arm_predictions = list(
              generator_run.best_arm_predictions[1]
          )
          best_arm_name = best_arm._name
          best_arm_parameters = best_arm.parameters
      model_predictions = (
          list(generator_run.model_predictions)
          if generator_run.model_predictions is not None
          else None
      )
  
      generator_run_type = self.get_enum_value(
          value=generator_run.generator_run_type,
          enum=self.config.generator_run_type_enum,
      )
  
      # pyre-fixme: Expected `Base` for 1st...ing.Type[GeneratorRun]`.
      generator_run_class: SQAGeneratorRun = (
          self.config.class_to_sqa_class[GeneratorRun]
      )
      gr_sqa = generator_run_class(  # pyre-ignore[29]: `SQAGeneratorRun` not a func.
          id=generator_run.db_id,
          arms=arms,
          metrics=metrics,
          parameters=parameters,
          parameter_constraints=parameter_constraints,
          time_created=generator_run.time_created,
          generator_run_type=generator_run_type,
          weight=weight,
          index=generator_run.index,
          fit_time=generator_run.fit_time,
          gen_time=generator_run.gen_time,
          best_arm_name=best_arm_name,
          best_arm_parameters=best_arm_parameters,
          best_arm_predictions=best_arm_predictions,
          model_predictions=model_predictions,
          model_key=generator_run._model_key,
          model_kwargs=object_to_json(
              generator_run._model_kwargs,
              encoder_registry=self.config.json_encoder_registry,
              class_encoder_registry=self.config.json_class_encoder_registry,
          )
          if not reduced_state
          else None,
          bridge_kwargs=object_to_json(
              generator_run._bridge_kwargs,
              encoder_registry=self.config.json_encoder_registry,
              class_encoder_registry=self.config.json_class_encoder_registry,
          )
          if not reduced_state
          else None,
          gen_metadata=object_to_json(
              generator_run._gen_metadata,
              encoder_registry=self.config.json_encoder_registry,
              class_encoder_registry=self.config.json_class_encoder_registry,
          )
          if not reduced_state
          else None,
          model_state_after_gen=object_to_json(
              generator_run._model_state_after_gen,
              encoder_registry=self.config.json_encoder_registry,
              class_encoder_registry=self.config.json_class_encoder_registry,
          )
          if not reduced_state
          else None,
          generation_step_index=generator_run._generation_step_index,
          candidate_metadata_by_arm_signature=object_to_json(
              generator_run._candidate_metadata_by_arm_signature,
              encoder_registry=self.config.json_encoder_registry,
              class_encoder_registry=self.config.json_class_encoder_registry,
          ),
          generation_node_name=generator_run._generation_node_name,
      )
      return gr_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 24 for calling the Encoder obj's underlying member method code with example usage: obj.generator_run_to_sqa(generator_run, weight, reduced_state) and returns: gr_sqa