XiaoMaColtAI/math-modeling-skill / dsh-plugin/math-modeling-agent/skills/math-modeling/references/roles/编程手
编程手
Verified数学建模的 Python 或 MATLAB 实现、运行、表格输出、可视化和复现阶段。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.3 KB |
| references/MATLAB规范.md | markdown | 3.4 KB |
| references/工作流程.md | markdown | 9.9 KB |
| references/质检清单.md | markdown | 4.2 KB |
| scripts/apply_publication_style.m | other | 2.2 KB |
| scripts/audit_publication_figure.m | other | 3.4 KB |
| scripts/check_env.py | script | 2.7 KB |
| scripts/check_matlab_env.m | other | 1.3 KB |
| scripts/export_publication_figure.m | other | 1.4 KB |
| scripts/figure_audit.py | script | 7.1 KB |
| scripts/plot_style.py | script | 16.8 KB |
| scripts/repro_manifest.py | script | 4.2 KB |
scripts/repro_manifest.py
View on GitHub#!/usr/bin/env python3
"""生成可复现运行清单,并隔离 SKILL_ROOT 与 PROJECT_ROOT。"""
import argparse
import hashlib
import importlib.metadata
import json
import platform
import sys
from datetime import datetime, timezone
from pathlib import Path
SKILL_ROOT = Path(__file__).resolve().parents[4]
def sha256_file(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as stream:
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def build_manifest(
inputs,
seed,
parameters,
command,
packages,
runtime_name="python",
runtime_version=None,
dependencies=None,
):
files = []
for item in inputs:
path = Path(item).resolve()
if not path.is_file():
raise FileNotFoundError(f"输入文件不存在: {path}")
files.append({"path": str(path), "sha256": sha256_file(path), "bytes": path.stat().st_size})
versions = dict(dependencies or {})
if runtime_name == "python":
for package in packages:
try:
versions[package] = importlib.metadata.version(package)
except importlib.metadata.PackageNotFoundError:
versions[package] = None
runtime_version = runtime_version or sys.version.split()[0]
return {
"schema_version": 1,
"created_at_utc": datetime.now(timezone.utc).isoformat(),
"random_seed": seed,
"input_files": files,
"runtime": {
"name": runtime_name,
"version": runtime_version,
"platform": platform.platform(),
"dependencies": versions,
},
"key_parameters": parameters,
"reproduce_command": command,
}
def _is_within(path: Path, parent: Path) -> bool:
try:
path.relative_to(parent)
return True
except ValueError:
return False
def resolve_output(project_root, relative_output):
project = Path(project_root).resolve()
if _is_within(project, SKILL_ROOT):
raise ValueError("PROJECT_ROOT 不能位于 SKILL_ROOT 内部")
output = (project / relative_output).resolve()
if not _is_within(output, project):
raise ValueError("输出路径必须位于 PROJECT_ROOT 内部")
if _is_within(output, SKILL_ROOT):
raise ValueError("输出路径不能位于 SKILL_ROOT 内部")
return output
def main() -> int:
parser = argparse.ArgumentParser(description="生成数学建模复现清单")
parser.add_argument("--project-root", required=True)
parser.add_argument("--input", action="append", default=[])
parser.add_argument("--seed", required=True, type=int)
parser.add_argument("--parameters", default="{}", help="JSON 对象")
parser.add_argument("--command", required=True)
parser.add_argument("--package", action="append", default=[])
parser.add_argument("--runtime", choices=["python", "matlab"], default="python")
parser.add_argument("--runtime-version")
parser.add_argument("--dependencies", default="{}", help="依赖或 MATLAB 工具箱版本 JSON 对象")
parser.add_argument("--output", default="results/复现清单.json")
parser.add_argument("--overwrite", action="store_true")
args = parser.parse_args()
output = resolve_output(args.project_root, args.output)
if output.exists() and not args.overwrite:
print(f"错误: 输出已存在,未覆盖: {output}", file=sys.stderr)
return 1
parameters = json.loads(args.parameters)
if not isinstance(parameters, dict):
raise ValueError("--parameters 必须是 JSON 对象")
dependencies = json.loads(args.dependencies)
if not isinstance(dependencies, dict):
raise ValueError("--dependencies 必须是 JSON 对象")
manifest = build_manifest(
args.input,
args.seed,
parameters,
args.command,
args.package,
runtime_name=args.runtime,
runtime_version=args.runtime_version,
dependencies=dependencies,
)
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding="utf-8")
print(output)
return 0
if __name__ == "__main__":
raise SystemExit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |