Exemple #1
0
 def list(self):
     count = 0
     for project in iter(Project(self.ctx).list()):
         self.ctx.log(project.get('name'))
         count += 1
     self.ctx.log('%s Project(s) listed' % str(count))
     return {'projects': Project(self.ctx).list()}
Exemple #2
0
    def __init__(self, ctx):
        self.ctx = ctx

        def print_(*args, **kwargs):
            print(*args, **kwargs)

        self.ctx.log = print_
        self.dataset = None
        self.model_id = None
        self.project = Project(self.ctx, self.ctx.config.get('name', None))
Exemple #3
0
def _get_project(self, autocreate):
    project_name = self.ctx.config.get('name', None)
    if project_name is None:
        raise AugerException(
            'Please specify project name in auger.yaml/name...')
    project = Project(self.ctx, project_name)
    project_properties = project.properties()
    if project_properties is None:
        if autocreate:
            self.ctx.log('Can\'t find project %s on the Auger Cloud. '
                         'Creating...' % project_name)
            project.create()
        else:
            raise AugerException('Can\'t find project %s' % project_name)
    return project
Exemple #4
0
    def _setup_op(self, name, verify_project=True):
        old_name = self.ctx.config.get('name', None)
        if name is None:
            name = old_name
        if name is None:
            raise AugerException('Please specify Project name...')

        project = Project(self.ctx, name)

        if verify_project and not project.is_exists:
            raise AugerException('Project %s doesn\'t exists...' % name)

        return old_name, name, project
Exemple #5
0
class ExampleApp():
    def __init__(self, ctx):
        self.ctx = ctx

        def print_(*args, **kwargs):
            print(*args, **kwargs)

        self.ctx.log = print_
        self.dataset = None
        self.model_id = None
        self.project = Project(self.ctx, self.ctx.config.get('name', None))

    def _get_datasets(self):
        """return list of existing datasets in the Aguer Cloud"""
        dataset_list = []
        for dataset in iter(DataSet(self.ctx, self.project).list()):
            dataset_list.append(dataset['name'])
        return dataset_list

    def _start_experiment(self, experiment_name):
        experiment = Experiment(self.ctx, self.dataset, experiment_name)
        experiment_name, session_id = \
            experiment.start()
        AugerConfig(self.ctx).set_experiment(experiment_name, session_id)
        return experiment, session_id

    def prepare_dataset(self):
        """check whether dataset selected, if not, select or create one"""
        self.ctx.log("Checking dataset...")
        selected = self.ctx.config.get('dataset', None)
        if selected is None:
            if DATASET_NAME in self._get_datasets():
                # try to select existing
                AugerConfig(self.ctx).set_data_set(DATASET_NAME,
                                                   '').set_experiment(None)
                self.dataset = DataSet(self.ctx, self.project, DATASET_NAME)
            else:
                # or create new
                self.ctx.log("No dataset found, creating the first one...")
                source = self.ctx.config.get('source', None)
                dataset = DataSet(self.ctx, self.project).create(source)
                AugerConfig(self.ctx).set_data_set(dataset.name,
                                                   source).set_experiment(None)
                self.dataset = DataSet(self.ctx, self.project, dataset.name)
        else:
            self.dataset = DataSet(self.ctx, self.project, selected)
            self.ctx.log("Currently selected: %s" % selected)

    def run_experiment(self):
        experiment_name = self.ctx.config.get('experiment/name', None)
        # run_id = self.ctx.config.get(
        #     'experiment/experiment_session_id', None)

        # if run_id is None or experiment_name is None:
        # if no experiment ran:
        # run_id = self._start_experiment(experiment_name)
        self.experiment, run_id = self._start_experiment(experiment_name)
        # else:
        #     # if experiment exists, (start if needed) and wait for it
        #     session_api = AugerExperimentSessionApi(
        #         self.ctx, None, None, run_id)
        #     status = session_api.properties().get('status')
        #     self.ctx.log('Experiment status is %s' % status)
        #     # available choices are:
        #     # [preprocess, started, completed, interrupted]
        #     if status not in ('preprocess', 'started'):
        #         run_id = self._start_experiment(experiment_name)
        # wait for experiment to stop
        self.ctx.log("waiting for experiment %s to finish" % experiment_name)

        self.experiment.wait(run_id)
        leaderboard, status = self.experiment.leaderboard(run_id)
        self.model_id = leaderboard[0]['model id']

    def deploy(self):
        Model(self.ctx, self.project).deploy(self.model_id, locally=True)

    def predict(self):
        if os.path.exists(PREDICTION_TARGET):
            self.ctx.log(
                "Prediction already exists."
                " If you want to re-run predict, just delete prediction file: "
                % PREDICTION_TARGET)
        else:
            Model(self.ctx, self.project).predict(PREDICTION_SOURCE,
                                                  self.model_id,
                                                  locally=True)

    def cleanup(self):
        self.project.delete()