lenskit.batch.BatchPipelineRunner ================================= .. py:class:: lenskit.batch.BatchPipelineRunner(*, n_jobs = None, use_ray = None, profiler = None, batch_size = None) :canonical: lenskit.batch._runner.BatchPipelineRunner Apply a pipeline to a collection of test users. :Stability: Caller Argss: pipeline: The pipeline to evaluate. n_jobs: The number of parallel threads to use, or ``None`` for default defined by LensKit configuration and environment variables (see :ref:`parallel-config`). use_ray: Use Ray instead of threads to parallelize batch inference, overriding any option set in an environment variable or :file:`lenskit.toml`. batch_size: The batch size for multiprocess execution. If ``None``, a batch size based on the number of inputs is used, with a maximum batch size of 1000. .. py:attribute:: n_jobs :type: int .. py:attribute:: use_ray :type: bool .. py:attribute:: batch_size :type: int | None :value: None .. py:attribute:: profiler :type: lenskit.pipeline.PipelineProfiler | None .. py:attribute:: invocations :type: list[InvocationSpec] .. py:method:: add_invocation(inv) .. py:method:: score(component = 'scorer', *, output = 'scores') Request the batch run to generate test item scores. :param component: The name of the rating predictor component to run. :param output: The name of the results in the output dictionary. .. py:method:: predict(component = 'rating-predictor', *, output = 'predictions') Request the batch run to generate test item rating predictions. It is identical to :meth:`score` but with different defaults. :param component: The name of the rating predictor component to run. :param output: The name of the results in the output dictionary. .. py:method:: recommend(component = 'recommender', *, output = 'recommendations', **extra) Request the batch run to generate recomendations. :param component: The name of the recommender component to run. :param output: The name of the results in the output dictionary. :param extra: Extra inputs to the recommender. A common option is ``n``, the number of recommendations to return (a default may be baked into the pipeline). .. py:method:: run(pipeline, queries) Run the pipeline and collect its results. .. note:: The runner does **not** guarantee that results are in the same order as the original inputs. :param pipeline: The pipeline to run. :param queries: The collection of test queries use. See :ref:`batch-queries` for details on the various input formats. :returns: The batch results, mapping output names to item list collections of outputs. .. py:method:: run_iter(pipeline, queries) Run the pipeline and yield its results. This generator should be closed when it is done or the run is aborted, to ensure resources are properly cleaned up. The best way to use this method is as follows:: with closing(runner.run_iter()) as results: for key, outs in results: # do something with the data pass .. note:: The runner does **not** guarantee that results are in the same order as the original inputs — with parallelism, they may be yielded in the order they are ready. :param pipeline: The pipeline to run. :param queries: The collection of test queries use. See :ref:`batch-queries` for details on the various input formats.