Skip to content

Commit

Permalink
Update batch example (#1129)
Browse files Browse the repository at this point in the history
closes #1128

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
  • Loading branch information
beckykd and jyu00 authored Apr 5, 2024
1 parent b9a40a1 commit acd422e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions docs/run/run-jobs-batch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ Batch mode can shorten processing time if all jobs can be provided at the outset
The following example shows how you can divide up a long list of circuits into multiple jobs and run them as a batch to take advantage of the parallel processing.

```python
from qiskit_ibm_runtime import SamplerV2 as Sampler, Batch

max_circuits = 100
all_partitioned_circuits = []
for i in range(0, len(circuits), max_circuits):
all_partitioned_circuits.append(circuits[i : i + max_circuits])
jobs = []
with Batch(backend) as batch:
estimator = Estimator(batch)
# calls within this context are part of the batch.
for obs_set in observable_sets:
jobs.append(estimator.run(circuits, observables=obs_set))
start_idx = 0

with Batch(backend=backend):
sampler = Sampler()
for partitioned_circuits in all_partitioned_circuits:
job = sampler.run(partitioned_circuits)
jobs.append(job)
```

0 comments on commit acd422e

Please sign in to comment.