Skip to main content

MatrixHook

Trait MatrixHook 

Source
pub trait MatrixHook: Send + Sync {
    // Required methods
    fn on_converge(
        &self,
        node_name: &str,
        actual_contribution: f64,
        surprise: f64,
        quality: f64,
    );
    fn route(&self, from: &str, candidates: &[String]) -> Option<Vec<String>>;
    fn c_value(&self) -> f64;
    fn completion(&self) -> f64;
    fn is_converged(&self) -> bool;
    fn record_transition(&self, from: &str, to: &str, quality: f64);
}
Expand description

Hook for the optional matrix layer.

Injected into the Pregel engine by pe-runtime when the matrix layer is active. The engine calls these methods at the right moments; the hook implementation does the actual convergence tracking and routing.

Send + Sync because the engine may run nodes in parallel.

§Thread safety

The hook is shared across the BSP loop (single-threaded per superstep) but must be Send + Sync to satisfy trait object requirements. Interior mutability (via Mutex) is expected since the BSP loop is sequential.

Required Methods§

Source

fn on_converge( &self, node_name: &str, actual_contribution: f64, surprise: f64, quality: f64, )

Called when a node returns NodeResult::Converge.

Records the convergence signal metadata. The engine has already extracted and applied the partial_update — this receives only the signal values (contribution, surprise, quality) and the originating node name.

Source

fn route(&self, from: &str, candidates: &[String]) -> Option<Vec<String>>

Resolve routing for a conditional edge using learned probabilities.

Called instead of the user’s router function when the matrix layer is active. from is the source node, candidates are the possible target nodes (from the conditional edge’s router output).

Returns the selected candidate(s). If this returns None, the engine falls back to the user’s router function (graceful degradation).

Source

fn c_value(&self) -> f64

Current C value (aggregate confidence).

Source

fn completion(&self) -> f64

Current completion estimate.

Source

fn is_converged(&self) -> bool

Whether convergence threshold has been reached.

Source

fn record_transition(&self, from: &str, to: &str, quality: f64)

Record that a transition occurred (for learning).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§