Skip to content

v3.1.0 feat: 重构算法复杂度分析体系为多规模采样与经验倍率拟合 - #1

Merged
SummerOneTwo merged 7 commits into
masterfrom
feat/multi-scale-complexity-empirical-fitting
Sep 19, 2026
Merged

SummerOneTwo merged 7 commits into
masterfrom
feat/multi-scale-complexity-empirical-fitting

Conversation

@SummerOneTwo

Copy link
Copy Markdown
Collaborator

变更概述

依据 docs/designs/multi-scale-complexity-empirical-fitting-design.md 与 docs/plans/multi-scale-complexity-empirical-fitting-plan.md,实施对 AutoCode 复杂度与算法分析体系的全面重构。
彻底移除原有的脆弱正则表达式静态分析,建立“大语言模型声明理论复杂度 + 底层工具链多规模物理实测与对数线性倍率拟合”的确定性实证架构。

核心变更

  1. MultiScaleSampler(多规模阶梯数据采样器):

    • 实现自适应 5 点阶梯采样,针对多项式($N_{\max} \ge 1000$)、小规模多项式($N_{\max} < 1000$)与指数级($N_{\max} \le 30$)提供单调递增采样点,杜绝数值倒挂。
    • 支持 testlib 规范命令行调用与模板参数注入,支持多测极端数据分布生成。
  2. DynamicExecutionMonitor(动态执行监控器):

    • 采集纯 CPU 耗时(utime + stime)与物理内存,测量并扣除系统原生启动物理底噪(约 2.1ms)。
    • 完整实现交互题双向匿名管道并发调度,独立采集解法程序纯 CPU 耗时。
    • 完善进程树生命周期管控,支持 Linux 会话隔离与深层进程回收。
  3. EmpiricalRatioAnalyzer(经验倍率拟合分析器):

    • 基于对数线性回归拟合幂指数 $\alpha$ 与判定系数 $R^2$。
    • 引入动态理论期望倍率 $R_{\text{expected}} = f(N_b) / f(N_a)$ 与自适应容差校验。
    • 具备处理器缓存容量跨越保护(Cache Jump Protection),限制在 $N \ge 50000$ 跨越硬件缓存时允许触发。
    • 支持阶乘复杂度 $O(n!)$ 校验;放宽 $O(n)$ 容差下限至 0.35 避免误阻断。
  4. 工具层与质量门禁联动:

    • solution_analyze 与 solution_audit_std 接入 claimed_complexity 归一化解析。
    • problem_audit 将 empirical_complexity 纳入质量信号门禁,未通过时追加阻断提示与修复指引。

测试验证与覆盖结论

  • 针对性测试套件(31/31 全部通过):
    • tests/test_tools/test_empirical_ratio_analyzer.py(10/10 通过)
    • tests/test_tools/test_multi_scale_sampler.py(8/8 通过)
    • tests/test_utils/test_execution_monitor.py(4/4 通过)
    • tests/test_tools/test_solution_audit.py(5/5 通过)
    • tests/test_integration/test_complexity_empirical_e2e.py(4/4 通过)
  • 全量回归测试:
    • uv run pytest tests/ -q:403 passed, 7 skipped in 360.69s,403 个用例全部通过。
  • 静态检查与类型检查:
    • uv run ruff check .:通过(All checks passed)
    • uv run mypy src/:通过(41 个源文件全部通过,零报错)

计划达成度审计(Plan Completion Audit)

  • 任务 1:经验倍率拟合分析器与数学单元测试:DONE
  • 任务 2:自适应多规模阶梯数据采样器与单元测试:DONE
  • 任务 3:纯 CPU 耗时采集与环境底噪扣除监控器:DONE
  • 任务 4:工具层整合与脆弱正则清理:DONE
  • 任务 5:端到端集成测试与小常数二次方算法证伪验证:DONE
  • 任务 6:代码规范与全量回归测试:DONE
  • 达成度:6/6 DONE (100%)

Copilot AI lite review requested due to automatic review settings September 19, 2026 07:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved correctness and safety issues affect complexity defaults, resource enforcement, sampling, and monitoring.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity · 1 Medium severity · 1 Low severity

Open (5)
What changed in this PR

Refactors complexity analysis around multi-scale sampling, execution monitoring, and empirical growth fitting.

Changes:

  • Adds sampling, ratio analysis, and process-monitoring utilities.
  • Integrates empirical verification into solution and problem audits.
  • Adds tests, documentation, release notes, and version metadata.
File Summary
uv.lock Updates locked package metadata.
tests/​test_utils/​test_execution_monitor.py Tests execution monitoring.
tests/​test_tools/​test_solution_audit.py Tests solution-audit integration.
tests/​test_tools/​test_multi_scale_sampler.py Tests multi-scale sampling.
tests/​test_tools/​test_empirical_ratio_analyzer.py Tests empirical fitting.
tests/​test_integration/​test_complexity_empirical_e2e.py Adds end-to-end complexity tests.
src/​autocode_mcp/​utils/​scale_sampler.py Implements scale sampling and generator commands.
src/​autocode_mcp/​utils/​ratio_analyzer.py Implements empirical complexity fitting.
src/​autocode_mcp/​utils/​execution_monitor.py Adds process and resource monitoring.
src/​autocode_mcp/​tools/​solution_audit.py Integrates empirical audit results.
src/​autocode_mcp/​tools/​schemas.py Adds claimed-complexity input.
src/​autocode_mcp/​tools/​complexity.py Integrates empirical verification.
src/​autocode_mcp/​tools/​audit.py Adds empirical audit quality gates.
pyproject.toml Bumps project version.
docs/​plans/​multi-scale-complexity-empirical-fitting-plan.md Documents implementation tasks.
docs/​designs/​multi-scale-complexity-empirical-fitting-design.md Documents the architecture.
CHANGELOG.md Records the release.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/autocode_mcp/tools/complexity.py Outdated
actual_n_max = int(constraints.get("n_max") or 10000)
time_limit_ms = float(constraints.get("time_limit_ms") or 2000.0)

effective_complexity = claimed_complexity or "O(n)"
baseline_overhead_ms: float = 0.0,
) -> dict[str, Any]:
timeout_sec = max(0.1, time_limit_ms / 1000.0)
max_output_bytes = 10 * 1024 * 1024 # 10MB 输出上限,防止管道填满挂起
Comment on lines +70 to +73
if normalized_expr in ("O(2^n)",):
return math.pow(2.0, min(n, 60.0))
if normalized_expr in ("O(n!)",):
return float(math.factorial(min(int(n), 20)))
Comment on lines +63 to +68
generator_exe,
str(seed),
"random",
str(vars_map.get("n_min", n)),
str(n),
str(vars_map.get("t_min", 1)),
# 多规模阶梯数据采样与经验复杂度拟合执行计划

## 一、概述
本计划依据 [docs/designs/multi-scale-complexity-empirical-fitting-design.md](file:///home/cvm-204/AutoCode/docs/designs/multi-scale-complexity-empirical-fitting-design.md),实施对 AutoCode 复杂度与算法分析体系的全面重构。
@SummerOneTwo
SummerOneTwo merged commit 0a57dce into master Sep 19, 2026
7 checks passed
@SummerOneTwo
SummerOneTwo deleted the feat/multi-scale-complexity-empirical-fitting branch September 19, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants