Core data models and I/O for the psforge power system analysis ecosystem. LLM-friendly design for AI-assisted analysis.
Project description
psforge-grid
Hub data model for the psforge power system analysis ecosystem
Core data models and I/O for power system analysis with LLM-friendly design.
Quick Start
pip install psforge-grid
from psforge_grid import System
# Load from PSS/E RAW format
system = System.from_raw("ieee14.raw")
# Load from MATPOWER format (pglib-opf compatible)
system = System.from_matpower("pglib_opf_case14_ieee.m")
# Load from CPAT formats (IEEJ standard models)
system = System.from_pop("WEST10peak.pop") # CPAT-GUI project file (ZIP/XML)
system = System.from_dyna("model.dyna") # CPAT Fortran card format
# Auto-detect format by file extension
system = System.from_file("case14.m")
# Explore the system
print(f"Buses: {len(system.buses)}, Branches: {len(system.branches)}")
# Get LLM-friendly summary
print(system.to_summary())
# Or use the CLI
psforge-grid info ieee14.raw
psforge-grid show pglib_opf_case14_ieee.m buses -f json
Why psforge-grid?
| Feature | psforge-grid | Others |
|---|---|---|
| LLM-friendly output | Built-in JSON/summary formats | Manual formatting |
| Educational design | Rich docstrings, clear naming | Varies |
| Type hints | Complete type annotations | Often missing |
| CLI included | Yes, with multiple output formats | Usually separate |
| Multi-format I/O | PSS/E RAW, MATPOWER, CPAT (.pop/.dyna) | Usually single format |
Overview
psforge-grid serves as the Hub of the psforge ecosystem, providing:
- Common data classes (
System,Bus,Branch,Generator,GeneratorCost,Load,Shunt) - PSS/E RAW file parser (v33/v34 partial support)
- MATPOWER .m file parser (pglib-opf compatible)
- CPAT .pop file parser (CPAT-GUI ZIP/XML project format)
- CPAT dyna card format parser (Fortran fixed-column format)
- OPF data support (
GeneratorCostwith polynomial and piecewise-linear cost models) - Zero-sequence impedance data (
Branch.r0_pu,x0_pu,b0_pu) for fault analysis - Generator machine parameters (
Generator.xd_pu,xdp_pu,xdpp_pu, etc.) for fault/stability analysis - Shared utilities for power system analysis
LLM Affinity Design
"Pickaxe in the Gold Rush" - psforge is designed for seamless LLM integration.
psforge-grid implements LLM-friendly data structures and CLI:
| Feature | Description |
|---|---|
| Explicit Units | Field names include units (voltage_pu, power_mw) |
| Semantic Status | Enum-based status annotations (VoltageStatus.LOW) |
| Self-Documenting | Rich docstrings explaining physical meaning |
| to_description() | Human/LLM-readable output methods |
# Example: LLM-friendly bus description
bus = system.get_bus(14)
print(bus.to_description())
# Output: "Bus 14 (LOAD_BUS): 13.8 kV, PQ type"
CLI for LLM Integration
psforge-grid includes a CLI designed for LLM-friendly output:
# System summary in different formats
psforge-grid info ieee14.raw # Table format
psforge-grid info ieee14.raw -f json # JSON for API/LLM
psforge-grid info ieee14.raw -f summary # Compact for tokens
# Display element details
psforge-grid show ieee14.raw buses
psforge-grid show ieee14.raw branches -f json
# Validate system data
psforge-grid validate ieee14.raw
psforge-grid validate ieee14.raw --strict
Output Formats:
table: Human-readable tables (default)json: Structured JSON for LLM/API processingsummary: Compact text for token-efficient LLM usagecsv: Comma-separated values for data analysis
See CLAUDE.md for detailed AI development guidelines.
PSS/E RAW Format Support
Current Status
The parser supports core power flow data required for basic AC power flow analysis:
| Section | v33 | v34 | Notes |
|---|---|---|---|
| Case Identification | Yes | Yes | Base MVA, system info |
| Bus Data | Yes | Yes | All bus types (PQ, PV, Slack, Isolated) |
| Load Data | Yes | Yes | Constant power loads |
| Fixed Shunt Data | Yes | Yes | Capacitors and reactors |
| Generator Data | Yes | Yes | P, Q, voltage setpoint, Q limits |
| Branch Data | Yes | Yes | Transmission lines |
| Transformer Data | Yes | Yes | Two-winding transformers only |
Not Yet Supported
The following sections are parsed but ignored (data is skipped):
- Area Data, Zone Data, Owner Data
- Two-Terminal DC Data, Multi-Terminal DC Data
- VSC DC Line Data, FACTS Device Data
- Switched Shunt Data (use Fixed Shunt instead)
- Multi-Section Line Data, Impedance Correction Data
- GNE Data, Induction Machine Data, Substation Data
- Three-winding Transformers
Test Data Sources
Parser has been validated with IEEE test cases from multiple sources:
- IEEE 9-bus (v34): GitHub - todstewart1001
- IEEE 14-bus (v33): GitHub - ITI/models
- IEEE 118-bus (v33): GitHub - powsybl
Future Plans
- Three-winding transformer support
- Switched shunt data support
- HVDC, FACTS device support (as needed)
MATPOWER Format Support
psforge-grid supports MATPOWER .m files, enabling direct use of pglib-opf benchmark cases.
Supported Sections
| Section | Status | Notes |
|---|---|---|
| Bus Data (13 columns) | Yes | All bus types, Vmin/Vmax for OPF |
| Generator Data (10 columns) | Yes | Pmin/Pmax, Qmin/Qmax |
| Branch Data (13 columns) | Yes | Including angmin/angmax for OPF |
| Generator Cost Data | Yes | Polynomial (model=2) and piecewise-linear (model=1) |
| baseMVA | Yes | System base MVA |
Generator Cost Functions
from psforge_grid import System
system = System.from_matpower("pglib_opf_case14_ieee.m")
# Access generator cost data (for OPF)
for cost in system.generator_costs:
print(cost.to_description())
# "Generator Cost (polynomial, degree 2): 0.0430 * P^2 + 20.00 * P + 0.00"
# Evaluate cost at a given power output
cost_value = cost.evaluate(p_mw=50.0) # $/hr
CPAT Format Support
psforge-grid supports two CPAT (Computer Program for Analysis of Power Transmission) input formats, enabling direct use of IEEJ standard model systems.
.pop Format (Recommended)
The .pop format is the native project file format of CPAT-GUI. It is a ZIP archive containing XML data files.
from psforge_grid import System
# Load from .pop file (CPAT-GUI project)
system = System.from_pop("WEST10peak.pop")
| Feature | Status | Notes |
|---|---|---|
| System data (pnsd) | Yes | Nodes, branches, generators, loads |
| Generator machine data | Yes | G1-G5 card fields (Xd, Xd', Xd'', etc.) |
| Zero-sequence data | Yes | Branch and generator zero-sequence impedances |
| GUI drawing data (pnsw) | No | Drawing layout is ignored |
.dyna Card Format
The .dyna format is the legacy Fortran fixed-column (80-character) card format used by CPAT's text-based interface.
from psforge_grid import System
# Load from dyna card format
system = System.from_dyna("model.dyna")
| Card Type | Description | Status |
|---|---|---|
| DATA | System name, base MVA, frequency | Yes |
| T card | Transmission lines (positive & zero sequence) | Yes |
| X card | Transformers (tap ratio, impedance) | Yes |
| N card | Nodes (voltage, generation, load) | Yes |
| G1-G5 | Generator machine parameters | Yes |
CPAT Test Data
Parser validation uses IEEJ standard model systems:
| Fixture | Description | Buses | Branches | Generators |
|---|---|---|---|---|
WEST10peak.pop |
IEEJ WEST 10-machine peak model | 27 | 35 | 10 |
cpat_model11.dyna |
CPAT Manual p.26 model system | 10 | 14 | 4 |
Installation
# Install the package
pip install psforge-grid
# Or install from source
pip install -e .
Development Setup
Prerequisites
- Python 3.9+
- uv (recommended) or pip
Install Development Dependencies
# Using uv (recommended)
uv pip install -e ".[dev]"
# Or using pip
pip install -e ".[dev]"
Setup Pre-commit Hooks
Pre-commit hooks automatically run ruff and mypy checks before each commit.
Option 1: Global Install with pipx (Recommended)
Using pipx for global installation is recommended, especially when using git worktree for parallel development. This ensures pre-commit is available across all worktrees without additional setup.
# Install pipx if not already installed
brew install pipx # macOS
# or: pip install --user pipx
# Install pre-commit globally
pipx install pre-commit
# Install hooks (only needed once per repository)
pre-commit install
# Run hooks manually on all files
pre-commit run --all-files
Why pipx?
- Works across all git worktrees without per-worktree setup
- Isolated environment prevents dependency conflicts
- Single installation, works everywhere
Option 2: Local Install in Virtual Environment
# Install pre-commit in your virtual environment
pip install pre-commit
# Install hooks
pre-commit install
# Run hooks manually on all files
pre-commit run --all-files
Note: CI runs ruff and mypy checks via GitHub Actions (
.github/workflows/test.yml), so code quality is enforced on push/PR even if local hooks are skipped.
Manual Code Quality Checks
# Lint with ruff
ruff check src/ tests/
# Format with ruff
ruff format src/ tests/
# Type check with mypy
mypy src/
Run Tests
pytest tests/ -v
Editor Setup (VSCode/Cursor)
This project includes .vscode/ configuration for seamless development:
- Format on Save: Automatically formats code with ruff
- Organize Imports: Automatically sorts imports
- Type Checking: Mypy extension provides real-time type checking
Recommended Extensions:
charliermarsh.ruff- Ruff linter and formatterms-python.mypy-type-checker- Mypy type checkerms-python.python- Python language support
psforge Ecosystem (Hub & Spoke Architecture)
psforge is a modular power system analysis ecosystem built on a Hub & Spoke architecture. psforge-grid is the Hub — all Spoke packages depend on it for common data models and I/O.
┌──────────────────────┐
│ psforge-grid │
│ (Hub: Data & I/O) │
└──────────┬───────────┘
│
┌─────────────┬───────────┼───────────┬─────────────┐
│ │ │ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼─────┐ ┌───▼────┐ ┌────▼────┐
│ psforge │ │ psforge │ │ psforge- │ │psforge-│ │ psforge │
│ -flow │ │ -fault │ │stability │ │schedule│ │ -turbo │
│ (Power │ │ (Fault │ │(Transient│ │ (Unit │ │ (C++ │
│ Flow) │ │Analysis)│ │Stability)│ │Commit.)│ │ Engine) │
└─────────┘ └─────────┘ └──────────┘ └────────┘ └─────────┘
| Package | PyPI Name | Description | Status |
|---|---|---|---|
| psforge-grid (this) | psforge-grid |
Core data models, parsers (RAW, MATPOWER), and CLI | Active |
| psforge-flow | psforge-flow |
AC power flow (Newton-Raphson) and optimal power flow | Active |
| psforge-fault | psforge-fault |
Short-circuit fault analysis (symmetrical components) | Active |
| psforge-stability | psforge-stability |
Transient stability analysis (DAE solver) | Planned |
| psforge-schedule | psforge-schedule |
Unit commitment optimization (HiGHS/Gurobi) | Planned |
| psforge-turbo | psforge-turbo |
High-performance C++ engine (Phase 2) | Frozen |
All packages are developed and maintained by Manabe Lab LLC.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
pytest tests/) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
See CLAUDE.md for AI development guidelines.
License
MIT License - see LICENSE for details.
Developed by Manabe Lab LLC
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file psforge_grid-0.4.0.tar.gz.
File metadata
- Download URL: psforge_grid-0.4.0.tar.gz
- Upload date:
- Size: 85.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d6d8e0209ad1bbd7f057c7f38022bc246299dfaa976ba04b5d9e73ee06e67ac
|
|
| MD5 |
5a0ab3ebca3e6563cefb2d2f842ddde5
|
|
| BLAKE2b-256 |
f618d58b7c35274c0d9dab4c8bd67a3a1d82ac57ff81bb8a48b821760d32ba1a
|
Provenance
The following attestation bundles were made for psforge_grid-0.4.0.tar.gz:
Publisher:
publish.yml on manabelab/psforge-grid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psforge_grid-0.4.0.tar.gz -
Subject digest:
0d6d8e0209ad1bbd7f057c7f38022bc246299dfaa976ba04b5d9e73ee06e67ac - Sigstore transparency entry: 1091178542
- Sigstore integration time:
-
Permalink:
manabelab/psforge-grid@f62546a419ab27d5b409277173e7cfa2339d1602 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/manabelab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f62546a419ab27d5b409277173e7cfa2339d1602 -
Trigger Event:
release
-
Statement type:
File details
Details for the file psforge_grid-0.4.0-py3-none-any.whl.
File metadata
- Download URL: psforge_grid-0.4.0-py3-none-any.whl
- Upload date:
- Size: 80.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ef1a89882b870ab1bc9b8432ffba56d68660ce0eb49decef2ccb86749c5de8d
|
|
| MD5 |
337c1a8ed90e2dfeda91e23d7f5efa7d
|
|
| BLAKE2b-256 |
ccb329eb925d04a964528a0aac462fa4449b7eda2b99ff240c5c95af426846c2
|
Provenance
The following attestation bundles were made for psforge_grid-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on manabelab/psforge-grid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psforge_grid-0.4.0-py3-none-any.whl -
Subject digest:
6ef1a89882b870ab1bc9b8432ffba56d68660ce0eb49decef2ccb86749c5de8d - Sigstore transparency entry: 1091178545
- Sigstore integration time:
-
Permalink:
manabelab/psforge-grid@f62546a419ab27d5b409277173e7cfa2339d1602 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/manabelab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f62546a419ab27d5b409277173e7cfa2339d1602 -
Trigger Event:
release
-
Statement type: