This repository contains the code to simulate hardware artificial neural networks where neurons and synapses are implemented by radiofrequency spintronic devices.
The RF spintronic neural network concept and experimental demonstration can be found in the article "Multilayer spintronic neural networks with radio-frequency connections" by Ross, Leroux et al. [1], available here
In particular, this code can be used to reproduce the results of the drone classification task, which dataset can be downloaded here and is inspired from [2].
In order to avoid potential conflicts with other packages it is strongly recommended to use a virtual environment (venv) or a conda environment. The dependencies are:
- Python 3.11
- Pytorch 2.0.1
- Optuna 3.1.1
- scikit-learn 1.2.2
- matplotlib 3.7.1
- h5py 3.7.0
- pandas 1.5.3
The requirements.yml file can be used to create the environment with the command:
conda env create --name environment_name --file requirements.yml
conda activate environment_name
Disclaimer: While it is possible for us to reproduce exactly the accuracy given in the paper, the results are not exactly reproducible if the code run on an other machine. This is actually a known issue (see Pytorch forum). However, it is expected that you find very close results.
In order to reproduce the training and evaluation procedure for the spintronic MLP and the standard MLP, we need two commands:
- Execute the code with the spintronic MLP model:
python main.py --procedure train_eval --config config_spinMLP.yaml
- Execute the code with the standard MLP model:
python main.py --procedure train_eval --config config_MLP.yaml
The results will be saved in the directory results/train_eval under the names YYYYmmdd-HHMMSS-<model_name>.
The code can run three different procedures:
- Selection of the best hyper-parameters followed by training and evaluation of a network on the entire dataset
python main.py --procedure select_train_eval
- Training and evaluation of a network
python main.py --procedure train_eval
- Evaluation of an existing model (need to load one) on the test dataset
python main.py --procedure eval --config <path_to_config_from_results>
The results are saved in the results directory where there is one directory for each procedure.
By default, the physical model do not consider the nonidealities of the magnetic tunnel junctions. To take into account the nonidealities you have to use the argument --with-nonidealities:
python main.py --procedure select_train_eval --with-nonidealities
The nonidealities that are implemented as the variation of the resonance frequencies, the variation of the frequency and the power of the output signal of the oscillators. It can be adjusted using the arguments --freq-var-percentage and --power-var-percentage:
python main.py --procedure select_train_eval --with-nonidealities --freq-var-percentage 0.001 --power-var-percentage 0.001
where 1.0 corresponds to 100%.
[1] Ross, A., Leroux, N., de Riz, A., Marković, D., Sanz-Hernández, D., Trastoy, J., ... & Grollier, J. (2022). "Multilayer spintronic neural networks with radio-frequency connections". arXiv preprint arXiv:2211.03659.
[2] S. Basak, S. Rajendran, S. Pollin and B. Scheers, "Drone classification from RF fingerprints using deep residual nets," 2021 International Conference on COMmunication Systems & NETworkS (COMSNETS), Bangalore, India, 2021, pp. 548-555, doi: 10.1109/COMSNETS51098.2021.9352891. link to dataset.