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

Use built-in int type for get_counts() #1713

Merged
merged 3 commits into from
Dec 9, 2024
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: 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
Loading