qbench.batching module#

Functions for splitting sequences of circuits into batches.

class qbench.batching.BatchJob(job, keys)#
Parameters:
  • job (JobV1) –

  • keys (Sequence[Any]) –

job: JobV1#

Alias for field number 0

keys: Sequence[Any]#

Alias for field number 1

class qbench.batching.BatchWithKey(circuits, keys)#
Parameters:
circuits: Sequence[QuantumCircuit]#

Alias for field number 0

keys: Sequence[Any]#

Alias for field number 1

qbench.batching.batch_circuits_with_keys(circuits, keys, max_circuits_per_batch)#

Split sequence of circuits into batches, preserving correspondence between circuits and keys.

Parameters:
  • circuits (Sequence[QuantumCircuit]) – sequence of circuits to be split.

  • keys (Sequence[Any]) – keys corresponding to given circuits (i.e. keys[i] -> circuits[i]. Keys do not have to be unique.

  • max_circuits_per_batch (Optional[int]) – maximum size of the batch. All batches will be of this size, except possibly last batch, which can be smaller.

Returns:

sequence of namedtuples with fields circuits and keys. Each such tuple, possibly except the last one, is of size max_circuits_per_batch. Correspondence between circuits and keys are preserved in each batch.

Return type:

Sequence[BatchWithKey]

qbench.batching.execute_in_batches(backend, circuits, keys, shots, batch_size, show_progress=False, **kwargs)#

Execute given sequence of circuits with corresponding keys in batches on a backend.

Parameters:
  • backend (Union[BackendV1, BackendV2]) – backend which will be usd for executing circuits.

  • circuits (Sequence[QuantumCircuit]) – sequence of circuits to be executed.

  • keys (Sequence[Any]) – sequence of keys corresponding to the circuits.

  • shots (int) – number of shots for each circuit.

  • batch_size (Optional[int]) – number of circuits in a batch. The circuits and keys will be batches using batch_circuits_with_keys_function, and each batch will be executed as a single job on the backend.

  • show_progress (bool) – flag determining if a tqdm progress bar should be shown (True) or not (False). Defaults to False.

Returns:

Iterable of namedtuples with fields job and keys. Each job runs circuits corresponding to keys in keys, and the order of circuits in the job corresponds to order of keys.

Return type:

Iterable[BatchJob]