# Monitor Solver

> 监控求解进度，检查中间结果，估算剩余时间。当用户说'检查进度'、'is it done'、'monitor'、'求解完了吗'时使用。

- Skill: `best6668/monitor-solver` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add best6668/monitor-solver`
- Raw SKILL.md: https://api.skillmd.com/api/skills/best6668/monitor-solver/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: best6668 (https://skillmd.com/u/best6668)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/best6668/monitor-solver

---


# 监控求解进度

Monitor: $ARGUMENTS

## Workflow

### Step 1: 检查运行状态
```bash
# Check for running solver processes
ps aux | grep -E "python|matlab" | grep -v grep

# Check if PID file exists
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:
```bash
# Find recent log files
ls -lt *.log solve_log.txt *.txt 2>/dev/null | head -10

# Show last 50 lines of the most recent log
tail -50 solve_log.txt 2>/dev/null
```

If no log files found, check for output files in results/ directory.

### Step 3: 检查结果文件
```bash
# Check for result files
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:
```bash
# For CSV results
python3 -c "import pandas as pd; df = pd.read_csv('results/latest.csv'); print(df.describe())"

# For JSON results
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:

```bash
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

