Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate PrimitivesV1 reference implementations and their utils #12575

Merged
merged 25 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
48e7182
Deprecate V1 Primitives and their utils
LeanderCS Jun 13, 2024
6f7d158
Fix tests
LeanderCS Jun 13, 2024
24c4609
Fix yaml error
LeanderCS Jun 13, 2024
3678783
Fix build
LeanderCS Jun 13, 2024
594b7d9
Merge branch 'main' into deprecate-primitives-v1
LeanderCS Jun 14, 2024
49e35bf
Merge branch 'main' into deprecate-primitives-v1
LeanderCS Jun 22, 2024
9e03a86
Fix error after mc
LeanderCS Jun 23, 2024
c349353
Fix error after mc
LeanderCS Jun 24, 2024
e81e86f
Apply comments
LeanderCS Jun 24, 2024
71ad3fb
Use correct deprecate version for warning message
LeanderCS Jun 25, 2024
620707e
Update deprecation messages
LeanderCS Jul 4, 2024
e3e0f54
Add missed ``
LeanderCS Jul 4, 2024
143960f
update releasenote
t-imamichi Jul 5, 2024
fbc65dd
Merge branch 'main' into deprecate-primitives-v1
t-imamichi Jul 5, 2024
c0103f7
Deprecate SamplerResult and EstimatorResult
LeanderCS Jul 8, 2024
e7094eb
fix deprecation warning for SamplerResult and EstimatorResult
t-imamichi Jul 9, 2024
94486dd
apply review comments
t-imamichi Jul 16, 2024
4ca4f77
Merge branch 'main' into deprecate-primitives-v1
t-imamichi Jul 17, 2024
696a196
Applying the agreement of deprecations.
t-imamichi Jul 24, 2024
0b66c6a
revert SamplerResult, EstimatorResult, and BasePrimitiveResult
t-imamichi Jul 24, 2024
17c34b4
fix test_backend_sampler
t-imamichi Jul 24, 2024
593e751
revert tox.ini
t-imamichi Jul 24, 2024
02a288f
revise deprecation warning for BaseSampler and BaseEstimator
t-imamichi Jul 25, 2024
4de78e2
update reno
t-imamichi Jul 25, 2024
3704f35
revert BaseSampler and BaseEstimator
t-imamichi Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions qiskit/primitives/backend_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Optimize1qGatesDecomposition,
SetLayout,
)
from qiskit.utils.deprecation import deprecate_func

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

@deprecate_func(since="1.0", additional_msg="Use BackendEstimatorV2 instead.")
LeanderCS marked this conversation as resolved.
Show resolved Hide resolved
def __init__(
self,
backend: BackendV1 | BackendV2,
Expand Down
2 changes: 2 additions & 0 deletions qiskit/primitives/backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from qiskit.providers.options import Options
from qiskit.result import QuasiDistribution, Result
from qiskit.transpiler.passmanager import PassManager
from qiskit.utils.deprecation import deprecate_func

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

@deprecate_func(since="1.0", additional_msg="Use BackendSamplerV2 instead.")
def __init__(
self,
backend: BackendV1 | BackendV2,
Expand Down
2 changes: 2 additions & 0 deletions qiskit/primitives/base/base_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from qiskit.providers import JobV1 as Job
from qiskit.quantum_info.operators import SparsePauliOp
from qiskit.quantum_info.operators.base_operator import BaseOperator
from qiskit.utils.deprecation import deprecate_func

from ..containers import (
DataBin,
Expand Down Expand Up @@ -103,6 +104,7 @@ class BaseEstimatorV1(BasePrimitive, Generic[T]):

__hash__ = None

@deprecate_func(since="1.0", additional_msg="Use BaseEstimatorV2 instead.")
def __init__(
self,
*,
Expand Down
2 changes: 2 additions & 0 deletions qiskit/primitives/base/base_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
from abc import ABC

from qiskit.providers import Options
from qiskit.utils.deprecation import deprecate_func


class BasePrimitive(ABC):
"""Primitive abstract base class."""

@deprecate_func(since="1.0", additional_msg="Use BasePrimitiveV2 instead.")
def __init__(self, options: dict | None = None):
self._run_options = Options()
if options is not None:
Expand Down
8 changes: 8 additions & 0 deletions qiskit/primitives/base/base_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from collections.abc import Sequence
from dataclasses import fields
from typing import Any, Dict
from warnings import warn

from numpy import ndarray

Expand All @@ -42,6 +43,13 @@ def __post_init__(self) -> None:
TypeError: If one of the data fields is not a Sequence or ``numpy.ndarray``.
ValueError: Inconsistent number of experiments across data fields.
"""
warn(
"The class ``BasePrimitiveResult`` is deprecated as of qiskit 1.0. "
LeanderCS marked this conversation as resolved.
Show resolved Hide resolved
"It will be removed no earlier than 3 months after the release date. "
"Use PrimitiveResult class in `qiskit.primitives.containers` instead.",
LeanderCS marked this conversation as resolved.
Show resolved Hide resolved
DeprecationWarning,
)

num_experiments = None
for value in self._field_values: # type: Sequence
if num_experiments is None:
Expand Down
2 changes: 2 additions & 0 deletions qiskit/primitives/base/base_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from qiskit.circuit import QuantumCircuit
from qiskit.providers import JobV1 as Job
from qiskit.utils.deprecation import deprecate_func

from ..containers.primitive_result import PrimitiveResult
from ..containers.sampler_pub import SamplerPubLike
Expand Down Expand Up @@ -96,6 +97,7 @@ class BaseSamplerV1(BasePrimitive, Generic[T]):

__hash__ = None

@deprecate_func(since="1.0", additional_msg="Use BaseSamplerV2 instead.")
def __init__(
self,
*,
Expand Down
2 changes: 2 additions & 0 deletions qiskit/primitives/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from qiskit.exceptions import QiskitError
from qiskit.quantum_info import Statevector
from qiskit.quantum_info.operators.base_operator import BaseOperator
from qiskit.utils.deprecation import deprecate_func

from .base import BaseEstimator, EstimatorResult
from .primitive_job import PrimitiveJob
Expand Down Expand Up @@ -51,6 +52,7 @@ class Estimator(BaseEstimator[PrimitiveJob[EstimatorResult]]):
this option is ignored.
"""

@deprecate_func(since="1.0", additional_msg="Use StatevectorEstimator instead.")
def __init__(self, *, options: dict | None = None):
"""
Args:
Expand Down
2 changes: 2 additions & 0 deletions qiskit/primitives/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from qiskit.exceptions import QiskitError
from qiskit.quantum_info import Statevector
from qiskit.result import QuasiDistribution
from qiskit.utils.deprecation import deprecate_func

from .base import BaseSampler, SamplerResult
from .primitive_job import PrimitiveJob
Expand Down Expand Up @@ -52,6 +53,7 @@ class Sampler(BaseSampler[PrimitiveJob[SamplerResult]]):
option is ignored.
"""

@deprecate_func(since="1.0", additional_msg="Use StatevectorSampler instead.")
def __init__(self, *, options: dict | None = None):
"""
Args:
Expand Down
4 changes: 4 additions & 0 deletions qiskit/primitives/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
from qiskit.quantum_info import PauliList, SparsePauliOp, Statevector
from qiskit.quantum_info.operators.base_operator import BaseOperator
from qiskit.quantum_info.operators.symplectic.base_pauli import BasePauli
from qiskit.utils.deprecation import deprecate_func


@deprecate_func(since="1.0", additional_msg="There is no replacement for this.")
def init_circuit(state: QuantumCircuit | Statevector) -> QuantumCircuit:
"""Initialize state by converting the input to a quantum circuit.

Expand All @@ -45,6 +47,7 @@ def init_circuit(state: QuantumCircuit | Statevector) -> QuantumCircuit:
return qc


@deprecate_func(since="1.0", additional_msg="There is no replacement for this.")
def init_observable(observable: BaseOperator | str) -> SparsePauliOp:
"""Initialize observable by converting the input to a :class:`~qiskit.quantum_info.SparsePauliOp`.

Expand All @@ -68,6 +71,7 @@ def init_observable(observable: BaseOperator | str) -> SparsePauliOp:
return SparsePauliOp(observable)


@deprecate_func(since="1.0", additional_msg="There is no replacement for this.")
def final_measurement_mapping(circuit: QuantumCircuit) -> dict[int, int]:
"""Return the final measurement mapping for the circuit.

Expand Down
14 changes: 14 additions & 0 deletions releasenotes/notes/deprecate-primitives-v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
deprecations_primitives:
- |
BackendEstimator has been deprecated. Use BackendEstimatorV2 instead.
BackendSampler has been deprecated. Use BackendSamplerV2 instead.
Estimator has been deprecated. Use StatevectorEstimator instead.
Sampler has been deprecated. Use StatevectorSampler instead.

BaseEstimatorV1 has been deprecated. Use BaseEstimatorV2 instead.
BasePrimitive has been deprecated. Use BasePrimitiveV2 instead.
BasePrimitiveResult has been deprecated. Use PrimitiveResult class in `qiskit.primitives.containers` instead.
BaseSamplerV1 has been deprecated. Use BaseSamplerV2 instead.

Functions: init_circuit, init_observable and final_measurement_mapping has been deprecated. There is no replacement.
Loading