def to_dict(self, flatten=False): """Convert to a dictionary (optionally flatten to single level) Parameters ---------- flatten : bool Should the return dictionary be single level (i.e. should `paramsspec` be serialized). Returns ------- dict Dictionary representing the application- if flattened then `paramsspec` is returned as a JSON format sting. """ if flatten: out_dict = self.to_dict() out_dict['params'] = self.paramsspec.serialize() else: out_dict = { 'name': self.name, 'params': self.paramsspec, 'actions': easyvvuq_serialize(self.actions), } return out_dict
def replace_actions(self, app_name, actions): """Replace actions for an app with a given name. Parameters ---------- app_name: str Name of the app. actions: Actions `Actions` instance, will replace the current `Actions` of an app. """ self.session.query(AppTable).filter_by(name=app_name).update( {'actions': easyvvuq_serialize(actions)}) self.session.commit()
def update_sampler(self, sampler_id, sampler_element): """Update the state of the Sampler with id 'sampler_id' to that in the passed 'sampler_element' Parameters ---------- sampler_id: int The id of the sampler in the db to update sampler_element: Sampler The sampler that should be used as the new state """ selected = self.session.query(SamplerTable).get(sampler_id) selected.sampler = easyvvuq_serialize(sampler_element) self.session.commit()
def add_sampler(self, sampler_element): """ Add new Sampler to the 'sampler' table. Parameters ---------- sampler_element: BaseSamplingElement Returns ------- """ db_entry = SamplerTable(sampler=easyvvuq_serialize(sampler_element)) self.session.add(db_entry) self.session.commit() return db_entry.id
def add_sampler(self, sampler_element): """Add new Sampler to the 'sampler' table. Parameters ---------- sampler_element: Sampler An EasyVVUQ sampler. Returns ------- int The sampler `id` in the database. """ db_entry = SamplerTable(sampler=easyvvuq_serialize(sampler_element)) self.session.add(db_entry) self.session.commit() return db_entry.id