This repository implements Graph Neural Networks for Power Flow (PF) simulation. This implementation will guide future works considering the control (RL based) problem in which the agent's policy could be enhanced using physics informed neural networks.
In this implementation the inputs to the GNN are the injections (
📂 graph-neural-solver
├── 📂 configs
│ └── ...
├── 📂 getting_started
│ └── 0_generate_data.ipynb
│ └── 1_example_gnn_without_nn.ipynb
│ └── 2_gnn_powergrid.ipynb
├── 📂 gnn_powergrid
│ └── 📂 dataset
│ └── ...
│ └── 📂 evaluation
│ └── ...
│ └── 📂 gnn
│ └── ...
├── setup.py
The folder configs includes all the required configurations for data generation and hyperparameters for constructing GNN based solvers, the folder getting_started contains a set of jupyter notebooks guiding the user to how generate, train and evaluate the GNN based implementations, the folder gnn_powergrid is the python package including different modules which are dataset
, evaluation
and gnn
. The setup.py
allows the installation of the package using the required dependencies.
To be able to run the experiments in this repository, the following steps show how to install this package and its dependencies from source.
- Python >= 3.6
conda create -n venv_gnn python=3.10
conda activate venv_gnn
cd my-project-folder
pip3 install -U virtualenv
python3 -m virtualenv venv_gnn
source venv_gnn/bin/activate
git clone https://gitlab.inesctec.pt/cpes/european-projects/ai4realnet/irt-systemx/task-1.2/graph-neural-solver.git
cd graph-neural-solver
pip3 install -U .[recommended]
cd ..
pip3 install -e .[recommended]
The results presented in the slides could be reproduced by executing main_wo_nn.py
and main.py
script.
main_wo_nn.py
is the script that used the local conservation law as the optimization criteria and do not use any Neural Network for learningmain.py
is the script that add a Dense neural network for the estimation of intitial voltage angles, which should help the faster convergence of the optimization criteria (local conservation law).Under improvement
The set of inputs for the generation of datasets could be found in configs folder. There are two configuration files for two different power grid environments presenting each a different grid size. l2rpn_case14_sandbox
is the toy example with a grid including 14 nodes and 20 power lines. l2rpn_neurips_2020_track1_small
includes a more complex environment with 38 nodes. The user could use one of the sections in these configuration files when generating and importing datasets.
Once the environment is selected, you should change the number of samples per dataset before the main
function which are set only for illustration purpose as:
NB_SAMPLE_TRAIN = 1e2
NB_SAMPLE_VAL = 1e2
NB_SAMPLE_TEST = 1e2
NB_SAMPLE_OOD = 1e2
You could also change the set of hyperparameters of the GNN by modifying the gnn.ini
configuration file in configs folder or by setting them directly as the arguments to the GnnSimulator
class instantiation.
env_name="l2rpn_case14_sandbox"
name = "torch_gnn"
ref_node = 0
num_gnn_layers = 10
latent_dimension = 20
hidden_layers = 3
input_dim=2
output_dim=1
train_batch_size = 128
eval_batch_size = 128
device="cpu"
optimizer = {"name": "adam",
"params": {"lr": 3e-4}}
epochs = 10
train_with_discount=False
save_freq = False
ckpt_freq = 50
As the output of the script main_wo_nn.py
or main.py
, two files are created:
- logs.log file which includes all the logs of the LIPS framework alongside the outputs
- results.json a json file including the metrics computed on the prediction of GNN.