Skip to content

ComputeEngine API Reference

The ComputeEngine class is designed to process and execute computational flows defined by a set of blocks and flow schemas.

Class barfi.flow.ComputeEngine

Parameters

  • blocks (Union[List[Block], Dict[str, List[Block]]]): A collection of Block instances representing the components available for computation. Can be provided as:
    • A list of Block instances
    • A dictionary where keys are category names and values are lists of Block instances
  • execution_mode (Literal[“serial”, “parallel”]): The mode of execution for the flow. Options:
    • "parallel": Independent nodes (associated Block) are executed concurrently (default)
    • "serial": Nodes (associated Block) are executed sequentially

Example

from barfi.flow import Block, ComputeEngine
 
block1 = Block(name="block1")
block2 = Block(name="block2")
blocks = [block1, block2]
 
# Using default parallel execution mode
engine = ComputeEngine(blocks)
 
# Or specify serial execution mode
engine = ComputeEngine(blocks, execution_mode="serial")

Methods

execute(schema: FlowSchema) -> None

Executes a flow schema using the registered blocks.

Parameters

  • schema (FlowSchema): The flow schema to execute, containing block configurations and connections.

Raises

  • ValueError: If the schema contains invalid block references or connections.

Example

flow_schema = FlowSchema(...)
engine.execute(schema=flow_schema)