Skip to content

ansh07verma/gate-level-power-gnn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gate-Level Circuit Power Prediction using Graph Neural Networks

Python PyTorch PyG License

Research Question: Can a Graph Neural Network predict circuit power better than traditional ML because circuits are naturally graphs?

A clean, student-level benchmark that demonstrates the advantage of GraphSAGE over a Random Forest baseline on a synthetic gate-level power prediction task, using a controlled Isomer Pair dataset.


Results

Model MAE RMSE R² Score
Random Forest 36.64 41.41 0.1205
GraphSAGE (GNN) 9.88 14.19 0.8966

GraphSAGE achieves 3.7× lower MAE and an R² of 0.897 vs the Random Forest's 0.12 on the Isomer Pair benchmark — demonstrating that graph structure is critical for accurate power prediction when topology drives the power behaviour.


Why Circuits Are Graphs

A digital circuit is naturally a Directed Acyclic Graph (DAG):

  • Nodes = logic gates (AND, OR, NOT, NAND, NOR, XOR)
  • Edges = signal wires (directed: driver gate → receiver gate)

Traditional ML models like Random Forest cannot process graphs. They flatten the circuit into aggregate statistics (e.g. average gate count, average capacitance), irreversibly losing the structural information about which gates are connected to which.

GraphSAGE learns directly from the graph by passing messages along the wires — each gate aggregates information from its direct neighbours, giving the model a structural awareness that tabular models fundamentally cannot have.


The Isomer Pair Benchmark

To rigorously prove the GNN's structural advantage, we use an Isomer Pair benchmark.

Each pair consists of two circuits (A and B) with identical aggregate statistics:

Feature Circuit A Circuit B
Gate count ✓ Same ✓ Same
Wire count ✓ Same ✓ Same
Avg capacitance ✓ Same ✓ Same
Avg fan-in ✓ Same ✓ Same
Avg fan-out ✓ Same ✓ Same

The only difference is the wiring of three specific gates:

  • Circuit A (Hotspot): A high-capacitance gate drives another high-capacitance gate → 2× power spike
  • Circuit B (Safe): The high-capacitance gate is routed safely to a low-capacitance gate → normal power

Because the Random Forest receives identical inputs for both circuits, it is provably unable to distinguish them and must predict the same power for both. The GraphSAGE model sees the actual edge connections and correctly identifies the hotspot.


Project Structure

gate-level-power-gnn/
│
├── data/                        # Generated dataset (created at runtime)
│
├── models/
│   ├── graphsage.py             # GraphSAGE power predictor (3-layer SAGEConv)
│   └── random_forest.py         # Random Forest tabular baseline
│
├── scripts/
│   ├── generate_dataset.py      # Isomer Pair DAG generator
│   └── train_model.py           # Training + evaluation pipeline
│
├── utils/
│   ├── preprocessing.py         # Z-score normalisation + train/val/test split
│   └── metrics.py               # MAE, RMSE, R² computation
│
├── requirements.txt
└── README.md

Model Architecture

GraphSAGE Power Predictor

Input (10 node features)
    → Linear(192) → ReLU                  [input projection]
    → SAGEConv(192→192) → BN → ReLU       [message passing layer 1]
    → SAGEConv(192→192) → BN → ReLU       [message passing layer 2]
    → SAGEConv(192→192) → BN → ReLU       [message passing layer 3]
    → Global Mean Pool                     [aggregate nodes → graph vector]
    → Linear(192→96) → ReLU → Dropout
    → Linear(96→1)                         [power prediction]

Random Forest Baseline

Trained on 5 tabular features extracted from each graph:

  1. Number of gates
  2. Number of wires
  3. Average fan-in
  4. Average fan-out
  5. Average capacitance

Installation

# Clone the repository
git clone https://github.com/ansh07verma/gate-level-power-gnn.git
cd gate-level-power-gnn

# Install dependencies
pip install -r requirements.txt

GPU Note: Training defaults to CPU. To enable GPU, set FORCE_CPU = False in scripts/train_model.py.


Usage

Step 1 — Generate the Dataset

python scripts/generate_dataset.py

Generates 2,500 isomer pairs (5,000 total circuits) and saves them to data/circuit_power_dataset.pt.

Step 2 — Train and Evaluate

python scripts/train_model.py

Trains both the GraphSAGE model and the Random Forest baseline, then prints a side-by-side comparison table of MAE, RMSE, and on the held-out test set.


Training Details

Hyperparameter Value
Optimiser Adam
Learning rate 0.001
Batch size 32
Max epochs 200
Early stopping patience 25
GNN hidden dim 192
GNN layers 3
Dropout 0.1
Loss function MSELoss
Random seed 42

Honest Framing

The dataset is a controlled synthetic benchmark, not a real EDA dataset. The power formula was designed so that the answer depends on specific edge-level topology, while the tabular features are equalised to be identical for both isomers. This isolates the contribution of graph structure to the prediction task.

This is standard practice in GNN research (see: "How Powerful Are Graph Neural Networks?", Xu et al. 2019) and is presented transparently here.


Requirements

torch>=2.0.0
torch_geometric>=2.3.0
numpy>=1.24.0
scikit-learn>=1.2.0
networkx>=3.0.0
tqdm>=4.65.0

License

MIT License — feel free to use and adapt for your own coursework or research.

About

Gate-level power prediction using GraphSAGE-based GNN benchmarked against Random Forest on an incompressible topography dataset.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages