lenskit.pipeline#
LensKit pipeline abstraction.
Submodules#
Definition of the component interfaces. |
|
Pydantic models for pipeline configuration and serialization support. |
|
Node objects used to represent pipelines internally. It is very rare |
Attributes#
Classes#
Builder for LensKit recommendation pipelines. Pipelines |
|
A cache to share components between pipelines. |
|
Builder to help assemble common pipeline patterns. |
|
Inspect or process data as it passes to a component's input. |
|
LensKit recommendation pipeline. This is the core abstraction for using |
|
Collect pipeline run statistics for profiling pipeline executions. |
|
Interface for creating recording pipeline run profiling information. |
|
Full results of running a pipeline. A pipeline state is a dictionary |
Functions#
|
Create a pipeline that predicts ratings, but does not include any |
|
Create a pipeline that produces top-N recommendations using a scoring model. |
Package Contents#
- class lenskit.pipeline.PipelineBuilder(name=None, version=None)#
Builder for LensKit recommendation pipelines. Pipelines are the core abstraction for using LensKit models and other components to produce recommendations in a useful way. They allow you to wire together components in (mostly) abitrary graphs, train them on data, and serialize the resulting pipelines to disk for use elsewhere.
The builder configures and builds pipelines that can then be run. If you have a scoring model and just want to generate recommenations with a default setup and minimal configuration, see
topn_pipeline()orRecPipelineBuilder.- Parameters:
- Stability:
- Caller (see Stability Levels).
- classmethod from_pipeline(pipeline)#
Create a builder initialized with a pipeline’s internal state. See
Pipeline.modify()for details — that is the main entry point, and this method exists to be the implementation of that method.- Parameters:
pipeline (lenskit.pipeline._impl.Pipeline)
- Return type:
- meta(*, include_hash=True)#
Get the metadata (name, version, hash, etc.) for this pipeline without returning the whole config.
- Parameters:
include_hash (bool) – Whether to include a configuration hash in the metadata.
- Return type:
- nodes()#
Get the nodes in the pipeline graph.
- Return type:
- node(node: str, *, missing: Literal['error'] = 'error') lenskit.pipeline.nodes.Node[object]#
- node(node: str, *, missing: Literal['none'] | None) lenskit.pipeline.nodes.Node[object] | None
- node(node: lenskit.pipeline.nodes.Node[T]) lenskit.pipeline.nodes.Node[T]
Get the pipeline node with the specified name. If passed a node, it returns the node or fails if the node is not a member of the pipeline.
- Parameters:
node – The name of the pipeline node to look up, or a node to check for membership.
- Returns:
The pipeline node, if it exists.
- Raises:
KeyError – The specified node does not exist.
- property default_node: lenskit.pipeline.nodes.Node[Any] | None#
Get the default node for this pipeline.
- Return type:
lenskit.pipeline.nodes.Node[Any] | None
- create_input[T](name, *types)#
Create an input node for the pipeline. Pipelines expect their inputs to be provided when they are run.
- Parameters:
name (str) – The name of the input. The name must be unique in the pipeline (among both components and inputs).
types (type[T] | types.UnionType | None) – The allowable types of the input; input data can be of any specified type. If
Noneis among the allowed types, the input can be omitted.
- Returns:
A pipeline node representing this input.
- Raises:
ValueError – a node with the specified
namealready exists.- Return type:
- literal[T](value, *, name=None)#
Create a literal node (a node with a fixed value).
Note
Literal nodes cannot be serialized witih
get_config()orsave_config().- Parameters:
value (T)
name (str | None)
- Return type:
- default_connection(name, node)#
Set the default wiring for a component input. Components that declare an input parameter with the specified
namebut no configured input will be wired to this node.This is intended to be used for things like wiring up user parameters to semi-automatically receive the target user’s identity and history.
Important
Defaults are a feature of the builder only, and are resolved in
build(). They are not included in serialized configuration or resulting pipeline.- Parameters:
name (str) – The name of the parameter to set a default for.
node (lenskit.pipeline.nodes.Node[Any] | object) – The node or literal value to wire to this parameter.
- Return type:
None
- default_component(node)#
Set the default node for the pipeline. If
Pipeline.run()is called without a node, then it will run this node (and all of its dependencies).- Parameters:
node (str | lenskit.pipeline.nodes.Node[Any])
- Return type:
None
- remove_alias(alias, *, exist_ok=False)#
Remove an alias from the builder.
- alias(alias, node, *, replace=False)#
Create an alias for a node. After aliasing, the node can be retrieved from
node()using either its original name or its alias.- Parameters:
alias (str) – The alias to add to the node.
node (lenskit.pipeline.nodes.Node[Any] | str) – The node (or node name) to alias.
replace (bool) – If
True, replace the alias if one already exists.
- Raises:
ValueError – if the alias is already used as an alias or node name.
- Return type:
None
- add_component[CFG, T](name: str, cls: lenskit.pipeline.components.ComponentConstructor[CFG, T], config: CFG = None, /, **inputs: lenskit.pipeline.nodes.Node[Any]) lenskit.pipeline.nodes.Node[T]#
- add_component(name: str, instance: lenskit.pipeline.components.Component[T] | lenskit.pipeline.components.PipelineFunction[T], /, **inputs: lenskit.pipeline.nodes.Node[Any] | object) lenskit.pipeline.nodes.Node[T]
Add a component and connect it into the graph.
- Parameters:
name – The name of the component in the pipeline. The name must be unique in the pipeline (among both components and inputs).
cls – A component class.
config – The configuration object for the component class.
instance – A raw function or pre-instantiated component.
inputs – The component’s input wiring. See Connections for details.
- Returns:
The node representing this component in the pipeline.
- replace_component[CFG, T](name: str | lenskit.pipeline.nodes.Node[T], cls: lenskit.pipeline.components.ComponentConstructor[CFG, T], config: CFG = None, /, **inputs: lenskit.pipeline.nodes.Node[Any]) lenskit.pipeline.nodes.Node[T]#
- replace_component(name: str | lenskit.pipeline.nodes.Node[T], instance: lenskit.pipeline.components.Component[T] | lenskit.pipeline.components.PipelineFunction[T], /, **inputs: lenskit.pipeline.nodes.Node[Any] | object) lenskit.pipeline.nodes.Node[T]
Replace a component in the graph. The new component must have a type that is compatible with the old component. Both input and output connections are retained, except for those overridden with with keyword arguments.
- Parameters:
name – The name or node to replace.
comp – The component or constructor to use instead of the current node’s component.
config – A configuration for the component (if passed as a class or constructor).
inputs – New input wiring(s) for the new component.
- connect(obj, **inputs)#
Provide additional input connections for a component that has already been added. See Connections for details.
- Parameters:
obj (str | lenskit.pipeline.nodes.Node[Any]) – The name or node of the component to wire.
inputs (lenskit.pipeline.nodes.Node[Any] | str | object) – The component’s input wiring. For each keyword argument in the component’s function signature, that argument can be provided here with an input that the pipeline will provide to that argument of the component when the pipeline is run.
- clear_inputs(node)#
Remove input wirings for a node.
- Parameters:
node (str | lenskit.pipeline.nodes.Node[Any]) – The node whose input wiring should be removed.
- add_run_hook(name, hook, *, priority=1)#
Add a hook to be called when the pipeline is run (see Pipeline Hooks).
- Parameters:
name (Literal['component-input']) – The name of the hook to add a handler for.
hook (lenskit.pipeline._hooks.ComponentInputHook) – The hook function to run.
priority (int) – The hook priority. Hooks are run in ascending priority, and hooks with the same priority are run in the order they are added. LensKit’s built-in hooks run at priority 0.
- Return type:
None
- validate()#
Check the built pipeline for errors.
- clone()#
Clone the pipeline builder. The resulting builder starts as a copy of this builder, and any subsequent modifications only the copy to which they are applied.
- Return type:
- build_config(*, include_hash=True)#
Get this pipeline’s configuration for serialization. The configuration consists of all inputs and components along with their configurations and input connections. It can be serialized to disk (in JSON, YAML, or a similar format) to save a pipeline.
The configuration does not include any trained parameter values, although the configuration may include things such as paths to checkpoints to load such parameters, depending on the design of the components in the pipeline.
Note
Literal nodes (from
literal(), or literal values wired to inputs) cannot be serialized, and this method will fail if they are present in the pipeline.- Parameters:
include_hash (bool)
- Return type:
- config_hash()#
Get a hash of the pipeline’s configuration to uniquely identify it for logging, version control, or other purposes.
The hash format and algorithm are not guaranteed, but hashes are stable within a LensKit version. For the same version of LensKit and component code, the same configuration will produce the same hash, so long as there are no literal nodes. Literal nodes will usually hash consistently, but since literals other than basic JSON values are hashed by pickling, hash stability depends on the stability of the pickle bytestream.
In LensKit 2025.1, the configuration hash is computed by computing the JSON serialization of the pipeline configuration without a hash and returning the hex-encoded SHA256 hash of that configuration.
- Return type:
- classmethod load_config(cfg_file)#
Load a pipeline from a saved configuration file.
- Parameters:
cfg_file (pathlib.Path | os.PathLike[str]) – The path to a TOML, YAML, or JSON file containing the pipeline configuration.
- Returns:
The consructed pipeline.
- Return type:
See also
from_config()for the actual pipeline instantiation logic.
- classmethod from_config(config, *, file_path=None)#
Reconstruct a pipeline builder from a serialized configuration.
- Parameters:
config (object) – The configuration object, as loaded from JSON, TOML, YAML, or similar. Will be validated into a
PipelineConfig.file_path (pathlib.Path | None)
- Returns:
The configured (but not trained) pipeline.
- Raises:
PipelineError – If there is a configuration error reconstructing the pipeline.
- Warns:
PipelineWarning – If the configuration is funny but usable; for example, the configuration includes a hash but the constructed pipeline does not have a matching hash.
- Return type:
- apply_config(config, *, extend=False, check_hash=False)#
Apply a configuration to this builder.
- Parameters:
config (lenskit.pipeline.config.PipelineConfig) – The pipeline configuration to apply.
extend (bool) – Whether the configuration should extend the current pipeline, or fail when there are conflicting definitions.
check_hash (bool)
- use_first_of[T](name, primary, fallback)#
Ergonomic method to create a new node that returns the result of its
inputif it is provided and notNone, and otherwise returns the result offallback. This method is used for things like filling in optional pipeline inputs. For example, if you want the pipeline to take candidate items through anitemsinput, but look them up from the user’s history and the training data ifitemsis not supplied, you would do:pipe = Pipeline() # allow candidate items to be optionally specified items = pipe.create_input('items', list[EntityId], None) # find candidates from the training data (optional) lookup_candidates = pipe.add_component( 'select-candidates', TrainingItemsCandidateSelector(), user=history, ) # if the client provided items as a pipeline input, use those; otherwise # use the candidate selector we just configured. candidates = pipe.use_first_of('candidates', items, lookup_candidates)
Note
This method does not distinguish between an input being unspecified and explicitly specified as
None.Note
This method does not implement item-level fallbacks, only fallbacks at the level of entire results. For item-level score fallbacks, see
FallbackScorer.Note
If one of the fallback elements is a component
Athat depends on another component or inputB, andBis missing or returnsNonesuch thatAwould usually fail, thenAwill be skipped and the fallback will move on to the next node. This works with arbitrarily-deep transitive chains.- Parameters:
name (str) – The name of the node.
primary (lenskit.pipeline.nodes.Node[T | None]) – The node to use as the primary input, if it is available.
fallback (lenskit.pipeline.nodes.Node[T]) – The node to use if the primary input does not provide a value.
- Return type:
- build(cache=None)#
Build the pipeline.
- Parameters:
cache (lenskit.pipeline._cache.PipelineCache | None) – The pipeline cache to use.
- Return type:
- class lenskit.pipeline.PipelineCache#
A cache to share components between pipelines.
This cache can be used by
PipelineBuilderto cache pipeline component instances between multiple pipelines using the same components with the same configuration.- get_cached(ctor, config)#
- Parameters:
ctor (lenskit.pipeline.components.ComponentConstructor[Any, Any])
config (object | None)
- cache(ctor, config, instance)#
- Parameters:
ctor (lenskit.pipeline.components.ComponentConstructor[Any, Any])
config (object | None)
instance (object)
- get_instance(ctor, config)#
Get a component instance from the cache, creating if it necessry.
- Parameters:
ctor (lenskit.pipeline.components.ComponentConstructor[Any, Any])
config (object | None)
- class lenskit.pipeline.RecPipelineBuilder#
Builder to help assemble common pipeline patterns.
This is a convenience class; you can always directly assemble a
Pipelineif this class’s behavior is inadquate.- Stability:
- Caller (see Stability Levels).
- scorer(score, config=None)#
Specify the scoring model.
- Parameters:
score (lenskit.pipeline.components.Component | lenskit.pipeline.components.ComponentConstructor)
config (object | None)
- ranker(rank=None, config=None, *, n=None)#
Specify the ranker to use. If
None, sets up aTopNRankerwithn=n.- Parameters:
rank (lenskit.pipeline.components.Component | lenskit.pipeline.components.ComponentConstructor | None)
config (object | None)
n (int | None)
- candidate_selector(sel, config=None)#
Specify the candidate selector component. The component should accept a query as its input and return an item list.
- Parameters:
sel (lenskit.pipeline.components.Component | lenskit.pipeline.components.ComponentConstructor)
config (object | None)
- predicts_ratings(*, transform=None, fallback=None)#
Specify that this pipeline will predict ratings, optionally providing a rating transformer and fallback scorer for the rating predictions.
- Parameters:
transform (lenskit.pipeline.components.Component | None) – A component to transform scores prior to returning them. If supplied, it will be applied to both primary scores and fallback scores.
fallback (lenskit.pipeline.components.Component | None) – A fallback scorer to use when the primary scorer cannot score an item. The fallback should accept
queryanditemsinputs, and return an item list.
- reranker(reranker, config=None)#
Specify a reranker to add to the pipeline.
- Parameters:
reranker (lenskit.pipeline.components.Component | lenskit.pipeline.components.ComponentConstructor) – The reranker to use in the pipeline.
config (object | None) – Configuration parameters to initialize the reranker if a reranker is specified.
- lenskit.pipeline.predict_pipeline(scorer, *, fallback=True, name=None)#
Create a pipeline that predicts ratings, but does not include any ranking capabilities. Mostly userful for testing and historical purposes. The resulting pipeline must be called with an item list.
- Stability:
- Caller (see Stability Levels).
- Parameters:
scorer (lenskit.pipeline.components.Component) – The scorer to use in the pipeline (it will added with the component name
scorer, see Component Names).fallback (bool | lenskit.pipeline.components.Component) – Whether to use a fallback predictor when the scorer cannot score. When configured, the scorer node is the scorer, and the rating-predictor node applies the fallback.
name (str | None) – The pipeline name.
- Return type:
- lenskit.pipeline.topn_pipeline(scorer, config=None, *, predicts_ratings=False, n=None, name=None)#
Create a pipeline that produces top-N recommendations using a scoring model.
- Stability:
- Caller (see Stability Levels).
- Parameters:
scorer (lenskit.pipeline.components.Component | lenskit.pipeline.components.ComponentConstructor) – The scorer to use in the pipeline (it will added with the component name
scorer, see Component Names).predicts_ratings (bool | Literal['raw']) – If
True, make set up to predict ratings (rating-predictor), usingscorerwith a fallback ofBiasScorer; if"raw", usescorerdirectly with no fallback.n (int | None) – The recommendation list length to configure in the pipeline.
name (str | None) – The pipeline name.
config (object | None)
- Return type:
- class lenskit.pipeline.ComponentInputHook#
Bases:
ProtocolInspect or process data as it passes to a component’s input.
As with all Pipeline Hooks, an input hook is a callable that is run at the appropriate stage of the input.
Component input hooks are installed under the name
component-input.- Stability:
Experimental
- __call__(node, input, value, **context)#
Inspect or process the component input data.
- Parameters:
node (lenskit.pipeline.nodes.ComponentInstanceNode[Any]) – The component node being invoked.
input_name – The name of the component’s input that will receive the data.
input_type – The type of data the component expects for this input, if one was specified in the component definition.
value (object) – The data value to be supplied. This is declared
object, because its type is not known or guaranteed in the genral case.context (Any) – Additional context variables, mostly for the use of internal hooks.
- Returns:
The value to pass to the component. For inspection-only hooks, this will just be
value; hooks can also substitute alternative values depending on application needs.- Return type:
Any
- type lenskit.pipeline.CloneMethod = Literal['config', 'pipeline-config']#
- class lenskit.pipeline.Pipeline(config, nodes, *, run_hooks)#
LensKit recommendation pipeline. This is the core abstraction for using LensKit models and other components to produce recommendations in a useful way. It allows you to wire together components in (mostly) abitrary graphs, train them on data, and serialize pipelines to disk for use elsewhere.
Pipelines should not be directly instantiated; they must be built with a
PipelineBuilderclass, or loaded from a configuration withfrom_config(). If you have a scoring model and just want to generate recommenations with a default setup and minimal configuration, seetopn_pipeline()orRecPipelineBuilder.Pipelines are also
Trainable, and train all trainable components.- Stability:
- Caller (see Stability Levels).
- Parameters:
config (Pipeline.__init__.config)
nodes (collections.abc.Iterable[lenskit.pipeline.nodes.Node[Any]])
run_hooks (lenskit.pipeline._hooks.RunHooks)
- property config: lenskit.pipeline.config.PipelineConfig#
Get the pipline configuration.
Important
Do not modify the configuration returned, or it will become out-of-sync with the pipeline and likely not behave correctly.
- Return type:
- meta()#
Get the metadata (name, version, hash, etc.) for this pipeline without returning the whole config.
- Return type:
- nodes()#
Get the nodes in the pipeline graph.
- Return type:
- node(node: str, *, missing: Literal['error'] = 'error') lenskit.pipeline.nodes.Node[object]#
- node(node: str, *, missing: Literal['none'] | None) lenskit.pipeline.nodes.Node[object] | None
- node(node: lenskit.pipeline.nodes.Node[T]) lenskit.pipeline.nodes.Node[T]
Get the pipeline node with the specified name. If passed a node, it returns the node or fails if the node is not a member of the pipeline.
- Parameters:
node – The name of the pipeline node to look up, or a node to check for membership.
- Returns:
The pipeline node, if it exists.
- Raises:
KeyError – The specified node does not exist.
- property default_node: lenskit.pipeline.nodes.Node[Any] | None#
Get the default node for this pipeline.
- Return type:
lenskit.pipeline.nodes.Node[Any] | None
- node_input_connections(node)#
Get the input wirings for a node.
- Parameters:
node (str | lenskit.pipeline.nodes.Node[Any])
- Return type:
Mapping[str, lenskit.pipeline.nodes.Node[Any]]
- component(node)#
Get the component at a particular node, if any.
- Parameters:
node (str | lenskit.pipeline.nodes.Node[Any])
- Return type:
object | None
- clone()#
Clone the pipeline, without its trained parameters.
- Returns:
A new pipeline with the same components and wiring, but fresh instances created by round-tripping the configuration.
- Return type:
- property config_hash: str#
Get a hash of the pipeline’s configuration to uniquely identify it for logging, version control, or other purposes.
The hash format and algorithm are not guaranteed, but is stable within a LensKit version. For the same version of LensKit and component code, the same configuration will produce the same hash, so long as there are no literal nodes. Literal nodes will usually hash consistently, but since literals other than basic JSON values are hashed by pickling, hash stability depends on the stability of the pickle bytestream.
In LensKit 2025.1, the configuration hash is computed by computing the JSON serialization of the pipeline configuration without a hash and returning the hex-encoded SHA256 hash of that configuration.
- Return type:
- static from_config(config, file_path=None)#
Reconstruct a pipeline from a serialized configuration.
- Parameters:
config (object) – The configuration object, as loaded from JSON, TOML, YAML, or similar. Will be validated into a
PipelineConfig.file_path (pathlib.Path | None) – The path of the file from which the configuration was read, when available.
- Returns:
The configured (but not trained) pipeline.
- Raises:
PipelineError – If there is a configuration error reconstructing the pipeline.
- Warns:
PipelineWarning – If the configuration is funny but usable; for example, the configuration includes a hash but the constructed pipeline does not have a matching hash.
- Return type:
- classmethod load_config(cfg_file)#
Load a pipeline from a saved configuration file.
- Parameters:
cfg_file (pathlib.Path | os.PathLike[str]) – The path to a TOML, YAML, or JSON file containing the pipeline configuration.
- Returns:
The consructed pipeline.
- Return type:
See also
from_config()for the actual pipeline instantiation logic.
- modify()#
Create a pipeline builder from this pipeline in order to modify it.
Pipelines cannot be modified in-place, but this method sets up a new builder that will create a modified copy of the pipeline. Unmodified component instances are reused as-is.
Note
Since default connections are applied in
build(), the modifying builder does not have default connections.- Return type:
- train(data, options=None)#
Trains the pipeline’s trainable components (those implementing the
Trainableinterface) on some training data.If the
retrainoption isFalse, this method will skip training components that are already trained (as reported by theis_trained()method).Random Number Generation
If
TrainingOptions.rngis set and is not a generator or bit generator (i.e. it is a seed), then this method wraps the seed in aSeedSequenceand callsspawn()to generate a distinct seed for each component in the pipeline.- Parameters:
data (lenskit.data.Dataset) – The dataset to train on.
options (lenskit.training.TrainingOptions | None) – The training options. If
None, default options are used.
- Return type:
None
- run(/, **kwargs: object) object#
- run(node: str, /, **kwargs: object) object
- run(nodes: tuple[str, Ellipsis], /, **kwargs: object) tuple[object, Ellipsis]
- run(node: lenskit.pipeline.nodes.Node[T], /, **kwargs: object) T
- run(nodes: tuple[lenskit.pipeline.nodes.Node[T1], lenskit.pipeline.nodes.Node[T2]], /, **kwargs: object) tuple[T1, T2]
- run(nodes: tuple[lenskit.pipeline.nodes.Node[T1], lenskit.pipeline.nodes.Node[T2], lenskit.pipeline.nodes.Node[T3]], /, **kwargs: object) tuple[T1, T2, T3]
- run(nodes: tuple[lenskit.pipeline.nodes.Node[T1], lenskit.pipeline.nodes.Node[T2], lenskit.pipeline.nodes.Node[T3], lenskit.pipeline.nodes.Node[T4]], /, **kwargs: object) tuple[T1, T2, T3, T4]
- run(nodes: tuple[lenskit.pipeline.nodes.Node[T1], lenskit.pipeline.nodes.Node[T2], lenskit.pipeline.nodes.Node[T3], lenskit.pipeline.nodes.Node[T4], lenskit.pipeline.nodes.Node[T5]], /, **kwargs: object) tuple[T1, T2, T3, T4, T5]
Run the pipeline and obtain the return value(s) of one or more of its components. See Execution for details of the pipeline execution model.
- Parameters:
nodes – The component(s) to run.
kwargs – The pipeline’s inputs, as defined with
create_input(). These are passed as-is torun_all(), so they can also contain auxillary options like _profile.
- Returns:
The pipeline result. If no nodes are supplied, this is the result of the default node. If a single node is supplied, it is the result of that node. If a tuple of nodes is supplied, it is a tuple of their results.
- Raises:
PipelineError – when there is a pipeline configuration error (e.g. a cycle).
ValueError – when one or more required inputs are missing.
TypeError – when one or more required inputs has an incompatible type.
other – exceptions thrown by components are passed through.
- run_all(*nodes, _profile=None, **kwargs)#
Run all nodes in the pipeline, or all nodes required to fulfill the requested node, and return a mapping with the full pipeline state (the data attached to each node). This is useful in cases where client code needs to be able to inspect the data at arbitrary steps of the pipeline. It differs from
run()in two ways:It returns the data from all nodes as a mapping (dictionary-like object), not just the specified nodes as a tuple.
If no nodes are specified, it runs all nodes. This has the consequence of running nodes that are not required to fulfill the last node (such scenarios typically result from using
use_first_of()).
- Parameters:
nodes (str | lenskit.pipeline.nodes.Node[Any]) – The nodes to run, as positional arguments (if no nodes are specified, this method runs all nodes).
_profile (lenskit.pipeline._profiling.ProfileSink | None) – A profiler to profile this pipeline run.
kwargs (object) – The pipeline inputs.
- Returns:
The full pipeline state, with
defaultset to the last node specified.- Return type:
- class lenskit.pipeline.PipelineProfiler(pipeline, file)#
Collect pipeline run statistics for profiling pipeline executions.
- Parameters:
pipeline (lenskit.pipeline._impl.Pipeline)
file (pathlib.Path)
- writer: csv.DictWriter[str]#
- output: TextIO#
- multiprocess()#
- Return type:
- close()#
- run_profiler()#
- __enter__()#
- __exit__(*args)#
- class lenskit.pipeline.ProfileSink#
Bases:
lenskit.logging.multiprocess.RecordSink[dict[str,float]],ProtocolInterface for creating recording pipeline run profiling information.
- multiprocess()#
Obtain a version of this sink that can be shared across processes.
- Return type:
- run_profiler()#
Get a profiler for a single run using this sink.
- Return type:
RunProfiler
- class lenskit.pipeline.PipelineState(state=None, aliases=None, default=None, meta=None)#
Bases:
collections.abc.Mapping[str,Any]Full results of running a pipeline. A pipeline state is a dictionary mapping node names to their results; it is implemented as a separate class instead of directly using a dictionary to allow data to be looked up by node aliases in addition to original node names (and to be read-only).
Client code will generally not construct this class directly.
- Stability:
Calller
- Parameters:
state (dict[str, Any] | None) – The pipeline state to wrap. The state object stores a reference to this dictionary.
aliases (dict[str, str] | None) – Dictionary of node aliases.
default (str | None) – The name of the default node (whose data should be returned by
default).meta (lenskit.pipeline.config.PipelineMeta | None) – The metadata for the pipeline generating this state.
- meta: lenskit.pipeline.config.PipelineMeta | None#
Pipeline metadata.
- property default: Any#
Return the data from of the default node (typically the last node run).
- Returns:
The data associated with the default node.
- Raises:
ValueError – if there is no specified default node.
- Return type:
Any
- property default_node: str | None#
Return the name of the default node (typically the last node run).
- Return type:
str | None
- __len__()#
Exported Aliases#
- exception lenskit.pipeline.PipelineError#
Re-exported alias for
lenskit.diagnostics.PipelineError.
- exception lenskit.pipeline.PipelineWarning#
Re-exported alias for
lenskit.diagnostics.PipelineWarning.
- class lenskit.pipeline.Lazy#
Re-exported alias for
lenskit.lazy.Lazy.
- class lenskit.pipeline.Component#
Re-exported alias for
lenskit.pipeline.components.Component.
- class lenskit.pipeline.ComponentConstructor#
Re-exported alias for
lenskit.pipeline.components.ComponentConstructor.
- lenskit.pipeline.PipelineFunction#
Re-exported alias for
lenskit.pipeline.components.PipelineFunction.
- class lenskit.pipeline.PipelineConfig#
Re-exported alias for
lenskit.pipeline.config.PipelineConfig.
- class lenskit.pipeline.Node#
Re-exported alias for
lenskit.pipeline.nodes.Node.