Simulation Workflow
The framework's architecture which is summarized in Figure 1 is modular. Each module is geared towards simplifying and automating the complex processes involved in SNN design, training, and analysis. The scripts of the framework work together to perform simulations and analysis of the SNN, with the main Python script (snn_simulator.py) coordinating the flow between the following components:
-
First, the
gen_letters.pyscript generates images of various letters for training. Using a specific script to generate personalized images allow us to control the complexity and size of training dataset, each image is saved as.npyfile in theletter_imgsdirectory. Additionally, it saves a dictionary of all images in a pickle file for later use. There is also a possibility to train the network with images from MNIST. for that, a small set of MNIST images should first be extracted usingextract_mnist.pyand optionally visualize it usingsee_image.py. Thes scripts and the generated images are organized ininput_imagesdirectory from which the simulator loads the inputs. -
Next, the main script (
snn_simulator.py) orchestrates the entire simulation process. It sets up simulation parameters, prepares combinations for multiprocessing, and runs the simulations in parallel using therun_simulationfunction. This function loads the generated.npyimage files and flattens them to create input data for the SNN simulation. These images represent the spiking neurons' intensity, which is used to configure the neuron inputs. The user is requested to input design and simulation options in this main script. Subsequently, design choices such as the number of input and output neurons and the synapse composition are handed tonet_generator.pyto generate the netlist. Similarly, simulation options such as step, duration and file paths are handed tosubst_run.pyto prepare the ocean script that should be executed. It might be worth highlighting the parallel processing capability of the framework, this means that we can train many SNNs with different sizes and design parameters at the same time, with a complete separation between the input and output files of each SNN, and with no intervention from the user. -
The
net_generator.pyscript is responsible for generating the netlist file required for the simulation. It uses various classes to define components of the SNN, such as synapses, input neurons, and output neurons. These components are assembled into a complete netlist file, which includes references to the Verilog-A models. If different SNN sizes are requested to run in parallel, the main script tells the netlist generator to output eachnetlistin a different simulation directory. -
The
subst_run.pyscript contains utility functions for substituting values into templates and executing shell commands. The main script usessubst_run.substitute_templto replace placeholders in theoceanScript.ocntemplate with actual values from the simulation parameters. It then usessubst_run.exec_cmdto run the simulation commands using the substituted script (final Ocean script) and the generated netlist. In short, the scriptsubst_run.pyhas two functions: first, it prepares the final ocean script by substituting the user-defined parameters in a generic template (oceanScript.ocn). Second, it executes shell commands to run the simulation. This substitution method is inspired by the approach used in monaco project by @servinagrero. -
The
oceanScript.ocnfile is an OCEAN script used by the Cadence Spectre simulator to set up and run a transient analysis for the SNN simulation. It specifies the design file, analysis parameters, environment options, and variables, and it controls the simulation flow and data saving. This script is crucial for defining how the simulation should be run and what data should be saved. -
The Verilog-A models (
in_neuron.va,out_neuron.va, andmtj_model.va) define the behavior of the different components in the SNN. Thein_neuron.vafile models the input neurons that generate spikes, theout_neuron.vafile models the output neurons with leaky integrate-and-fire behavior, and themtj_model.vafile models the PMA MTJ based on the STT mechanism. These models are included in the netlist and are used by the simulator to simulate the electrical behavior of the SNN. -
After the simulations are run, the
plot_weig_membr.pyscript reads the output data (results.txt) produced by the simulations. It usesmatplotlibto plot the weights history and membrane potentials of the neurons during training, providing a visual representation of the simulation results. These visualizations are saved as PDF files for further analysis. If the simulations consists of variability study od the SNN,plot_eucl_dist.pyallows to evaluate the resiliance of the netwok against the variability. In fact, it calculates the euclidian destance between the weights of a dependable SNN and the weights of an ideal one, it then plots the euclidian distnaces with respect to the dependability magnitude (standard deviation of the variability distribution, injected defects values, ...)
In summary, the process starts with generating input images using gen_letters.py, which are then used by snn_simulator.py to set up and run simulations. The net_generator.py script creates the necessary netlist files, while subst_run.py substitutes parameters in the oceanScript.ocn template and executes the simulation commands. The Verilog-A models define the behavior of the SNN components, and the plot_weig_membr.py script visualizes the simulation results. This integrated workflow allows for efficient simulation and analysis of SNNs.
The following diagram summurises every file involved in the simulaiton of SNN online training and it output visualisation, and how they interact in an automatic way.

Figure 1: Overview of the SNN Training Framework detailing module interactions and data flow.