Worker factory used by Samplers to construct Workers.
This function exists so it can be pickled.
WorkerFactory(*, seed, max_episode_length, n_workers=psutil.cpu_count(logical=False), worker_class=DefaultWorker, worker_args=None)¶
Constructs workers for Samplers.
The intent is that this object should be sufficient to avoid subclassing the sampler. Instead of subclassing the sampler for e.g. a specific backend, implement a specialized WorkerFactory (or specify appropriate functions to this one). Not that this object must be picklable, since it may be passed to workers. However, its fields individually need not be.
All arguments to this type must be passed by keyword.
seed (int) – The seed to use to intialize random number generators.
n_workers (int) – The number of workers to use.
max_episode_length (int) – The maximum length episodes which will be sampled.
worker_class (type) – Class of the workers. Instances should implement the Worker interface.
prepare_worker_messages(self, objs, preprocess=identity_function)¶
Take an argument and canonicalize it into a list for all workers.
This helper function is used to handle arguments in the sampler API which may (optionally) be lists. Specifically, these are agent, env, agent_update, and env_update. Checks that the number of parameters is correct.
ValueError – If a list is passed of a length other than n_workers.
A list of length self.n_workers.
- Return type