Skip to main content

Xircuits Context

Aside from passing data between components by connecting the outPort to inPort, data can be passed between components via Context (ctx). This is useful for variables that are constantly used in most if not all components (such as SparkSession in Spark Xircuits), so you don't have to link it multiple times.

  • The ctx is added to the base component execute() method.
  • A component that would like to pass data to the context can be treated as a dict, and would be implemented as the following:
from xai_components.base import Component, xai_component
class HelloContext(Component):

def execute(self, ctx):
context_dict = {"new ctx": "Hello Xircuits!"}
  • In codegen, by default ctx will contain the Xircuits args and hyperparameters.
# python --epoch=554
{'args': Namespace(epoch=554, experiment_name='2022-04-22 16:13:40')}