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, )
def enable(self, monitored_entity, environment=None, wait=False): """Build and deploy this uploaded profiler. This method instructs Verta Services to build and deploy a docker image for the profiler which was uploaded. Environment variables for this deployment can be specified in the `environment` keyword argument as a dictionary from strings to strings. By default this method will issue a command to Verta Services to build an image, or to deploy the built image if the build is ready. In order to fully build and deploy an image, and to block on the completion of this process, users should specify ``wait=True``. Parameters ---------- monitored_entity : :class:`~verta.monitoring.monitored_entity.MonitoredEntity` The monitored entity for which this profiler should be enabled. environment : dict, optional Dictionary from strings to strings specifying environment variables. wait: bool, optional Whether to block on completion of the full build-and-deploy process. Defaults to False. Returns ------- ai.verta.monitoring.ProfilerStatus Deployment and build status of this profiler """ if wait: return self._blocking_enable(monitored_entity, environment) profiler_id = self.id monitored_entity_id = arg_handler.extract_id(monitored_entity) environment = environment.copy() if environment else dict() environment["PROFILER_ID"] = profiler_id key_values = [ KeyValue(key=k, value=_utils.python_to_val_proto(v, allow_collection=True)) for k, v in environment.items() ] msg = EnableProfilerRequest( profiler_id=profiler_id, monitored_entity_id=monitored_entity_id, environment=key_values, ) endpoint = "/api/v1/monitored_entity/enableProfiler" response = self._conn.make_proto_request("POST", endpoint, body=msg) status = self._conn.must_proto_response( response, EnableProfilerRequest.Response).status return status # TODO: wrap this in a nicer type
def get_or_create(self, name, data_type_cls, monitored_entity): """Get or create a summary by name and data type. Parameters ---------- name : str The name of this summary. data_type_cls: :mod:`VertaDataType <verta.data_types>` The class of data type which summary samples must conform to. monitored_entity: :class:`~verta.monitoring.monitored_entity.MonitoredEntity` A monitored entity object. Returns ------- :class:`~verta.monitoring.summaries.summary.Summary` A retrieved or created summary. """ if not issubclass(data_type_cls, data_types._VertaDataType): raise TypeError( "expected a supported VertaDataType, found {}".format( type(data_type_cls))) query = SummaryQuery(names=[name], monitored_entities=[monitored_entity]) retrieved = self.find(query) # if retrieved and len(retrieved) > 1: # warnings.warn( # "found multiple summaries with name: {}, for monitored entity: {}".format( # name, monitored_entity # ) # ) if retrieved: monitored_entity_id = arg_handler.extract_id(monitored_entity) cond = (lambda s: s.name == name and s.monitored_entity_id == monitored_entity_id) retrieved = list(filter(cond, retrieved)) if retrieved: summary = retrieved[0] else: summary = self.create(name, data_type_cls, monitored_entity) if not summary.has_type(data_type_cls): warnings.warn( "retrieved summary has type {} although type {} was specified for create" .format(summary.type, data_type_cls._type_string())) return summary
def __init__(self, comparison, reference_sample): self._comparison = _Alerter._validate_comparison(comparison) self._reference_sample_id = arg_handler.extract_id(reference_sample)