power-market-tutor
README.md
# Power Market Tutor (`power-market-tutor`)
An interactive **Electricity Market Clearing & Settlement Sandbox** built for AI-assisted learning. It provides a zero-dependency **MCP Server**, a **Python CLI / library**, and a portable **Agent Skill** compatible with **Qoder**, **Antigravity**, **Claude Code**, and **Cursor**.
电力市场交互式学习沙盒与 AI 助教工具包:内置确定性的 **统一边际出清(SMP)**、**2 节点 / 3 节点直流潮流与节点边际电价(LMP & PTDF 阻塞分析)** 以及 **国内电力现货市场“中长期差价合约(CfD)+ 日前 + 实时”偏差结算** 计算引擎,彻底消除大模型在电价出清与电费结算推导中的算术幻觉。
---
## Features / 核心功能
- **Uniform Marginal Clearing (`simulate_smp_clearing`)**: Merit-order dispatch stack, marginal unit identification, inframarginal generator rent, and comparison with Pay-as-Bid.
- **2-Bus Radial LMP (`simulate_two_bus_lmp`)**: Exact decomposition of $\text{LMP} = \text{LMP}_{\text{energy}} + \text{LMP}_{\text{congestion}}$, shadow prices, and Congestion Rent ($\text{Rent} = \Delta \text{LMP} \times F_{AB}$).
- **3-Bus Kirchhoff Loop LMP (`simulate_three_bus_loop_lmp`)**: Power Transfer Distribution Factor (`PTDF`) loop-flow model demonstrating why nodal prices can counter-intuitively exceed the highest generator bid in the system.
- **Chinese Spot Market CfD Dual/Triple Settlement (`calculate_cfd_spot_settlement`)**: Full breakdown of Mid-to-Long-Term contract settlement + Day-Ahead deviation + Real-Time deviation, alongside dispatch incentive analysis.
- **Portable Agent Skill (`skills/electricity-market-tutor/SKILL.md`)**: Drop-in domain tutor prompt rules ensuring AI assistants distinguish PJM/ISO theory from Chinese provincial spot market rules.
---
## Quick Start / 快速上手
### 1. Install Locally
```bash
pip install -e .
```
### 2. Run Benchmark CLI Cases
```bash
# 1) 5-generator Merit-Order SMP Clearing
pmt smp --demand 420
# 2) 2-Bus Radial Congestion & LMP
pmt lmp2 --load 300 --limit 120
# 3) 3-Bus Kirchhoff Loop Flow (Counter-Intuitive High LMP!)
pmt lmp3 --load 300 --limit 120
# 4) CfD + Spot Dual Settlement
pmt settle --qc 300 --pc 380 --qs 200 --ps 150 --cost 300
```
### 3. Configure MCP Server (Qoder / Claude / Cursor / Antigravity)
Add to your IDE's MCP configuration JSON:
```json
{
"mcpServers": {
"power-market-tutor": {
"command": "python",
"args": ["-m", "power_market_tutor.mcp_server"]
}
}
}
```
### 4. Run Tests
```bash
python -m unittest discover -s tests -v
```
---
## License
MIT © cyc-dacaigouzi
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues