Skip to content

Commit 986f758

Browse files
committed
🐛 Fixed grid metric and span retrieval
1 parent 9c53a74 commit 986f758

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

simvue/api/objects/grids.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,36 @@ def get_run_metric_span(self, *, run_id: str, metric_name: str) -> dict:
221221
metric to retrieve span information for.
222222
223223
Returns
224-
------
224+
-------
225225
dict[str, list[dict[str, float]]
226226
dictionary containing span from this for the run at specified step.
227227
"""
228228
_response = sv_get(
229-
url=f"{self.run_metric_values_url(run_id, metric_name) / 'span'}",
229+
url=f"{self.run_metric_url(run_id, metric_name) / 'span'}",
230230
headers=self._headers,
231231
)
232232

233-
return get_json_from_response(
234-
response=_response,
235-
expected_status=[http.HTTPStatus.OK],
236-
expected_type=dict,
237-
scenario=f"Retrieving grid span for run '{run_id}'",
233+
_response = typing.cast(
234+
"list[dict[str, int | float | str]]",
235+
get_json_from_response(
236+
response=_response,
237+
expected_status=[http.HTTPStatus.OK],
238+
expected_type=list,
239+
scenario=f"Retrieving grid span for run '{run_id}'",
240+
),
238241
)
239242

243+
if not _response:
244+
raise RuntimeError("Failed to retrieve span, no data.")
245+
246+
return _response[0]
247+
240248
@classmethod
241249
def get(
242250
cls,
243251
*_,
244252
**__,
245-
) -> typing.Generator[tuple[str, Self | None], None, None]:
253+
) -> typing.Generator[tuple[str, Self | None]]:
246254
raise NotImplementedError
247255

248256

@@ -309,7 +317,7 @@ def get(
309317
step: pydantic.NonNegativeInt,
310318
spans: bool = False,
311319
**kwargs,
312-
) -> typing.Generator[dict[str, dict[str, list[dict[str, float]]]], None, None]:
320+
) -> typing.Generator[dict[str, dict[str, list[dict[str, float]]]]]:
313321
"""Retrieve tensor-metrics from the server for a given set of runs.
314322
315323
Parameters

tests/unit/test_grids.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def test_grid_metrics_creation_online() -> None:
132132
time.sleep(1)
133133
# Online metrics
134134
assert list(GridMetrics.get(runs=[_run.id], metrics=["A"], step=_step))
135+
assert _grid.get_run_metric_values(run_id=_run.id, metric_name="A", step=_step)
136+
assert _grid.get_run_metric_span(run_id=_run.id, metric_name="A").get("max_timestamp")
135137
_run.delete()
136138
_folder.delete(recursive=True, delete_runs=True, runs_only=False)
137139

0 commit comments

Comments
 (0)