snntorch.import_nir

snntorch.import_nir is a module that enables cross-compatibility with other SNN libraries by converting snntorch models to a Neuromorphic Intermediate Representation (NIR)

snntorch.import_nir.import_from_nir(graph: NIRGraph) Module[source]

Convert a NIRGraph to a snnTorch module. This function is the inverse of export_to_nir. It proceeds by wrapping any recurrent connections into NIR sub-graphs, then converts each NIR module into the equivalent snnTorch module, and wraps them into a torch.nn.Module using the generic GraphExecutor from NIRTorch to execute all modules in the right order.

Missing features: - RLeaky (LIF inside RNN)

Example:

import snntorch as snn
import torch
from snntorch.export_nir import export_to_nir
from snntorch.import_nir import import_from_nir

lif1 = snn.Leaky(beta=0.9, init_hidden=True)
lif2 = snn.Leaky(beta=0.9, init_hidden=True, output=True)

net = torch.nn.Sequential(
    torch.nn.Flatten(),
    torch.nn.Linear(784, 500),
    lif1,
    torch.nn.Linear(500, 10),
    lif2
)

sample_data = torch.randn(1, 784)
nir_graph = export_to_nir(net, sample_data, model_name="snntorch")

net2 = import_from_nir(nir_graph)
Parameters:

graph (NIR.NIRGraph) – NIR graph

Returns:

snnTorch network

Return type:

torch.nn.Module