This repository contains the source code for implementing graph classification in a graph neural network using PyTorch (CPU/GPU). The code transforms analog/digital circuits described in the papers into a graph network.
- Yusuke Yamakaji, Hayaru Shouno, and Kunihiko Fukushima, Circuit2Graph: Circuits With Graph Neural Networks, IEEE Access, vol. 12, pp. 51818-51827, 2024.
- Yusuke Yamakaji, Hayaru Shouno, and Kunihiko Fukushima, Circuit2Graph: Diodes as Asymmetric Directional Nodes, IEEE Access, vol. 12, pp. 168963-168974, 2024.
- Yusuke Yamakaji, Hayaru Shouno, and Kunihiko Fukushima, Equivalent Circuit for Single/Three Phase Magnetic Coupling With Graph Neural Networks, IEEE Transactions on Power Electronics, vol. 40, no. 2, pp. 3313-3325, Feb. 2025.
Assume that LTspice XVII is installed in the "C:\LTspice" directory. If the installation path is different, please modify the "default=os.path.join('C:', 'LTspice')" in params.py
. Additionally, LTspice XVII may have files like examples.zip
and lib.zip
in the "C:\LTspice" directory. Please unzip these files beforehand so that "C:\LTspice\examples" and "C:\LTspice\lib" are accessible.
Ensure that LTspice XVII is installed in the C:\LTspice
directory. If the installation path is different, modify the default=os.path.join('C:', 'LTspice')
in params.py
. Additionally, unzip examples.zip
and lib.zip
in the C:\LTspice
directory so that C:\LTspice\examples
and C:\LTspice\lib
are accessible.
-
Install the NVIDIA driver and CUDA Toolkit according to your environment. This guide uses CUDA Toolkit version 11.8.
-
Install the required libraries:
pip install torch --index-url https://download.pytorch.org/whl/cu118 pip install numpy torch_geometric # Optional pip install matplotlib networkx
This code has been tested with the following library versions:
- numpy: 2.2.1
- torch: 2.5.1
- torch_geometric: 2.6.1
- matplotlib: 3.10.0 (optional)
- networkx: 3.4.2 (optional)
The calculation time is slower compared to a GPU environment, but the code supports training and inference on a CPU.
- Install the required libraries:
pip install numpy torch torch_geometric # Optional pip install matplotlib networkx
When running this code for the first time, execute the batch file _make_netlist.bat
created by the make_net_batch
function in extract_netlist.py
to extract netlists from sample circuits of LTspice.
To execute, run the following scripts in order:
python extract_netlist.py
python extract_node_edge.py
python data_loading.py
python train.py
The hyperparameters can be adjusted in params.py
:
-
--semiconductor: Defines how semiconductors are treated. Options are single, star, or complete.
- "single": Semiconductors are treated as single nodes.
- "star": Semiconductors are treated as a star graph.
- "complete": Semiconductors are treated as a complete graph.
-
--mutual: Defines how the coupling coefficient of magnetic coupling is handled. Options are equiv or none.
- "none": The coupling coefficient is not held.
- "equiv": The coupling coefficient is held by transforming it into an equivalent circuit.