示例#1
0
 def test_experiment_with_jobs_config(self):
     config_dict = {
         'sequence':
         2,
         'config': {},
         'content':
         '',
         'uuid':
         uuid.uuid4().hex,
         'project':
         uuid.uuid4().hex,
         'group':
         uuid.uuid4().hex,
         'last_status':
         'Running',
         'num_jobs':
         1,
         'jobs': [
             ExperimentJobConfig(uuid.uuid4().hex,
                                 uuid.uuid4().hex,
                                 datetime.now(),
                                 definition={}).to_dict()
         ]
     }
     config = ExperimentConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict
 def test_experiment_config(self):
     config_dict = {
         'name': 'test',
         'uuid': uuid.uuid4().hex,
         'project': uuid.uuid4().hex
     }
     config = ExperimentConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict
示例#3
0
    def test_experiment_with_jobs_config(self):
        config_dict = {
            'sequence':
            2,
            'config': {},
            'content':
            '',
            'unique_name':
            'adam.proj.1',
            'uuid':
            uuid.uuid4().hex,
            'project':
            uuid.uuid4().hex,
            'project_name':
            'user.name',
            'experiment_group':
            uuid.uuid4().hex,
            'experiment_group_name':
            'user.name.1',
            'last_status':
            'Running',
            'num_jobs':
            1,
            'created_at':
            local_now().isoformat(),
            'updated_at':
            local_now().isoformat(),
            'started_at':
            local_now().isoformat(),
            'finished_at':
            local_now().isoformat(),
            'jobs': [
                ExperimentJobConfig(uuid=uuid.uuid4().hex,
                                    experiment=uuid.uuid4().hex,
                                    experiment_name='name.name.1',
                                    created_at=local_now(),
                                    updated_at=local_now(),
                                    definition={}).to_dict()
            ]
        }
        config = ExperimentConfig.from_dict(config_dict)
        config_to_dict = config.to_dict()
        assert config_to_dict.pop('total_run') == '0s'
        config_to_dict.pop('declarations')
        config_to_dict.pop('description')
        config_to_dict.pop('is_clone')
        config_to_dict.pop('is_done')
        config_to_dict.pop('is_running')
        config_to_dict.pop('last_metric')
        config_to_dict.pop('resources')
        config_to_dict.pop('user')
        assert config_to_dict == config_dict

        config_to_dict = config.to_light_dict(humanize_values=True)
        assert config_to_dict.pop('total_run') == '0s'
        assert config_to_dict.pop('created_at') == 'a few seconds ago'
        assert config_to_dict.pop('started_at') == 'a few seconds ago'
        assert config_to_dict.pop('finished_at') == 'a few seconds ago'
示例#4
0
 def update_experiment(self, experiment_uuid, patch_dict):
     request_url = self._build_url(self._get_http_url(), experiment_uuid)
     try:
         response = self.patch(request_url, json=patch_dict)
         return ExperimentConfig.from_dict(response.json())
     except PolyaxonException as e:
         self.handle_exception(
             e=e, log_message='Error while updating experiment')
         return None
示例#5
0
 def get_experiment(self, experiment_uuid):
     request_url = self._build_url(self._get_http_url(), experiment_uuid)
     try:
         response = self.get(request_url)
         return ExperimentConfig.from_dict(response.json())
     except PolyaxonException as e:
         self.handle_exception(
             e=e, log_message='Error while retrieving experiment')
         return None
示例#6
0
    def create_experiment(self, username, project_name, experiment_config):
        request_url = self._build_url(self._get_http_url(), username, project_name, 'experiments')

        try:
            response = self.post(request_url, json=experiment_config.to_dict())
            return ExperimentConfig.from_dict(response.json())
        except PolyaxonException as e:
            self.handle_exception(e=e, log_message='Error while creating experiment group')
            return None
示例#7
0
 def test_experiment_config(self):
     config_dict = {
         'uuid': uuid.uuid4().hex,
         'project': uuid.uuid4().hex,
         'group': uuid.uuid4().hex,
         'last_status': 'Running',
         'num_jobs': 1,
     }
     config = ExperimentConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict
示例#8
0
    def test_experiment_config(self):
        config_dict = {
            'uuid': uuid.uuid4().hex,
            'project': uuid.uuid4().hex,
            'project_name': 'name.name',
            'experiment_group': uuid.uuid4().hex,
            'experiment_group_name': 'name.name.1',
            'unique_name': 'user.proj.1',
            'last_status': 'Running',
            'description': 'description',
            'content': 'content',
            'config': {
                'k': 'v'
            },
            'num_jobs': 1,
            'created_at': local_now().isoformat(),
            'updated_at': local_now().isoformat(),
        }
        config = ExperimentConfig.from_dict(config_dict)
        config_to_dict = config.to_dict()
        config_to_dict.pop('declarations')
        config_to_dict.pop('finished_at')
        config_to_dict.pop('is_clone')
        config_to_dict.pop('is_done')
        config_to_dict.pop('is_running')
        config_to_dict.pop('jobs')
        config_to_dict.pop('last_metric')
        config_to_dict.pop('resources')
        config_to_dict.pop('sequence')
        config_to_dict.pop('started_at')
        config_to_dict.pop('total_run')
        config_to_dict.pop('user')
        assert config_to_dict == config_dict

        config_to_dict = config.to_light_dict()
        config_dict.pop('uuid')
        config_dict.pop('description')
        config_dict.pop('content')
        config_dict.pop('config')
        config_dict.pop('project')
        config_dict.pop('experiment_group')
        config_dict.pop('updated_at')
        config_dict.pop('project_name')
        config_to_dict.pop('finished_at')
        config_to_dict.pop('is_done')
        config_to_dict.pop('is_running')
        config_to_dict.pop('sequence')
        config_to_dict.pop('started_at')
        config_to_dict.pop('total_run')
        config_to_dict.pop('user')
        assert config_to_dict == config_dict

        config_to_dict = config.to_light_dict(humanize_values=True)
        assert config_to_dict.pop('created_at') == 'a few seconds ago'
        assert config_to_dict.pop('started_at') is None
示例#9
0
    def restart(self, experiment_uuid):
        """Restart an experiment."""
        request_url = self._build_url(self._get_http_url(), experiment_uuid,
                                      'restart')

        try:
            response = self.post(request_url)
            return ExperimentConfig.from_dict(response.json())
        except PolyaxonException as e:
            self.handle_exception(
                e=e, log_message='Error while restarting experiment')
            return None
示例#10
0
 def list_experiments(self, page=1):
     """This gets all experiments visible to the user from the server."""
     try:
         response = self.get(self._get_http_url(),
                             params=self.get_page(page=page))
         experiments_dict = response.json()
         return [
             ExperimentConfig.from_dict(experiment)
             for experiment in experiments_dict.get("results", [])
         ]
     except PolyaxonException as e:
         self.handle_exception(
             e=e, log_message='Error while retrieving experiments')
         return []
示例#11
0
    def list_experiments(self, project_uuid, page=1):
        """Fetch list of experiments related to this project."""
        request_url = self._build_url(self._get_http_url(), project_uuid,
                                      'experiments')

        try:
            response = self.get(request_url, params=self.get_page(page=page))
            experiment_dicts = response.json()
            return [
                ExperimentConfig.from_dict(experiment_group)
                for experiment_group in experiment_dicts.get("results", [])
            ]
        except PolyaxonException as e:
            self.handle_exception(
                e=e, log_message='Error while retrieving experiments')
            return []
 def test_experiment_with_jobs_config(self):
     config_dict = {
         'name':
         'test',
         'uuid':
         uuid.uuid4().hex,
         'project':
         uuid.uuid4().hex,
         'group':
         uuid.uuid4().hex,
         'jobs': [
             ExperimentJobConfig(uuid.uuid4().hex,
                                 uuid.uuid4().hex,
                                 datetime.now(),
                                 definition='').to_dict()
         ]
     }
     config = ExperimentConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict