Skip to main content

BspEngine

Struct BspEngine 

Source
pub struct BspEngine<S = ()> { /* private fields */ }
Expand description

The dynamic scheduler that organizes nodes into supersteps and executes them concurrently (bounded), re-executing nodes as loops deliver new activation tokens.

S is the consumer-owned run state; it defaults to () for pure dataflow graphs.

Implementations§

Source§

impl<S> BspEngine<S>

Source

pub fn new(graph: BspGraph<S>) -> Self

Instantiates a new BSP engine using a compiled graph layout.

Source

pub fn with_context(self, ctx: BspContext) -> Self

Attaches a shared execution context for dependency injection.

Source

pub const fn context(&self) -> &BspContext

Returns a reference to the active execution context.

Source

pub const fn graph(&self) -> &BspGraph<S>

The graph this engine runs.

Source

pub fn with_interceptor(self, interceptor: Arc<dyn BspInterceptor>) -> Self

Attaches a performance and audit logging interceptor.

Source

pub const fn with_max_concurrency(self, limit: usize) -> Self

Configures the maximum concurrency (throttling limit) for task execution within a superstep.

The throttle is scoped to this engine instance (buffer_unordered per superstep); a nested graph-as-node runs a child engine with its own independent throttle, so nesting can never deadlock or halve capacity per level.

Source

pub const fn with_max_steps(self, steps: u64) -> Self

Configures the global superstep budget. Exceeding it yields EngineResult::StepLimitReached with the live run state — never a silent salvage.

Source

pub const fn with_max_pending_tokens(self, cap: u64) -> Self

Configures the per-edge pending-token cap (token-flood guard).

Source

pub fn with_branch_transform(self, transform: BranchTransform<S>) -> Self

Attaches a transform applied to each branch state clone at multi-node frontier formation, right after the clone is taken from the trunk.

The second argument is the branch’s ordinal within the frontier formation (declaration order, 0-based). This is the hook for fork-fan-out semantics where sibling clones must not all inherit the full trunk — the reference consumer (llm-net) zeroes branch metrics for every sibling after the first so boundary rollups never double-count the parent’s history.

The default (None) is the identity: every branch is an exact clone. The transform never runs for single-node frontiers (they borrow the trunk directly) or on the sequential path (run_sequential does no branch cloning).

Source

pub fn validate(&self) -> Result<(), BspError>

Validates the graph (errors only), looking for unfireable cycles, missing links, invalid port configurations, and unregistered condition/merger references.

Source

pub fn validate_with_report(&self) -> ValidationReport

Validates the graph, additionally returning non-fatal warnings (loop-aware analysis: unbounded cycles, unreachable nodes, dead ends, All-joins on cycles, joins without mergers).

Source§

impl<S: Clone> BspEngine<S>

Source

pub async fn run(&self, state: S) -> Result<EngineResult<S>, BspError>

Initiates a clean run of the graph with the given initial consumer state (run(()) for pure dataflow graphs).

Requires S: Clone because concurrent frontiers execute against per-task clones (see the module docs); single-node frontiers borrow the trunk directly. For !Clone states, use BspEngine::run_sequential.

Source

pub async fn run_with_entries( &self, state: S, entries: impl IntoIterator<Item = NodeId>, ) -> Result<EngineResult<S>, BspError>

Like BspEngine::run, but forces the given nodes as the run’s entry frontier instead of the graph’s declared entries.

This is the resumable-control-flow primitive for hosts that checkpoint only the consumer state S (not the engine’s SuspendedExecution snapshot): resuming is “start a fresh run forced at the recorded cursor node(s)”, exactly the model the reference consumer’s resume_at graph cursor uses. Forced nodes join the first frontier unconditionally, even when their incoming edges hold no tokens.

Source

pub async fn resume( &self, suspended: SuspendedExecution<S>, injections: IndexMap<InputPin, BspValue>, ) -> Result<EngineResult<S>, BspError>

Resumes a suspended graph execution, injecting external values into the waiting ports. Iteration and execution counters continue — they never reset.

Source§

impl<S> BspEngine<S>

Source

pub async fn run_sequential( &self, state: S, ) -> Result<EngineResult<S>, BspError>

Like BspEngine::run but without a Clone bound on S: frontier tasks execute sequentially, each borrowing the trunk state. Linear chains and loops behave identically; parallel frontiers serialize and share the trunk in declaration order (no isolation, no merging).

Source

pub async fn resume_sequential( &self, suspended: SuspendedExecution<S>, injections: IndexMap<InputPin, BspValue>, ) -> Result<EngineResult<S>, BspError>

Sequential counterpart of BspEngine::resume for !Clone states.

Auto Trait Implementations§

§

impl<S = ()> !Freeze for BspEngine<S>

§

impl<S = ()> !RefUnwindSafe for BspEngine<S>

§

impl<S = ()> !UnwindSafe for BspEngine<S>

§

impl<S> Send for BspEngine<S>
where BspGraph<S>: Send, Option<Arc<dyn Fn(&mut S, usize) + Send + Sync>>: Send,

§

impl<S> Sync for BspEngine<S>
where BspGraph<S>: Sync, Option<Arc<dyn Fn(&mut S, usize) + Send + Sync>>: Sync,

§

impl<S> Unpin for BspEngine<S>
where BspGraph<S>: Unpin, Option<Arc<dyn Fn(&mut S, usize) + Send + Sync>>: Unpin,

§

impl<S> UnsafeUnpin for BspEngine<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more