asayghe1/GridFM

A Physics-Informed Foundation Model for Multi-Task Energy Forecasting

Python

2

3 commits

updated Jan 7, 2026

See the code

README

GridFM: A Physics-Informed Foundation Model for Multi-Task Energy Forecasting

Python 3.9+ PyTorch 2.0+ License: MIT arXiv

GridFM Architecture

GridFM is a physics-informed foundation model designed for multi-task energy forecasting using real-time data from Independent System Operators (ISOs). It combines pre-trained time series foundation models with domain-specific adaptations that respect power system physics.

🌟 Key Features

  • FreqMixer Adaptation Layer: Novel frequency-domain mixing mechanism that transforms general-purpose foundation model representations into power-grid-specific patterns
  • Physics-Informed Constraints: Integration of power balance equations and DC power flow approximations
  • Multi-Task Learning: Simultaneous forecasting of load, prices, emissions, and renewable generation
  • Graph Neural Networks: Zonal topology encoding via GCN for spatial dependencies
  • Explainability: SHAP-based feature attribution and attention visualization

πŸ“Š Performance

GridFM achieves state-of-the-art performance on NYISO, PJM, and CAISO datasets:

TaskMAPEImprovement vs. Fine-tuned Baseline
Load Forecasting2.14% Β± 0.05%10.1%
Price Forecasting7.80% Β± 0.31%15.9%
Emission Prediction4.73% Β± 0.18%14.3%
Renewable Generation8.92% Β± 0.42%12.7%

πŸš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/GridFM/GridFM.git
cd GridFM

# Create conda environment
conda create -n gridfm python=3.10
conda activate gridfm

# Install dependencies
pip install -r requirements.txt

# Install GridFM
pip install -e .

Basic Usage

from gridfm import GridFM
from gridfm.data import NYISODataLoader

# Load pre-trained model
model = GridFM.from_pretrained("gridfm-base-nyiso")

# Load data
dataloader = NYISODataLoader(
    start_date="2023-01-01",
    end_date="2023-12-31",
    zones=["WEST", "CENTRL", "NORTH"]
)

# Generate forecasts
forecasts = model.predict(
    dataloader,
    horizon=24,  # 24 steps ahead (2 hours at 5-min resolution)
    tasks=["load", "lbmp", "emissions"]
)

# Access results
print(f"Load MAPE: {forecasts.metrics['load_mape']:.2f}%")

Training from Scratch

from gridfm import GridFM, GridFMConfig
from gridfm.training import Trainer

# Configure model
config = GridFMConfig(
    backbone="moirai-moe-base",
    num_zones=11,
    hidden_dim=256,
    num_freq_components=64,
    physics_weight=0.1,
    coupling_weight=0.05
)

# Initialize model
model = GridFM(config)

# Train
trainer = Trainer(
    model=model,
    train_dataloader=train_loader,
    val_dataloader=val_loader,
    learning_rate=1e-4,
    num_epochs=100
)
trainer.train()

πŸ“ Repository Structure

GridFM/
β”œβ”€β”€ gridfm/                    # Main package
β”‚   β”œβ”€β”€ models/               # Model architectures
β”‚   β”‚   β”œβ”€β”€ gridfm.py        # Main GridFM model
β”‚   β”‚   β”œβ”€β”€ backbone.py      # Foundation model backbone
β”‚   β”‚   └── task_heads.py    # Task-specific output heads
β”‚   β”œβ”€β”€ layers/              # Custom layers
β”‚   β”‚   β”œβ”€β”€ freqmixer.py     # FreqMixer adaptation layer
β”‚   β”‚   β”œβ”€β”€ gcn.py           # Graph convolutional network
β”‚   β”‚   └── attention.py     # Attention mechanisms
β”‚   β”œβ”€β”€ physics/             # Physics constraints
β”‚   β”‚   β”œβ”€β”€ power_balance.py # Power balance equations
β”‚   β”‚   └── dc_power_flow.py # DC power flow approximation
β”‚   β”œβ”€β”€ data/                # Data loading utilities
β”‚   β”‚   β”œβ”€β”€ nyiso.py         # NYISO data loader
β”‚   β”‚   β”œβ”€β”€ pjm.py           # PJM data loader
β”‚   β”‚   └── caiso.py         # CAISO data loader
β”‚   └── utils/               # Utility functions
β”œβ”€β”€ configs/                  # Configuration files
β”œβ”€β”€ scripts/                  # Training and evaluation scripts
β”œβ”€β”€ examples/                 # Example notebooks
β”œβ”€β”€ docs/                     # Documentation
β”œβ”€β”€ paper/                    # Paper and supplementary materials
└── tests/                    # Unit tests

πŸ“– Documentation

πŸ”§ Configuration

GridFM uses YAML configuration files. Example:

# configs/gridfm_nyiso.yaml
model:
  backbone: moirai-moe-base
  hidden_dim: 256
  num_freq_components: 64
  freq_delta: 2
  
physics:
  enable_power_balance: true
  enable_dc_power_flow: true
  physics_weight: 0.1
  
training:
  batch_size: 32
  learning_rate: 1e-4
  num_epochs: 100
  early_stopping_patience: 10

πŸ“ˆ Reproducing Paper Results

To reproduce the results from our paper:

# Download and preprocess data
python scripts/download_data.py --iso nyiso --start 2019-01-01 --end 2023-12-31

# Train model
python scripts/train.py --config configs/gridfm_nyiso.yaml

# Evaluate
python scripts/evaluate.py --checkpoint checkpoints/best_model.pt --test_year 2023

# Generate figures
python scripts/generate_figures.py --results results/evaluation/

πŸ§ͺ Testing

# Run all tests
pytest tests/

# Run specific test module
pytest tests/test_freqmixer.py -v

# Run with coverage
pytest --cov=gridfm tests/

πŸ“ Citation

If you use GridFM in your research, please cite our paper:

@article{gridfm2024,
  title={GridFM: A Physics-Informed Foundation Model for Multi-Task Energy Forecasting Using Real-Time NYISO Data},
  author={Sayghe, Ali},
  journal={MDPI Energies},
  year={2024}
}

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • NYISO, PJM, and CAISO for providing open access to grid data
  • The Moirai team for the foundation model backbone
  • PyTorch Geometric team for GNN implementations

πŸ“§ Contact

For questions or feedback, please open an issue or contact [[email protected]].


Made with ❀️ for sustainable energy systems

energy-forecasting-physics-informed
machine-learning-deep-learning
pytorch-time-series-power-systems

asayghe1/GridFM

A Physics-Informed Foundation Model for Multi-Task Energy Forecasting

Python

2

3 commits

updated Jan 7, 2026

See the code

README

GridFM: A Physics-Informed Foundation Model for Multi-Task Energy Forecasting

Python 3.9+ PyTorch 2.0+ License: MIT arXiv

GridFM Architecture

GridFM is a physics-informed foundation model designed for multi-task energy forecasting using real-time data from Independent System Operators (ISOs). It combines pre-trained time series foundation models with domain-specific adaptations that respect power system physics.

🌟 Key Features

  • FreqMixer Adaptation Layer: Novel frequency-domain mixing mechanism that transforms general-purpose foundation model representations into power-grid-specific patterns
  • Physics-Informed Constraints: Integration of power balance equations and DC power flow approximations
  • Multi-Task Learning: Simultaneous forecasting of load, prices, emissions, and renewable generation
  • Graph Neural Networks: Zonal topology encoding via GCN for spatial dependencies
  • Explainability: SHAP-based feature attribution and attention visualization

πŸ“Š Performance

GridFM achieves state-of-the-art performance on NYISO, PJM, and CAISO datasets:

TaskMAPEImprovement vs. Fine-tuned Baseline
Load Forecasting2.14% Β± 0.05%10.1%
Price Forecasting7.80% Β± 0.31%15.9%
Emission Prediction4.73% Β± 0.18%14.3%
Renewable Generation8.92% Β± 0.42%12.7%

πŸš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/GridFM/GridFM.git
cd GridFM

# Create conda environment
conda create -n gridfm python=3.10
conda activate gridfm

# Install dependencies
pip install -r requirements.txt

# Install GridFM
pip install -e .

Basic Usage

from gridfm import GridFM
from gridfm.data import NYISODataLoader

# Load pre-trained model
model = GridFM.from_pretrained("gridfm-base-nyiso")

# Load data
dataloader = NYISODataLoader(
    start_date="2023-01-01",
    end_date="2023-12-31",
    zones=["WEST", "CENTRL", "NORTH"]
)

# Generate forecasts
forecasts = model.predict(
    dataloader,
    horizon=24,  # 24 steps ahead (2 hours at 5-min resolution)
    tasks=["load", "lbmp", "emissions"]
)

# Access results
print(f"Load MAPE: {forecasts.metrics['load_mape']:.2f}%")

Training from Scratch

from gridfm import GridFM, GridFMConfig
from gridfm.training import Trainer

# Configure model
config = GridFMConfig(
    backbone="moirai-moe-base",
    num_zones=11,
    hidden_dim=256,
    num_freq_components=64,
    physics_weight=0.1,
    coupling_weight=0.05
)

# Initialize model
model = GridFM(config)

# Train
trainer = Trainer(
    model=model,
    train_dataloader=train_loader,
    val_dataloader=val_loader,
    learning_rate=1e-4,
    num_epochs=100
)
trainer.train()

πŸ“ Repository Structure

GridFM/
β”œβ”€β”€ gridfm/                    # Main package
β”‚   β”œβ”€β”€ models/               # Model architectures
β”‚   β”‚   β”œβ”€β”€ gridfm.py        # Main GridFM model
β”‚   β”‚   β”œβ”€β”€ backbone.py      # Foundation model backbone
β”‚   β”‚   └── task_heads.py    # Task-specific output heads
β”‚   β”œβ”€β”€ layers/              # Custom layers
β”‚   β”‚   β”œβ”€β”€ freqmixer.py     # FreqMixer adaptation layer
β”‚   β”‚   β”œβ”€β”€ gcn.py           # Graph convolutional network
β”‚   β”‚   └── attention.py     # Attention mechanisms
β”‚   β”œβ”€β”€ physics/             # Physics constraints
β”‚   β”‚   β”œβ”€β”€ power_balance.py # Power balance equations
β”‚   β”‚   └── dc_power_flow.py # DC power flow approximation
β”‚   β”œβ”€β”€ data/                # Data loading utilities
β”‚   β”‚   β”œβ”€β”€ nyiso.py         # NYISO data loader
β”‚   β”‚   β”œβ”€β”€ pjm.py           # PJM data loader
β”‚   β”‚   └── caiso.py         # CAISO data loader
β”‚   └── utils/               # Utility functions
β”œβ”€β”€ configs/                  # Configuration files
β”œβ”€β”€ scripts/                  # Training and evaluation scripts
β”œβ”€β”€ examples/                 # Example notebooks
β”œβ”€β”€ docs/                     # Documentation
β”œβ”€β”€ paper/                    # Paper and supplementary materials
└── tests/                    # Unit tests

πŸ“– Documentation

πŸ”§ Configuration

GridFM uses YAML configuration files. Example:

# configs/gridfm_nyiso.yaml
model:
  backbone: moirai-moe-base
  hidden_dim: 256
  num_freq_components: 64
  freq_delta: 2
  
physics:
  enable_power_balance: true
  enable_dc_power_flow: true
  physics_weight: 0.1
  
training:
  batch_size: 32
  learning_rate: 1e-4
  num_epochs: 100
  early_stopping_patience: 10

πŸ“ˆ Reproducing Paper Results

To reproduce the results from our paper:

# Download and preprocess data
python scripts/download_data.py --iso nyiso --start 2019-01-01 --end 2023-12-31

# Train model
python scripts/train.py --config configs/gridfm_nyiso.yaml

# Evaluate
python scripts/evaluate.py --checkpoint checkpoints/best_model.pt --test_year 2023

# Generate figures
python scripts/generate_figures.py --results results/evaluation/

πŸ§ͺ Testing

# Run all tests
pytest tests/

# Run specific test module
pytest tests/test_freqmixer.py -v

# Run with coverage
pytest --cov=gridfm tests/

πŸ“ Citation

If you use GridFM in your research, please cite our paper:

@article{gridfm2024,
  title={GridFM: A Physics-Informed Foundation Model for Multi-Task Energy Forecasting Using Real-Time NYISO Data},
  author={Sayghe, Ali},
  journal={MDPI Energies},
  year={2024}
}

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • NYISO, PJM, and CAISO for providing open access to grid data
  • The Moirai team for the foundation model backbone
  • PyTorch Geometric team for GNN implementations

πŸ“§ Contact

For questions or feedback, please open an issue or contact [[email protected]].


Made with ❀️ for sustainable energy systems

energy-forecasting-physics-informed
machine-learning-deep-learning
pytorch-time-series-power-systems