Repository navigation
3.1 RustBackend
Relevant source files
The following files were used as context for generating this wiki page:
The RustBackend is a native, pure-Rust implementation of the IpcBackend trait. Unlike the ZmqIpcBackend, it has no external dependencies and requires no external compute engine (e.g., Julia) to function. It serves as the default software fallback and a high-performance smoke-test stub for the corpus-ipc ecosystem.
The RustBackend is designed for three primary use cases:
- Smoke Testing: Validating the signal pipeline without the overhead of ZMQ or a running external environment.
- Push-Pull Encoding: Providing a reference implementation of a signal-to-spike encoding algorithm where positive and negative magnitudes are isolated into separate channels.
- Stateless Fallback: Serving as a "pass-through" model when complex neural dynamics are not required.
| Feature | Implementation Detail |
|---|---|
| Statefulness | Stateless; does not track internal membrane potentials or synaptic weights. |
| Complexity |
|
| Dependencies | None (Standard Library only). |
| Lifecycle | Requires explicit initialization via initialize() before processing. |
Sources: src/rust_backend.rs:3-17
The core logic of the RustBackend resides in its process_batch implementation. It transforms a continuous input vector into a push-pull encoded output vector of double the length.
For every input channel i in the inputs slice, the backend generates two output channels in the resulting Vec<f32>:
-
Positive Channel:
output[i * 2]. Captures positive magnitudes src/rust_backend.rs:44-46. -
Negative Channel:
output[i * 2 + 1]. Captures the absolute value of negative magnitudes src/rust_backend.rs:47-50.
The following diagram illustrates how the RustBackend::process_batch function maps input data to the encoded output vector.
graph TD
subgraph "Natural Language Space"
Input["Input Signals (f32)"]
Logic{"Encoding Logic"}
Output["Encoded Output (f32)"]
end
subgraph "Code Entity Space"
inputs["inputs: &[f32]"]
process["RustBackend::process_batch"]
output_vec["output: Vec<f32>"]
pos["Positive Channel (i*2)"]
neg["Negative Channel (i*2+1)"]
end
Input --> inputs
inputs --> process
process --> Logic
Logic -- "val > 0.0" --> pos
Logic -- "val <= 0.0" --> neg
pos --> output_vec
neg --> output_vec
output_vec --> Output
Sources: src/rust_backend.rs:9-11, src/rust_backend.rs:33-53, src/rust_backend.rs:89-106
The RustBackend maintains a simple internal state machine via the initialized boolean flag src/rust_backend.rs:16-16.
-
Creation:
RustBackend::new()src/rust_backend.rs:21-23 orRustBackend::default()src/rust_backend.rs:26-30 setsinitializedtofalse. -
Activation:
initialize(Option<&str>)src/rust_backend.rs:55-58 must be called to setinitializedtotrue. Themodel_pathargument is currently ignored as the backend is stateless. -
Validation: Every call to
process_batchchecks theinitializedflag src/rust_backend.rs:34-38. Iffalse, it returnsBackendError::InitializationError. -
Reset: Calling
reset()src/rust_backend.rs:69-75 setsinitializedback tofalse, requiring a newinitialize()call before further processing.
sequenceDiagram
participant App as "Application Logic"
participant RB as "RustBackend [src/rust_backend.rs]"
App->>RB: "new()"
Note over RB: initialized = false
App->>RB: "process_batch(inputs)"
RB-->>App: "Err(BackendError::InitializationError)"
App->>RB: "initialize(None)"
Note over RB: initialized = true
RB-->>App: "Ok(())"
App->>RB: "process_batch(inputs)"
Note over RB: Run Push-Pull Algorithm
RB-->>App: "Ok(output_vec)"
App->>RB: "reset()"
Note over RB: initialized = false
RB-->>App: "Ok(())"
Sources: src/rust_backend.rs:21-23, src/rust_backend.rs:33-38, src/rust_backend.rs:55-58, src/rust_backend.rs:69-75
Because the RustBackend is designed as a functional transform rather than a simulation, several IpcBackend trait methods are implemented as stubs:
-
save_state(&self, _model_path: &str): ReturnsOk(())immediately src/rust_backend.rs:60-62. Since there are no weights or membrane potentials, there is nothing to persist. -
get_spike_states(&self): Returns an emptyVec<bool>src/rust_backend.rs:64-67. It does not track discrete spike events over time. -
reset(&mut self): Clears theinitializedflag for consistency with other backends but performs no data clearing as the backend is stateless src/rust_backend.rs:69-75.
Sources: src/rust_backend.rs:60-75
The RustBackend includes a comprehensive test suite in src/rust_backend.rs that validates the encoding logic and lifecycle constraints.
| Test Function | Purpose |
|---|---|
process_before_init_returns_error |
Ensures the backend rejects signal processing if initialize() hasn't been called src/rust_backend.rs:83-86. |
positive_input_goes_to_even_channel |
Verifies that a value like 0.8 appears at index i*2 and index i*2+1 is 0.0 src/rust_backend.rs:89-96. |
negative_input_goes_to_odd_channel |
Verifies that a value like -0.5 appears as 0.5 (absolute value) at index i*2+1 and index i*2 is 0.0 src/rust_backend.rs:99-106. |
output_has_double_the_elements |
Confirms the output vector length is exactly |
spike_states_is_empty |
Confirms the stateless nature by checking for an empty spike vector src/rust_backend.rs:119-122. |
reset_clears_initialized_and_next_process_fails |
Verifies that reset() correctly forces a re-initialization requirement src/rust_backend.rs:125-132. |
Sources: src/rust_backend.rs:79-133
- 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