def search_space_spec(self) -> dict[str, ParameterSpec]: # TODO: Recreating the space here. # The spec should be moved to definition of Cell itself. space_spec = {} for i in range(self.num_predecessors, self.num_nodes + self.num_predecessors): for k in range(self.num_ops_per_node): op_label = f'{self.label}/op_{i}_{k}' input_label = f'{self.label}/input_{i}_{k}' space_spec[op_label] = ParameterSpec(op_label, 'choice', self.op_names, (op_label,), True, size=len(self.op_names)) space_spec[input_label] = ParameterSpec(input_label, 'choice', list(range(i)), (input_label, ), True, size=i) return space_spec
def create_default(candidates: List[ValueType], default: Union[Callable[[List[ValueType]], ValueType], ValueType], label: Optional[str]) -> ValueType: if default not in candidates: # could be callable try: default = cast(Callable[[List[ValueType]], ValueType], default)(candidates) except TypeError as e: if 'not callable' in str(e): raise TypeError( "`default` is not in `candidates`, and it's also not callable." ) raise default = cast(ValueType, default) label = generate_new_label(label) parameter_spec = ParameterSpec( label, # name 'choice', # TODO: support more types candidates, # value (label, ), # we don't have nested now True, # yes, categorical ) # there could be duplicates. Dedup is done in mutator ModelNamespace.current_context().parameter_specs.append(parameter_spec) return default
def _deformat_single_parameter(x, spec): if math.isinf(x): return x spec_dict = spec._asdict() spec_dict['key'] = (spec.name,) spec = ParameterSpec(**spec_dict) params = deformat_parameters({spec.key: x}, {spec.key: spec}) return params[spec.name]
def search_space_spec(self): return { self.label: ParameterSpec(self.label, 'choice', self.op_names, (self.label, ), True, size=len(self.op_names)) }
def search_space_spec(self): return { self.label: ParameterSpec(self.label, 'choice', list(range(self.n_candidates)), (self.label, ), True, size=self.n_candidates, chosen_size=self.n_chosen) }
def dedup_inner_choices( value_choices: list[ValueChoiceX]) -> dict[str, ParameterSpec]: """Find all leaf nodes in ``value_choices``, save them into in the format of ``{label: parameter_spec}``. """ result = {} for value_choice in value_choices: for choice in value_choice.inner_choices(): param_spec = ParameterSpec(choice.label, 'choice', choice.candidates, (choice.label, ), True, size=len(choice.candidates)) if choice.label in result: if param_spec != result[choice.label]: raise ValueError( 'Value choice conflict: same label with different candidates: ' f'{param_spec} vs. {result[choice.label]}') else: result[choice.label] = param_spec return result