-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
docs/migration-guides/qiskit-runtime-from-third-party-provider.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters