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

Fixes for mypy. #160

Merged
merged 4 commits into from
Jan 4, 2022
Merged
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
1 change: 0 additions & 1 deletion pytket/pytket/circuit/display/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def format_logic_exp(exp: Union[LogicExp, Bit, BitRegister, int]) -> str:
exp.op.value,
format_logic_exp(exp.args[1]),
)
return ""


def get_gate_colour(op_type: str) -> str:
Expand Down
8 changes: 5 additions & 3 deletions pytket/pytket/utils/outcomearray.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"""`OutcomeArray` class and associated methods."""
import operator
from functools import reduce
from typing import Counter, List, Sequence, Dict, Tuple, Any, cast
from typing import Counter, List, Sequence, Dict, Tuple, Any, Optional, cast

import numpy as np
from numpy.typing import ArrayLike


class OutcomeArray(np.ndarray):
Expand Down Expand Up @@ -57,12 +58,13 @@ def __array_finalize__(self, obj): # type: ignore
# see InfoArray.__array_finalize__ for comments
if obj is None:
return
self._width: int = getattr(obj, "_width", None)
self._width: Optional[int] = getattr(obj, "_width", None)

@property
def width(self) -> int:
"""Number of bit entries stored, less than or equal to the bit capacity of the
array."""
assert type(self._width) is int
return self._width

@property
Expand All @@ -77,7 +79,7 @@ def __eq__(self, other: "OutcomeArray") -> bool: # type: ignore
return bool(np.array_equal(self, other) and self.width == other.width)

@classmethod
def from_readouts(cls, readouts: Sequence[Sequence[int]]) -> "OutcomeArray":
def from_readouts(cls, readouts: ArrayLike) -> "OutcomeArray":
"""Create OutcomeArray from a 2D array like object of read-out integers,
e.g. [[1, 1, 0], [0, 1, 1]]"""
readouts_ar = np.array(readouts, dtype=int)
Expand Down
9 changes: 5 additions & 4 deletions pytket/pytket/utils/spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,14 @@ def calculate_matrices(self, results_list: List[BackendResult]) -> None:
# produced state
measured_state_index = binary_to_int(measured_state)
# update characterisation matrix
self.subsets_matrix_map[qb_sub][
measured_state_index, prepared_state_index
] += count
M = self.subsets_matrix_map[qb_sub]
assert type(M) is np.ndarray
M[measured_state_index, prepared_state_index] += count

# normalise everything
self.characterisation_matrices = [
mat / np.sum(mat, axis=0) for mat in self.subsets_matrix_map.values()
mat / np.sum(cast(np.ndarray, mat), axis=0)
for mat in self.subsets_matrix_map.values()
]

def get_parallel_measure(self, circuit: Circuit) -> ParallelMeasures:
Expand Down