-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbenchmark_run.py
More file actions
127 lines (103 loc) · 3.91 KB
/
Copy pathbenchmark_run.py
File metadata and controls
127 lines (103 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""BenchmarkRun resource class for synchronous operations."""
from __future__ import annotations
from typing import List
from typing_extensions import Unpack, override
from ..types import BenchmarkRunView
from ._types import BaseRequestOptions, LongRequestOptions, SDKBenchmarkRunListScenarioRunsParams
from .._client import Runloop
from .scenario_run import ScenarioRun
class BenchmarkRun:
"""A benchmark run for evaluating agent performance across scenarios.
Provides methods for monitoring run status, managing the run lifecycle,
and accessing scenario run results. Obtain instances via
``benchmark.start_run()`` or ``benchmark.list_runs()``.
Example:
>>> benchmark = runloop.benchmark.from_id("bench-xxx")
>>> run = benchmark.start_run(run_name="evaluation-v1")
>>> info = run.get_info()
>>> scenario_runs = run.list_scenario_runs()
"""
def __init__(self, client: Runloop, run_id: str, benchmark_id: str) -> None:
"""Create a BenchmarkRun instance.
:param client: Runloop client instance
:type client: Runloop
:param run_id: Benchmark run ID
:type run_id: str
:param benchmark_id: Parent benchmark ID
:type benchmark_id: str
"""
self._client = client
self._id = run_id
self._benchmark_id = benchmark_id
@override
def __repr__(self) -> str:
return f"<BenchmarkRun id={self._id!r}>"
@property
def id(self) -> str:
"""Return the benchmark run ID.
:return: Unique benchmark run ID
:rtype: str
"""
return self._id
@property
def benchmark_id(self) -> str:
"""Return the parent benchmark ID.
:return: Parent benchmark ID
:rtype: str
"""
return self._benchmark_id
def get_info(
self,
**options: Unpack[BaseRequestOptions],
) -> BenchmarkRunView:
"""Retrieve current benchmark run status and metadata.
:param options: See :typeddict:`~runloop_api_client.sdk._types.BaseRequestOptions` for available options
:return: Current benchmark run state info
:rtype: BenchmarkRunView
"""
return self._client.benchmark_runs.retrieve(
self._id,
**options,
)
def cancel(
self,
**options: Unpack[LongRequestOptions],
) -> BenchmarkRunView:
"""Cancel the benchmark run.
Stops all running scenarios and marks the run as canceled.
:param options: See :typeddict:`~runloop_api_client.sdk._types.LongRequestOptions` for available options
:return: Updated benchmark run state
:rtype: BenchmarkRunView
"""
return self._client.benchmark_runs.cancel(
self._id,
**options,
)
def complete(
self,
**options: Unpack[LongRequestOptions],
) -> BenchmarkRunView:
"""Complete the benchmark run.
Marks the run as completed. Call this after all scenarios have finished.
:param options: See :typeddict:`~runloop_api_client.sdk._types.LongRequestOptions` for available options
:return: Completed benchmark run state
:rtype: BenchmarkRunView
"""
return self._client.benchmark_runs.complete(
self._id,
**options,
)
def list_scenario_runs(
self,
**params: Unpack[SDKBenchmarkRunListScenarioRunsParams],
) -> List[ScenarioRun]:
"""List all scenario runs for this benchmark run.
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKBenchmarkRunListScenarioRunsParams` for available parameters
:return: List of scenario run objects
:rtype: List[ScenarioRun]
"""
page = self._client.benchmark_runs.list_scenario_runs(
self._id,
**params,
)
return [ScenarioRun(self._client, run.id, run.devbox_id) for run in page.runs]