| name | monitor-solver |
| description | 监控求解进度,检查中间结果,估算剩余时间。当用户说'检查进度'、'is it done'、'monitor'、'求解完了吗'时使用。 |
| argument-hint | ["solver-name or log-file"] |
| allowed-tools | Bash(*), Read, Write, Edit, Grep, Glob |
监控求解进度
Monitor: $ARGUMENTS
Workflow
Step 1: 检查运行状态
ps aux | grep -E "python|matlab" | grep -v grep
if [ -f solver_pid.txt ]; then
PID=$(cat solver_pid.txt)
ps -p $PID > /dev/null 2>&1 && echo "Solver running (PID: $PID)" || echo "Solver finished/crashed"
fi
Step 2: 收集日志输出
Check the most recent log files:
ls -lt *.log solve_log.txt *.txt 2>/dev/null | head -10
tail -50 solve_log.txt 2>/dev/null
If no log files found, check for output files in results/ directory.
Step 3: 检查结果文件
ls -lt results/*.{json,csv,xlsx,txt} output/*.{json,csv,xlsx,txt} 2>/dev/null | head -20
If result files exist, read and parse them:
python3 -c "import pandas as pd; df = pd.read_csv('results/latest.csv'); print(df.describe())"
python3 -c "import json; data = json.load(open('results/latest.json')); print(json.dumps(data, indent=2, ensure_ascii=False)[:2000])"
Step 3.5: 提取求解指标
Parse the log file for key solving metrics:
python3 -c "
import re
with open('solve_log.txt') as f:
lines = f.readlines()
# Extract iteration progress
iterations = [l for l in lines if 'iteration' in l.lower() or 'iter' in l.lower()]
if iterations:
print('Latest iteration:', iterations[-1].strip())
# Extract objective function values
objectives = [l for l in lines if 'objective' in l.lower() or 'obj' in l.lower()]
if objectives:
print('Latest objective:', objectives[-1].strip())
# Extract convergence info
convergence = [l for l in lines if 'residual' in l.lower() or 'converge' in l.lower()]
if convergence:
print('Convergence:', convergence[-1].strip())
# Extract timing info
timing = [l for l in lines if 'time' in l.lower() or 'elapsed' in l.lower()]
if timing:
print('Timing:', timing[-1].strip())
"
What to extract:
- 迭代进度 — current iteration / total iterations
- 目标函数值 — is it converging? diverging? oscillating?
- 残差/误差 — convergence indicator
- 已用时间 — elapsed time and estimated remaining
- 求解状态 — running / finished / error?
This gives the /auto-optimize-loop richer signal than just log output — convergence trends, objective evolution, and timing estimates.
Step 4: 结果汇总
Present results in a comparison table:
| 子问题 | 方法 | 关键指标 | 与预期对比 | 状态 |
|--------|------|---------|----------|------|
| 问题1 | 线性规划 | 最优值=X.XX | 符合预期 | done |
| 问题2 | 回归分析 | R²=0.95 | +0.05 vs baseline | done |
Step 5: 解读与建议
- Compare against expected results or baselines
- Flag unexpected results (divergence, NaN, unreasonable values)
- Estimate remaining time if solver is still running
- Suggest next steps based on findings
Step 6: 进度报告
Generate a brief progress report:
=== 求解进度报告 ===
运行状态: [running/completed/error]
已完成子问题: X/Y
当前子问题: [name] (迭代 M/N)
目标函数趋势: [converging/oscillating/diverging]
已用时间: XX min
预估剩余: XX min
Key Rules
- Large file handling: If the Write tool fails due to file size, immediately retry using Bash (
cat << 'EOF' > file) to write in chunks. Do NOT ask the user for permission — just do it silently.
- Always show raw numbers before interpretation
- Compare against the correct baseline or expected values
- Note if solvers are still running (check iteration progress, convergence indicators)
- If results look wrong, check solver logs for errors before concluding
- Estimate remaining time based on iteration speed and total iterations
- If a solver appears stuck (no progress for > 5 minutes), flag it