Skip to main content

Core data models and I/O for the psforge power system analysis ecosystem. LLM-friendly design for AI-assisted analysis.

Project description

psforge-grid

PyPI version Python versions Tests License: MIT

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 a PSS/E RAW file
system = System.from_raw("ieee14.raw")

# 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 ieee14.raw 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
PSS/E RAW support v33/v34 core sections Varies

Overview

psforge-grid serves as the Hub of the psforge ecosystem, providing:

  • Common data classes (System, Bus, Branch, Generator, Load, Shunt)
  • PSS/E RAW file parser (v33/v34 partial support)
  • 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 processing
  • summary: Compact text for token-efficient LLM usage
  • csv: 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:

Future Plans

  1. Phase 2: Three-winding transformer support
  2. Phase 3: Switched shunt data support
  3. Future: HVDC, FACTS device support (as needed)

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 formatter
  • ms-python.mypy-type-checker - Mypy type checker
  • ms-python.python - Python language support

Related Projects

psforge is a modular power system analysis ecosystem:

Package Description Status
psforge-grid (this) Core data models and I/O (Hub) Active
psforge-flow AC power flow calculation Active
psforge-stability Transient stability analysis Planned
psforge-schedule Unit commitment optimization Planned

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run tests (pytest tests/)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psforge_grid-0.1.1.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psforge_grid-0.1.1-py3-none-any.whl (46.5 kB view details)

Uploaded Python 3

File details

Details for the file psforge_grid-0.1.1.tar.gz.

File metadata

  • Download URL: psforge_grid-0.1.1.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for psforge_grid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8ecdd5febdf20ef972de06b149261f042e6ba2bf9f0cb1123f6b6e94d343a27c
MD5 1987b81e567738f48a18df5aba8844a3
BLAKE2b-256 fa010bf29ef418e59786765f9f33fdf8fb02b600b1ff351fe9186d236abb08b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for psforge_grid-0.1.1.tar.gz:

Publisher: publish.yml on manabelab/psforge-grid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file psforge_grid-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: psforge_grid-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 46.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for psforge_grid-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af59daf774f3a9f0338cbb4dff047040f740b33ca1094258b0d20317e6b75657
MD5 186a2b2b532e0155d24c24b185b6e0eb
BLAKE2b-256 4bd1d8e5d55629cbcbdcfb27f71dba94891fe8deaa6d601cef4368c6321bdae0

See more details on using hashes here.

Provenance

The following attestation bundles were made for psforge_grid-0.1.1-py3-none-any.whl:

Publisher: publish.yml on manabelab/psforge-grid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page