Skip to content

Commit

Permalink
Fix primitives mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Randl committed Jun 29, 2022
1 parent 1082240 commit 3ad10fc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
9 changes: 5 additions & 4 deletions qiskit/primitives/base_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
from abc import ABC, abstractmethod
from collections.abc import Iterable, Sequence
from copy import copy
from typing import List

import numpy as np

Expand Down Expand Up @@ -163,8 +164,8 @@ def __init__(

# To guarantee that they exist as instance variable.
# With only dynamic set, the python will not know if the attribute exists or not.
self._circuit_ids = self._circuit_ids
self._observable_ids = self._observable_ids
self._circuit_ids: List[int] = self._circuit_ids
self._observable_ids: List[int] = self._observable_ids

if parameters is None:
self._parameters = tuple(circ.parameters for circ in self._circuits)
Expand Down Expand Up @@ -296,7 +297,7 @@ def __call__(
if not isinstance(circuit, (int, np.integer))
else circuit
for circuit in circuits
]
] # TODO: typed as list of int after this operations
except StopIteration as err:
raise QiskitError(
"The circuits passed when calling estimator is not one of the circuits used to "
Expand All @@ -308,7 +309,7 @@ def __call__(
if not isinstance(observable, (int, np.integer))
else observable
for observable in observables
]
] # TODO: typed as list of int after this operations
except StopIteration as err:
raise QiskitError(
"The observables passed when calling estimator is not one of the observables used to "
Expand Down
3 changes: 2 additions & 1 deletion qiskit/primitives/base_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
from abc import ABC, abstractmethod
from collections.abc import Iterable, Sequence
from copy import copy
from typing import List

import numpy as np

Expand Down Expand Up @@ -138,7 +139,7 @@ def __init__(

# To guarantee that they exist as instance variable.
# With only dynamic set, the python will not know if the attribute exists or not.
self._circuit_ids = self._circuit_ids
self._circuit_ids: List[int] = self._circuit_ids

if parameters is None:
self._parameters = tuple(circ.parameters for circ in self._circuits)
Expand Down
3 changes: 2 additions & 1 deletion qiskit/primitives/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

from collections.abc import Iterable, Sequence
from typing import List, Dict, Any

import numpy as np

Expand Down Expand Up @@ -87,7 +88,7 @@ def _call(
rng = np.random.default_rng(seed)

# Initialize metadata
metadata = [{}] * len(circuits)
metadata: List[Dict[str, Any]] = [{}] * len(circuits)

bound_circuits = []
for i, value in zip(circuits, parameter_values):
Expand Down
4 changes: 2 additions & 2 deletions qiskit/primitives/estimator_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Dict, List

if TYPE_CHECKING:
import numpy as np
Expand All @@ -41,4 +41,4 @@ class EstimatorResult:
"""

values: "np.ndarray[Any, np.dtype[np.float64]]"
metadata: list[dict[str, Any]]
metadata: List[Dict[str, Any]]
3 changes: 2 additions & 1 deletion qiskit/primitives/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

from collections.abc import Iterable, Sequence
from typing import Dict, List, Any

import numpy as np

Expand Down Expand Up @@ -97,7 +98,7 @@ def _call(
rng = np.random.default_rng(seed)

# Initialize metadata
metadata = [{}] * len(circuits)
metadata: List[Dict[str, Any]] = [{}] * len(circuits)

bound_circuits_qargs = []
for i, value in zip(circuits, parameter_values):
Expand Down
6 changes: 3 additions & 3 deletions qiskit/primitives/sampler_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any
from typing import Any, List, Dict

from qiskit.result import QuasiDistribution

Expand All @@ -39,5 +39,5 @@ class SamplerResult:
metadata (list[dict]): List of the metadata.
"""

quasi_dists: list[QuasiDistribution]
metadata: list[dict[str, Any]]
quasi_dists: List[QuasiDistribution]
metadata: List[Dict[str, Any]]

0 comments on commit 3ad10fc

Please sign in to comment.