コード例 #1
0
    def create_version_from_run(self, run_id, name=None, lock_level=None):
        """Create a model version copied from an experiment run.

        Parameters
        ----------
        run_id : str or :class:`~verta.tracking.entities.ExperimentRun`
            Run from which to create the model version.
        name : str, optional
            Name of the model version. If no name is provided, one will be generated.
        lock_level : :mod:`~verta.registry.lock`, default :class:`~verta.registry.lock.Open`
            Lock level to set when creating this model version.

        Returns
        -------
        :class:`~verta.registry.entities.RegisteredModelVersion`

        """
        run_id = arg_handler.extract_id(run_id)

        ctx = _Context(self._conn, self._conf)
        ctx.registered_model = self
        return RegisteredModelVersion._create(
            self._conn,
            self._conf,
            ctx,
            name=name,
            experiment_run_id=run_id,
            lock_level=lock_level,
        )
コード例 #2
0
    def create(
        self,
        name,
        channel,
        workspace=None,
        created_at=None,
        updated_at=None,
    ):
        """
        Create a new notification channel.

        Parameters
        ----------
        name : str
            A unique name for this notification channel.
        channel : :mod:`~verta.monitoring.notification_channel`
            The configuration for this notification channel.
        workspace : str, optional
            Workspace in which to create this notification channel. Defaults to
            the client's default workspace.
        created_at : datetime.datetime or int, optional
            An override creation time to assign to this channel. Either a
            timezone aware datetime object or unix epoch milliseconds.
        updated_at : datetime.datetime or int, optional
            An override update time to assign to this channel. Either a
            timezone aware datetime object or unix epoch milliseconds.

        Returns
        -------
        :class:`NotificationChannel`
            Notification channel.

        Examples
        --------
        .. code-block:: python

            from verta.monitoring.notification_channel import SlackNotificationChannel

            channels = Client().monitoring.notification_channels

            channel = notification_channels.create(
                "Slack alerts",
                SlackNotificationChannel("https://hooks.slack.com/services/.../.../......"),
            )

        """
        if workspace is None:
            workspace = self._client.get_workspace()

        ctx = _Context(self._conn, self._conf)
        return NotificationChannel._create(
            self._conn,
            self._conf,
            ctx,
            name=name,
            channel=channel,
            workspace=workspace,
            created_at_millis=time_utils.epoch_millis(created_at),
            updated_at_millis=time_utils.epoch_millis(updated_at),
        )
コード例 #3
0
ファイル: _profilers.py プロジェクト: vishalbelsare/modeldb
 def create(self, name, model_version):
     ctx = _Context(self._conn, self._conf)
     reference = str(model_version.id)
     reference = ProfilerReference._create(self._conn,
                                           self._conf,
                                           ctx,
                                           name=name,
                                           reference=reference)
     reference._set_version(model_version)
     reference._set_client(self._client)
     return reference
コード例 #4
0
    def create_version(self,
                       name=None,
                       desc=None,
                       labels=None,
                       attrs=None,
                       time_created=None,
                       lock_level=None):
        """
        Creates a model registry entry.

        Parameters
        ----------
        name : str, optional
            Name of the Model Version. If no name is provided, one will be generated.
        desc : str, optional
            Description of the Model Version.
        labels : list of str, optional
            Labels of the Model Version.
        attrs : dict of str to {None, bool, float, int, str}, optional
            Attributes of the Model Version.
        lock_level : :mod:`~verta.registry.lock`, default :class:`~verta.registry.lock.Open`
            Lock level to set when creating this model version.

        Returns
        -------
        :class:`~verta.registry.entities.RegisteredModelVersion`

        """
        ctx = _Context(self._conn, self._conf)
        ctx.registered_model = self
        return RegisteredModelVersion._create(
            self._conn,
            self._conf,
            ctx,
            name=name,
            desc=desc,
            tags=labels,
            attrs=attrs,
            date_created=time_created,
            lock_level=lock_level,
        )
コード例 #5
0
    def get_or_create_version(self,
                              name=None,
                              desc=None,
                              labels=None,
                              attrs=None,
                              time_created=None,
                              lock_level=None,
                              id=None):
        """
        Gets or creates a Model Version.

        If an accessible Model Version with name `name` does not already exist under this
        Registered Model, it will be created and initialized with specified metadata
        parameters. If such a Model Version does already exist, it will be retrieved;
        specifying metadata parameters in this case will raise a warning.

        Parameters
        ----------
        name : str, optional
            Name of the Model Version. If no name is provided, one will be generated.
        desc : str, optional
            Description of the Model Version.
        labels : list of str, optional
            Labels of the Model Version.
        attrs : dict of str to {None, bool, float, int, str}, optional
            Attributes of the Model Version.
        lock_level : :mod:`~verta.registry.lock`, default :class:`~verta.registry.lock.Open`
            Lock level to set when creating this model version.
        id : str, optional
            ID of the Model Version. This parameter cannot be provided alongside `name`, and other
            parameters will be ignored.

        Returns
        -------
        :class:`~verta.registry.entities.RegisteredModelVersion`

        Raises
        ------
        ValueError
            If `name` and `id` are both passed in.

        """
        if name is not None and id is not None:
            raise ValueError("cannot specify both `name` and `id`")

        resource_name = "Model Version"
        param_names = "`desc`, `labels`, `attrs`, `time_created`, or `lock_level`"
        params = (desc, labels, attrs, time_created, lock_level)
        if id is not None:
            check_unnecessary_params_warning(resource_name, "id {}".format(id),
                                             param_names, params)
            return RegisteredModelVersion._get_by_id(self._conn, self._conf,
                                                     id)
        else:
            ctx = _Context(self._conn, self._conf)
            ctx.registered_model = self
            return RegisteredModelVersion._get_or_create_by_name(
                self._conn, name,
                lambda name: RegisteredModelVersion._get_by_name(
                    self._conn, self._conf, name, self.id),
                lambda name: RegisteredModelVersion._create(
                    self._conn,
                    self._conf,
                    ctx,
                    name=name,
                    desc=desc,
                    tags=labels,
                    attrs=attrs,
                    date_created=time_created,
                    lock_level=lock_level,
                ), lambda: check_unnecessary_params_warning(
                    resource_name,
                    "name {}".format(name),
                    param_names,
                    params,
                ))
コード例 #6
0
    def create(
        self,
        name,
        alerter,
        notification_channels=None,
        labels=None,
        starting_from=None,
        _created_at=None,
        _updated_at=None,
        _last_evaluated_at=None,
    ):
        """
        Create a new alert.

        Parameters
        ----------
        name : str
            A unique name for this alert.
        alerter : :mod:`~verta.monitoring.alert`
            The configuration for this alert.
        notification_channels : list of :class:`~verta.monitoring.notification_channel.entities.NotificationChannel`, optional
            Channels for this alert to propagate notifications to.
        labels : dict of str to list of str, optional
            Alert on samples that have at least one of these labels. A mapping
            between label keys and lists of corresponding label values.
        starting_from : datetime.datetime or int, optional
            Alert on samples associated with periods after this time; useful
            for monitoring samples representing past data. Either a timezone
            aware datetime object or unix epoch milliseconds.

        Returns
        -------
        :class:`Alert`
            Alert.

        Examples
        --------
        .. code-block:: python

            alert = summary.alerts.create(
                name="MSE",
                alerter=alerter,
                notification_channels=[channel],
            )

        """
        if self._summary is None:
            raise RuntimeError(
                "this Alert cannot be used to create because it was not"
                " obtained via summary.alerts")

        summary_sample_query = SummarySampleQuery(
            summary_query=self._build_summary_query(),
            labels=labels,
            time_window_start=time_utils.epoch_millis(starting_from),
        )

        if notification_channels is None:
            notification_channels = []
        for channel in notification_channels:
            Alert._validate_notification_channel(channel)

        ctx = _Context(self._conn, self._conf)
        return Alert._create(
            self._conn,
            self._conf,
            ctx,
            name=name,
            monitored_entity_id=(self._monitored_entity_id
                                 or self._summary.monitored_entity_id),
            alerter=alerter,
            summary_sample_query=summary_sample_query,
            notification_channels=notification_channels,
            created_at_millis=time_utils.epoch_millis(_created_at),
            updated_at_millis=time_utils.epoch_millis(_updated_at),
            last_evaluated_at_millis=time_utils.epoch_millis(
                _last_evaluated_at),
        )
コード例 #7
0
    def get_or_create(
        self,
        name=None,
        channel=None,
        workspace=None,
        created_at=None,
        updated_at=None,
        id=None,
    ):
        """Get or create a notification channel by name.

        Either `name` or `id` can be provided but not both. If `id` is
        provided, this will act only as a get method and no object will be
        created.

        Parameters
        ----------
        name : str, optional
            A unique name for this notification channel.
        channel : :mod:`~verta.monitoring.notification_channel`, optional
            The configuration for this notification channel.
        workspace : str, optional
            Workspace in which to create this notification channel. Defaults to
            the client's default workspace.
        created_at : datetime.datetime or int, optional
            An override creation time to assign to this channel. Either a
            timezone aware datetime object or unix epoch milliseconds.
        updated_at : datetime.datetime or int, optional
            An override update time to assign to this channel. Either a
            timezone aware datetime object or unix epoch milliseconds.
        id : int, optional
            Notification channel ID. This should not be provided if `name`
            is provided.

        Returns
        -------
        :class:`NotificationChannel`
            Notification channel.

        Examples
        --------
        .. code-block:: python

            from verta.monitoring.notification_channel import SlackNotificationChannel

            channels = Client().monitoring.notification_channels

            channel = notification_channels.get_or_create(
                "Slack alerts",
                SlackNotificationChannel("https://hooks.slack.com/services/.../.../......"),
            )

            # get it back later with the same method
            channel = notification_channels.get_or_create(
                "Slack alerts",
            )

        """
        if name and id:
            raise ValueError("cannot specify both `name` and `id`")
        if workspace and id:
            raise ValueError(
                "cannot specify both `workspace` and `id`;"
                " getting by ID does not require a workspace name"
            )

        name = self._client._set_from_config_if_none(name, "notification_channel")
        if workspace is None:
            workspace = self._client.get_workspace()

        resource_name = "Notification Channel"
        param_names = "`channel`, `created_at`, or `updated_at`"
        params = (channel, created_at, updated_at)
        if id is not None:
            channel = NotificationChannel._get_by_id(self._conn, self._conf, id)
            _utils.check_unnecessary_params_warning(
                resource_name,
                "id {}".format(id),
                param_names,
                params,
            )
        else:
            channel = NotificationChannel._get_or_create_by_name(
                self._conn,
                name,
                lambda name: NotificationChannel._get_by_name(
                    self._conn,
                    self._conf,
                    name,
                    workspace,
                ),
                lambda name: NotificationChannel._create(
                    self._conn,
                    self._conf,
                    _Context(self._conn, self._conf),
                    name=name,
                    channel=channel,
                    workspace=workspace,
                    created_at_millis=time_utils.epoch_millis(created_at),
                    updated_at_millis=time_utils.epoch_millis(updated_at),
                ),
                lambda: _utils.check_unnecessary_params_warning(
                    resource_name,
                    "name {}".format(name),
                    param_names,
                    params,
                ),
            )

        return channel