def testSortable(self): generator_run1 = GeneratorRun( arms=self.arms, weights=self.weights, ) generator_run2 = GeneratorRun( arms=self.arms, weights=self.weights, ) generator_run1.index = 1 generator_run2.index = 2 self.assertTrue(generator_run1 < generator_run2)
def add_generator_run(self, generator_run: GeneratorRun, multiplier: float = 1.0) -> "Trial": """Add a generator run to the trial. Note: since trial includes only one arm, this will raise a ValueError if the generator run includes multiple arms. Returns: The trial instance. """ if len(generator_run.arms) > 1: raise ValueError( "Trial includes only one arm, but this generator run " "included multiple.") self.experiment.search_space.check_types( generator_run.arms[0].parameters, raise_error=True) self._check_existing_and_name_arm(generator_run.arms[0]) self._generator_run = generator_run generator_run.index = 0 return self
def add_generator_run(self, generator_run: GeneratorRun, multiplier: float = 1.0) -> Trial: """Add a generator run to the trial. Note: since trial includes only one arm, this will raise a ValueError if the generator run includes multiple arms. Returns: The trial instance. """ # Copy the generator run, to preserve initial and skip mutations to arms. generator_run = generator_run.clone() if len(generator_run.arms) > 1: raise ValueError( "Trial includes only one arm, but this generator run " "included multiple.") self.experiment.search_space.check_types( generator_run.arms[0].parameters, raise_error=True) self._check_existing_and_name_arm(generator_run.arms[0]) self._generator_run = generator_run generator_run.index = 0 self._set_generation_step_index( generation_step_index=generator_run._generation_step_index) return self
def add_generator_run( self, generator_run: GeneratorRun, multiplier: float = 1.0 ) -> BatchTrial: """Add a generator run to the trial. The arms and weights from the generator run will be merged with the existing arms and weights on the trial, and the generator run object will be linked to the trial for tracking. Args: generator_run: The generator run to be added. multiplier: The multiplier applied to input weights before merging with the current set of arms and weights. Returns: The trial instance. """ # First validate generator run arms for arm in generator_run.arms: self.experiment.search_space.check_types(arm.parameters, raise_error=True) # Clone arms to avoid mutating existing state generator_run._arm_weight_table = OrderedDict( { arm_sig: ArmWeight(arm_weight.arm.clone(), arm_weight.weight) for arm_sig, arm_weight in generator_run._arm_weight_table.items() } ) # Add names to arms # For those not yet added to this experiment, create a new name # Else, use the name of the existing arm for arm in generator_run.arms: self._check_existing_and_name_arm(arm) self._generator_run_structs.append( GeneratorRunStruct(generator_run=generator_run, weight=multiplier) ) generator_run.index = len(self._generator_run_structs) - 1 if self.status_quo is not None and self.optimize_for_power: self.set_status_quo_and_optimize_power(status_quo=not_none(self.status_quo)) self._set_generation_step_index( generation_step_index=generator_run._generation_step_index ) self._refresh_arms_by_name() return self
def add_generator_run(self, generator_run: GeneratorRun, multiplier: float = 1.0) -> "BatchTrial": """Add a generator run to the trial. The arms and weights from the generator run will be merged with the existing arms and weights on the trial, and the generator run object will be linked to the trial for tracking. Args: generator_run: The generator run to be added. multiplier: The multiplier applied to input weights before merging with the current set of arms and weights. Returns: The trial instance. """ # Copy the generator run, to preserve initial and skip mutations to arms. generator_run = generator_run.clone() # First validate generator run arms for arm in generator_run.arms: self.experiment.search_space.check_types(arm.parameters, raise_error=True) # Add names to arms # For those not yet added to this experiment, create a new name # Else, use the name of the existing arm for arm in generator_run.arms: self._check_existing_and_name_arm(arm) self._generator_run_structs.append( GeneratorRunStruct(generator_run=generator_run, weight=multiplier)) generator_run.index = len(self._generator_run_structs) - 1 if self.status_quo is not None and self.optimize_for_power: self.set_status_quo_and_optimize_power( status_quo=not_none(self.status_quo)) return self