-
Notifications
You must be signed in to change notification settings - Fork 2
3.1 SynapticGraph and CSR Representation
Relevant source files
The following files were used as context for generating this wiki page:
The SynapticGraph struct ([src/topology/graph.rs:33-47]()) serves as the core adjacency and wiring representation for the synaptic-wiring crate. It extends traditional Compressed Sparse Row (CSR) sparse graph storage with domain-specific metadata: signed synaptic weights, axonal propagation delays, and Dale's law polarities. This page details its internal layout, construction from descriptors, validation invariants, and serialization/export characteristics.
To achieve cache-friendly traversal during spike propagation in SynapticMesh ([src/mesh.rs:49-63]()), SynapticGraph stores outgoing edges sequentially per source neuron using a CSR layout.
The structural components of SynapticGraph are:
-
neuron_count: The total number of neurons in the graph ([src/topology/graph.rs:35]). -
row_ptr: An array of lengthneuron_count + 1whererow_ptr[i]indicates the starting index of outgoing edges for neuroni([src/topology/graph.rs:36-38]()). -
targets: Flattened array of destination neuron IDs ([src/topology/graph.rs:39-40]()). -
weights: Flattened array of signed synaptic weights ([src/topology/graph.rs:41-42]()). -
delays: Flattened array of axonal propagation delays in simulation ticks ([src/topology/graph.rs:43-44]()). -
polarities: Flattened array of Dale's law polarities ([src/topology/graph.rs:45-46]()).
graph TD
subgraph "Conceptual Wiring Space"
A["Source Neuron i"] -->|Weight, Delay, Polarity| B["Target Neuron j"]
end
subgraph "Code Entity Space: SynapticGraph"
SG["SynapticGraph"] --> RP["row_ptr: Vec<usize>"]
SG --> T["targets: Vec<NeuronId>"]
SG --> W["weights: Vec<f32>"]
SG --> D["delays: Vec<DelayTicks>"]
SG --> P["polarities: Vec<Polarity>"]
end
Sources: src/topology/graph.rs:33-47
Graphs are typically constructed from a collection of SynapseDescriptor instances ([src/types.rs:52-64]()). During construction, edges are sorted and grouped by source neuron to build the monotonic row_ptr index structure.
Because external serialization formats (such as Postcard or JSON) can inject arbitrary values, RawSynapticGraph ([src/topology/graph.rs:50-57]()) implements a strict validation phase via into_graph ([src/topology/graph.rs:65-88]()) before instantiating a valid SynapticGraph. The validation suite enforces the following checks:
-
Row Pointer Monotonicity & Length:
validate_row_ptrensuresrow_ptrhas lengthneuron_count + 1, starts at0, and is non-decreasing ([src/topology/graph.rs:93-111]()). -
Edge Array Alignment:
validate_edge_array_lengthsconfirms thattargets,weights,delays, andpolaritiesall have lengths exactly equal to the total non-zero edge count (nnz) given by the final entry ofrow_ptr([src/topology/graph.rs:114-126]()). -
Target Bounds:
validate_targets_in_boundsguarantees all target neuron IDs fall within[0, neuron_count)([src/topology/graph.rs:129-137]()). -
Finite Weights:
validate_weights_finiterejectsNaNor infinite weights ([src/topology/graph.rs:142-147]()). -
Polarity Agreement:
validate_weights_agree_with_polaritiesensures that signed weights agree with their assignedPolarity(excitatory weights must be$\ge 0$ , inhibitory weights must be$\le 0$ ) ([src/topology/graph.rs:149-161],[src/types.rs:105-113]()).
graph TD
Deserialization["RawSynapticGraph Deserialization"] --> VR["validate_row_ptr"]
VR --> VE["validate_edge_array_lengths"]
VE --> VT["validate_targets_in_bounds"]
VT --> VW["validate_weights_finite"]
VW --> VP["validate_weights_agree_with_polarities"]
VP -->|All Valid| SG["SynapticGraph Ready"]
VP -->|Failure| Err["Deserialization Error"]
Sources: src/topology/graph.rs:50-89, src/topology/graph.rs:93-161, src/types.rs:105-113
The size of a SynapticGraph is bounded by available system memory and integer type capacities:
- Neuron IDs are represented by
NeuronId(u32), limiting networks to$2^{32}-1$ neurons ([src/types.rs:14]()). - Axonal delays are represented by
DelayTicks(u16), bounding maximum delays to$65,535$ simulation ticks ([src/types.rs:18]()). - Row pointer allocations check for overflow during network scaling using checked arithmetic via
neuron_count.checked_add(1)([src/topology/graph.rs:94-96]()).
The flat vector design of SynapticGraph (row_ptr, targets, weights, delays, polarities) maps directly to GPU memory layouts (such as CUDA or OpenCL buffers). Because all sparse connections are stored contiguously in standard Vec<T> buffers, they can be exported to device arrays or serialized via serde without pointer-chasing overhead.
Deserialization is guarded by RawSynapticGraph ([src/topology/graph.rs:50-57]()), which intercepts raw deserialized streams to run comprehensive structural validation before releasing the object to runtime code ([src/topology/graph.rs:163-172]()).
Sources: src/topology/graph.rs:33-89, src/topology/graph.rs:163-172
- 1. Overview
- 1.1. Getting Started & Public API
- 1.2. Release History and Versioning
- 2. Core Runtime: SynapticMesh
- 2.1. Propagation APIs and Tick Semantics
- 2.2. Spike Delay Buffer (Ring Buffer)
- 2.3. Core Types and Error Model
- 2.4. Checkpointing and Serde State Restoration
- 3. Topology Subsystem
- 3.1. SynapticGraph and CSR Representation
- 3.2. Topology Generators
- 3.3. Wiring Rules, Dale's Law and Delay Assignment
- 3.4. Topology Digest
- 4. Sparse Maps and Channel Routing
- 4.1. ChannelRouter and RouterConfig
- 4.2. Neuromodulation and Plasticity
- 4.3. SparseSynapticMap (CSR)
- 5. Testing, Benchmarks and Quality Gates
- 5.1. Propagation Contract Tests
- 5.2. Checkpoint Resume Property Suite
- 5.3. Benchmarks and Unit Test Module
- 6. Build, CI and Project Tooling
- 6.1. Cargo Manifest, Profiles and Dependencies
- 6.2. CI Workflows and Packaging Validation
- 6.3. Code Quality, Licensing and Review Gates
- 7. Glossary