# Parallelized Models¶

## DirectViewParallelizedModel¶

class qinfer.parallel.DirectViewParallelizedModel(serial_model, direct_view, purge_client=False, serial_theshold=None)[source]

Bases: qinfer.derived_models.DerivedModel

Given an instance of a Model, parallelizes execution of that model’s likelihood by breaking the modelparams array into segments and executing a segment on each member of a DirectView.

This Model assumes that it has ownership over the DirectView, such that no other processes will send tasks during the lifetime of the Model.

Parameters: serial_model (qinfer.Model) – Model to be parallelized. This model will be distributed to the engines in the direct view, such that the model must support pickling. direct_view (ipyparallel.DirectView) – Direct view onto the engines that will be used to parallelize evaluation of the model’s likelihood function. purge_client (bool) – If True, then this model will purge results and metadata from the IPython client whenever the model cache is cleared. This is useful for solving memory leaks caused by very large numbers of calls to likelihood. By default, this is disabled, since enabling this option can cause data loss if the client is being sent other tasks during the operation of this model. serial_threshold (int) – Sets the number of model vectors below which the serial model is to be preferred. By default, this is set to 10 * n_engines, where n_engines is the number of engines exposed by direct_view.
n_engines

The number of engines seen by the direct view owned by this parallelized model.

clear_cache()[source]

Clears any cache associated with the serial model and the engines seen by the direct view.

likelihood(outcomes, modelparams, expparams)[source]

Returns the likelihood for the underlying (serial) model, distributing the model parameter array across the engines controlled by this parallelized model.