Skip to content

2.2 HybridFlowBackend Trait

Wiki Keeper (Grok Bot) edited this page Oct 16, 2026 · 2 revisions

HybridFlowBackend Trait

Optional message-oriented trait for structured spike/embedding exchange and non-blocking gradient/trace receive. Defined in src/trait_def.rs. It does not own the wire encoding; JSON implementors should decode with decode_ipc_message_json, then Validate.

Methods

Method Direction Payload IpcMessage variant
send_spikes Outbound SpikeBatch Spikes
send_embeddings Outbound EmbeddingBatch Embeddings
try_receive_gradients Inbound Option<GradientBatch> GradientUpdate
try_receive_traces Inbound Option<TraceBatch> EligibilityTraces

Stimuli, neuromodulators, loss, config, and control variants are real IpcMessage values on a generic structured transport; they are not methods of this trait. Observing one on a receive call returns BackendError::Protocol (ProtocolError::UnexpectedVariant) instead of discarding the frame.

Ok(None) means nothing queued right now. InvalidInput is payload validation failure. CommunicationError covers framing, version, transport, and structural JSON decode failures.

In-repository implementor (zmq)

With feature zmq, ZmqHybridFlowBackend implements this trait over ZmqMessagePublisher / ZmqMessageSubscriber (one canonical JSON envelope per ZeroMQ message). See #55 / 08d2f28.

ZmqIpcBackend does not implement HybridFlowBackend. It is the binary [i64 tick][N × f32 LE] readout subscriber only.

classDiagram
    class IpcBackend {
        <<trait>>
        +initialize()
        +process_batch()
        +save_state()
        +get_spike_states()
        +reset()
    }
    class HybridFlowBackend {
        <<trait>>
        +send_spikes()
        +send_embeddings()
        +try_receive_gradients()
        +try_receive_traces()
    }
    class RustBackend
    class ZmqIpcBackend
    class ZmqHybridFlowBackend
    IpcBackend <|.. RustBackend
    IpcBackend <|.. ZmqIpcBackend
    HybridFlowBackend <|.. ZmqHybridFlowBackend
Loading

Message flow

flowchart LR
  subgraph Outbound
    Spikes["send_spikes"] --> Sp["IpcMessage::Spikes"]
    Emb["send_embeddings"] --> Em["IpcMessage::Embeddings"]
  end
  subgraph Inbound
    Gu["IpcMessage::GradientUpdate"] --> Rg["try_receive_gradients"]
    Tr["IpcMessage::EligibilityTraces"] --> Rt["try_receive_traces"]
  end
  Sp --> Peer["Peer engine"]
  Em --> Peer
  Peer --> Gu
  Peer --> Tr
Loading

Sources: src/trait_def.rs, src/zmq_message/hybrid.rs

Clone this wiki locally