BatchConfig¶
- class BatchConfig(mode=BatchMode.MERGED, max_batch_size=None, max_concurrent_programs=None, _sort_programs=False)[source]¶
Bases:
objectConfiguration for circuit batching in
ProgramEnsemble.run().Choosing values
The two main knobs —
max_concurrent_programsandmax_batch_size— work together to shape merged backend submissions:max_concurrent_programscontrols how many programs run at once. It sizes the executor pool and the wait-for-all barrier.max_batch_sizecaps the number of circuits in a single merged backend call.
The default (both unset) sizes the pool to fit every program (up to 256) and waits for all to submit — one merged call. For larger ensembles or to bound the merged-call payload, set the relevant knob.
Cloud submission (e.g.
QoroService) typically benefits from one large merged job to amortize HTTP round trips. Pass-1to unleash every program concurrently:ensemble.run( batch_config=BatchConfig(max_concurrent_programs=-1), )
Local simulators benefit from smaller merges that overlap circuit construction with execution. The default settings already do this.
- Variables:
mode – Whether to merge circuit submissions across programs. Defaults to
MERGED.max_batch_size – Flush-trigger threshold on the pending circuit count, not a hard cap on merged-call size. When set, the coordinator fires a flush as soon as pending circuits reach this value, and the flush includes every circuit pending at that moment — so an actual merged submission may exceed
max_batch_sizewhen programs submit multiple circuits per call.None(the default) preserves the wait-for-all barrier behavior. Setting this value also couples the executor pool size to it (whenmax_concurrent_programsis unset): the pool is sized tomin(max_batch_size, len(programs))so the barrier predicate can fill the batch in one wave. Only meaningful whenmodeisMERGED.max_concurrent_programs – Maximum number of programs running concurrently. When set to a positive integer, sizes the executor pool to that value and bypasses the default ensemble-size cap, letting the wait-for-all barrier admit a single merged submission of up to this many programs. Pass
-1to size the pool to the entire ensemble — the cloud-merge recipe — without having to querylen(ensemble.programs)yourself; when combined withmax_batch_sizethe pool is capped atmin(max_batch_size, len(programs))so the barrier and batch size align (one full wave per flush, no surplus threads).None(the default) auto-sizes the pool:max(len(programs), cpu_count + 4)in barrier mode (capped at 256), ormin(max_batch_size, len(programs))whenmax_batch_sizeis set. Explicit values above 1024 emit aUserWarning; the-1form is silent because it’s an intentional opt-in. Only meaningful whenmodeisMERGED._sort_programs –
Whether to sort programs by key before merging their circuits into a single backend call. Defaults to
False.When
False(default), circuits are merged in submission-arrival order — the order in which program threads reach the flush barrier. This preserves backward-compatible behavior.Set to
Trueto merge circuits in a consistent, key-sorted order regardless of thread scheduling. This ensures that position-dependent seeds (e.g.seed + circuit_indexinQiskitSimulatordeterministic mode) map to the same circuit on every run, making seeded experiments fully reproducible. Only meaningful whenmodeisMERGED.
Attributes Summary
Attributes Documentation