GNN4CIRCUITS is a platform for applying Graph Neural Networks (GNNs) to circuit analysis and design. This repository supports graph conversion from hardware description files and the training of GNN models for both node-level and graph-level tasks including both classification and regression.
Modern ICs can be represented as graphs, with gates as nodes and wires as edges. GNN4CIRCUITS leverages this structure to provide:
- Circuit-to-graph conversion
- Node and graph-level machine learning tasks
- Support for both classification and regression
- Multiple GNN model support (GCN, GIN and PNA)
- Compatibility with real-world and synthetic benchmarks
-
Clone the repository:
git clone https://github.com/hanasel/GNN4CIRCUITS.git cd GNN4CIRCUITS
-
Create the conda environment:
conda env create -f gnn4circuits.yml
-
Activate the environment:
conda activate gnn4circuits
Convert Verilog, Bench, or RTL files into graph format:
python GNN4CIRCUITS.py parse -ver <path-to-verilog> -hw <GL|RTL|BENCH> -class graph -lib <optional-lib-path> [feature flags]
python GNN4CIRCUITS.py parse -ver designs/ -hw GL -class graph -lib lib.v -id -od -gt -pi -po
This generates a directory called files4training
containing:
node_features.csv
graph_edges.csv
graph_properties.csv
Once graph files are generated, train a GNN model on the dataset:
python GNN4CIRCUITS.py train -class graph -task <classification|regression> -model <model> -hdim <hidden-dimension> -n_layers <number-of-layers> -epochs <number-of-epochs> -input <input-path>
Optional arguments can be used to provide validation or test sets separately using -val
and -test
.
python GNN4CIRCUITS.py train -class graph -task regression -model GIN -hdim 128 -n_layers 3 -epochs 200 -input files4training
python GNN4CIRCUITS.py train -class node -task classification -model GCN -hdim 64 -n_layers 2 -epochs 300 -input files4training
Used for netlist to graph conversion
-ver
: Path to the Verilog or directory of files.-hw
: Hardware type (GL
,RTL
,BENCH
,TXT
).-class
: Classification type (graph
ornode
).-lib
: Optional library file for gate-level parsing.- Optional Feature Flags:
-id
: Input degree-od
: Output degree-iod
: I/O degree-mdi
: Min. dist. to input-mdo
: Min. dist. to output-pi
,-po
: Primary I/O flags-gt
: Gate type
Used for training and evaluation
-class
:graph
ornode
-task
:classification
orregression
Specifies whether the task is a classification (e.g., logic type) or a regression (e.g., resource usage).-model
:GCN
,GIN
, orPNA
-hdim
: Hidden dimension size-n_layers
: Number of GNN layers-epochs
: Training epochs-batch_size
: Batch size-input
: Path to directory withnode_features.csv
,graph_edges.csv
, andgraph_properties.csv
-val
,-test
: Optional paths for validation and test sets-output
: Output results log file (default:gnn4circuits_results.txt
)
This use case allows users to load and process hardware design graphs represented in coordinate list (COO) format, typically extracted from sparse matrices. It is useful for datasets where graph structures and features are pre-encoded in .txt
format.
To run this parsing pipeline, use the parse_txt
command:
python GNN4CIRCUITS.py parse_txt -path /path/to/folder/
This folder must contain the following files:
row.txt
: A list of source node indices for edges.col.txt
: A list of destination node indices for edges.cell.txt
: Contains metadata or circuit cell names corresponding to each node.feat.txt
: A tab-separated file where each row corresponds to a node's feature vector. All vectors must be of the same length.label.txt
: A list of integer class labels, one per node.
Ensure consistency:
- The number of rows in
feat.txt
,label.txt
, andcell.txt
(if present) must match the total number of unique nodes. row.txt
andcol.txt
must have the same number of entries, each pair representing one edge.
Suppose you have the following files in /data/parsed_graph
:
/data/parsed_graph/
├── row.txt # e.g., 0, 0, 1, ...
├── col.txt # e.g., 1, 2, 2, ...
├── cell.txt
├── feat.txt # e.g., 0.1 0.2 0.3 ...
├── label.txt # e.g., 0, 1, 2, ...
You can parse them with:
python GNN4CIRCUITS.py parse_txt -path /data/parsed_graph
This will generate a graph object compatible with GNN training pipelines using DGL, with features and labels attached to each node.
An example dataset can be found here. This is extracted data taken from Alrahis et al., and the original can be downloaded here.
The cell.txt
file provides metadata mapping each node index to its corresponding circuit cell instance and source file. This is useful for:
- Traceability: Knowing where a cell originated from in the Verilog design.
- Debugging: Mapping graph nodes back to specific hardware components.
Each line in cell.txt
must follow the format:
<node_id> <cell_name> from file <source_filename>
For example:
1841 \multiplier_1/U57 from file Test_add_mul_16_bit_syn.v
1456 \multiplier_1/U442 from file Test_add_mul_16_bit_syn.v
Notes:
- Node IDs should correspond to those used in
feat.txt
,label.txt
, and the indices inrow.txt
/col.txt
.