diff --git a/docs/migration-guides/_toc.json b/docs/migration-guides/_toc.json index 7e0d19547c0..f12cc4cd78d 100644 --- a/docs/migration-guides/_toc.json +++ b/docs/migration-guides/_toc.json @@ -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" diff --git a/docs/migration-guides/qiskit-runtime-from-third-party-provider.mdx b/docs/migration-guides/qiskit-runtime-from-third-party-provider.mdx new file mode 100644 index 00000000000..814207370af --- /dev/null +++ b/docs/migration-guides/qiskit-runtime-from-third-party-provider.mdx @@ -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 +``` \ No newline at end of file diff --git a/qiskit_bot.yaml b/qiskit_bot.yaml index caae97d82c4..af284255cf2 100644 --- a/qiskit_bot.yaml +++ b/qiskit_bot.yaml @@ -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"