Skip to content

Commit

Permalink
Use self._get_self_as_msg() (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
convoliution authored Jun 23, 2020
1 parent e9595b5 commit f8780ec
Showing 1 changed file with 10 additions and 45 deletions.
55 changes: 10 additions & 45 deletions client/verta/verta/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f8780ec

Please sign in to comment.