def push(self, task: Task = None) -> 'Model': """ Pushes :py:class:`~ebonite.core.objects.Model` instance into metadata and artifact repositories :param task: :py:class:`~ebonite.core.objects.Task` instance to save model to. Optional if model already has task :return: same saved :py:class:`~ebonite.core.objects.Model` instance """ if self.id is not None: raise errors.ExistingModelError(self) if task is not None: if self.task_id is not None: if self.task_id != task.id: raise ValueError('This model is already in task {}'.format( self.task_id)) else: self.task = task self._meta.create_model(self) # save model to get model.id try: self._art.push_artifacts(self) except: # noqa self._meta.delete_model(self) raise return self._meta.save_model(self)
def push_model(self, model: 'core.Model', task: 'core.Task' = None) -> 'core.Model': """ Pushes :py:class:`~ebonite.core.objects.Model` instance into metadata and artifact repositories :param model: :py:class:`~ebonite.core.objects.Model` instance :param task: :py:class:`~ebonite.core.objects.Task` instance to save model to. Optional if model already has task :return: same saved :py:class:`~ebonite.core.objects.Model` instance """ if model.id is not None: raise errors.ExistingModelError(model) if task is not None: if model.task_id is not None: if model.task_id != task.id: raise ValueError('This model is already in task {}'.format( model.task_id)) else: model.task = task model = self.meta_repo.create_model( model) # save model to get model.id try: self.artifact_repo.push_artifacts(model) except: # noqa self.meta_repo.delete_model(model) raise model = self.meta_repo.save_model(model) return model
def save_model(self, model: Model) -> Model: """ Saves model in the repository :param model: model to save :return: saved model :exception: :exc:`errors.ExistingModelError` if given model has the same name and task as existing one """ if model.task_id is None: raise ValueError("A task is not assigned to the model {}".format(model)) existing_model = self.get_model_by_name(model.name, model.task_id) if model.id is None and existing_model is None: return self.create_model(model) elif existing_model is not None: if model.id is None or existing_model.id != model.id: raise errors.ExistingModelError(model) return self.update_model(model)