Skip to content

Commit 250acc3

Browse files
LeanderCSt-imamichimtreinishElePT
authored
Deprecate V1 Primitives and their utils (Qiskit#12575)
* Deprecate V1 Primitives and their utils * Fix tests * Fix yaml error * Fix build * Fix error after mc * Fix error after mc * Apply comments * Use correct deprecate version for warning message * Update deprecation messages * Add missed `` * update releasenote * Deprecate SamplerResult and EstimatorResult * fix deprecation warning for SamplerResult and EstimatorResult * apply review comments Co-authored-by: Matthew Treinish <[email protected]> Co-authored-by: Elena Peña Tapia <[email protected]> * Applying the agreement of deprecations. - Revert BaseSamplerV1 and BaseEstimatorV1 - Deprecate BaseSampler and BaseEstimator Qiskit#12497 (comment) * revert SamplerResult, EstimatorResult, and BasePrimitiveResult * fix test_backend_sampler * revert tox.ini * revise deprecation warning for BaseSampler and BaseEstimator * update reno * revert BaseSampler and BaseEstimator --------- Co-authored-by: Takashi Imamichi <[email protected]> Co-authored-by: Takashi Imamichi <[email protected]> Co-authored-by: Matthew Treinish <[email protected]> Co-authored-by: Elena Peña Tapia <[email protected]>
1 parent 6ce5250 commit 250acc3

19 files changed

+540
-326
lines changed

qiskit/primitives/backend_estimator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
Optimize1qGatesDecomposition,
3636
SetLayout,
3737
)
38+
from qiskit.utils.deprecation import deprecate_func
3839

3940
from .base import BaseEstimator, EstimatorResult
4041
from .primitive_job import PrimitiveJob
@@ -104,6 +105,7 @@ class BackendEstimator(BaseEstimator[PrimitiveJob[EstimatorResult]]):
104105
precludes doing any provider- or backend-specific optimizations.
105106
"""
106107

108+
@deprecate_func(since="1.2", additional_msg="Use BackendEstimatorV2 instead.")
107109
def __init__(
108110
self,
109111
backend: BackendV1 | BackendV2,

qiskit/primitives/backend_sampler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from qiskit.providers.options import Options
2424
from qiskit.result import QuasiDistribution, Result
2525
from qiskit.transpiler.passmanager import PassManager
26+
from qiskit.utils.deprecation import deprecate_func
2627

2728
from .backend_estimator import _prepare_counts, _run_circuits
2829
from .base import BaseSampler, SamplerResult
@@ -46,6 +47,7 @@ class BackendSampler(BaseSampler[PrimitiveJob[SamplerResult]]):
4647
precludes doing any provider- or backend-specific optimizations.
4748
"""
4849

50+
@deprecate_func(since="1.2", additional_msg="Use BackendSamplerV2 instead.")
4951
def __init__(
5052
self,
5153
backend: BackendV1 | BackendV2,

qiskit/primitives/base/base_estimator.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
r"""Base Estimator Classes"""
13+
"""Base Estimator Classes"""
1414

1515
from __future__ import annotations
1616

@@ -23,6 +23,7 @@
2323
from qiskit.providers import JobV1 as Job
2424
from qiskit.quantum_info.operators import SparsePauliOp
2525
from qiskit.quantum_info.operators.base_operator import BaseOperator
26+
from qiskit.utils.deprecation import deprecate_func
2627

2728
from ..containers import (
2829
DataBin,
@@ -187,7 +188,26 @@ def _run(
187188
raise NotImplementedError("The subclass of BaseEstimator must implement `_run` method.")
188189

189190

190-
BaseEstimator = BaseEstimatorV1
191+
class BaseEstimator(BaseEstimatorV1[T]):
192+
"""DEPRECATED. Type alias of Estimator V1 base class.
193+
194+
See :class:`.BaseEstimatorV1` for details.
195+
"""
196+
197+
@deprecate_func(since="1.2", additional_msg="Use BaseEstimatorV2 instead.")
198+
def __init__(
199+
self,
200+
*,
201+
options: dict | None = None,
202+
):
203+
"""
204+
Creating an instance of an Estimator, or using one in a ``with`` context opens a session that
205+
holds resources until the instance is ``close()`` ed or the context is exited.
206+
207+
Args:
208+
options: Default options.
209+
"""
210+
super().__init__(options=options)
191211

192212

193213
class BaseEstimatorV2(ABC):

qiskit/primitives/base/base_primitive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
"""Primitive abstract base class."""
13+
"""Primitive V1 abstract base class."""
1414

1515
from __future__ import annotations
1616

@@ -20,7 +20,7 @@
2020

2121

2222
class BasePrimitive(ABC):
23-
"""Primitive abstract base class."""
23+
"""Primitive V1 abstract base class."""
2424

2525
def __init__(self, options: dict | None = None):
2626
self._run_options = Options()

qiskit/primitives/base/base_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212
"""
13-
Primitive result abstract base class
13+
Primitive V1 result abstract base class
1414
"""
1515

1616
from __future__ import annotations
@@ -27,7 +27,7 @@
2727

2828
class _BasePrimitiveResult(ABC):
2929
"""
30-
Base class for deprecated Primitive result methods.
30+
Base class for deprecated Primitive V1 result methods.
3131
"""
3232

3333
def __post_init__(self) -> None:

qiskit/primitives/base/base_sampler.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from qiskit.circuit import QuantumCircuit
2323
from qiskit.providers import JobV1 as Job
24+
from qiskit.utils.deprecation import deprecate_func
2425

2526
from ..containers.primitive_result import PrimitiveResult
2627
from ..containers.sampler_pub import SamplerPubLike
@@ -150,7 +151,23 @@ def _run(
150151
raise NotImplementedError("The subclass of BaseSampler must implement `_run` method.")
151152

152153

153-
BaseSampler = BaseSamplerV1
154+
class BaseSampler(BaseSamplerV1[T]):
155+
"""DEPRECATED. Type alias of Sampler V1 base class
156+
157+
See :class:`.BaseSamplerV1` for details.
158+
"""
159+
160+
@deprecate_func(since="1.2", additional_msg="Use BaseSamplerV2 instead.")
161+
def __init__(
162+
self,
163+
*,
164+
options: dict | None = None,
165+
):
166+
"""
167+
Args:
168+
options: Default options.
169+
"""
170+
super().__init__(options=options)
154171

155172

156173
class BaseSamplerV2(ABC):

qiskit/primitives/base/estimator_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212
"""
13-
Estimator result class
13+
Estimator V1 result class
1414
"""
1515

1616
from __future__ import annotations
@@ -26,7 +26,7 @@
2626

2727
@dataclass(frozen=True)
2828
class EstimatorResult(_BasePrimitiveResult):
29-
"""Result of Estimator.
29+
"""Result of Estimator V1.
3030
3131
.. code-block:: python
3232

qiskit/primitives/base/sampler_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212
"""
13-
Sampler result class
13+
Sampler V1 result class
1414
"""
1515

1616
from __future__ import annotations
@@ -25,7 +25,7 @@
2525

2626
@dataclass(frozen=True)
2727
class SamplerResult(_BasePrimitiveResult):
28-
"""Result of Sampler.
28+
"""Result of Sampler V1.
2929
3030
.. code-block:: python
3131

qiskit/primitives/estimator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from qiskit.exceptions import QiskitError
2525
from qiskit.quantum_info import Statevector
2626
from qiskit.quantum_info.operators.base_operator import BaseOperator
27+
from qiskit.utils.deprecation import deprecate_func
2728

2829
from .base import BaseEstimator, EstimatorResult
2930
from .primitive_job import PrimitiveJob
@@ -51,6 +52,7 @@ class Estimator(BaseEstimator[PrimitiveJob[EstimatorResult]]):
5152
this option is ignored.
5253
"""
5354

55+
@deprecate_func(since="1.2", additional_msg="Use StatevectorEstimator instead.")
5456
def __init__(self, *, options: dict | None = None):
5557
"""
5658
Args:

qiskit/primitives/sampler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from qiskit.exceptions import QiskitError
2525
from qiskit.quantum_info import Statevector
2626
from qiskit.result import QuasiDistribution
27+
from qiskit.utils.deprecation import deprecate_func
2728

2829
from .base import BaseSampler, SamplerResult
2930
from .primitive_job import PrimitiveJob
@@ -52,6 +53,7 @@ class Sampler(BaseSampler[PrimitiveJob[SamplerResult]]):
5253
option is ignored.
5354
"""
5455

56+
@deprecate_func(since="1.2", additional_msg="Use StatevectorSampler instead.")
5557
def __init__(self, *, options: dict | None = None):
5658
"""
5759
Args:

0 commit comments

Comments
 (0)