Scale#
Block 4 — parallel evaluation and pre-enumerated libraries. See the guide.
The user-facing knobs are fields on
ThompsonSamplingConfig
(processes, min_cpds_per_core, product_library_file) and the
sampler methods set_evaluator()
and load_product_library().
The machinery behind processes > 1:
- class TACTICS.thompson_sampling.core.parallel_evaluator.ParallelEvaluator(processes=1)[source]#
Wrapper for parallel evaluation of compounds with persistent pool.
The pool is created once and reused across all evaluations to avoid the overhead of repeatedly spawning processes.
Two execution paths:
processes == 1: sequential, callingevaluate_fndirectly. No pickling and no worker processes.processes > 1: a persistent pool whose workers each construct their own evaluator via_init_worker(). Requires a worker context to have been bound withbind_worker_context(); without one, falls back to sendingevaluate_fnitself, which works for picklable evaluators but not for OpenEye-backed ones.
- bind_worker_context(sampler, evaluator_config)[source]#
Record what each worker needs in order to rebuild its own evaluator.
Called by
ThompsonSampler.set_evaluatorwhen the evaluator’s config is known (i.e. when the sampler was built byfrom_config, or whenset_evaluatorwas given an explicitevaluator_config).Any existing pool is shut down, because its workers were initialized from the previous context and would otherwise keep using a stale evaluator.
- Parameters:
sampler – The ThompsonSampler whose
evaluatethe workers run.evaluator_config – Picklable evaluator config used to rebuild the evaluator inside each worker. If None, the context is cleared.
- evaluate_batch(evaluate_fn, compound_list)[source]#
Evaluate a batch of compounds in parallel.
- Parameters:
evaluate_fn (Callable) – Function that takes a compound representation (e.g. list of reagent indices) and returns [score, smiles, name]. Used directly when running sequentially, and as the fallback task function when no worker context has been bound.
compound_list (List[Any]) – List of compound representations to evaluate
- Returns:
List of evaluation results [score, smiles, name] for each compound
- Raises:
TypeError – if
processes > 1with no worker context bound and the evaluator cannot be pickled. The message explains how to fix it.- Return type: