Skip to content

Commit

Permalink
Use built-in int type for get_counts() (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Dec 9, 2024
1 parent e13ed26 commit 8de98ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
Fixes:

* Fix circuit iteration giving invalid slices in some cases.
* Use built-in int type for get_counts() instead of numpy int types.

Performance:

Expand Down
2 changes: 1 addition & 1 deletion pytket/pytket/utils/outcomearray.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ def readout_counts(
ctr: Counter[OutcomeArray],
) -> Counter[tuple[int, ...]]:
"""Convert counts from :py:class:`OutcomeArray` types to tuples of ints."""
return Counter({tuple(oa.to_readout()): n for oa, n in ctr.items()})
return Counter({tuple(map(int, oa.to_readout())): int(n) for oa, n in ctr.items()})
13 changes: 13 additions & 0 deletions pytket/tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,19 @@ def test_empty_backenresult() -> None:
assert r.get_counts() == Counter()


def test_int_type() -> None:
# https://github.com/CQCL/tket/issues/1677
b = TketSimShotBackend(ignore_measures=True)
c = Circuit(2).H(0).H(1).measure_all()
c1 = b.get_compiled_circuit(c)
h = b.process_circuit(c1, n_shots=10)
r = b.get_result(h)
counts = r.get_counts()
for k, v in counts.items():
assert all(isinstance(i, int) for i in k)
assert isinstance(v, int)


if __name__ == "__main__":
# test_resulthandle()
# test_bell()
Expand Down

0 comments on commit 8de98ae

Please sign in to comment.