Skip to content
DocumentationComputeEngineComputeEngine

ComputeEngine

The ComputeEngine is responsible for executing the each Block’s compute function within a flow. It achieves this by constructing a computational graph from the flow, performing a topological sort to determine the evaluation order of the blocks, and then traversing the graph in this order. During execution, it evaluates each block’s compute function and sets the input values for the downstream blocks’ input interfaces, ensuring seamless data propagation and computation across the flow.

⚠️

Cycles in the schema cannot be evaluated at this moment. The derived compuation graph needs to be a Directed Acyclic Graph (DAG).

ComputeEngine Implementation Example

Initializing a ComputeEngine

To begin using the compute engine, you’ll need to initialize it with your block definitions. The ComputeEngine constructor takes a list of block classes that define the available computational components in your flow.

my_blocks.py
from barfi.flow import ComputeEngine
 
# ... existing code ...
 
# 01: Initialize a ComputeEngine
my_compute_engine = ComputeEngine(blocks=my_blocks)

Executing a flow schema

Once you have initialized the compute engine, you can execute a flow schema. The execute() method takes a flow schema as input and processes all blocks in the correct order based on their dependencies and sets the input values of the downstream blocks.

my_blocks.py
# 02: Execute the flow schema
my_compute_engine.execute(my_flow_schema)