Skip to content

Commit

Permalink
will comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dcmckayibm committed Oct 24, 2024
1 parent 00981bc commit ebe7a33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 52 deletions.
57 changes: 10 additions & 47 deletions docs/howtos/runtime_sessions.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
Use Experiments with Runtime sessions and sampler
=================================================
Use Experiments with Sampler
=============================

Problem
-------

You want to run experiments with a custom `SamplerV2
<https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.SamplerV2>`_ service.
You want to run experiments with a custom :class:`qiskit.primitives.BaseSamplerV2` service.
A sampler can be instantiated with a backend, session or batch, which allows one to
run an experiment in different execution modes.

.. note::
All jobs, by default, run using the ``SamplerV2`` service. When calling ``exp.run`` a
``SamplerV2`` object will be automatically generated from the specified backend.
All jobs, by default, run using the :class:`qiskit_ibm_runtime.SamplerV2` class. When calling ``exp.run`` a
:class:`qiskit_ibm_runtime.SamplerV2` object will be automatically generated to wrap the specified backend.

Solution
--------

In this example, we will pass in a ``SamplerV2`` object to a tomography experiment.
In this example, we will pass in a :class:`qiskit_ibm_runtime.SamplerV2` object to a tomography experiment.

.. note::
If a sampler object is passed to ``exp.run`` then the `run options
If a sampler object is passed to :meth:`qiskit_experiments.framework.BaseExperiment.run` then the `run options
<https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.SamplerExecutionOptionsV2>`_ of the
sampler object are used. The execution options set by the experiment are ignored.

Expand All @@ -39,45 +40,7 @@ In this example, we will pass in a ``SamplerV2`` object to a tomography experime
# Artificially lower circuits per job, adjust value for your own application
exp.set_experiment_options(max_circuits=3)
# pass the sampler into the experiment
exp_data = exp.run(sampler)
exp_data = exp.run(sampler=sampler)

Problem
-------

You want to run experiments in a `Runtime session
<https://docs.quantum.ibm.com/run/sessions>`_ so that jobs can run in close temporal proximity.

Solution
--------

.. note::
This guide requires :external+qiskit_ibm_runtime:doc:`qiskit-ibm-runtime <index>` version 0.15 and up, which can be installed with ``python -m pip install qiskit-ibm-runtime``.
For how to migrate from the older ``qiskit-ibm-provider`` to :external+qiskit_ibm_runtime:doc:`qiskit-ibm-runtime <index>`,
consult the `migration guide <https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime-from-provider>`_.\

Use the :class:`~qiskit_ibm_runtime.IBMBackend` object in :external+qiskit_ibm_runtime:doc:`index`, which supports sessions.

In this example, we will set the ``max_circuits`` property to an artificially low value so that the experiment will be
split into multiple jobs that run sequentially in a single session. When running real experiments with a
large number of circuits that can't fit in a single job, it may be helpful to follow this usage pattern:

.. jupyter-input::

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_experiments.library.tomography import ProcessTomography
from qiskit import QuantumCircuit

service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.backend("ibm_osaka")
qc = QuantumCircuit(1)
qc.x(0)

backend.open_session()
exp = ProcessTomography(qc)
# Artificially lower circuits per job, adjust value for your own application
exp.set_experiment_options(max_circuits=3)
exp_data = exp.run(backend)
# This will prevent further jobs from being submitted without terminating current jobs
backend.close_session()


15 changes: 10 additions & 5 deletions releasenotes/notes/primitives_add-1a3bcbb2f189d18e.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
---
prelude: >
In this release we added support for the qiskit primitives so that
qiskit-experiments will use the SamplerV2 run path.
In this release we added support for the Qiskit primitives.
Qiskit Experiments will execute circuits using :class:`qiskit_ibm_runtime.SamplerV2` by default.
upgrade:
- |
Upgrade qiskit-experiments to use the SamplerV2 path. An option is
left in to use the old backend.run path, however, this is scheduled
to be deprecated by ibm-runtime in the near future.
When only a ``backend`` is set on an experiment, :meth:`qiskit_experiments.framework.BaseExperiment.run`
now defaults to wrapping the ``backend`` in a :class:`qiskit_ibm_runtime.SamplerV2` and
using that to execute the circuits. A new ``sampler`` argument is also
accepted by ``run()`` to allow for a custom :class:`qiskit.primitives.SamplerV2`
instance to be used for circuit execution. ``run()`` also accepts a ``backend_run``
option which will cause the old ``backend.run`` path to be used for circuit execution.
However, the ``backend.run()`` method is scheduled to be deprecated by
qiskit-ibm-runtime in the near future.

0 comments on commit ebe7a33

Please sign in to comment.