{"record":{"id":"dca1888813263a70","repo":"rohitg00/ai-engineering-from-scratch","slug":"n-c-0-and-k-0","errorCode":null,"errorMessage":"n, c >= 0 and k > 0","messagePattern":"n, c >= 0 and k > 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/72-code-exec-metric/code/main.py","lineNumber":255,"sourceCode":"    if exit_code not in EXIT_CODES:\n        exit_code = EXIT_ERROR\n    if exit_code == EXIT_PASS and passed < total:\n        exit_code = EXIT_ASSERTION_FAIL\n    if exit_code == EXIT_ASSERTION_FAIL and passed == total and total > 0:\n        exit_code = EXIT_PASS\n    return ExecResult(score, exit_code, passed, total, detail=detail, per_assertion=results)\n\n\ndef score_code_exec(prediction: str, assertions: list[str], timeout_s: float = DEFAULT_TIMEOUT_S) -> float:\n    code = extract_code(prediction)\n    if code is None:\n        return 0.0\n    return run_candidate(code, assertions, timeout_s=timeout_s).score\n\n\ndef pass_at_k(n: int, c: int, k: int) -> float:\n    if n < 0 or c < 0 or k <= 0:\n        raise ValueError(\"n, c >= 0 and k > 0\")\n    if c > n:\n        raise ValueError(\"c cannot exceed n\")\n    if k > n:\n        return float(c > 0)\n    if n - c < k:\n        return 1.0\n    log_prob = 0.0\n    for i in range(k):\n        log_prob += math.log(n - c - i) - math.log(n - i)\n    return float(1.0 - math.exp(log_prob))\n\n\ndef pass_at_k_estimator(samples: list[list[bool]], ks: list[int]) -> dict[int, float]:\n    out: dict[int, float] = {}\n    for k in ks:\n        per_task = []\n        for sample in samples:\n            n = len(sample)","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/72-code-exec-metric/code/main.py#L237-L273","documentation":"pass_at_k estimates the unbiased probability that at least one of k samples passes given n total completions and c correct ones; the combinatorial ratio 1 - C(n-c,k)/C(n,k) is only defined for n,c >= 0 and k > 0, so out-of-range arguments are rejected before the math runs.","triggerScenarios":"Thrown at phases/19-capstone-projects/72-code-exec-metric/code/main.py:255 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass n >= 0 completions, 0 <= c <= n passes, and k >= 1","Clamp k to at most n before calling","Aggregate per-task (n, c) counts from your sampling loop so values are always consistent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}