From f8780ecace643dcba180d670d2f7dc5d68451a7f Mon Sep 17 00:00:00 2001 From: Michael Liu Date: Mon, 22 Jun 2020 17:55:04 -0700 Subject: [PATCH] Use self._get_self_as_msg() (#846) --- client/verta/verta/client.py | 55 +++++++----------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/client/verta/verta/client.py b/client/verta/verta/client.py index 634fd393f1..64697b6c15 100644 --- a/client/verta/verta/client.py +++ b/client/verta/verta/client.py @@ -1888,14 +1888,7 @@ def __repr__(self): @property def workspace(self): - response = _utils.make_request( - "GET", - "{}://{}/api/v1/modeldb/experiment-run/getExperimentRunById".format(self._conn.scheme, self._conn.socket), - self._conn, params={'id': self.id}, - ) - _utils.raise_for_http_error(response) - - proj_id = _utils.body_to_json(response)['experiment_run']['project_id'] + proj_id = self._get_self_as_msg().project_id response = _utils.make_request( "GET", "{}://{}/api/v1/modeldb/project/getProjectById".format(self._conn.scheme, self._conn.socket), @@ -1934,16 +1927,7 @@ def workspace(self): @property def name(self): - Message = _ExperimentRunService.GetExperimentRunById - msg = Message(id=self.id) - data = _utils.proto_to_json(msg) - response = _utils.make_request("GET", - "{}://{}/api/v1/modeldb/experiment-run/getExperimentRunById".format(self._conn.scheme, self._conn.socket), - self._conn, params=data) - _utils.raise_for_http_error(response) - - response_msg = _utils.json_to_proto(_utils.body_to_json(response), Message.Response) - return response_msg.experiment_run.name + return self._get_self_as_msg().name @staticmethod def _generate_default_name(): @@ -3136,11 +3120,8 @@ def log_model(self, model, custom_modules=None, model_api=None, artifacts=None, # validate that `artifacts` are actually logged if artifacts: - response = _utils.make_request("GET", - "{}://{}/api/v1/modeldb/experiment-run/getExperimentRunById".format(self._conn.scheme, self._conn.socket), - self._conn, params={'id': self.id}) - _utils.raise_for_http_error(response) - existing_artifact_keys = {artifact['key'] for artifact in _utils.body_to_json(response)['experiment_run'].get('artifacts', [])} + run_msg = self._get_self_as_msg() + existing_artifact_keys = {artifact.key for artifact in run_msg.artifacts} unlogged_artifact_keys = set(artifacts) - existing_artifact_keys if unlogged_artifact_keys: raise ValueError("`artifacts` contains keys that have not been logged: {}".format(sorted(unlogged_artifact_keys))) @@ -3568,16 +3549,8 @@ def get_observations(self): Names and values of all observation series. """ - Message = _ExperimentRunService.GetExperimentRunById - msg = Message(id=self.id) - data = _utils.proto_to_json(msg) - response = _utils.make_request("GET", - "{}://{}/api/v1/modeldb/experiment-run/getExperimentRunById".format(self._conn.scheme, self._conn.socket), - self._conn, params=data) - _utils.raise_for_http_error(response) - - response_msg = _utils.json_to_proto(_utils.body_to_json(response), Message.Response) - return _utils.unravel_observations(response_msg.experiment_run.observations) + run_msg = self._get_self_as_msg() + return _utils.unravel_observations(run_msg.observations) def log_requirements(self, requirements, overwrite=False): """ @@ -3902,11 +3875,8 @@ def fetch_artifacts(self, keys): raise TypeError("`keys` must be list of str, not {}".format(type(keys))) # validate that `keys` are actually logged - response = _utils.make_request("GET", - "{}://{}/api/v1/modeldb/experiment-run/getExperimentRunById".format(self._conn.scheme, self._conn.socket), - self._conn, params={'id': self.id}) - _utils.raise_for_http_error(response) - existing_artifact_keys = {artifact['key'] for artifact in _utils.body_to_json(response)['experiment_run'].get('artifacts', [])} + run_msg = self._get_self_as_msg() + existing_artifact_keys = {artifact.key for artifact in run_msg.artifacts} unlogged_artifact_keys = set(keys) - existing_artifact_keys if unlogged_artifact_keys: raise ValueError("`keys` contains keys that have not been logged: {}".format(sorted(unlogged_artifact_keys))) @@ -4011,13 +3981,8 @@ def deploy(self, path=None, token=None, no_token=False, wait=False): data = {} if path is not None: # get project ID for URL path - response = _utils.make_request( - "GET", - "{}://{}/api/v1/modeldb/experiment-run/getExperimentRunById".format(self._conn.scheme, self._conn.socket), - self._conn, params={'id': self.id}) - _utils.raise_for_http_error(response) - - data.update({'url_path': "{}/{}".format(_utils.body_to_json(response)['experiment_run']['project_id'], path)}) + run_msg = self._get_self_as_msg() + data.update({'url_path': "{}/{}".format(run_msg.project_id, path)}) if no_token: data.update({'token': ""}) elif token is not None: