# neuromorphs/nir architecture

> Architecture diagram of the GitHub repository neuromorphs/nir, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neuromorphs/nir
- Repository: https://github.com/neuromorphs/nir

## Overview

##### Project type and purpose
- NIR is an open-source Python library providing a unified intermediate representation (IR) for spiking/neuromorphic models.
- Its core goal is to let users “write” a model in one framework, serialize it to a `.nir` file, and “read” it back into another framework (or the same one) seamlessly.

##### File structure
- Top-level:
- `nir/` – the Python package containing the core IR, nodes, utilities, and serialization logic.
- `tests/` – unit tests covering architectures, IR transforms, read/write, and utilities.
- `docs/` – Sphinx-based documentation source and built site under `docs/neuroir.org/`.
- `.github/workflows/` – CI pipelines for build, docs deploy, and PyPI release.
- `pyproject.toml`, `dev_requirements.txt`, Nix/Flake files – packaging, linting, and reproducible dev environment.
- `paper/` – examples, benchmarks, and scripts used for the accompanying scientific paper.

##### README for additional insights
- NIR exposes two main APIs: `nir.write(path, model)` and `nir.read(path)`
- Supports seven simulators and four hardware back-ends via adapter code.
- Documentation covers primitives, usage, and supported platforms.

##### Elements
- External Frameworks (grouped left)
- NIR API Layer
- IR Core modules
- Serialization module
- NIR file (artifact)
- Development tooling (CI, docs)
- Blue rectangles for NIR internal modules
- Purple rectangles for external frameworks

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Frameworks
    subgraph "External Frameworks"
        class EF extern
        E1["Lava-DL"] 
        E2["Nengo"]
        E3["Norse"]
        E4["Rockpool/Xylo"]
        E5["Sinabs/Speck"]
        E6["snnTorch"]
        E7["SpiNNaker2"]
        E8["Spyx"]
    end

    %% NIR Library Core
    subgraph "NIR Library" 
        subgraph "API Layer"
            API["nir/__init__.py"] 
        end
        subgraph "IR Core"
            G["Graph (graph.py)"]
            N["Node (node.py)"]
            C1["Conv (conv.py)"]
            C2["Delay (delay.py)"]
            C3["Flatten (flatten.py)"]
            C4["Linear (linear.py)"]
            C5["Neuron (neuron.py)"]
            C6["Pooling (pooling.py)"]
            C7["Threshold (threshold.py)"]
            C8["Typing (typing.py)"]
            C9["Utils (utils.py)"]
        end
        subgraph "Serialization"
            S["serialization.py"]
        end
        NIRFile[".nir File"] 
    end

    %% Data Flow Write
    E1 -->|"write(path, model)"| API
    E2 -->|"write(path, model)"| API
    E3 -->|"write(path, model)"| API
    E4 -->|"write(path, model)"| API
    E5 -->|"write(path, model)"| API
    E6 -->|"write(path, model)"| API
    E7 -->|"write(path, model)"| API
    E8 -->|"write(path, model)"| API

    API -->|"construct IR"| G
    G --> N
    N --> C1
    N --> C2
    N --> C3
    N --> C4
    N --> C5
    N --> C6
    N --> C7
    G --> C8
    G --> C9
    C9 --> S
    S -->|"serialize"| NIRFile

    %% Data Flow Read
    NIRFile -->|"load"| S
    S -->|"populate IR"| G
    G --> API
    API -->|"return model"| E1
    API -->|"return model"| E2
    API -->|"return model"| E3
    API -->|"return model"| E4
    API -->|"return model"| E5
    API -->|"return model"| E6
    API -->|"return model"| E7
    API -->|"return model"| E8

    %% Development Tooling
    subgraph "Development Tooling"
        class DT tooling
        T["Tests (tests/)"]
        DS["Docs Source (docs/source/)"]
        DD["Built Docs (docs/neuroir.org/)"]
        CI["CI Pipelines (.github/workflows/)"]
        DC["Dev Container (.devcontainer/)"]
        NX["Nix Flake (flake.nix, flake.lock)"]
        PK["Packaging (pyproject.toml, dev_requirements.txt)"]
        PP["Paper Examples (paper/)"]
        RM["README & CITATION (README.md, CITATION.cff)"]
        PC["Pre-commit (.pre-commit-config.yaml)"]
        RD["ReadTheDocs (.readthedocs.yaml)"]
    end

    %% Styles
    classDef extern fill:#D0B0FF,stroke:#666,stroke-width:1px
    classDef internal fill:#B0E0FF,stroke:#333,stroke-width:1px
    classDef artifact fill:#FFE066,stroke:#999,stroke-width:1px
    classDef tooling fill:#C6EBC5,stroke:#4B8B3B,stroke-width:1px

    class API,G,N,C1,C2,C3,C4,C5,C6,C7,C8,C9,S internal
    class NIRFile artifact
    class DT,T,DS,DD,CI,DC,NX,PK,PP,RM,PC,RD tooling

    %% Click Events
    click API "https://github.com/neuromorphs/nir/blob/main/nir/__init__.py"
    click G "https://github.com/neuromorphs/nir/blob/main/nir/ir/graph.py"
    click N "https://github.com/neuromorphs/nir/blob/main/nir/ir/node.py"
    click C1 "https://github.com/neuromorphs/nir/blob/main/nir/ir/conv.py"
    click C2 "https://github.com/neuromorphs/nir/blob/main/nir/ir/delay.py"
    click C3 "https://github.com/neuromorphs/nir/blob/main/nir/ir/flatten.py"
    click C4 "https://github.com/neuromorphs/nir/blob/main/nir/ir/linear.py"
    click C5 "https://github.com/neuromorphs/nir/blob/main/nir/ir/neuron.py"
    click C6 "https://github.com/neuromorphs/nir/blob/main/nir/ir/pooling.py"
    click C7 "https://github.com/neuromorphs/nir/blob/main/nir/ir/threshold.py"
    click C8 "https://github.com/neuromorphs/nir/blob/main/nir/ir/typing.py"
    click C9 "https://github.com/neuromorphs/nir/blob/main/nir/ir/utils.py"
    click S "https://github.com/neuromorphs/nir/blob/main/nir/serialization.py"
    click T "https://github.com/neuromorphs/nir/tree/main/tests/"
    click DS "https://github.com/neuromorphs/nir/tree/main/docs/source/"
    click DD "https://github.com/neuromorphs/nir/tree/main/docs/neuroir.org/"
    click CI "https://github.com/neuromorphs/nir/tree/main/.github/workflows/"
    click DC "https://github.com/neuromorphs/nir/tree/main/.devcontainer/Dockerfile"
    click DC "https://github.com/neuromorphs/nir/blob/main/.devcontainer/devcontainer.json"
    click NX "https://github.com/neuromorphs/nir/blob/main/flake.nix"
    click NX "https://github.com/neuromorphs/nir/blob/main/flake.lock"
    click PK "https://github.com/neuromorphs/nir/blob/main/pyproject.toml"
    click PK "https://github.com/neuromorphs/nir/blob/main/dev_requirements.txt"
    click PP "https://github.com/neuromorphs/nir/tree/main/paper/"
    click RM "https://github.com/neuromorphs/nir/blob/main/README.md"
    click RM "https://github.com/neuromorphs/nir/blob/main/CITATION.cff"
    click PC "https://github.com/neuromorphs/nir/blob/main/.pre-commit-config.yaml"
    click RD "https://github.com/neuromorphs/nir/blob/main/.readthedocs.yaml"
```
