Exemplo n.º 1
0
 def create(
     self,
     name: str = None,
     description: str = None,
     tags: Union[str, Sequence[str]] = None,
     content: Union[str, V1Operation] = None,
 ):
     is_managed = True
     if not content:
         is_managed = False
     elif not isinstance(content, (str, V1Operation)):
         raise PolyaxonClientException(
             "Received an invalid content: {}".format(content))
     if content:
         content = (content if isinstance(content, str) else
                    content.to_dict(dump=True))
     data = polyaxon_sdk.V1OperationBody(
         name=name,
         description=description,
         tags=tags,
         content=content,
         is_managed=is_managed,
     )
     self._create(data=data, async_req=False)
     self._post_create()
Exemplo n.º 2
0
    def create(
        self,
        name: str = None,
        description: str = None,
        tags: Union[str, Sequence[str]] = None,
        content: Union[str, Dict, V1Operation] = None,
    ):
        """Creates a new run based on the data passed.

        N.B. Create methods are only useful if you want to create a run programmatically,
        if you run a component/operation from the CLI/UI an instance will be created automatically.

        This is a generic create function, you can check other methods for creating runs:
          * from yaml: `create_from_polyaxonfile`
          * from url: `create_from_url`
          * from hub: `create_from_hub`

        > Note that if you don't pass `content`, the creation will pass,
        and the run will be marked as non-managed.

        [Run API](/docs/api/#operation/CreateRun)

        Args:
            name: str, optional, it will override the name in the operation if provided.
            description: str, optional,
                it will override the description in the operation if provided.
            tags: str or List[str], optional, list of tags,
                it will override the tags in the operation if provided.
            content: str or Dict or V1Operation, optional.

        Returns:
            V1Run, run instance from the response.
        """
        is_managed = True
        if not content:
            is_managed = False
        elif not isinstance(content, (str, Mapping, V1Operation)):
            raise PolyaxonClientException(
                "Received an invalid content: {}".format(content)
            )
        if content:
            if isinstance(content, Mapping):
                content = V1Operation.from_dict(content)
            content = (
                content if isinstance(content, str) else content.to_dict(dump=True)
            )
        data = polyaxon_sdk.V1OperationBody(
            name=name,
            description=description,
            tags=tags,
            content=content,
            is_managed=is_managed,
        )
        self._create(data=data, async_req=False)
        self._post_create()
        return self.run_data
Exemplo n.º 3
0
    def create(self, name=None, tags=None, description=None, content=None):
        operation = polyaxon_sdk.V1OperationBody()
        if name:
            operation.name = name
        if tags:
            operation.tags = tags
        if description:
            operation.description = description
        if content:
            try:
                specification = OperationSpecification.read(content)
            except Exception as e:
                raise PolyaxonClientException("Client error: %s" % e) from e
            operation.content = specification.to_dict(dump=True)
        else:
            operation.is_managed = False

        if self.client:
            try:
                run = self.client.runs_v1.create_run(owner=self.owner,
                                                     project=self.project,
                                                     body=operation)
            except (ApiException, HTTPError) as e:
                raise PolyaxonClientException("Client error: %s" % e) from e
            if not run:
                raise PolyaxonClientException("Could not create a run.")
        else:
            run = polyaxon_sdk.V1Run(
                name=operation.name,
                tags=operation.tags,
                description=operation.description,
                content=operation.content,
                is_managed=operation.is_managed,
            )

        self._run = run
        self._run_uuid = run.uuid

        if self.artifacts_path:
            self.set_run_event_logger()

        if self.track_code:
            self.log_code_ref()
        if self.track_env:
            self.log_run_env()

        if not settings.CLIENT_CONFIG.is_managed:
            self._start()
        else:
            self._register_wait()

        return self
Exemplo n.º 4
0
    def create(
        self,
        name: str = None,
        description: str = None,
        tags: Union[str, Sequence[str]] = None,
        content: Union[str, Dict, V1Operation] = None,
    ):
        """Creates a new run based on the data passed.

        This is a generic create function, you can check other methods for creating runs:
          * from yaml
          * from hub
          * from url

        Note that if you don't pass data, the creation will pass,
        and the run will be marked as non-managed.

        [Run API](/docs/api/#operation/CreateRun)

        Args:
            name: str, optional, name
                note it will override the name in the operation if available.
            description: str, optional, description
                note it will override the description in the operation if available.
            tags: str or List[str], optional, list of tags,
                note it will override the tags in the operation if available.
            content: str or Dict or V1Operation, optional.

        Returns:
            V1Run, run instance from the response.
        """
        is_managed = True
        if not content:
            is_managed = False
        elif not isinstance(content, (str, Mapping, V1Operation)):
            raise PolyaxonClientException(
                "Received an invalid content: {}".format(content))
        if content:
            if isinstance(content, Mapping):
                content = V1Operation.from_dict(content)
            content = (content if isinstance(content, str) else
                       content.to_dict(dump=True))
        data = polyaxon_sdk.V1OperationBody(
            name=name,
            description=description,
            tags=tags,
            content=content,
            is_managed=is_managed,
        )
        self._create(data=data, async_req=False)
        self._post_create()