def add_parameter_values(self, spec: ParamSpec, values: VALUES): """ Add a parameter to the DataSet and associates result values with the new parameter. Adds a parameter to the DataSet and associates result values with the new parameter. If the DataSet is not empty, then the count of provided values must equal the current count of results in the DataSet, or an error will result. It is an error to add parameters to a completed DataSet. # TODO: fix type checking """ # first check that the len of values (if dataset is not empty) # is the right size i.e. the same as the dataset if len(self) > 0: if len(values) != len(self): raise ValueError("Need to have {} values but got {}.".format( len(self), len(values) )) with atomic(self.conn) as self.conn: add_parameter(self.conn, self.table_name, spec) # now add values! results = [{spec.name: value} for value in values] self.add_results(results)
def _perform_start_actions(self) -> None: """ Perform the actions that must take place once the run has been started """ for spec in self.description.interdeps.paramspecs: add_parameter(self.conn, self.table_name, spec) update_run_description(self.conn, self.run_id, self.description.to_json()) set_run_timestamp(self.conn, self.run_id)
def add_parameter(self, spec: ParamSpec): """ Add a parameter to the DataSet. To ensure sanity, parameters must be added to the DataSet in a sequence matching their internal dependencies, i.e. first independent parameters, next other independent parameters inferred from the first ones, and finally the dependent parameters """ if self.parameters: old_params = self.parameters.split(',') else: old_params = [] if spec.name in old_params: raise ValueError(f'Duplicate parameter name: {spec.name}') inf_from = spec.inferred_from.split(', ') if inf_from == ['']: inf_from = [] for ifrm in inf_from: if ifrm not in old_params: raise ValueError('Can not infer parameter ' f'{spec.name} from {ifrm}, ' 'no such parameter in this DataSet') dep_on = spec.depends_on.split(', ') if dep_on == ['']: dep_on = [] for dp in dep_on: if dp not in old_params: raise ValueError('Can not have parameter ' f'{spec.name} depend on {dp}, ' 'no such parameter in this DataSet') add_parameter(self.conn, self.table_name, spec) desc = self.description desc.interdeps = InterDependencies(*desc.interdeps.paramspecs, spec) self._description = desc
def add_parameters(self, specs: SPECS): add_parameter(self.conn, self.table_name, *specs)