Skip to content

Commit dd8070b

Browse files
committed
oddish run shows only new trials
1 parent ac2be89 commit dd8070b

5 files changed

Lines changed: 39 additions & 12 deletions

File tree

backend/api/routers/tasks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,26 @@ async def create_task_sweep(
261261

262262
await session.commit()
263263

264-
provider_counts: Counter[str] = Counter(
265-
t.provider for t in (new_trials if is_append else task.trials)
266-
)
264+
response_trials = new_trials if is_append else list(task.trials)
265+
provider_counts: Counter[str] = Counter(t.provider for t in response_trials)
267266
primary = (
268267
experiment
269268
or (task.experiments[0] if task.experiments else None)
270269
)
271270
resp_experiment_id = primary.id if primary else None
272271
resp_experiment_name = primary.name if primary else None
273-
272+
274273
return TaskResponse(
275274
id=task.id,
276275
name=task.name,
277276
status=task.status,
278277
priority=task.priority,
279-
trials_count=len(new_trials) if is_append else len(task.trials),
278+
trials_count=len(response_trials),
280279
providers=dict(provider_counts),
281280
experiment_id=resp_experiment_id,
282281
experiment_name=resp_experiment_name,
283282
created_at=task.created_at,
283+
new_trial_ids=[t.id for t in response_trials],
284284
)
285285

286286

oddish/src/oddish/cli/api.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from concurrent.futures import ThreadPoolExecutor, as_completed
1010
from datetime import datetime
1111
from pathlib import Path
12+
from collections.abc import Iterable
1213
from typing import Any, cast
1314

1415
import httpx
@@ -1346,14 +1347,20 @@ def watch_task(
13461347
api_url: str,
13471348
task_id: str,
13481349
experiment_id: str | None = None,
1350+
trial_ids: Iterable[str] | None = None,
13491351
) -> dict | None:
13501352
"""Watch a task until completion. Returns the final result.
13511353
13521354
When *experiment_id* is given, only trials belonging to that experiment
13531355
are displayed (others are hidden from the table and summary counts).
1356+
1357+
When *trial_ids* is given, only trials whose ``id`` is in that set are
1358+
shown. This is useful when appending trials to an existing task and the
1359+
caller only wants to monitor the freshly-submitted trials.
13541360
"""
13551361
final_result = None
13561362
headers = get_auth_headers()
1363+
trial_id_filter = set(trial_ids) if trial_ids is not None else None
13571364
with Live(console=console, refresh_per_second=2) as live:
13581365
while True:
13591366
try:
@@ -1368,7 +1375,11 @@ def watch_task(
13681375
final_result = result
13691376

13701377
all_trials = result.get("trials", [])
1371-
if experiment_id:
1378+
if trial_id_filter is not None:
1379+
all_trials = [
1380+
t for t in all_trials if t.get("id") in trial_id_filter
1381+
]
1382+
elif experiment_id:
13721383
all_trials = [
13731384
t for t in all_trials if t.get("experiment_id") == experiment_id
13741385
]
@@ -1450,7 +1461,7 @@ def watch_task(
14501461
live.update(table)
14511462

14521463
# Check if done
1453-
if experiment_id:
1464+
if trial_id_filter is not None or experiment_id:
14541465
terminal = {"success", "failed", "cancelled"}
14551466
if all_trials and all(
14561467
t.get("status") in terminal for t in all_trials

oddish/src/oddish/cli/run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,17 @@ def submit_task(
715715
if not quiet:
716716
console.print("[dim]Watching task progress (Ctrl+C to stop)...[/dim]")
717717
console.print()
718+
# When appending to an existing task, restrict the live view to the
719+
# trials we just submitted so prior trials on the same experiment
720+
# don't clutter the table. For fresh tasks the list is equivalent
721+
# to the full trial set anyway, so passing it is harmless.
722+
new_trial_ids = all_results[0].get("new_trial_ids") or None
718723
try:
719724
final_result = watch_task(
720725
api_url,
721726
all_results[0]["id"],
722727
experiment_id=experiment_id_resolved,
728+
trial_ids=new_trial_ids,
723729
)
724730
# Print final results table
725731
if final_result:

oddish/src/oddish/schemas.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,16 @@ class TaskResponse(BaseModel):
463463
experiment_id: str | None = None
464464
experiment_name: str | None = None
465465
created_at: datetime
466+
new_trial_ids: list[str] = Field(
467+
default_factory=list,
468+
description=(
469+
"IDs of the trials created by this sweep submission. "
470+
"For append-mode submissions, this contains only the newly appended "
471+
"trials (not any pre-existing trials on the task). Clients can use "
472+
"this to filter status/watch views to only the trials they just "
473+
"submitted."
474+
),
475+
)
466476

467477

468478
class TaskBatchCancelRequest(BaseModel):

oddish/src/oddish/server/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,26 +361,26 @@ async def create_task_sweep(submission: TaskSweepSubmission):
361361
if not is_append and hasattr(task, "task_s3_key") and task.task_s3_key:
362362
await session.commit()
363363

364-
provider_counts: Counter[str] = Counter(
365-
t.provider for t in (new_trials if is_append else task.trials)
366-
)
364+
response_trials = new_trials if is_append else list(task.trials)
365+
provider_counts: Counter[str] = Counter(t.provider for t in response_trials)
367366
primary = (
368367
experiment
369368
or (task.experiments[0] if task.experiments else None)
370369
)
371370
resp_experiment_id = primary.id if primary else None
372371
resp_experiment_name = primary.name if primary else None
373-
372+
374373
return TaskResponse(
375374
id=task.id,
376375
name=task.name,
377376
status=task.status,
378377
priority=task.priority,
379-
trials_count=len(new_trials) if is_append else len(task.trials),
378+
trials_count=len(response_trials),
380379
providers=dict(provider_counts),
381380
experiment_id=resp_experiment_id,
382381
experiment_name=resp_experiment_name,
383382
created_at=task.created_at,
383+
new_trial_ids=[t.id for t in response_trials],
384384
)
385385

386386

0 commit comments

Comments
 (0)