Skip to content

Commit

Permalink
[bugfix] Fixes for mypy. (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Jan 4, 2022
1 parent 61b2d75 commit ac877e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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

0 comments on commit ac877e8

Please sign in to comment.