def get_experiment_by_name(self, experiment_name): try: req_body = message_to_json( GetExperimentByName(experiment_name=experiment_name)) response_proto = self._call_endpoint(GetExperimentByName, req_body) return Experiment.from_proto(response_proto.experiment) except MlflowException as e: if e.error_code == databricks_pb2.ErrorCode.Name( databricks_pb2.RESOURCE_DOES_NOT_EXIST): return None elif e.error_code == databricks_pb2.ErrorCode.Name( databricks_pb2.REQUEST_LIMIT_EXCEEDED): raise e # Fall back to using ListExperiments-based implementation. for experiment in self.list_experiments(ViewType.ALL): if experiment.name == experiment_name: return experiment return None
def test_creation_and_hydration(self): exp_id = random_int() name = "exp_%d_%d" % (random_int(), random_int()) lifecycle_stage = Experiment.ACTIVE_LIFECYCLE location = random_file(".json") exp = Experiment(exp_id, name, location, lifecycle_stage) self._check(exp, exp_id, name, location, lifecycle_stage) as_dict = {"experiment_id": exp_id, "name": name, "artifact_location": location, "lifecycle_stage": lifecycle_stage} self.assertEqual(dict(exp), as_dict) proto = exp.to_proto() exp2 = Experiment.from_proto(proto) self._check(exp2, exp_id, name, location, lifecycle_stage) exp3 = Experiment.from_dictionary(as_dict) self._check(exp3, exp_id, name, location, lifecycle_stage)
def list_experiments( self, view_type=ViewType.ACTIVE_ONLY, max_results=None, page_token=None, ): """ :param view_type: Qualify requested type of experiments. :param max_results: If passed, specifies the maximum number of experiments desired. If not passed, the server will pick a maximum number of results to return. :param page_token: Token specifying the next page of results. It should be obtained from a ``list_experiments`` call. :return: A :py:class:`PagedList <mlflow.store.entities.PagedList>` of :py:class:`Experiment <mlflow.entities.Experiment>` objects. The pagination token for the next page can be obtained via the ``token`` attribute of the object. """ req_body = message_to_json( ListExperiments(view_type=view_type, max_results=max_results, page_token=page_token) ) response_proto = self._call_endpoint(ListExperiments, req_body) experiments = [Experiment.from_proto(x) for x in response_proto.experiments] # If the response doesn't contain `next_page_token`, `response_proto.next_page_token` # returns an empty string (default value for a string proto field). token = ( response_proto.next_page_token if response_proto.HasField("next_page_token") else None ) return PagedList(experiments, token)