Exemple #1
0
    def __init__(
        self,
        owner: str = None,
        project: str = None,
        run_uuid: str = None,
        client: PolyaxonClient = None,
    ):

        try:
            owner, project = get_project_or_local(
                get_project_full_name(owner=owner, project=project))
        except PolyaxonClientException:
            pass

        if project is None:
            if settings.CLIENT_CONFIG.is_managed:
                owner, project, _run_uuid = get_run_info()
                run_uuid = run_uuid or _run_uuid
            else:
                raise PolyaxonClientException(
                    "Please provide a valid project.")

        if not owner or not project:
            raise PolyaxonClientException(
                "Please provide a valid project with owner.")

        self.client = client
        if not (self.client or settings.CLIENT_CONFIG.is_offline):
            self.client = PolyaxonClient()

        self._owner = owner
        self._project = project
        self._run_uuid = get_run_or_local(run_uuid)
        self._run_data = polyaxon_sdk.V1Run()
        self._namespace = None
Exemple #2
0
 def resume(self, override_config=None, **kwargs):
     body = polyaxon_sdk.V1Run(content=override_config)
     return self.client.runs_v1.resume_run(self.owner,
                                           self.project,
                                           self.run_uuid,
                                           body=body,
                                           **kwargs)
Exemple #3
0
    def __init__(
        self,
        owner: str = None,
        project: str = None,
        run_uuid: str = None,
        client: RunClient = None,
        track_code: bool = True,
        track_env: bool = True,
        refresh_data: bool = False,
        artifacts_path: str = None,
    ):
        super().__init__(
            owner=owner,
            project=project,
            run_uuid=run_uuid,
            client=client,
        )
        self.track_code = track_code
        self.track_env = track_env
        self._has_model = False
        self._has_events = False
        self._has_metrics = False
        self._has_tensorboard = False
        self._artifacts_path = None
        self._outputs_path = None
        self._event_logger = None
        self._resource_logger = None
        self._results = {}

        if (settings.CLIENT_CONFIG.is_managed and self.run_uuid) or artifacts_path:
            self.set_artifacts_path(artifacts_path)

        if (
            self._artifacts_path
            and settings.CLIENT_CONFIG.is_managed
            and get_collect_artifact()
        ):
            self.set_run_event_logger()
            if get_collect_resources():
                self.set_run_resource_logger()

        # no artifacts path is set, we use the temp path
        if not self._artifacts_path:
            self._artifacts_path = TEMP_RUN_ARTIFACTS
            self._outputs_path = TEMP_RUN_ARTIFACTS

        self._run = polyaxon_sdk.V1Run()
        if settings.CLIENT_CONFIG.is_offline:
            return

        if self._run_uuid and (refresh_data or settings.CLIENT_CONFIG.is_managed):
            self.refresh_data()

        # Track run env
        if settings.CLIENT_CONFIG.is_managed and self.track_env:
            self.log_env()

        if settings.CLIENT_CONFIG.is_managed:
            self._register_wait()
Exemple #4
0
    def create(
        self,
        name=None,
        tags=None,
        description=None,
        content=None,
        base_outputs_path=None,
    ):
        run = polyaxon_sdk.V1Run()
        if self.track_env:
            run.run_env = get_run_env()
        if name:
            run.name = name
        if tags:
            run.tags = tags
        if description:
            run.description = description
        if content:
            try:
                specification = get_specification(data=[content])
            except Exception as e:
                raise PolyaxonClientException(e)
            run.content = specification.config_dump
        else:
            run.is_managed = False

        if self.client:
            try:
                run = self.client.runs_v1.create_run(owner=self.owner,
                                                     project=self.project,
                                                     body=run)
            except (ApiException, HTTPError) as e:
                raise PolyaxonClientException(e)
            if not run:
                raise PolyaxonClientException("Could not create a run.")
        if not settings.CLIENT_CONFIG.is_managed and self.track_logs:
            setup_logging(send_logs=self.send_logs)
        self._run = run
        self._run_uuid = run.uuid
        self.status = "created"

        # Setup the outputs store
        if self.outputs_store is None and base_outputs_path:
            outputs_path = "{}/{}/{}/{}".format(base_outputs_path, self.owner,
                                                self.project, self.run_uuid)
            self.set_outputs_store(outputs_path=outputs_path)

        if self.track_code:
            self.log_code_ref()

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

        return self
Exemple #5
0
 def restart(self, override_config=None, copy: bool = False, **kwargs):
     body = polyaxon_sdk.V1Run(content=override_config)
     if copy:
         return self.client.runs_v1.copy_run(
             self.owner, self.project, self.run_uuid, body=body, **kwargs
         )
     else:
         return self.client.runs_v1.restart_run(
             self.owner, self.project, self.run_uuid, body=body, **kwargs
         )
Exemple #6
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
Exemple #7
0
    def resume(self, override_config=None, **kwargs):
        """Resumes the current run

        Args:
            override_config: Dict or str, optional,
                config to use for overriding the original run's config.

        Returns:
            V1Run instance.
        """
        body = polyaxon_sdk.V1Run(content=override_config)
        return self.client.runs_v1.resume_run(
            self.owner, self.project, self.run_uuid, body=body, **kwargs
        )
Exemple #8
0
    def __init__(
        self,
        owner=None,
        project=None,
        run_uuid=None,
        client=None,
        track_logs=True,
        track_code=True,
        track_env=False,
        outputs_store=None,
    ):

        owner, project = get_project_info(owner=owner, project=project)

        if project is None:
            if settings.CLIENT_CONFIG.is_managed:
                owner, project, _run_uuid = self.get_run_info()
                run_uuid = run_uuid or _run_uuid
            else:
                raise PolyaxonClientException(
                    "Please provide a valid project.")

        self.status = None
        self.client = client
        if not (self.client or settings.CLIENT_CONFIG.is_offline):
            self.client = PolyaxonClient()

        self.track_logs = track_logs
        self.track_code = track_code
        self.track_env = track_env
        self._owner = owner
        self._project = project
        self._run_uuid = run_uuid
        self.outputs_store = outputs_store

        # Setup the outputs store
        if outputs_store is None and settings.CLIENT_CONFIG.is_managed:
            self.set_outputs_store(outputs_path=get_outputs_path(),
                                   set_env_vars=True)

        self._run = polyaxon_sdk.V1Run()
        if settings.CLIENT_CONFIG.is_offline:
            return

        if self._run_uuid:
            self.refresh_data()

        # Track run env
        if settings.CLIENT_CONFIG.is_managed and self.track_env:
            self.log_run_env()
Exemple #9
0
    def __init__(
        self,
        owner=None,
        project=None,
        run_uuid=None,
        client=None,
        track_code=True,
        track_env=False,
        refresh_data=True,
    ):
        super().__init__(
            owner=owner,
            project=project,
            run_uuid=run_uuid,
            client=client,
        )
        self.track_code = track_code
        self.track_env = track_env
        self._artifacts_path = None
        self._outputs_path = None
        self._event_logger = None
        self._resource_logger = None
        self._results = {}

        if settings.CLIENT_CONFIG.is_managed and self.run_uuid:
            self.set_run_event_path()

        if (self.artifacts_path and settings.CLIENT_CONFIG.is_managed
                and get_collect_artifact()):
            self.set_run_event_logger()
            if get_collect_resources():
                self.set_run_resource_logger()

        self._run = polyaxon_sdk.V1Run()
        if settings.CLIENT_CONFIG.is_offline:
            return

        if self._run_uuid and refresh_data:
            self.refresh_data()

        # Track run env
        if settings.CLIENT_CONFIG.is_managed and self.track_env:
            self.log_run_env()

        self._register_wait()
Exemple #10
0
    def restart(self, override_config=None, copy: bool = False, **kwargs):
        """Restarts the current run

        Args:
            override_config: Dict or str, optional,
                config to use for overriding the original run's config.
            copy: bool, optional, default: False, to restart with copy mechanism.

        Returns:
            V1Run instance.
        """
        body = polyaxon_sdk.V1Run(content=override_config)
        if copy:
            return self.client.runs_v1.copy_run(
                self.owner, self.project, self.run_uuid, body=body, **kwargs
            )
        else:
            return self.client.runs_v1.restart_run(
                self.owner, self.project, self.run_uuid, body=body, **kwargs
            )