From 8d635a8519c2630ebb583afe92eba8995ba24b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= <57907331+ElePT@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:44:35 +0200 Subject: [PATCH] Revert base class change for Sampler and Estimator V1 implementations to avoid breaking instance checks. (#12871) (cherry picked from commit 919cfd3baf8e02c21ca26074e94191cedf98b5d8) --- qiskit/primitives/backend_estimator.py | 15 ++++++++------- qiskit/primitives/backend_sampler.py | 13 +++++++------ qiskit/primitives/estimator.py | 6 +++--- qiskit/primitives/sampler.py | 6 +++--- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/qiskit/primitives/backend_estimator.py b/qiskit/primitives/backend_estimator.py index f6a53c02ea9e..722ee900ceea 100644 --- a/qiskit/primitives/backend_estimator.py +++ b/qiskit/primitives/backend_estimator.py @@ -36,7 +36,7 @@ ) from qiskit.utils.deprecation import deprecate_func -from .base import BaseEstimatorV1, EstimatorResult +from .base import BaseEstimator, EstimatorResult from .primitive_job import PrimitiveJob from .utils import _circuit_key, _observable_key, init_observable @@ -88,17 +88,18 @@ def _prepare_counts(results: list[Result]): return counts -class BackendEstimator(BaseEstimatorV1[PrimitiveJob[EstimatorResult]]): +class BackendEstimator(BaseEstimator[PrimitiveJob[EstimatorResult]]): """Evaluates expectation value using Pauli rotation gates. The :class:`~.BackendEstimator` class is a generic implementation of the - :class:`~.BaseEstimatorV1` interface that is used to wrap a :class:`~.BackendV2` - (or :class:`~.BackendV1`) object in the :class:`~.BaseEstimatorV1` API. It + :class:`~.BaseEstimator` (V1) interface that is used to wrap a :class:`~.BackendV2` + (or :class:`~.BackendV1`) object in the :class:`~.BaseEstimator` V1 API. It facilitates using backends that do not provide a native - :class:`~.BaseEstimatorV1` implementation in places that work with - :class:`~.BaseEstimatorV1`. + :class:`~.BaseEstimator` V1 implementation in places that work with + :class:`~.BaseEstimator` V1. However, if you're using a provider that has a native implementation of - :class:`~.BaseEstimatorV1` or :class:`~.BaseEstimatorV2`, it is a better + :class:`~.BaseEstimatorV1` ( :class:`~.BaseEstimator`) or + :class:`~.BaseEstimatorV2`, it is a better choice to leverage that native implementation as it will likely include additional optimizations and be a more efficient implementation. The generic nature of this class precludes doing any provider- or diff --git a/qiskit/primitives/backend_sampler.py b/qiskit/primitives/backend_sampler.py index 213b9701a556..905fa2371542 100644 --- a/qiskit/primitives/backend_sampler.py +++ b/qiskit/primitives/backend_sampler.py @@ -26,22 +26,23 @@ from qiskit.utils.deprecation import deprecate_func from .backend_estimator import _prepare_counts, _run_circuits -from .base import BaseSamplerV1, SamplerResult +from .base import BaseSampler, SamplerResult from .primitive_job import PrimitiveJob from .utils import _circuit_key -class BackendSampler(BaseSamplerV1[PrimitiveJob[SamplerResult]]): - """A :class:`~.BaseSamplerV1` implementation that provides a wrapper for +class BackendSampler(BaseSampler[PrimitiveJob[SamplerResult]]): + """A :class:`~.BaseSampler` (V1) implementation that provides a wrapper for leveraging the Sampler V1 interface from any backend. This class provides a sampler interface from any backend and doesn't do any measurement mitigation, it just computes the probability distribution from the counts. It facilitates using backends that do not provide a - native :class:`~.BaseSamplerV1` implementation in places that work with - :class:`~.BaseSamplerV1`. + native :class:`~.BaseSampler` V1 implementation in places that work with + :class:`~.BaseSampler` V1. However, if you're using a provider that has a native implementation of - :class:`~.BaseSamplerV1` or :class:`~.BaseESamplerV2`, it is a better + :class:`~.BaseSamplerV1` ( :class:`~.BaseSampler`) or + :class:`~.BaseESamplerV2`, it is a better choice to leverage that native implementation as it will likely include additional optimizations and be a more efficient implementation. The generic nature of this class precludes doing any provider- or diff --git a/qiskit/primitives/estimator.py b/qiskit/primitives/estimator.py index 1ca1529852c3..6ae50ee7f0f5 100644 --- a/qiskit/primitives/estimator.py +++ b/qiskit/primitives/estimator.py @@ -26,7 +26,7 @@ from qiskit.quantum_info.operators.base_operator import BaseOperator from qiskit.utils.deprecation import deprecate_func -from .base import BaseEstimatorV1, EstimatorResult +from .base import BaseEstimator, EstimatorResult from .primitive_job import PrimitiveJob from .utils import ( _circuit_key, @@ -36,9 +36,9 @@ ) -class Estimator(BaseEstimatorV1[PrimitiveJob[EstimatorResult]]): +class Estimator(BaseEstimator[PrimitiveJob[EstimatorResult]]): """ - Reference implementation of :class:`BaseEstimatorV1`. + Reference implementation of :class:`BaseEstimator` (V1). :Run Options: diff --git a/qiskit/primitives/sampler.py b/qiskit/primitives/sampler.py index d93db4f04116..9155e50ad2ce 100644 --- a/qiskit/primitives/sampler.py +++ b/qiskit/primitives/sampler.py @@ -26,7 +26,7 @@ from qiskit.result import QuasiDistribution from qiskit.utils.deprecation import deprecate_func -from .base import BaseSamplerV1, SamplerResult +from .base import BaseSampler, SamplerResult from .primitive_job import PrimitiveJob from .utils import ( _circuit_key, @@ -36,11 +36,11 @@ ) -class Sampler(BaseSamplerV1[PrimitiveJob[SamplerResult]]): +class Sampler(BaseSampler[PrimitiveJob[SamplerResult]]): """ Sampler V1 class. - :class:`~Sampler` is a reference implementation of :class:`~BaseSamplerV1`. + :class:`~Sampler` is a reference implementation of :class:`~BaseSampler` (V1). :Run Options: