class_docstr: An object that represents a single run of a generator.
  
  This object is created each time the ``gen`` method of a generator is
  called. It stores the arms and (optionally) weights that were
  generated by the run. When we add a generator run to a trial, its
  arms and weights will be merged with those from previous generator
  runs that were already attached to the trial.
class_docstr_tok: ["An","object","that","represents","a","single","run","of","a","generator",".","This","object","is","created","each","time","the","``","gen","``","method","of","a","generator","is","called",".","It","stores","the","arms","and","(","optionally",")","weights","that","were","generated","by","the","run",".","When","we","add","a","generator","run","to","a","trial",",","its","arms","and","weights","will","be","merged","with","those","from","previous","generator","runs","that","were","already","attached","to","the","trial","."]
docstr: Inits GeneratorRun.
  
  Args:
      arms: The list of arms generated by this run.
      weights: An optional list of weights to associate with the arms.
      optimization_config: The optimization config used during generation
          of this run.
      search_space: The search used during generation of this run.
      model_predictions: Means and covariances for the arms in this
          run recorded at the time the run was executed.
      best_arm_predictions: Optional tuple of best arm in this run
          (according to the optimization config) and its optional respective
          model predictions.
      type: Optional type of the run.
      fit_time: Optional number of seconds it took to fit the model that produced
          this generator run. For models with multiple invocations of gen, this is
          typically the fitting time since the last call to gen.
      gen_time: Optional number of seconds generation took.
      model_key: Optional name of the model that was used to produce this
          generator run.
      model_kwargs: Optional dictionary of keyword arguments to the model
          that was used to produce this generator run.
      bridge_kwargs: Optional dictionary of keyword arguments to the model
          bridge that was used to produce this generator run.
      gen_metadata: Optional dictionary of metadata generated by alongside
          the generator_run.
      model_state_after_gen: Optional dictionary of model state attributes
          to those attributes' values, to use when reinstantiating the model
          from the generator run. Note that this is the state of the model
          after generation, so these settings should only be applied to the
          model when reinstantiating it to continue generation from it,
          rather than to reproduce the conditions, in which this generator
          run was created.
      generation_step_index: Deprecated in favor of generation_node_name.
          Optional index of the generation step that produced this generator run.
          Applicable only if the generator run was created via a generation
          strategy (in which case this index should reflect the index of
          generation step in a generation strategy) or a standalone generation
          step (in which case this index should be ``-1``).
      candidate_metadata_by_arm_signature: Optional dictionary of arm signatures
          to model-produced candidate metadata that corresponds to that arm in
          this generator run.
      generation_node_name: Optional name of the generation node that produced
          this generator run. Applicable only if the generator run was created
          via a generation strategy (in which case this name should reflect the
          name of the generation node in a generation strategy) or a standalone
          generation node (in which case this name should be ``-1``).
docstr_tok: ["Inits","GeneratorRun",".","Args",":","arms",":","The","list","of","arms","generated","by","this","run",".","weights",":","An","optional","list","of","weights","to","associate","with","the","arms",".","optimization_config",":","The","optimization","config","used","during","generation","of","this","run",".","search_space",":","The","search","used","during","generation","of","this","run",".","model_predictions",":","Means","and","covariances","for","the","arms","in","this","run","recorded","at","the","time","the","run","was","executed",".","best_arm_predictions",":","Optional","tuple","of","best","arm","in","this","run","(","according","to","the","optimization","config",")","and","its","optional","respective","model","predictions",".","type",":","Optional","type","of","the","run",".","fit_time",":","Optional","number","of","seconds","it","took","to","fit","the","model","that","produced","this","generator","run",".","For","models","with","multiple","invocations","of","gen",",","this","is","typically","the","fitting","time","since","the","last","call","to","gen.","gen_time",":","Optional","number","of","seconds","generation","took",".","model_key",":","Optional","name","of","the","model","that","was","used","to","produce","this","generator","run",".","model_kwargs",":","Optional","dictionary","of","keyword","arguments","to","the","model","that","was","used","to","produce","this","generator","run",".","bridge_kwargs",":","Optional","dictionary","of","keyword","arguments","to","the","model","bridge","that","was","used","to","produce","this","generator","run",".","gen_metadata",":","Optional","dictionary","of","metadata","generated","by","alongside","the","generator_run",".","model_state_after_gen",":","Optional","dictionary","of","model","state","attributes","to","those","attributes","'","values",",","to","use","when","reinstantiating","the","model","from","the","generator","run",".","Note","that","this","is","the","state","of","the","model","after","generation",",","so","these","settings","should","only","be","applied","to","the","model","when","reinstantiating","it","to","continue","generation","from","it",",","rather","than","to","reproduce","the","conditions",",","in","which","this","generator","run","was","created",".","generation_step_index",":","Deprecated","in","favor","of","generation_node_name",".","Optional","index","of","the","generation","step","that","produced","this","generator","run",".","Applicable","only","if","the","generator","run","was","created","via","a","generation","strategy","(","in","which","case","this","index","should","reflect","the","index","of","generation","step","in","a","generation","strategy",")","or","a","standalone","generation","step","(","in","which","case","this","index","should","be","``","-1","``",")",".","candidate_metadata_by_arm_signature",":","Optional","dictionary","of","arm","signatures","to","model-produced","candidate","metadata","that","corresponds","to","that","arm","in","this","generator","run",".","generation_node_name",":","Optional","name","of","the","generation","node","that","produced","this","generator","run",".","Applicable","only","if","the","generator","run","was","created","via","a","generation","strategy","(","in","which","case","this","name","should","reflect","the","name","of","the","generation","node","in","a","generation","strategy",")","or","a","standalone","generation","node","(","in","which","case","this","name","should","be","``","-1","``",")","."]
code: def __init__(
      self,
      arms: List[Arm],
      weights: Optional[List[float]] = None,
      optimization_config: Optional[OptimizationConfig] = None,
      search_space: Optional[SearchSpace] = None,
      model_predictions: Optional[TModelPredict] = None,
      best_arm_predictions: Optional[
          Tuple[Arm, Optional[TModelPredictArm]]
      ] = None,
      type: Optional[str] = None,
      fit_time: Optional[float] = None,
      gen_time: Optional[float] = None,
      model_key: Optional[str] = None,
      model_kwargs: Optional[Dict[str, Any]] = None,
      bridge_kwargs: Optional[Dict[str, Any]] = None,
      gen_metadata: Optional[TGenMetadata] = None,
      model_state_after_gen: Optional[Dict[str, Any]] = None,
      generation_step_index: Optional[int] = None,
      candidate_metadata_by_arm_signature: Optional[
          Dict[str, TCandidateMetadata]
      ] = None,
      generation_node_name: Optional[str] = None,
  ) -> None:
      """
      Inits GeneratorRun.
  
      Args:
          arms: The list of arms generated by this run.
          weights: An optional list of weights to associate with the arms.
          optimization_config: The optimization config used during generation
              of this run.
          search_space: The search used during generation of this run.
          model_predictions: Means and covariances for the arms in this
              run recorded at the time the run was executed.
          best_arm_predictions: Optional tuple of best arm in this run
              (according to the optimization config) and its optional respective
              model predictions.
          type: Optional type of the run.
          fit_time: Optional number of seconds it took to fit the model that produced
              this generator run. For models with multiple invocations of gen, this is
              typically the fitting time since the last call to gen.
          gen_time: Optional number of seconds generation took.
          model_key: Optional name of the model that was used to produce this
              generator run.
          model_kwargs: Optional dictionary of keyword arguments to the model
              that was used to produce this generator run.
          bridge_kwargs: Optional dictionary of keyword arguments to the model
              bridge that was used to produce this generator run.
          gen_metadata: Optional dictionary of metadata generated by alongside
              the generator_run.
          model_state_after_gen: Optional dictionary of model state attributes
              to those attributes' values, to use when reinstantiating the model
              from the generator run. Note that this is the state of the model
              after generation, so these settings should only be applied to the
              model when reinstantiating it to continue generation from it,
              rather than to reproduce the conditions, in which this generator
              run was created.
          generation_step_index: Deprecated in favor of generation_node_name.
              Optional index of the generation step that produced this generator run.
              Applicable only if the generator run was created via a generation
              strategy (in which case this index should reflect the index of
              generation step in a generation strategy) or a standalone generation
              step (in which case this index should be ``-1``).
          candidate_metadata_by_arm_signature: Optional dictionary of arm signatures
              to model-produced candidate metadata that corresponds to that arm in
              this generator run.
          generation_node_name: Optional name of the generation node that produced
              this generator run. Applicable only if the generator run was created
              via a generation strategy (in which case this name should reflect the
              name of the generation node in a generation strategy) or a standalone
              generation node (in which case this name should be ``-1``).
      """
      self._arm_weight_table: OrderedDict[
          str, ArmWeight
      ] = OrderedDict()
      if weights is None:
          weights = [1.0 for i in range(len(arms))]
      if len(arms) != len(weights):
          raise ValueError(
              "Weights and arms must have the same length. Arms have length "
              f"{len(arms)}, weights have length {len(weights)}."
          )
      if bridge_kwargs is not None or model_kwargs is not None:
          if model_key is None:
              raise ValueError(
                  "Model key is required if model or bridge kwargs are provided."
              )
          if bridge_kwargs is None or model_kwargs is None:
              raise ValueError(
                  "Both model kwargs and bridge kwargs are required if either "
                  "one is provided."
              )
      for arm, weight in zip(arms, weights):
          existing_cw = self._arm_weight_table.get(arm.signature)
          if existing_cw:
              self._arm_weight_table[arm.signature] = ArmWeight(
                  arm=arm, weight=existing_cw.weight + weight
              )
          else:
              self._arm_weight_table[arm.signature] = ArmWeight(
                  arm=arm, weight=weight
              )
  
      self._generator_run_type: Optional[str] = type
      self._time_created: datetime = datetime.now()
      self._optimization_config = optimization_config
      self._search_space = search_space
      self._model_predictions = model_predictions
      self._best_arm_predictions = best_arm_predictions
      self._index: Optional[int] = None
      self._fit_time = fit_time
      self._gen_time = gen_time
      self._model_key = model_key
      self._model_kwargs = model_kwargs
      self._bridge_kwargs = bridge_kwargs
      self._gen_metadata = gen_metadata
      self._model_state_after_gen = model_state_after_gen
      # If candidate metadata is not None and not empty, check that all arm
      # signatures in it correspond to arms in this generator run.
      if candidate_metadata_by_arm_signature:
          unknown_arms_in_cand_metadata = (
              set(candidate_metadata_by_arm_signature.keys())
              - self.arm_signatures
          )
          if unknown_arms_in_cand_metadata:
              raise ValueError(
                  f"Arms with signatures {unknown_arms_in_cand_metadata} appear in "
                  "candidate metadata, but not among the arms on this GeneratorRun."
              )
      self._candidate_metadata_by_arm_signature = (
          candidate_metadata_by_arm_signature
      )
  
      # Validate that generation step index is either not set (not from generation
      # strategy or ste), is non-negative (from generation step) or is -1 (from a
      # standalone generation step that was not a part of a generation strategy).
      assert (
          generation_step_index is None  # Not generation strategy/step
          or generation_step_index == -1  # Standalone generation step
          or generation_step_index >= 0  # Generation strategy
      )
      self._generation_step_index = generation_step_index
      self._generation_node_name = generation_node_name
  
imports: from __future__ import annotations
  import copy
  from collections import OrderedDict
  from dataclasses import dataclass
  from datetime import datetime
  from enum import Enum
  from logging import Logger
  from typing import Any, Dict, List, MutableMapping, Optional, Set, Tuple
  import pandas
  from ax.core.arm import Arm
  from ax.core.optimization_config import OptimizationConfig
  from ax.core.search_space import SearchSpace
  from ax.core.types import TCandidateMetadata, TGenMetadata, TModelPredict, TModelPredictArm
  from ax.exceptions.core import UnsupportedError
  from ax.utils.common.base import Base, SortableBase
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import not_none
label_desc: Use image node_id 1 to create a new GeneratorRun object from inherited base classes: SortableBase with example: obj = GeneratorRun(arms, weights, optimization_config, search_space, model_predictions, best_arm_predictions, type, fit_time, gen_time, model_key, model_kwargs, bridge_kwargs, gen_metadata, model_state_after_gen, generation_step_index, candidate_metadata_by_arm_signature, generation_node_name)