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

Remove DeprecationWarning when import qiskit.primitives #10288

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion qiskit/primitives/backend_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import copy
from collections.abc import Sequence
from itertools import accumulate
from typing import TYPE_CHECKING

import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.compiler import transpile
from qiskit.opflow import PauliSumOp
from qiskit.providers import BackendV1, BackendV2, Options
from qiskit.quantum_info import Pauli, PauliList
from qiskit.quantum_info.operators.base_operator import BaseOperator
Expand All @@ -34,6 +34,9 @@
from .primitive_job import PrimitiveJob
from .utils import _circuit_key, _observable_key, init_observable

if TYPE_CHECKING:
from qiskit.opflow import PauliSumOp


def _run_circuits(
circuits: QuantumCircuit | list[QuantumCircuit],
Expand Down
6 changes: 4 additions & 2 deletions qiskit/primitives/base/base_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@
from abc import abstractmethod
from collections.abc import Sequence
from copy import copy
from typing import Generic, TypeVar
from typing import TYPE_CHECKING, Generic, TypeVar

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.parametertable import ParameterView
from qiskit.opflow import PauliSumOp
from qiskit.providers import JobV1 as Job
from qiskit.quantum_info.operators import SparsePauliOp
from qiskit.quantum_info.operators.base_operator import BaseOperator
Expand All @@ -97,6 +96,9 @@

T = TypeVar("T", bound=Job)

if TYPE_CHECKING:
from qiskit.opflow import PauliSumOp


class BaseEstimator(BasePrimitive, Generic[T]):
"""Estimator base class.
Expand Down
13 changes: 5 additions & 8 deletions qiskit/primitives/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@
from __future__ import annotations

from collections.abc import Sequence
from typing import Any
from typing import TYPE_CHECKING, Any

import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.exceptions import QiskitError
from qiskit.opflow import PauliSumOp
from qiskit.quantum_info import Statevector
from qiskit.quantum_info.operators.base_operator import BaseOperator

from .base import BaseEstimator, EstimatorResult
from .primitive_job import PrimitiveJob
from .utils import (
_circuit_key,
_observable_key,
bound_circuit_to_instruction,
init_observable,
)
from .utils import _circuit_key, _observable_key, bound_circuit_to_instruction, init_observable

if TYPE_CHECKING:
from qiskit.opflow import PauliSumOp


class Estimator(BaseEstimator[PrimitiveJob[EstimatorResult]]):
Expand Down
7 changes: 5 additions & 2 deletions qiskit/primitives/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
from __future__ import annotations

from collections.abc import Iterable
from typing import TYPE_CHECKING

import numpy as np

from qiskit.circuit import Instruction, ParameterExpression, QuantumCircuit
from qiskit.circuit.bit import Bit
from qiskit.extensions.quantum_initializer.initializer import Initialize
from qiskit.opflow import PauliSumOp
from qiskit.quantum_info import SparsePauliOp, Statevector
from qiskit.quantum_info.operators.base_operator import BaseOperator
from qiskit.quantum_info.operators.symplectic.base_pauli import BasePauli

if TYPE_CHECKING:
from qiskit.opflow import PauliSumOp


def init_circuit(state: QuantumCircuit | Statevector) -> QuantumCircuit:
"""Initialize state by converting the input to a quantum circuit.
Expand Down Expand Up @@ -60,7 +63,7 @@ def init_observable(observable: BaseOperator | PauliSumOp | str) -> SparsePauliO
"""
if isinstance(observable, SparsePauliOp):
return observable
elif isinstance(observable, PauliSumOp):
elif hasattr(observable, "primitive") and isinstance(observable.primitive, SparsePauliOp):
if isinstance(observable.coeff, ParameterExpression):
raise TypeError(
f"Observable must have numerical coefficient, not {type(observable.coeff)}."
Expand Down