Skip to content
Merged
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
6 changes: 1 addition & 5 deletions pisek/cms/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,11 @@ def create_dataset(

files = FileCacher()

outputs_needed = (
config.task.task_type == TaskType.batch and config.tests.judge_needs_out
)

for input_ in testcases:
name = input_.name.removesuffix(".in")
output: TaskPath | None = None

if outputs_needed:
if config.judge_needs_out:
output = input_.to_output()

if not path.exists(output.path):
Expand Down
35 changes: 28 additions & 7 deletions pisek/config/task_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ def test_nums(self) -> list[int]:
def input_globs(self) -> list[str]:
return sum((sub.all_globs for sub in self.test_sections.values()), start=[])

@computed_field # type: ignore[misc]
@cached_property
def judge_needs_in(self) -> bool:
if self.task.task_type == TaskType.interactive:
return True
elif self.tests.out_check == OutCheck.judge:
return self.tests.raw_judge_needs_in
else:
return False

@computed_field # type: ignore[misc]
@cached_property
def judge_needs_out(self) -> bool:
if self.task.task_type == TaskType.interactive:
return False
elif self.tests.out_check == OutCheck.judge:
return self.tests.raw_judge_needs_out
else:
return True

@computed_field # type: ignore[misc]
@property
def primary_solution(self) -> str:
Expand Down Expand Up @@ -368,8 +388,8 @@ class TestsSection(BaseEnv):
out_check: OutCheck
out_judge: Maybe["RunSection"]
judge_type: Maybe[JudgeType]
judge_needs_in: bool | None
judge_needs_out: bool | None
raw_judge_needs_in: bool
raw_judge_needs_out: bool
tokens_ignore_newlines: bool | None
tokens_ignore_case: bool | None
tokens_float_rel_error: Maybe[Decimal]
Expand Down Expand Up @@ -409,8 +429,8 @@ def load_dict(task_type: str, configs: ConfigHierarchy) -> ConfigValuesDict:
OUT_CHECK_SPECIFIC_KEYS = [
((None, "judge"), "out_judge", ""),
((None, "judge"), "judge_type", ""),
((TaskType.batch, "judge"), "judge_needs_in", "0"),
((TaskType.batch, "judge"), "judge_needs_out", "1"),
((TaskType.batch, "judge"), "raw_judge_needs_in", "0"),
((TaskType.batch, "judge"), "raw_judge_needs_out", "1"),
((None, "tokens"), "tokens_ignore_newlines", "0"),
((None, "tokens"), "tokens_ignore_case", "0"),
((None, "tokens"), "tokens_float_rel_error", ""),
Expand All @@ -431,13 +451,14 @@ def load_dict(task_type: str, configs: ConfigHierarchy) -> ConfigValuesDict:
)

# Load judge specific keys
for (task_type_cond, out_check), key, default in OUT_CHECK_SPECIFIC_KEYS:
for (task_type_cond, out_check), python_key, default in OUT_CHECK_SPECIFIC_KEYS:
key = python_key.removeprefix("raw_")
if (task_type_cond is None or task_type_cond == task_type) and args[
"out_check"
].value == out_check:
args[key] = configs.get("tests", key)
args[python_key] = configs.get("tests", key)
else:
args[key] = ConfigValue.make_internal(default, "tests", key)
args[python_key] = ConfigValue.make_internal(default, "tests", key)

return {"_section": configs.get("tests", None), **args}

Expand Down
2 changes: 1 addition & 1 deletion pisek/env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def load(
else:
assert_never(target)

if expanded_solutions and config.tests.judge_needs_out:
if expanded_solutions and config.judge_needs_out:
if config.primary_solution in expanded_solutions:
expanded_solutions.remove(config.primary_solution)
expanded_solutions.insert(0, config.primary_solution)
Expand Down
2 changes: 1 addition & 1 deletion pisek/jobs/task_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _get_named_pipeline(self, env: Env) -> list[tuple[JobManager, str]]:
else:
# First solution generates inputs
assert (
not env.config.tests.judge_needs_out
not env.config.judge_needs_out
or env.solutions[0] == env.config.primary_solution
)

Expand Down
8 changes: 4 additions & 4 deletions pisek/opendata/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ def gen_output(self, clear: bool = True) -> None:
self._run_pipeline(output_needed=True, clear=clear)

def check(self, contestant_output_path: str, clear: bool = True) -> OpendataVerdict:
assert self._built_task._config.tests.judge_needs_in is not None
assert self._built_task._config.tests.judge_needs_out is not None
assert self._built_task._config.judge_needs_in is not None
assert self._built_task._config.judge_needs_out is not None

res = self._run_pipeline(
input_needed=self._built_task._config.tests.judge_needs_in,
output_needed=self._built_task._config.tests.judge_needs_out,
input_needed=self._built_task._config.judge_needs_in,
output_needed=self._built_task._config.judge_needs_out,
check=True,
contestant_output=contestant_output_path,
clear=clear,
Expand Down
8 changes: 4 additions & 4 deletions pisek/task_jobs/checker/cms_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def _check(self) -> SolutionResult:
config = self._env.config

self._access_file(self.output)
if config.tests.judge_needs_in:
if config.judge_needs_in:
self._access_file(self.input)
if config.tests.judge_needs_out:
if config.judge_needs_out:
self._access_file(self.correct_output)

self.checker_rr = self._run_program(
Expand All @@ -135,12 +135,12 @@ def _check(self) -> SolutionResult:
args=[
(
self.input.abspath
if config.tests.judge_needs_in
if config.judge_needs_in
else RunCMSBatchJudge._invalid_path("input")
),
(
self.correct_output.abspath
if config.tests.judge_needs_out
if config.judge_needs_out
else RunCMSBatchJudge._invalid_path("output")
),
self.output.abspath,
Expand Down
4 changes: 2 additions & 2 deletions pisek/task_jobs/checker/opendata_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ def _load_stderr(self) -> tuple[str, dict[str, Any]]:

def _check(self) -> SolutionResult:
envs = {}
if self._env.config.tests.judge_needs_in:
if self._env.config.judge_needs_in:
envs["TEST_INPUT"] = self.input.abspath
self._access_file(self.input)
if self._env.config.tests.judge_needs_out:
if self._env.config.judge_needs_out:
envs["TEST_OUTPUT"] = self.correct_output.abspath
self._access_file(self.correct_output)

Expand Down
6 changes: 2 additions & 4 deletions pisek/task_jobs/solution/solution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _add_solution_jobs(
if isinstance(sanitize, SanitizeAbstract):
run_checker.add_prerequisite(sanitize, "sanitize")

if self._env.config.tests.judge_needs_out:
if self._env.config.judge_needs_out:
self._add_job(
SymlinkData(
self._env,
Expand Down Expand Up @@ -204,9 +204,7 @@ def _create_batch_jobs(
self._env,
seed,
solution=(
self.solution_label
if self._env.config.tests.judge_needs_out
else None
self.solution_label if self._env.config.judge_needs_out else None
),
),
test,
Expand Down
Loading