def evaluate_solution(problem_spec, solution_spec):
"""Evaluates a solution submission.
Args:
problem_spec: Specification string of a problem.
solution_spec: Specification string of a solution.
Returns:
(resemblance_int, raw_evaluator_output)
Raises:
VerificationError: If any of the specifications are invalid.
subprocess.TimeoutExpired: On judge timeout.
AssertionError: On scrape error.
"""
with make_temporary_file_with_content(problem_spec) as problem_file, \
make_temporary_file_with_content(solution_spec) as solution_file:
proc = subprocess.Popen(
['./akatsuki', '--logtostderr', '--evaluate',
problem_file.name, solution_file.name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
try:
stdout_output, stderr_output = proc.communicate(
timeout=_JUDGE_TIMEOUT_SECONDS)
except subprocess.TimeoutExpired:
proc.kill()
proc.wait()
raise # report ISE
if proc.returncode:
m = _VERIFICATION_ERROR_RE.search(stdout_output)
assert m, stdout_output # report ISE
raise VerificationError(m.group(1))
m = re.search(r'integer_resemblance: (\d+)', stdout_output)
assert m, stdout_output # report ISE
resemblance_int = int(m.group(1))
return resemblance_int, stdout_output.decode('utf-8')
评论列表
文章目录