Skip to content

Commit

Permalink
Merge branch 'main' into use-reason-code-1305
Browse files Browse the repository at this point in the history
  • Loading branch information
kt474 authored Jun 21, 2024
2 parents 79945f0 + eea7df4 commit e00811a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -549,5 +549,5 @@ min-public-methods=2

# Exceptions that will emit a warning when being caught. Defaults to
# "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception
52 changes: 30 additions & 22 deletions qiskit_ibm_runtime/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,54 @@
class Batch(Session):
"""Class for running jobs in batch execution mode.
Similar to a ``session``, a Qiskit Runtime ``batch`` groups a collection of
iterative calls to the quantum computer. Batch mode can shorten processing time if all jobs
can be provided at the outset. To submit iterative jobs, use sessions instead.
The ``batch`` mode is designed to efficiently perform experiments that comprise multiple
independent jobs.
Using batch mode has these benefits:
Using the ``batch`` mode provides the following benefits:
- The jobs' classical computation, such as compilation, is run in parallel.
Thus, running multiple jobs in a batch is significantly faster than running them serially.
- There is minimal delay between job, which can help avoid drift.
- There is usually minimal delay between job, which can help avoid drift.
- If you partition your workload into multiple jobs and run them in ``batch`` mode, you can
get results from individual jobs, which makes them more flexible to work with. For example,
if a job's results do not meet your expectations, you can cancel the remaining jobs, or
simply re-submit that individual job and avoid re-running the entire workload.
All jobs need to be provided at the outset. To submit iterative jobs, use the ``session``
mode instead.
You can open a Qiskit Runtime batch by using this ``Batch`` class, then submit jobs
to one or more primitives.
For example::
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit.random import random_circuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import Batch, SamplerV2 as Sampler
from qiskit_ibm_runtime import Batch, SamplerV2 as Sampler, QiskitRuntimeService
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
# Bell Circuit
qr = QuantumRegister(2, name="qr")
cr = ClassicalRegister(2, name="cr")
qc = QuantumCircuit(qr, cr, name="bell")
qc.h(qr[0])
qc.cx(qr[0], qr[1])
qc.measure(qr, cr)
# generate fifty unique three-qubit random circuits
circuits = [pm.run(random_circuit(3, 2, measure=True)) for _ in range(50)]
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuit = pm.run(qc)
# split up the list of circuits into partitions
max_circuits = 10
partitions = [circuits[i : i + max_circuits] for i in range(0, len(circuits), max_circuits)]
with Batch(backend=backend) as batch:
sampler = Sampler(batch)
job = sampler.run([isa_circuit])
pub_result = job.result()[0]
print(f"Sampler job ID: {job.job_id()}")
print(f"Counts: {pub_result.data.cr.get_counts()}")
# run the circuits in batched mode
with Batch(backend=backend):
sampler = Sampler()
for partition in partitions:
job = sampler.run(partition)
pub_result = job.result()[0]
print(f"Sampler job ID: {job.job_id()}")
print(f"Counts for the first PUB: {pub_result.data.cr.get_counts()}")
For more details, check the "`Run jobs in a batch
<https://docs.quantum.ibm.com/run/run-jobs-batch>`_" tutorial.
"""

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/fake_provider/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def refresh(self, service: QiskitRuntimeService) -> None:
else:
logger.info("There are no available new updates for %s.", self.backend_name)

except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
logger.info("The refreshing of %s has failed: %s", self.backend_name, str(ex))


Expand Down

0 comments on commit e00811a

Please sign in to comment.