Esempio n. 1
0
 def get_project_members(self, project_identifier):
     try:
         r = self.backend_swagger_client.api.listProjectMembers(
             projectIdentifier=project_identifier).response()
         return r.result
     except HTTPNotFound:
         raise ProjectNotFound(project_identifier)
Esempio n. 2
0
    def get_leaderboard_entries(self,
                                project,
                                entry_types=None,
                                ids=None,
                                states=None,
                                owners=None,
                                tags=None,
                                min_running_time=None):
        try:
            if entry_types is None:
                entry_types = ['experiment', 'notebook']

            def get_portion(limit, offset):
                return self.leaderboard_swagger_client.api.getLeaderboard(
                    projectIdentifier=project.full_id,
                    entryType=entry_types,
                    shortId=ids,
                    groupShortId=None,
                    state=states,
                    owner=owners,
                    tags=tags,
                    minRunningTimeSeconds=min_running_time,
                    sortBy=['shortId'],
                    sortFieldType=['native'],
                    sortDirection=['ascending'],
                    limit=limit,
                    offset=offset).response().result.entries

            return [
                LeaderboardEntry(e)
                for e in self._get_all_items(get_portion, step=100)
            ]
        except HTTPNotFound:
            raise ProjectNotFound(project_identifier=project.full_id)
Esempio n. 3
0
    def get_project(self, project_qualified_name):
        """Get a project with given ``project_qualified_name``.

        In order to access experiments data one needs to get a :class:`~neptune.projects.Project` object first.
        This method gives you the ability to do that.

        Args:
            project_qualified_name (:obj:`str`):
                Qualified name of a project in a form of ``namespace/project_name``.

        Returns:
            :class:`~neptune.projects.Project` object.

        Raise:
            :class:`~neptune.api_exceptions.ProjectNotFound`: When a project with given name does not exist.

        Examples:

            .. code:: python3

                # Create a Session instance
                from neptune.sessions import Session
                session = Session()

                # Get a project by it's ``project_qualified_name``:
                my_project = session.get_project('namespace/project_name')

        """
        if not project_qualified_name:
            raise ProjectNotFound(project_qualified_name)

        if not re.match(PROJECT_QUALIFIED_NAME_PATTERN, project_qualified_name):
            raise IncorrectProjectQualifiedName(project_qualified_name)

        return self._backend.get_project(project_qualified_name)
    def create_notebook(self, project):
        try:
            api_notebook = self.leaderboard_swagger_client.api.createNotebook(
                projectIdentifier=project.internal_id).response().result

            return Notebook(backend=self,
                            project=project,
                            _id=api_notebook.id,
                            owner=api_notebook.owner)
        except HTTPNotFound:
            raise ProjectNotFound(project_identifier=project.full_id)
    def get_project(self, project_qualified_name):
        try:
            project = self.backend_swagger_client.api.getProject(
                projectIdentifier=project_qualified_name).response().result

            return Project(backend=self,
                           internal_id=project.id,
                           namespace=project.organizationName,
                           name=project.name)
        except HTTPNotFound:
            raise ProjectNotFound(project_qualified_name)
Esempio n. 6
0
 def get_project(self, project_qualified_name):
     """
     Raises:
         `ProjectNotFound`: When a project with given name does not exist.
     """
     if not project_qualified_name:
         raise ProjectNotFound(project_qualified_name)
     project = self._client.get_project(project_qualified_name)
     return Project(client=self._client,
                    internal_id=project.id,
                    namespace=project.organizationName,
                    name=project.name)
    def get_project(self, project_qualified_name):
        try:
            response = self.backend_swagger_client.api.getProject(
                projectIdentifier=project_qualified_name).response()
            warning = response.metadata.headers.get('X-Server-Warning')
            if warning:
                click.echo('{warning}{content}{end}'.format(content=warning,
                                                            **STYLES))
            project = response.result

            return Project(backend=self,
                           internal_id=project.id,
                           namespace=project.organizationName,
                           name=project.name)
        except HTTPNotFound:
            raise ProjectNotFound(project_qualified_name)
Esempio n. 8
0
    def create_experiment(self, project, name, description, params, properties,
                          tags, abortable, monitored):
        ExperimentCreationParams = self.backend_swagger_client.get_model(
            'ExperimentCreationParams')

        try:
            params = ExperimentCreationParams(
                projectId=project.internal_id,
                name=name,
                description=description,
                parameters=self._convert_to_api_parameters(params),
                properties=self._convert_to_api_properties(properties),
                tags=tags,
                enqueueCommand="command",  # FIXME
                entrypoint="",  # FIXME
                execArgsTemplate="",  # FIXME,
                abortable=abortable,
                monitored=monitored)

            api_experiment = self.backend_swagger_client.api.createExperiment(
                experimentCreationParams=params).response().result

            return self._convert_to_experiment(api_experiment)
        except HTTPNotFound:
            raise ProjectNotFound(project_identifier=project.full_id)
        except HTTPBadRequest as e:
            error_type = extract_response_field(e.response, 'type')
            if error_type == 'DUPLICATE_PARAMETER':
                raise ExperimentValidationError(
                    'Parameter list contains duplicates.')
            elif error_type == 'INVALID_TAG':
                raise ExperimentValidationError(
                    extract_response_field(e.response, 'message'))
            else:
                raise
        except HTTPUnprocessableEntity as e:
            if extract_response_field(
                    e.response,
                    'type') == 'LIMIT_OF_EXPERIMENTS_IN_PROJECT_REACHED':
                raise ExperimentLimitReached()
            else:
                raise
Esempio n. 9
0
    def get_leaderboard_entries(
        self,
        project,
        entry_types=None,  # deprecated
        ids=None,
        states=None,
        owners=None,
        tags=None,
        min_running_time=None,
    ):
        if states is not None:
            states = [
                state if state == "running" else "idle" for state in states
            ]
        try:

            def get_portion(limit, offset):
                return (self.leaderboard_swagger_client.api.getLeaderboard(
                    projectIdentifier=project.full_id,
                    shortId=ids,
                    state=states,
                    owner=owners,
                    tags=tags,
                    tagsMode="and",
                    minRunningTimeSeconds=min_running_time,
                    sortBy=["sys/id"],
                    sortFieldType=["string"],
                    sortDirection=["ascending"],
                    limit=limit,
                    offset=offset,
                ).response().result.entries)

            return [
                LeaderboardEntry(self._to_leaderboard_entry_dto(e))
                for e in self._get_all_items(get_portion, step=100)
            ]
        except HTTPNotFound:
            raise ProjectNotFound(project_identifier=project.full_id)
Esempio n. 10
0
 def get_project(self, project_qualified_name):
     try:
         return self.backend_swagger_client.api.getProject(
             projectIdentifier=project_qualified_name).response().result
     except HTTPNotFound:
         raise ProjectNotFound(project_qualified_name)
    def create_experiment(self,
                          project,
                          name,
                          description,
                          params,
                          properties,
                          tags,
                          abortable,
                          monitored,
                          git_info,
                          hostname,
                          entrypoint,
                          notebook_id,
                          checkpoint_id):
        if not isinstance(name, six.string_types):
            raise ValueError("Invalid name {}, should be a string.".format(name))
        if not isinstance(description, six.string_types):
            raise ValueError("Invalid description {}, should be a string.".format(description))
        if not isinstance(params, dict):
            raise ValueError("Invalid params {}, should be a dict.".format(params))
        if not isinstance(properties, dict):
            raise ValueError("Invalid properties {}, should be a dict.".format(properties))
        if not isinstance(hostname, six.string_types):
            raise ValueError("Invalid hostname {}, should be a string.".format(hostname))
        if entrypoint is not None and not isinstance(entrypoint, six.string_types):
            raise ValueError("Invalid entrypoint {}, should be a string.".format(entrypoint))

        ExperimentCreationParams = self.backend_swagger_client.get_model('ExperimentCreationParams')
        GitInfoDTO = self.backend_swagger_client.get_model('GitInfoDTO')
        GitCommitDTO = self.backend_swagger_client.get_model('GitCommitDTO')

        git_info_data = None
        if git_info is not None:
            git_info_data = GitInfoDTO(
                commit=GitCommitDTO(
                    commitId=git_info.commit_id,
                    message=git_info.message,
                    authorName=git_info.author_name,
                    authorEmail=git_info.author_email,
                    commitDate=git_info.commit_date
                ),
                remotes=git_info.remote_urls,
                currentBranch=git_info.active_branch,
                repositoryDirty=git_info.repository_dirty
            )

        try:
            params = ExperimentCreationParams(
                projectId=project.internal_id,
                name=name,
                description=description,
                parameters=self._convert_to_api_parameters(params),
                properties=self._convert_to_api_properties(properties),
                tags=tags,
                gitInfo=git_info_data,
                enqueueCommand="command",  # legacy (it's ignored but any non-empty string is required)
                entrypoint=entrypoint,
                execArgsTemplate="",  # legacy,
                abortable=abortable,
                monitored=monitored,
                hostname=hostname,
                notebookId=notebook_id,
                checkpointId=checkpoint_id
            )

            kwargs = {
                'experimentCreationParams': params,
                'X-Neptune-CliVersion': self.client_lib_version
            }
            api_experiment = self.backend_swagger_client.api.createExperiment(**kwargs).response().result

            return self._convert_to_experiment(api_experiment, project)
        except HTTPNotFound:
            raise ProjectNotFound(project_identifier=project.full_id)
        except HTTPBadRequest as e:
            error_type = extract_response_field(e.response, 'type')
            if error_type == 'DUPLICATE_PARAMETER':
                raise ExperimentValidationError('Parameter list contains duplicates.')
            elif error_type == 'INVALID_TAG':
                raise ExperimentValidationError(extract_response_field(e.response, 'message'))
            else:
                raise
        except HTTPUnprocessableEntity as e:
            if extract_response_field(e.response, 'type') == 'LIMIT_OF_EXPERIMENTS_IN_PROJECT_REACHED':
                raise ExperimentLimitReached()
            else:
                raise
Esempio n. 12
0
    def create_experiment(
        self,
        project,
        name,
        description,
        params,
        properties,
        tags,
        abortable,  # deprecated in alpha
        monitored,  # deprecated in alpha
        git_info,
        hostname,
        entrypoint,
        notebook_id,
        checkpoint_id,
    ):
        if not isinstance(name, six.string_types):
            raise ValueError(
                "Invalid name {}, should be a string.".format(name))
        if not isinstance(description, six.string_types):
            raise ValueError(
                "Invalid description {}, should be a string.".format(
                    description))
        if not isinstance(params, dict):
            raise ValueError(
                "Invalid params {}, should be a dict.".format(params))
        if not isinstance(properties, dict):
            raise ValueError(
                "Invalid properties {}, should be a dict.".format(properties))
        if hostname is not None and not isinstance(hostname, six.string_types):
            raise ValueError(
                "Invalid hostname {}, should be a string.".format(hostname))
        if entrypoint is not None and not isinstance(entrypoint,
                                                     six.string_types):
            raise ValueError(
                "Invalid entrypoint {}, should be a string.".format(
                    entrypoint))

        git_info = ({
            "commit": {
                "commitId": git_info.commit_id,
                "message": git_info.message,
                "authorName": git_info.author_name,
                "authorEmail": git_info.author_email,
                "commitDate": git_info.commit_date,
            },
            "repositoryDirty": git_info.repository_dirty,
            "currentBranch": git_info.active_branch,
            "remotes": git_info.remote_urls,
        } if git_info else None)

        api_params = {
            "notebookId": notebook_id,
            "checkpointId": checkpoint_id,
            "projectIdentifier": str(project.internal_id),
            "cliVersion": self.client_lib_version,
            "gitInfo": git_info,
            "customId": None,
        }

        kwargs = {
            "experimentCreationParams": api_params,
            "X-Neptune-CliVersion": self.client_lib_version,
            "_request_options": {
                "headers": {
                    "X-Neptune-LegacyClient": "true"
                }
            },
        }

        try:
            api_experiment = (
                self.leaderboard_swagger_client.api.createExperiment(
                    **kwargs).response().result)
        except HTTPNotFound:
            raise ProjectNotFound(project_identifier=project.full_id)

        experiment = self._convert_to_experiment(api_experiment, project)
        # Initialize new experiment
        init_experiment_operations = self._get_init_experiment_operations(
            name, description, params, properties, tags, hostname, entrypoint)
        self._execute_operations(
            experiment=experiment,
            operations=init_experiment_operations,
        )
        return experiment