Beispiel #1
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())
Beispiel #2
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)
Beispiel #3
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 test_get_experiment(self):
     object = ExperimentConfig(faker.word()).to_dict()
     httpretty.register_uri(httpretty.GET,
                            ExperimentClient._build_url(
                                self.client.base_url,
                                ExperimentClient.ENDPOINT, 'uuid'),
                            body=json.dumps(object),
                            content_type='application/json',
                            status=200)
     result = self.client.get_experiment('uuid')
     assert object == result.to_dict()
Beispiel #5
0
 def test_get_experiment(self):
     object = ExperimentConfig(config={}).to_dict()
     httpretty.register_uri(httpretty.GET,
                            ExperimentClient._build_url(
                                self.client.base_url,
                                ExperimentClient.ENDPOINT, 'username',
                                'project_name', 'experiments', 1),
                            body=json.dumps(object),
                            content_type='application/json',
                            status=200)
     result = self.client.get_experiment('username', 'project_name', 1)
     assert object == result.to_dict()
 def test_create_experiment(self):
     project_uuid = uuid.uuid4().hex
     object = ExperimentConfig(name=faker.word(), project=project_uuid)
     httpretty.register_uri(httpretty.POST,
                            ProjectClient._build_url(
                                self.client.base_url,
                                ProjectClient.ENDPOINT, project_uuid,
                                'experiments'),
                            body=json.dumps(object.to_dict()),
                            content_type='application/json',
                            status=200)
     result = self.client.create_experiment(project_uuid, object)
     assert result.to_dict() == object.to_dict()
Beispiel #7
0
 def test_update_project(self):
     object = ExperimentConfig(config={})
     httpretty.register_uri(httpretty.PATCH,
                            ExperimentClient._build_url(
                                self.client.base_url,
                                ExperimentClient.ENDPOINT, 'username',
                                'project_name', 'experiments', 1),
                            body=json.dumps(object.to_dict()),
                            content_type='application/json',
                            status=200)
     result = self.client.update_experiment('username', 'project_name', 1,
                                            {'name': 'new'})
     assert result.to_dict() == object.to_dict()
 def test_update_project(self):
     object = ExperimentConfig(faker.word())
     experiment_uuid = uuid.uuid4().hex
     httpretty.register_uri(httpretty.PATCH,
                            ExperimentClient._build_url(
                                self.client.base_url,
                                ExperimentClient.ENDPOINT, experiment_uuid),
                            body=json.dumps(object.to_dict()),
                            content_type='application/json',
                            status=200)
     result = self.client.update_experiment(experiment_uuid,
                                            {'name': 'new'})
     assert result.to_dict() == object.to_dict()
 def test_stop_experiment(self):
     object = ExperimentConfig(name=faker.word())
     experiment_uuid = uuid.uuid4().hex
     httpretty.register_uri(httpretty.POST,
                            ExperimentClient._build_url(
                                self.client.base_url,
                                ExperimentClient.ENDPOINT, experiment_uuid,
                                'stop'),
                            body=json.dumps(object.to_dict()),
                            content_type='application/json',
                            status=200)
     result = self.client.stop(experiment_uuid)
     assert result.to_dict() == object.to_dict()
 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
Beispiel #11
0
    def test_list_experiments(self):
        group_uuid = uuid.uuid4().hex
        project_uuid = uuid.uuid4().hex
        xp_uuid = uuid.uuid4().hex
        xps = [ExperimentConfig(uuid=xp_uuid,
                                config={},
                                project=project_uuid,
                                group=group_uuid).to_dict()
               for _ in range(10)]
        httpretty.register_uri(
            httpretty.GET,
            ExperimentGroupClient._build_url(
                self.client.base_url,
                ExperimentGroupClient.ENDPOINT,
                'username',
                'project_name',
                'groups',
                1,
                'experiments'),
            body=json.dumps({'results': xps, 'count': 10, 'next': None}),
            content_type='application/json',
            status=200)

        response = self.client.list_experiments('username', 'project_name', 1)
        assert len(response['results']) == 10
        assert response['count'] == 10
        assert response['next'] is None
        assert response['previous'] is None

        # pagination

        httpretty.register_uri(
            httpretty.GET,
            ExperimentGroupClient._build_url(
                self.client.base_url,
                ExperimentGroupClient.ENDPOINT,
                'username',
                'project_name',
                'groups',
                1,
                'experiments') + '?offset=2',
            body=json.dumps({'results': xps, 'count': 10, 'next': None}),
            content_type='application/json',
            status=200)

        response = self.client.list_experiments('username', 'project_name', 1, page=2)
        assert len(response['results']) == 10
Beispiel #12
0
    def test_list_experiments(self):
        experiments = [
            ExperimentConfig(config={}).to_dict() for _ in range(10)
        ]
        httpretty.register_uri(httpretty.GET,
                               ExperimentClient._build_url(
                                   self.client.base_url,
                                   ExperimentClient.ENDPOINT, 'experiments'),
                               body=json.dumps({
                                   'results': experiments,
                                   'count': 10,
                                   'next': None
                               }),
                               content_type='application/json',
                               status=200)

        response = self.client.list_experiments()
        assert len(response['results']) == 10
Beispiel #13
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)
    def test_list_experiments(self):
        group_uuid = uuid.uuid4().hex
        project_uuid = uuid.uuid4().hex
        xp_uuid = uuid.uuid4().hex
        xps = [
            ExperimentConfig(name='xp',
                             uuid=xp_uuid,
                             project=project_uuid,
                             group=group_uuid).to_dict() for _ in range(10)
        ]
        httpretty.register_uri(httpretty.GET,
                               ExperimentGroupClient._build_url(
                                   self.client.base_url,
                                   ExperimentGroupClient.ENDPOINT, group_uuid,
                                   'experiments'),
                               body=json.dumps({
                                   'results': xps,
                                   'count': 10,
                                   'next': None
                               }),
                               content_type='application/json',
                               status=200)

        xps_results = self.client.list_experiments(group_uuid)
        assert len(xps_results) == 10

        # pagination

        httpretty.register_uri(
            httpretty.GET,
            ExperimentGroupClient._build_url(
                self.client.base_url, ExperimentGroupClient.ENDPOINT,
                group_uuid, 'experiments') + '?offset=2',
            body=json.dumps({
                'results': xps,
                'count': 10,
                'next': None
            }),
            content_type='application/json',
            status=200)

        xps_results = self.client.list_experiments(group_uuid, page=2)
        assert len(xps_results) == 10