lenskit.pipeline.components#
Definition of the component interfaces.
Attributes#
Pure-function interface for pipeline functions. |
Classes#
Representation of a component input slot. |
|
Protocol for component constructors. |
|
Base class for pipeline component objects. Any component that is not just a |
|
Configuration for the placeholder component. |
|
Simple no-op component to use as a placeholder in partial pipelines. |
Functions#
|
|
|
|
|
Fallback to a second component if the primary input is None. |
|
Check if the provided object is a component class. |
Module Contents#
- type lenskit.pipeline.components.PipelineFunction = Callable[..., COut]#
Pure-function interface for pipeline functions.
- class lenskit.pipeline.components.ComponentInput#
Representation of a component input slot.
- type: ComponentInput.type | None = None#
- class lenskit.pipeline.components.ComponentConstructor[CFG, COut]#
Bases:
ProtocolProtocol for component constructors.
- validate_config(data=None)#
- Parameters:
data (Any)
- Return type:
CFG | None
- class lenskit.pipeline.components.Component[COut](config=None, **kwargs)#
Bases:
abc.ABCBase class for pipeline component objects. Any component that is not just a function should extend this class.
Pipeline components support configuration (e.g., hyperparameters or random seeds) through Pydantic models or Python dataclasses; see Configuring Components for further details. If the pipeline’s configuration class is
C, it has the following:The configuration is exposed through an instance variable
config.The constructor accepts the configuration object as its first parameter, also named
config, and saves this in the member variable.
The base class constructor handles both of these, so long as you declare the type of the
configmember:class MyComponent(Component): config: MyComponentConfig ...
If you do not declare a
configattribute, the base class will assume the pipeline uses no configuration.To work as components, derived classes also need to implement a
__call__method to perform their operations.- Parameters:
config (object | None) – The configuration object. If
None, the configuration class will be instantiated withkwargs.kwargs (Any)
- Stability:
- Full (see Stability Levels).
- config: Any = None#
The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.
- classmethod __init_subclass__(**kwargs)#
- Parameters:
kwargs (Any)
- dump_config()#
Dump the configuration to JSON-serializable format.
- classmethod validate_config(data=None)#
Validate and return a configuration object for this component.
- abstractmethod __call__(*args, **kwargs)#
Run the pipeline’s operation and produce a result. This is the key method for components to implement.
- Parameters:
args (Ellipsis)
kwargs (Ellipsis)
- Return type:
COut
- class lenskit.pipeline.components.PlaceholderConfig#
Bases:
pydantic.BaseModelConfiguration for the placeholder component.
- class lenskit.pipeline.components.Placeholder(config=None, **kwargs)#
Bases:
Component[Any]Simple no-op component to use as a placeholder in partial pipelines.
- Parameters:
config (object | None)
kwargs (Any)
- config: PlaceholderConfig#
The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.
- abstractmethod __call__(**kwargs)#
Run the pipeline’s operation and produce a result. This is the key method for components to implement.
- Parameters:
kwargs (Any)
- Return type:
Any
- lenskit.pipeline.components.component_inputs[COut](component, *, warn_on_missing=True, _warn_level=1)#
- Parameters:
component (Component[COut] | ComponentConstructor[Any, COut] | PipelineFunction[COut])
warn_on_missing (bool)
_warn_level (int)
- Return type:
- lenskit.pipeline.components.component_return_type[COut](component)#
- Parameters:
component (Component[COut] | ComponentConstructor[Any, COut] | PipelineFunction[COut])
- Return type:
type[COut] | None
- lenskit.pipeline.components.fallback_on_none[T](primary, fallback)#
Fallback to a second component if the primary input is None.
- Stability:
- Caller (see Stability Levels).
- Parameters:
primary (T)
fallback (lenskit.lazy.Lazy[T])
- Return type:
T
Exported Aliases#
- exception lenskit.pipeline.components.PipelineWarning#
Re-exported alias for
lenskit.diagnostics.PipelineWarning.
- class lenskit.pipeline.components.Lazy#
Re-exported alias for
lenskit.lazy.Lazy.
- exception lenskit.pipeline.components.TypecheckWarning#
Re-exported alias for
lenskit.pipeline._types.TypecheckWarning.
- lenskit.pipeline.components.is_compatible_data()#
Re-exported alias for
lenskit.pipeline._types.is_compatible_data().