Abstract BatchSampler solves a coordination problem that arises when running Optuna with multiple workers (n_jobs > 1).
With default samplers, each worker calls sample_relative concurrently and sees the same incomplete view of the trial history — pending trials from the same batch are invisible to one another. This causes workers to suggest near-duplicate configurations, wasting the throughput gained from parallelism.
BatchSampler uses a shared lock to coordinate workers: the first worker to find an empty cache calls a user-supplied suggest_fn once to obtain q suggestions jointly, then hands them out one at a time.