testing_plang
genlm.eval.domains.livecodebench_multilingual.vendored.testing_plang
Vendored from Multi-LCB (MIT): the multilingual stdin/stdout code executor.
github.com/Multi-LCB/Multi-LCB @ d80be9f
lcb_runner/evaluation/testing_plang.py (blob 208624d)
Entry point: eval_plang_code(program, input_data, output_data, plang, timeout).
This copy is edited for genlm-eval (not verbatim); each change is marked with a "genlm-eval edit:" comment.
SubprocessConfig
dataclass
TODO: maybe link with yaml files.
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
run(args, timeout_seconds=8, input_data=None, sconf=None)
Runs the given program with arguments. After the timeout elapses, kills the process and all other processes in the process group. Captures at most max_output_size bytes of stdout and stderr each, and discards any output beyond that.
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
check_js_runtime(program)
Check if script must be run using 'deno' runtime environment.
Examples: Deno.stdin Deno.readTextFromStdin Deno.readTextFileSync input = Deno.readAllSync(Deno.stdin) import { readline } from "https://deno.land/std@0.129.0/testing/readline.ts";
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
install_npm_packages(sconf)
Install standard npm packages.
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
eval_script_php(path, input_data, sconf, **kwargs)
Evaluates a PHP script.
:param path: Path to the PHP source file. :type path: Path :param input_data: List of input strings for each test case. :type input_data: List[str] :param timeout_seconds: Timeout for execution in seconds. :type timeout_seconds: int :param bufsizes: List of buffer sizes for each test case. :type bufsizes: List[int | None] :param kwargs: Additional keyword arguments, including 'output_data'. :type kwargs: dict :return: A dictionary containing the status, exit code, stdout, and stderr. :rtype: dict
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
eval_script_scala(path, input_data, sconf, **kwargs)
Evaluates a Scala script by compiling directly with scalac and running with scala.
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
eval_script_kotlin(path, input_data, sconf, **kwargs)
Evaluates a Kotlin script.
:param path: Path to the Kotlin source file. :type path: Path :param input_data: List of input strings for each test case. :type input_data: List[str] :param timeout_seconds: Timeout for execution in seconds. :type timeout_seconds: int :param bufsizes: List of buffer sizes for each test case. :type bufsizes: List[int | None] :param kwargs: Additional keyword arguments, including 'program' and 'output_data'. :type kwargs: dict :raises RuntimeError: If there is an issue during Kotlin compilation or execution. :return: A dictionary containing the status, exit code, stdout, and stderr. :rtype: dict
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
patch_prog(program, plang)
Minor compilation/run errors can be fixed by patching the code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program
|
str
|
code of a program |
required |
plang
|
str
|
name of a programming language |
required |
Returns:
| Type | Description |
|---|---|
str
|
patched program code |
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
eval_plang_code(program, input_data, output_data, plang, timeout, exact_match=False)
Main entry point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program
|
str
|
program code. |
required |
input_data
|
List[str]
|
tests input data in stdin format. Each string is one test. |
required |
output_data
|
List[str]
|
tests output data in stdin format. This list is matched correspondingly to input data. |
required |
plang
|
str
|
name of the programming language ["c++","c#", ...] |
required |
timeout
|
int
|
test timeout |
required |
exact_match
|
bool
|
genlm-eval edit - if True, grade with Agnostics-style whole-output rstrip equality (match_tests_exact) instead of the default lenient comparator. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
EvalScores |
EvalScores
|
list with scores for each test |
ResultMeta |
ResultMeta
|
information on error or other problems during execution |
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
match_tests_groud_truth(code_outputs, input_data, output_data)
Compare code outputs with ground truth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code_outputs
|
List[str]
|
results of code execution, stdout format, one variable for each test |
required |
input_data
|
List[str]
|
tests input data, stdin format, one variable for each test |
required |
output_data
|
List[str]
|
expected tests outputs, stdout format, one variable for each test |
required |
Returns:
| Type | Description |
|---|---|
Tuple[EvalScores, WrongAnswerMeta | SuccessRunMeta]
|
Tuple[EvalScores, WrongAnswerMeta | SuccessRunMeta]: description |
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 | |
match_tests_exact(code_outputs, output_data)
genlm-eval edit: Agnostics-style grading, whole-output rstrip equality per test.
The agnostics-framework executors compare real_output.rstrip() != expected_output.rstrip()
once per test (all must pass). This is stricter than match_tests_groud_truth: no per-line
split, no True/False aliasing, no float tolerance. Used for Agnostics parity. code_outputs
are already whitespace-stripped by compile_and_run, so a leading-whitespace difference
(which agnostics would keep) is not distinguished here.
Source code in genlm/eval/domains/livecodebench_multilingual/vendored/testing_plang.py
prepare_plang_env(plang, timeout=None)
Some languages might fail to compile and run if your system is not prepared properly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plang
|
str
|
name of a programming language. |
required |
timeout
|
int
|
value of the timeout that will be passed to process. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |