Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/ui_tests/test_judge_other_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
import unittest
from contextlib import ExitStack
from dataclasses import replace
from pathlib import Path
from unittest.mock import patch

Expand Down Expand Up @@ -63,6 +64,19 @@ def test_each_compare_column_reads_its_own_workspace(self):
view = web.compare._comparison_requested()
self.assertEqual([web.judge.ws_dir(s.workspace) for s in view.selected], [self.a.dir, self.b.dir])

def test_a_folded_run_s_side_reads_and_keeps_its_own_shard_s_record(self):
jx, jy = workspace.load_jobs(self.a, self.a.roots)[0], workspace.load_jobs(self.b, self.b.roots)[0]
fold = replace(jx, trials=jx.trials + jy.trials) # as launches.fold makes it: the first shard's
t = replace(next(t for t in jy.trials if t.trial_name == TRIAL), has_trajectory=True)
rec = {"questions": Q.VERSION, "answers": {web.judge.SIDE_QUESTION: {"score": 1}}, "judge": {"model": "m"}}
store.save(self.b.dir, "job-y", TRIAL, dict(rec), started=web.judge.started_of(t))
self.assertIsNotNone(web.judge.side_of(fold, t, self.b.dir), "the trial page's record is not read")
with patch.object(web.judge.trajectory, "load", return_value=unittest.mock.Mock(error=None)), \
patch.object(web.judge, "_states_for", return_value={}), patch.object(web.judge.batch, "ask_states", return_value=dict(rec)), \
patch.object(web.judge, "side_ids", return_value=["more"]): # one question still to ask
web.judge.judge_side(fold, t, self.b.dir, None)
self.assertIsNone(store.load(self.b.dir, "job-x", TRIAL), "saved under the first shard's job")

def test_a_job_of_the_open_workspace_keeps_its_store(self):
with web.app.test_request_context(f"/trial/job-x/{TRIAL}"):
self.assertEqual(web.judge.ws_dir(), self.a.dir)
Expand Down
7 changes: 4 additions & 3 deletions app/web/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ def side_of(job, trial, d) -> dict | None:
"""One side's score as the compare page shows it, from the trial's own
current record in its column's store `d`: the expectation, the level it rounds to, the judge's
confidence, the provenance. None until scored under the current vocabulary."""
rec = store.load(d, job.job_id, trial.trial_name, started=started_of(trial)) if d else None
# trial.job_id, not job's: a run folded from its shards (`launches.fold`) is its first shard's job
rec = store.load(d, trial.job_id, trial.trial_name, started=started_of(trial)) if d else None
if not rec or not store.is_current(rec):
return None
a = (rec.get("answers") or {}).get(SIDE_QUESTION)
Expand Down Expand Up @@ -450,15 +451,15 @@ def judge_side(job, trial, d, api_key: str, post=None, calibration=None) -> dict
when it has them all."""
if not trial.has_trajectory:
raise client.JudgeError(0, "this trial has no trajectory to judge")
rec = store.load(d, job.job_id, trial.trial_name, started=started_of(trial))
rec = store.load(d, trial.job_id, trial.trial_name, started=started_of(trial)) # its shard's, as in side_of
have = (rec.get("answers") or {}) if store.is_current(rec) else {}
ids = [q for q in side_ids(trial) if q not in have]
if not ids:
return rec
traj = trajectory.load(trial.trajectory_path)
if traj.error:
raise client.JudgeError(0, "the trajectory could not be read: " + traj.error)
return batch.ask_and_store(d, job.job_id, trial.trial_name, _states_for(trial, traj, ids), api_key, post=post,
return batch.ask_and_store(d, trial.job_id, trial.trial_name, _states_for(trial, traj, ids), api_key, post=post,
calibration=calibration, started=started_of(trial))


Expand Down