Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration guide for IBMBackend.run #1214

Merged
merged 39 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d211315
First version of migration guide for backend.run()
merav-aharoni Nov 9, 2023
1872ca0
Typoes and spacing
merav-aharoni Nov 9, 2023
f550d87
Added examples of Sessions
merav-aharoni Nov 9, 2023
ccf0633
Spacing
merav-aharoni Nov 9, 2023
ea899ec
Spacing
merav-aharoni Nov 9, 2023
6b6f247
Spacing
merav-aharoni Nov 9, 2023
295f0fb
removed unnecessary quotes
merav-aharoni Nov 9, 2023
26dcec3
added missing quote
merav-aharoni Nov 9, 2023
9d0038a
Fixed code blocks
merav-aharoni Nov 13, 2023
8d7c35a
Updates in migration guide
merav-aharoni Nov 13, 2023
470da63
Release note
merav-aharoni Nov 13, 2023
d0ab583
Merge branch 'main' into migrate_backend_run
merav-aharoni Nov 13, 2023
61b1de6
Fixed error
merav-aharoni Nov 13, 2023
7ebbf12
Merge branch 'main' of github.com:merav-aharoni/qiskit-ibm-runtime in…
merav-aharoni Nov 13, 2023
8d0de3f
Merge branch 'migrate_backend_run' of github.com:merav-aharoni/qiskit…
merav-aharoni Nov 13, 2023
1f0ff3d
Added new file to toc
merav-aharoni Nov 13, 2023
25d6e45
Fixed spelling
merav-aharoni Nov 13, 2023
64dba83
Fixed spelling
merav-aharoni Nov 13, 2023
ada27f2
Update docs/migrate/backend_run_migration_guide.rst
merav-aharoni Nov 14, 2023
23092ff
Update docs/migrate/backend_run_migration_guide.rst
merav-aharoni Nov 14, 2023
1e9b641
Update docs/migrate/backend_run_migration_guide.rst
merav-aharoni Nov 14, 2023
8879a2d
Update docs/migrate/backend_run_migration_guide.rst
merav-aharoni Nov 14, 2023
9521be6
Update docs/migrate/backend_run_migration_guide.rst
merav-aharoni Nov 14, 2023
fc6f69d
Update docs/migrate/backend_run_migration_guide.rst
merav-aharoni Nov 14, 2023
23a16de
Update docs/migrate/backend_run_migration_guide.rst
merav-aharoni Nov 14, 2023
5ead385
Added explanations following review
merav-aharoni Nov 14, 2023
fcf0372
Added comments in the code
merav-aharoni Nov 14, 2023
57de435
More consistency in names, such as IBMBackend
merav-aharoni Nov 14, 2023
2f1814e
Merge branch 'main' into migrate_backend_run
merav-aharoni Nov 14, 2023
e7454bd
minor wording changes
kt474 Nov 14, 2023
c6631e5
Editted text
merav-aharoni Nov 15, 2023
caa648a
Merge with main
merav-aharoni Nov 15, 2023
8a65ddc
Update docs/migrate/backend_run_migration_guide.rst
kt474 Nov 15, 2023
19108ad
Update docs/migrate/backend_run_migration_guide.rst
kt474 Nov 15, 2023
c18447b
Update docs/migrate/backend_run_migration_guide.rst
kt474 Nov 15, 2023
1b25cbb
Update docs/migrate/backend_run_migration_guide.rst
kt474 Nov 15, 2023
f10e366
Update docs/migrate/backend_run_migration_guide.rst
kt474 Nov 15, 2023
65c9c6c
address remaining comments
kt474 Nov 15, 2023
96ba7b3
Merge branch 'main' into migrate_backend_run
kt474 Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Next steps
Use Sampler to design an algorithm <migrate/migrate-sampler>
Update parameter values while running <migrate/migrate-update-parm>
Algorithm tuning options (shots, transpilation, error mitigation) <migrate/migrate-tuning>

Migrate backend.run() from qiskit_ibm_provider to qiskit_ibm_runtime <migrate/backend_run_migration_guide>

.. toctree::
:maxdepth: 1
Expand Down
98 changes: 98 additions & 0 deletions docs/migrate/backend_run_migration_guide.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Migration guide: Migrate ``backend.run()`` from ``qiskit_ibm_provider`` to ``qiskit_ibm_runtime``
=================================================================================================

The Qiskit Runtime interface includes two packages:
Qiskit IBM Provider (the ``qiskit_ibm_provider`` package) and
Qiskit IBM Runtime (the ``qiskit_ibm_runtime`` package). Until now,
Primitives (``Sampler`` and ``Estimator``)
kt474 marked this conversation as resolved.
Show resolved Hide resolved
were run in Runtime. Custom circuits that performed their own transpilation and used ``IBMBackend.run()``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"that performed their own transpilation" doesn't sound right. Maybe "...that had to be manually transpiled..."

were run in Provider.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a short introduction here? It should explain qiskit_ibm_provider vs qiskit_ibm_runtime and why you need to migrate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Please have a look.

In this release, we add support for running custom circuits using ``IBMBackend.run()`` in Runtime,
so users can run all programs through Runtime.
We eventually plan to deprecate Provider.
drew-distefano marked this conversation as resolved.
Show resolved Hide resolved

This guide describes how to migrate code that implemented ``IBMBackend.run()``
using Qiskit IBM Provider to use Qiskit IBM Runtime instead.

**Example 1: Straightforward execution of IBMBackend.run()**

.. code-block:: python

from qiskit import *
from qiskit.compiler import transpile, assemble
circuit = QuantumCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()

In Provider, the code is:

.. code-block:: python

from qiskit_ibm_provider import IBMProvider
provider = IBMProvider()
backend = provider.get_backend("ibmq_qasm_simulator")
transpiled_circuit = transpile(circuit, backend=backend)
job = backend.run(transpiled_circuit)
print(job.result())

In Runtime, the code is:

.. code-block:: python

from qiskit_ibm_runtime import QiskitRuntimeService
service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.backend("ibmq_qasm_simulator")
transpiled_circuit = transpile(circuit, backend=backend)
job = backend.run(transpiled_circuit)
print(job.result())

**Example 2: Execution of backend.run() within a session:**

This section of code is identical in Provider and in Runtime.

.. code-block:: python

with backend.open_session() as session:
job1 = backend.run(transpiled_circuit)
job2 = backend.run(transpiled_circuit)
print(job1.session_id)
print(job2.session_id)
backend.cancel_session()

The current implementation of Session is different for ``IBMBackend`` than that of Primitives.
kt474 marked this conversation as resolved.
Show resolved Hide resolved
Therefore, we cannot run a primitive and a backend using a single session. This will be remediated
kt474 marked this conversation as resolved.
Show resolved Hide resolved
in subsequent releases.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in subsequent releases.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best not to talk about "current" and "future", since those statements quickly go stale, and there's really nothing a user can do with that information right now anyway. We'll just update the information when the code is changed.


**Example 3: Primitive session containing backend.run:**

In this example, ``sampler`` is run within session, but ``backend`` is run independently
of ``session``.
kt474 marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python

from qiskit_ibm_runtime import Session, Sampler
with Session(backend=backend) as session:
sampler = Sampler(session=session)
job1 = sampler.run(transpiled_circuit)
job2 = backend.run(transpiled_circuit) # runs outside the session
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what makes job2 run outside the session. Is it just 'kicked out' of the session because it uses backend.run? Why would it have a session_id (from the print command) if it runs outside the session?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an explanation and comments in the code. Please check if they are helpful.

print(job1.session_id)
print(job2.session_id) # is None

**Example 4: Backend session containing Sampler:**

In this example, ``backend`` is run within a session, but ``sampler`` is run independently
of ``session``.
kt474 marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python

with backend.open_session() as session:
sampler = Sampler(backend=backend)
job1 = sampler.run(transpiled_circuit) # runs outside the session
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I don't understand why this runs outside the session. Is it because it was instantiated with backend.open_session(), so that session just won't accept jobs that don't use backend.run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

job2 = backend.run(transpiled_circuit)
session_id = session.session_id
print(job1.session_id) # is None
print(job2.session_id)


4 changes: 4 additions & 0 deletions releasenotes/notes/migrate_backend_run-06c4b0579f28061a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
other:
- |
Added migration code for running ``backend.run`` in `qiskit_ibm_runtime` instead of in `qiskit_ibm_provider`.
Loading