Skip to content

Commit

Permalink
Address #2543
Browse files Browse the repository at this point in the history
  • Loading branch information
beckykd committed Jan 21, 2025
1 parent 55c4a24 commit 3812adf
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/migration-guides/_toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
"title": "Migrate from qiskit-ibm-provider",
"url": "/migration-guides/qiskit-runtime-from-ibm-provider"
},
{
"title": "Migrate from a third-party provider",
"url": "/migration-guides/qiskit-runtime-from-third-party-provider"
},
{
"title": "Migrate options",
"url": "/migration-guides/qiskit-runtime-options"
Expand Down
61 changes: 61 additions & 0 deletions docs/migration-guides/qiskit-runtime-from-third-party-provider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: Migrate from a third-party provider
description: Migrate from a third-party provider to using Qiskit Runtime primitives

---

# Migrate from a third-party provider

This topic shows how to migrate code from a third-party provider that implemented `IBMBackend.run()` to use `qiskit_ibm_runtime`.

The Qiskit SDK offers wrappers for `backend.run` that can be easily adapted to a custom primitives workflow
through subclassing; these are the [`BackendEstimatorV2`](/api/qiskit/qiskit.primitives.BackendEstimatorV2) and [`BackendSamplerV2`.](/api/qiskit/qiskit.primitives.BackendSamplerV2) The inputs
to the primitives should follow the Primitive Unified Bloc (PUB) syntax specified in the V2 primitives interface. See the [Overview of PUBs section](/guides/primitive-input-output#pubs) in the Primitive inputs and outputs guide for details.

An advantage of this strategy is that the wrapper can handle the input and output manipulation, so knowledge of the PUB data
model is not required. However, this might result in a suboptimal runtime, which could be refined through a fully
custom primitives implementation.

The following snippets show how to create a custom Estimator instance following the strategy described above.
The process is analogous for a custom Sampler, modifying the base class to `BackendSamplerV2`.

``` python
from qiskit.primitives import BackendEstimatorV2

class CustomEstimator(BackendEstimatorV2):
"""Estimator primitive for custom provider."""

# This line is for type checking purposes.
# We are changing the type of self._backend from qiskit's
# BackendV1/BackendV2 classes to our custom provider resource.
_backend: CustomProviderResource

def __init__(
self,
backend: CustomProviderResource,
options: dict | None = None,
extra_flag_used_in_estimation: bool = True,
another_extra_flag: bool = False,
) -> None:
"""
Args:
backend: custom provider resource to evaluate circuits on.
options: options passed to through to the underlying BackendEstimatorV2.
extra_flag_used_in_estimation: if `False`, do this.
another_extra_flag: if `True`, do that,
"""

# preprocess arguments if necessary according to custom flags
processed_backend = ...
processed_options = ...

super().__init__(
processed_backend,
options=processed_options,
)

@property
def backend(self) -> CustomProviderResource:
"""Computing resource used for circuit evaluation."""
return self._backend
```
4 changes: 4 additions & 0 deletions qiskit_bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ notifications:
- "@jyu00"
- "@ElePT"
- "@beckykd"
"docs/migration-guides/qiskit-runtime-from-third-party-provider":
- "@jyu00"
- "@ElePT"
- "@beckykd"
"docs/migration-guides/qiskit-runtime-from-ibmq-provider":
- "@jyu00"
- "@ElePT"
Expand Down

0 comments on commit 3812adf

Please sign in to comment.