Skip to main content

rigoreval

当前版本:0.2.0 | Python:3.10+ | 运行时依赖:无(纯标准库) | 类型标注:py.typed | 开源协议:MIT

面向**有界配对评测(bounded, paired evaluations)**的固定检查点统计推断与可复核重放库。
Fixed-checkpoint inference and verifiable replay for bounded, paired evaluations.

在策略对比、AI / Agent 基准测试、仿真与 A/B 评测中,常见的问题是中途反复偷看导致假阳性(p-hacking)、缺块/乱序到达引发口径漂移,以及结果不可脱离原环境复核。rigoreval 将评测流程收敛为清晰的三步闭环:

  1. 开跑前冻结计划与精度预算:预先声明比较族、分层权重、观测值域、实际意义阈值与检查点,反算达到目标半宽所需的样本量;
  2. 执行中乱序收集与缺块定位:支持任意顺序提交完整配对块和幂等重投,仅按连续前缀推进正式检查点,实时指出首个缺块索引;
  3. 结束后跨机校验与无损重放:导出版本化 plan.json + blocks.jsonl 与 SHA-256 摘要,在任意装有 rigoreval 的机器上通过 Python API 或命令行重建完全一致的正式结论。

核心特性

  • 显式 FWER 错误预算:对 M 项比较 × K 个去重检查点统一分配 alpha_look = alpha / (M * K),按 Union Bound 严格控制整个比较族的误覆盖上界。
  • 连续前缀与乱序缓冲:收到块 0, 2 时,要求 2 块的检查点仍等待块 1;超前块保留在缓冲与导出产物中,不越界参与正式推断。
  • 保守外向舍入(抗极端尺度坍缩):内部采用精确有理数(Fraction)做均值与权重线性聚合,在 80 位 Decimal 下计算分层 Hoeffding 半径,并向 IEEE-754 float64 外侧保守舍入,避免极小值域或高量级移位值域坍缩为零宽区间导致误判。
  • 零运行时依赖与完整静态类型:运行时仅依赖 Python 3.10+ 标准库,随包附带 py.typed,通过 mypy --strict 校验。
  • 确定性块级种子派生:seed_for() 基于规范 UTF-8 JSON + SHA-256 生成 64 位无符号整数,跨平台跨进程一致,并隔离试跑与确认阶段命名空间。

安装

从 Gitee 直接安装

python -m pip install git+https://gitee.com/fan-yixu/rigoreval.git

从源码目录安装

git clone https://gitee.com/fan-yixu/rigoreval.git
cd rigoreval
python -m pip install .

从 Release 分发包离线安装

python -m pip install --no-deps rigoreval-0.2.0-py3-none-any.whl

快速开始

1. 运行内置端到端示例

源码仓库和源码分发包均附带纯标准库示例 examples/paired_comparison.py,演示了:精度反算 → 冻结计划 → 同场景共享随机输入 → 乱序提交 → 导出目录 → 独立命令行重放。

python examples/paired_comparison.py --save demo-run
rigoreval replay demo-run
# 也可使用模块入口:
python -m rigoreval replay demo-run

2. Python 最小用法

from rigoreval import ClaimSpec, Evaluation, EvaluationPlan, seed_for

plan = EvaluationPlan(
    claims={
        'candidate-minus-baseline': ClaimSpec(
            weights={'easy': 0.4, 'hard': 0.6},
            bounds=(-1.0, 1.0),
            epsilon=0.05,
        ),
    },
    checkpoints=[{'easy': 32, 'hard': 32}, {'easy': 128, 'hard': 128}],
    alpha=0.05,
)

evaluation = Evaluation(plan)
seed = seed_for(42, 'confirm', 'easy', 0)  # 传给你的评测 worker 以配对共享随机输入
evaluation.add_block('easy', 0, {'candidate-minus-baseline': 0.0})

report = evaluation.report()
assert report.checkpoint is None
assert report.available_prefix == {'easy': 1, 'hard': 0}
assert report.next_checkpoint == 1
assert report.next_missing == {'easy': 1, 'hard': 0}
  • 块身份与原子校验:每个块由 (stratum, index)(从 0 编号)唯一标识,必须一次性提供全部已声明比较项的有限、界内数值;相同内容重投返回 False(幂等),冲突内容或非法输入抛出 ValueError 且整块不入库。
  • 进度与报告字段:
    • sample_counts:当前正式检查点实际使用的各层样本数;
    • available_prefix:各层从 0 开始的连续已收到前缀长度;
    • received_counts:各层已收到的唯一块总数(含缺口之后缓存的乱序块);
    • next_checkpoint / next_missing:下一个检查点编号(从 1 开始)及各层首个缺失块索引;
    • report.to_dict():导出带 schema=1 的纯 JSON 字典。

开跑前估算精度与样本量

在采集确认块之前,可先预览各检查点的未裁剪 Hoeffding 半宽,并按目标半径反算保持分层比例的最小整数倍样本数:

from rigoreval import preview_precision, required_sample_counts

target = 0.14
claim = 'candidate-minus-baseline'

print('当前终检半径:', preview_precision(plan)[2][claim])
final_counts = required_sample_counts(plan, {claim: target})
plan = EvaluationPlan(plan.claims, [*plan.checkpoints[:-1], final_counts], alpha=plan.alpha)
print('调整后终检半径:', preview_precision(plan)[2][claim])

required_sample_counts() 沿用计划当前的每检查点错误预算 alpha_per_look,同时保证放大后的样本数对计划内所有比较项都具有可表示的有限正半径。请务必在采集任何确认块前冻结最终计划;最终判定结果同时取决于区间宽度与实际观测均值。


保存、重放与跨机续跑

from rigoreval import replay_run, write_run

write_run(
    'partial-run',
    evaluation,
    run_id='trial-42',
    evaluator_version='policy-v3',
    root_seed=42,
)

# 在另一进程或另一台机器上校验并恢复
restored = replay_run('partial-run')
assert restored.evaluation.report().to_dict() == evaluation.report().to_dict()

# 查看恢复出的计划与已接收块,补齐剩余块后可导出到新目录
print(restored.plan.checkpoints)
print(restored.evaluation.has_block('easy', 0))
  • 产物结构:write_run() 仅写入新建目录,以临时文件 + fsync + 原子替换依次落盘 plan.json 与 blocks.jsonl,中途失败自动清理脏目录。
  • 完整性校验:blocks.jsonl 首行记录 schema、plan_id、run_id、evaluator_version、root_seed、block_count 和规范化唯一块的 blocks_sha256。replay_run() 会校验语义一致性——拒绝重复检查点、篡改值、跨运行混入、截断或摘要不符(精确报告 文件名:行号),同时允许块记录重排与完全一致的幂等重放。
  • 命令行工具:rigoreval replay <RUN_DIR> 与 python -m rigoreval replay <RUN_DIR> 成功时向 stdout 输出 {"metadata": ..., "report": ...} JSON(退出码 0),校验失败时向 stderr 输出错误详情(退出码 2)。

公开 API 速查

符号 用途
ClaimSpec(weights, bounds, epsilon) 声明单项比较的分层权重(正数且和在 1e-12 内为 1)、观测上下界与实际意义阈值
EvaluationPlan(claims, checkpoints, *, alpha=0.05) 冻结比较族、检查点与错误预算;提供 plan_id、alpha_per_look、to_dict()、from_dict()
Evaluation(plan) 单线程内存收集器;提供 plan、add_block()、has_block()、report()
Report / Estimate 不可变报告快照;提供 Report.to_dict() 导出标准 JSON
seed_for(root_seed, phase, stratum, index, stream='default') 基于 SHA-256 派生可复现的 64 位无符号整数种子
preview_precision(plan) 预览各检查点、各比较项的未裁剪 Hoeffding 半宽
required_sample_counts(plan, target_radii) 保持终检各层比例,反算满足全部目标半宽的最小整数倍样本数
write_run(...) / replay_run(path) 导出与校验重放版本化运行目录,返回 ReplayedRun(metadata, evaluation)(含 .plan)
RunMetadata / ReplayedRun / __version__ 运行元数据契约、重放结果封装与当前包版本号

统计学契约与假设

  1. 事前冻结:所有比较项、分层权重、观测上下界、实际意义阈值 epsilon 与检查点必须在采集确认块前冻结。
  2. 独立性边界:同一比较项中,参与区间计算的各个块在块间与层间必须相互独立;单个配对块内部(候选与基线之间)允许相关,不同比较项可复用同一批块。
  3. 有限族误差控制:若有 M 项比较和 K 个去重后的检查点,每个双侧区间使用 alpha_look = alpha / (M * K)。任何事后新增指标或未声明的额外查看都不在此误差保证范围内。
  4. 区间计算与四态判定:
    • 分层均值估计为各层块均值的归一化加权和,双侧 Hoeffding 半径为 (U - L) * sqrt(ln(2 / alpha_look) * sum(w_s^2 / n_s) / 2),端点向外保守舍入并裁剪至 [L, U];
    • 区间下端严格大于 epsilon → meaningful_increase;
    • 区间上端严格小于 -epsilon → meaningful_decrease;
    • 整个区间落在 [-epsilon, epsilon] 内 → within_tolerance;
    • 其余情况或尚未完成首个检查点 → unresolved(未达首检时状态为 insufficient_coverage)。

测试与发布验收(Windows / Linux / Gitee Go)

运行标准库单元测试

python -m unittest discover -s tests -v

运行完整发布门禁

仓库内置跨平台验收脚本 scripts/verify_release.py,依次执行 ruff check、ruff format --check、mypy --strict、sdist/wheel 隔离构建、twine check、干净虚拟环境 --no-deps 安装、33 项单元测试、示例运行与双 CLI 入口一致性比对:

# 推荐:借助 uv 同时验收 Python 3.10 与 3.12(Windows / Linux 通用)
uv run --python 3.12 scripts/verify_release.py --python 3.10 --python 3.12 --out-dir dist

# 或仅使用当前 Python 3.10+ 环境(需预先安装 build / ruff / mypy / twine>=6.1)
python scripts/verify_release.py --out-dir dist

Gitee Go 云端 Linux 流水线配置位于 .workflow/rigoreval-ci.yml,推送 main 或发起 PR 时自动执行与上述一致的 Linux 双版本验证。


许可证

本项目基于 MIT License 开源(Copyright © 2026 @fanmm01)。

Metadata

Release files for rigoreval 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rigoreval 0.2.0
File Size Uploaded Provenance Actions
rigoreval-0.2.0.tar.gz 34.0 kB Without provenance Details for rigoreval-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rigoreval 0.2.0
File Interpreter ABI Platform Actions
rigoreval-0.2.0-py3-none-any.whl Python 3 none any Details for rigoreval-0.2.0-py3-none-any.whl

Total release size: 53.3 kB

Release files / rigoreval-0.2.0.tar.gz

Download URL rigoreval-0.2.0.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8d8667f70e68acd95cef5df37e981556e487096183f8d1f8dfa9e91f544b7bf3
BLAKE2b-256 checksum
How to use checksums
7301f72f62e31694e94172692e1b51304d0b186ac84265e92a371e1d295d1fda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / rigoreval-0.2.0-py3-none-any.whl

Download URL rigoreval-0.2.0-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95f27e6c9dc95d23f0f99ea325c4cf0eec88cc65f4a0a7d36be24a5207b6e7ca
BLAKE2b-256 checksum
How to use checksums
9b239be61a40b0f5c15f06a94c5fc53edce9ad532b45323a82ec87682421fe7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for rigoreval 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page