Skip to content

Commit df52166

Browse files
authored
Remove runtime type checks from sinter.AnonTaskStats (#1056)
This was causing problems in a variety of places, and ultimately just isn't very pythonic. Obsoletes #1039 Fixes #1000
1 parent f9ad388 commit df52166

2 files changed

Lines changed: 6 additions & 16 deletions

File tree

glue/sample/src/sinter/_data/_anon_task_stats.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import collections
22
import dataclasses
3-
from typing import Counter, Union, TYPE_CHECKING
4-
import numpy as np
5-
6-
if TYPE_CHECKING:
7-
from sinter._data._task_stats import TaskStats
3+
from typing import Counter
84

95

106
@dataclasses.dataclass(frozen=True)
@@ -35,16 +31,10 @@ class AnonTaskStats:
3531
custom_counts: Counter[str] = dataclasses.field(default_factory=collections.Counter)
3632

3733
def __post_init__(self):
38-
assert isinstance(self.errors, (int, np.integer))
39-
assert isinstance(self.shots, (int, np.integer))
40-
assert isinstance(self.discards, (int, np.integer))
41-
assert isinstance(self.seconds, (int, float, np.integer, np.floating))
42-
assert isinstance(self.custom_counts, collections.Counter)
4334
assert self.errors >= 0
4435
assert self.discards >= 0
4536
assert self.seconds >= 0
4637
assert self.shots >= self.errors + self.discards
47-
assert all(isinstance(k, str) and isinstance(v, (int, np.integer)) for k, v in self.custom_counts.items())
4838

4939
def __repr__(self) -> str:
5040
terms = []
@@ -80,10 +70,10 @@ def __add__(self, other: 'AnonTaskStats') -> 'AnonTaskStats':
8070
"""
8171
if isinstance(other, AnonTaskStats):
8272
return AnonTaskStats(
83-
shots=self.shots + other.shots,
84-
errors=self.errors + other.errors,
85-
discards=self.discards + other.discards,
86-
seconds=self.seconds + other.seconds,
73+
shots=int(self.shots + other.shots),
74+
errors=int(self.errors + other.errors),
75+
discards=int(self.discards + other.discards),
76+
seconds=float(self.seconds + other.seconds),
8777
custom_counts=self.custom_counts + other.custom_counts,
8878
)
8979

glue/sample/src/sinter/_decoding/_stim_then_decode_sampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def classify_discards_and_errors(
8181
out_count_observable_error_combos[err_key] += 1
8282

8383
num_errors = np.count_nonzero(fail_mask)
84-
return num_discards, num_errors
84+
return int(num_discards), int(num_errors)
8585

8686

8787
class DiskDecoder(CompiledDecoder):

0 commit comments

Comments
 (0)