Ejemplo n.º 1
0
 def test_create_experiment_group(self):
     project_uuid = uuid.uuid4().hex
     object = ExperimentGroupConfig(content=faker.word(),
                                    project=project_uuid)
     httpretty.register_uri(httpretty.POST,
                            ProjectClient._build_url(
                                self.client.base_url,
                                ProjectClient.ENDPOINT, project_uuid,
                                'experiment_groups'),
                            body=json.dumps(object.to_dict()),
                            content_type='application/json',
                            status=200)
     result = self.client.create_experiment_group(project_uuid, object)
     assert result.to_dict() == object.to_dict()
Ejemplo n.º 2
0
    def test_project_experiments_and_groups_config(self):
        uuid_value = uuid.uuid4().hex
        config_dict = {
            'name':
            'test',
            'description':
            '',
            'is_public':
            True,
            'experiment_groups': [
                ExperimentGroupConfig(content='content',
                                      uuid=uuid_value,
                                      project=uuid_value).to_dict()
            ],
            'experiments': [
                ExperimentConfig(config={},
                                 uuid=uuid_value,
                                 project=uuid_value).to_dict()
            ]
        }
        config = ProjectConfig.from_dict(config_dict)
        assert_equal_dict(config_dict, config.to_dict())

        config_dict.pop('description')
        config_dict.pop('experiment_groups')
        config_dict.pop('experiments')
        assert_equal_dict(config_dict, config.to_light_dict())
 def test_update_experiment_group(self):
     object = ExperimentGroupConfig(faker.word(),
                                    uuid=uuid.uuid4().hex,
                                    project=uuid.uuid4().hex)
     experiment_group_uuid = object.uuid
     httpretty.register_uri(httpretty.PATCH,
                            ExperimentGroupClient._build_url(
                                self.client.base_url,
                                ExperimentGroupClient.ENDPOINT,
                                experiment_group_uuid),
                            body=json.dumps(object.to_dict()),
                            content_type='application/json',
                            status=200)
     result = self.client.update_experiment_group(experiment_group_uuid,
                                                  {'content': 'new'})
     assert result.to_dict() == object.to_dict()
Ejemplo n.º 4
0
def run(ctx, file, description, u):  # pylint:disable=redefined-builtin
    """Run polyaxonfile specification.

    Example:

    \b
    ```bash
    $ polyaxon run -f file -f file_override ...
    ```

    Example: upload before running

    \b
    ```bash
    $ polyaxon run -f file -u
    ```

    """
    file = file or 'polyaxonfile.yml'
    specification = check_polyaxonfile(file, log=False).specification

    # Check if we need to upload
    if u:
        ctx.invoke(upload, async=False)

    project = ProjectManager.get_config_or_raise()
    project_client = PolyaxonClients().project

    if specification.is_experiment:
        click.echo('Creating an independent experiment.')
        experiment = ExperimentConfig(
            description=description,
            config=specification.parsed_data)
        try:
            project_client.create_experiment(project.user,
                                             project.name,
                                             experiment)
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not create experiment.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
        Printer.print_success('Experiment was created')
    else:
        click.echo('Creating an experiment group with the following definition:')
        experiments_def = specification.experiments_def
        get_group_experiments_info(**experiments_def)
        experiment_group = ExperimentGroupConfig(
            description=description,
            content=specification._data)  # pylint:disable=protected-access
        try:
            project_client.create_experiment_group(project.user,
                                                   project.name,
                                                   experiment_group)
            Printer.print_success('Experiment group was created')
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not create experiment group.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
Ejemplo n.º 5
0
 def get_experiment_group(self, username, project_name, group_sequence):
     request_url = self._build_url(self._get_http_url(), username,
                                   project_name, 'groups', group_sequence)
     try:
         response = self.get(request_url)
         return ExperimentGroupConfig.from_dict(response.json())
     except PolyaxonException as e:
         self.handle_exception(e=e,
                               log_message='Error while retrieving project')
         return None
Ejemplo n.º 6
0
    def create_experiment_group(self, username, project_name, experiment_group_config):
        request_url = self._build_url(
            self._get_http_url(), username, project_name, 'groups')

        try:
            response = self.post(request_url, json=experiment_group_config.to_dict())
            return ExperimentGroupConfig.from_dict(response.json())
        except PolyaxonException as e:
            self.handle_exception(e=e, log_message='Error while creating experiment group')
            return None
Ejemplo n.º 7
0
    def test_experiment_group_config(self):
        uuid_value = uuid.uuid4().hex
        config_dict = {
            'sequence':
            1,
            'content':
            'some content',
            'uuid':
            uuid_value,
            'project':
            uuid_value,
            'project_name':
            'user.name',
            'num_experiments':
            0,
            'created_at':
            local_now().isoformat(),
            'updated_at':
            local_now().isoformat(),
            'experiments': [
                ExperimentConfig(config={},
                                 uuid=uuid_value,
                                 experiment_group=uuid_value,
                                 project=uuid_value).to_dict()
            ]
        }
        config = ExperimentGroupConfig.from_dict(config_dict)
        config_to_dict = config.to_dict()
        config_to_dict.pop('concurrency', None)
        config_to_dict.pop('description', None)
        config_to_dict.pop('num_failed_experiments', None)
        config_to_dict.pop('num_pending_experiments', None)
        config_to_dict.pop('num_running_experiments', None)
        config_to_dict.pop('num_scheduled_experiments', None)
        config_to_dict.pop('num_stopped_experiments', None)
        config_to_dict.pop('num_succeeded_experiments', None)
        config_to_dict.pop('unique_name', None)
        config_to_dict.pop('user', None)
        assert config_to_dict == config_dict

        config_dict.pop('content')
        config_dict.pop('uuid')
        config_dict.pop('project')
        config_dict.pop('updated_at')
        config_dict.pop('sequence')
        config_dict.pop('experiments')
        config_dict.pop('project_name')
        assert_equal_dict(config_dict, config.to_light_dict())

        config_to_dict = config.to_dict(humanize_values=True)
        assert config_to_dict.pop('created_at') == 'a few seconds ago'
        assert config_to_dict.pop('updated_at') == 'a few seconds ago'

        config_to_dict = config.to_light_dict(humanize_values=True)
        assert config_to_dict.pop('created_at') == 'a few seconds ago'
    def update_experiment_group(self, experiment_group_uuid, patch_dict):
        request_url = self._build_url(self._get_http_url(),
                                      experiment_group_uuid)

        try:
            response = self.patch(request_url, json=patch_dict)
            return ExperimentGroupConfig.from_dict(response.json())
        except PolyaxonException as e:
            self.handle_exception(e=e,
                                  log_message='Error while updating project')
            return None
Ejemplo n.º 9
0
 def test_experiment_group_config(self):
     uuid_value = uuid.uuid4().hex
     config_dict = {'sequence': 1,
                    'content': 'some content',
                    'uuid': uuid_value,
                    'project': uuid_value,
                    'num_experiments': 0,
                    'experiments': [
                        ExperimentConfig(config={},
                                         uuid=uuid_value,
                                         group=uuid_value,
                                         project=uuid_value).to_dict()]}
     config = ExperimentGroupConfig.from_dict(config_dict)
     assert config.to_dict() == config_dict
Ejemplo n.º 10
0
    def list_experiment_groups(self, project_uuid, page=1):
        """Fetch list of experiment groups related to this project."""
        request_url = self._build_url(self._get_http_url(), project_uuid,
                                      'experiment_groups')

        try:
            response = self.get(request_url, params=self.get_page(page=page))
            experiment_group_dicts = response.json()
            return [
                ExperimentGroupConfig.from_dict(experiment_group)
                for experiment_group in experiment_group_dicts.get(
                    "results", [])
            ]
        except PolyaxonException as e:
            self.handle_exception(
                e=e, log_message='Error while retrieving experiment groups')
            return []
Ejemplo n.º 11
0
 def test_get_experiment_group(self):
     object = ExperimentGroupConfig(content=faker.word(),
                                    uuid=uuid.uuid4().hex,
                                    project=uuid.uuid4().hex).to_dict()
     httpretty.register_uri(
         httpretty.GET,
         ExperimentGroupClient._build_url(
             self.client.base_url,
             ExperimentGroupClient.ENDPOINT,
             'username',
             'project_name',
             'groups',
             1),
         body=json.dumps(object),
         content_type='application/json',
         status=200)
     result = self.client.get_experiment_group('username', 'project_name', 1)
     assert object == result.to_dict()
Ejemplo n.º 12
0
def run(file, description):
    """Command for running polyaxonfile specification.

    Example:

    ```
    polyaxon run -f file -f file_override ...
    ```
    """
    file = file or 'polyaxonfile.yml'
    plx_file = check_polyaxonfile(file)
    num_experiments, concurrency = plx_file.experiments_def
    project = get_current_project_or_exit()
    project_client = PolyaxonClients().project
    if num_experiments == 1:
        click.echo('Creating an independent experiment.')
        experiment = ExperimentConfig(
            description=description,
            content=plx_file._data,
            config=plx_file.experiment_specs[0].parsed_data)
        try:
            response = project_client.create_experiment(
                project.user, project.name, experiment)
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not create experiment.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
        Printer.print_success('Experiment was created')
    else:
        click.echo('Creating an experiment group with {} experiments.'.format(
            num_experiments))
        experiment_group = ExperimentGroupConfig(description=description,
                                                 content=plx_file._data)
        try:
            response = project_client.create_experiment_group(
                project.user, project.name, experiment_group)
            Printer.print_success('Experiment group was created')
        except (PolyaxonHTTPError, PolyaxonShouldExitError) as e:
            Printer.print_error('Could not create experiment group.')
            Printer.print_error('Error message `{}`.'.format(e))
            sys.exit(1)
    response = response.to_dict()
    dict_tabulate(response)
Ejemplo n.º 13
0
    def test_list_experiment_groups(self):
        project_uuid = uuid.uuid4().hex
        experiment_groups = [
            ExperimentGroupConfig(content=faker.word,
                                  project=project_uuid).to_dict()
            for _ in range(10)
        ]
        httpretty.register_uri(httpretty.GET,
                               ProjectClient._build_url(
                                   self.client.base_url,
                                   ProjectClient.ENDPOINT, project_uuid,
                                   'experiment_groups'),
                               body=json.dumps({
                                   'results': experiment_groups,
                                   'count': 10,
                                   'next': None
                               }),
                               content_type='application/json',
                               status=200)

        experiment_groups = self.client.list_experiment_groups(project_uuid)
        assert len(experiment_groups) == 10