Repository navigation
4.2 Batch Data Types
Relevant source files
The following files were used as context for generating this wiki page:
This page provides a technical reference for the data structures used to encapsulate neural activity, training gradients, and configuration updates within the corpus-ipc framework. These types serve as the payload for the IpcMessage protocol, facilitating communication between the Rust compute environment and external backends.
The corpus-ipc library utilizes a batch-centric approach to data transmission to minimize IPC overhead. Every data structure designed for neural signal transport includes mechanisms for session isolation and temporal correlation.
Most batch types share two critical fields for managing asynchronous data flow:
-
session_id: Used for concurrent experiment isolation. In input batches (Rust → External), this is anOption<String>src/models/spikes.rs:31, whereNonesignifies a global context. In output batches (External → Rust), it is a mandatoryStringsrc/models/traces.rs:28 orOption<String>to ensure data is routed back to the correct experiment or session. -
batch_id: Au64unique identifier used to correlate outputs (like gradients or traces) with the original input spikes or embeddings that triggered them src/models/spikes.rs:33, src/models/traces.rs:30, src/models/embeddings.rs:19.
The following diagram illustrates how high-level neural concepts map to specific Rust structs defined in the codebase.
Neural Space to Code Entity Mapping
graph TD
subgraph "Natural Language Space"
A["Neural Spiking Activity"]
B["Latent Representations"]
C["Learning Gradients"]
D["Credit Assignment"]
E["System Tuning"]
end
subgraph "Code Entity Space (src/models/)"
A --> S["struct SpikeBatch"]
S --> SE["struct SpikeEvent"]
B --> EB["struct EmbeddingBatch"]
C --> GB["struct GradientBatch"]
GB --> GU["struct GradientUpdate"]
D --> TB["struct TraceBatch"]
TB --> TD["struct TraceData"]
E --> CP["struct ConfigPayload"]
CP --> CV["enum ConfigValue"]
end
Sources: src/models/spikes.rs:14-100, src/models/traces.rs:13-93, src/models/embeddings.rs:12-24, src/models/gradients.rs:15-89, src/models/config.rs:14-114
These types represent the primary feed-forward signals sent from the Rust compute layer to the external runtime via the IpcMessage enum.
SpikeBatch aggregates discrete neural events. Each SpikeEvent represents a single activation on a specific channel src/models/spikes.rs:14-39.
To avoid name collisions with in-memory training batches of spike trains (spikes / times / targets) that other libraries also call SpikeBatch (the rustdoc stopped naming SynapticDistill.jl in #68), corpus-ipc defines an explicit type alias IpcSpikeBatch = SpikeBatch src/models/spikes.rs:20-26, src/models/spikes.rs:82-86.
| Field | Type | Description |
|---|---|---|
session_id |
Option<String> |
Isolation ID for multi-tenant environments src/models/spikes.rs:31. |
batch_id |
u64 |
Correlation ID for tracking this specific set of spikes src/models/spikes.rs:33. |
timestamp |
u64 |
Nanosecond timestamp (UTC or relative) src/models/spikes.rs:35. |
spikes |
Vec<SpikeEvent> |
A collection of individual spike occurrences src/models/spikes.rs:37. |
metadata |
Option<BatchMetadata> |
Diagnostic info like processing latency src/models/spikes.rs:39. |
SpikeEvent Details:
-
channel(u16): The identifier for the neuron or input channel src/models/spikes.rs:95. -
time(u32): The offset or absolute time of the spike src/models/spikes.rs:97. -
strength(f32): The amplitude/magnitude of the spike src/models/spikes.rs:99.
Used for high-dimensional vectors, typically for projector and transformer components src/models/embeddings.rs:12-24.
-
embedding: AVec<f32>containing the raw vector data src/models/embeddings.rs:21. -
sequence_length: Ausizefield ensuring compatibility with sequence-aware models src/models/embeddings.rs:23.
Sources: src/models/spikes.rs:14-100, src/models/embeddings.rs:12-24
These types are generated by the external backend and sent back to Rust for weight updates and credit assignment.
GradientBatch carries weight updates derived from training algorithms src/models/gradients.rs:15-25. It contains a vector of GradientUpdate structs, each targeting a specific layer src/models/gradients.rs:79-89.
-
layer_id: AStringidentifying the target layer src/models/gradients.rs:84. -
gradients: Flattened or sparseVec<f32>of gradient values src/models/gradients.rs:86. -
eligibility_trace: An optionalVec<f32>specifically for E-prop or STDP-based learning algorithms src/models/gradients.rs:88.
Used for credit assignment in spiking networks, providing decay-modulated spike history src/models/traces.rs:13-33. Like spike batches, an explicit alias IpcTraceBatch = TraceBatch prevents collisions with training-side batch types src/models/traces.rs:17-39.
-
channel_id:u16identifier (supportsneuron_idas a serde alias for backward wire compatibility) src/models/traces.rs:85-88. -
trace_value:f32representing the accumulated eligibility trace src/models/traces.rs:90. -
last_spike_time:u32timestamp of the last spike that contributed to this trace src/models/traces.rs:92.
Sources: src/models/gradients.rs:15-89, src/models/traces.rs:13-93
The ConfigPayload allows for runtime parameter updates (e.g., adjusting learning rates or thresholds) src/models/config.rs:14-22. It uses a HashMap<String, ConfigValue> src/models/config.rs:21.
The ConfigValue enum is untagged (#[serde(untagged)]), meaning the JSON representation is the raw value (e.g., 42.5 instead of {"Float": 42.5}) src/models/config.rs:89-91.
| Variant | Internal Type | Notes |
|---|---|---|
Float |
f32 |
First variant; catches all JSON numbers by default. Round-tripping integers through JSON often results in Float src/models/config.rs:92-96. |
Integer |
u64 |
Only reached for values that were originally Integer and serialized/deserialized in specific contexts src/models/config.rs:98-104. |
String |
String |
Raw JSON string src/models/config.rs:106-109. |
Boolean |
bool |
Raw JSON boolean src/models/config.rs:112. |
FloatArray |
Vec<f32> |
JSON array of numbers src/models/config.rs:113. |
Provides a side-channel for telemetry and debugging without altering the core neural data src/models/metadata.rs:11-21.
-
processing_latency_ns: Measures the time taken to generate the batch src/models/metadata.rs:16. -
source: A string like"encoder"or"snn_layer_2"to trace data provenance src/models/metadata.rs:18. -
custom: AHashMap<String, String>for arbitrary user-defined metadata src/models/metadata.rs:20.
Sources: src/models/config.rs:14-114, src/models/metadata.rs:11-21
The following diagram illustrates how batch_id and session_id are used to maintain state across the IPC boundary using the IpcMessage envelope.
Batch Correlation Sequence
sequenceDiagram
participant R as "IpcBackend (Rust)"
participant E as "External Backend"
Note over R: "Generates batch_id: 101"
R->>E: "IpcMessage::Spikes(SpikeBatch { batch_id: 101, .. })"
Note over E: "Processes spikes for batch 101"
E->>R: "IpcMessage::GradientUpdate(GradientBatch { batch_id: 101, .. })"
Note over R: "Applies gradients to batch 101 parameters"
Sources: src/models/spikes.rs:27-40, src/models/gradients.rs:16-25
- Home
- 1. Overview
- 1.1. Getting Started
- 1.2. Architecture Overview
- 1.3. Crate Exports and Module Map
- 2. Core Abstractions
- 2.1. IpcBackend Trait
- 2.2. HybridFlowBackend Trait
- 2.3. BackendFactory and BackendType
- 2.4. Error Handling
- 3. Backend Implementations
- 3.1. RustBackend
- 3.2. ZmqIpcBackend
- 3.3. ZMQ Readout Parsing and Golden Frames
- 3.4. Structured ZeroMQ IpcMessage Transport
- 4. IPC Protocol and Data Models
- 4.1. IpcMessage Protocol
- 4.2. Batch Data Types
- 4.3. NeuromodulatorSnapshot and Neuromodulator Packet
- 4.4. StimulusBatch and Runtime Ingress
- 4.5. Deserialization Hooks and Model Compat Aliases
- 5. Validation and Wire Compatibility
- 5.1. Validation Framework and ProtocolLimits
- 5.2. ValidationError and ValidationKind
- 5.3. WireCompatibility and Envelope Decoding
- 5.4. Canonical Wire-v1 Encoding
- 6. corpus_ipc_server HTTP Server
- 6.1. REST API Endpoints
- 6.2. Server Configuration and Deployment
- 7. Build, Dependencies, and Quality Gates
- 7.1. Cargo Features and Dependency Isolation
- 7.2. Testing Strategy
- 7.2.1. Wire-v1 Golden Test Vectors
- 7.2.2. Property-Based Wire Tests
- 7.3. CI, Coverage, and Release Qualification
- 8. Project History and Licensing
- 8.1. Naming History and Completed Renames
- 8.2. Licensing
- 9. Glossary