Skip to content

Commit

Permalink
Allow empty BackendResult (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Aug 17, 2023
1 parent d23c760 commit 76aab64
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Minor new features:
be overridden using the ``always_squash_symbols`` parameter to
``SquashCustom``.

Fixes:

* Allow ``BackendResult`` objects containing no results.

1.18.0 (August 2023)
--------------------

Expand Down
6 changes: 5 additions & 1 deletion pytket/pytket/backends/backendresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def _process_unitids(
raise ValueError(
"Provide either counts or shots, both is not valid."
)
_bitlength = next(self._counts.elements()).width
try:
_bitlength = next(self._counts.elements()).width
except StopIteration:
_bitlength = len(c_bits)

if self._shots is not None:
_bitlength = self._shots.width
Expand Down Expand Up @@ -252,6 +255,7 @@ def _get_measured_res(
Counter({outcome.choose_indices(chosen_readouts): count})
for outcome, count in new_counts.items()
),
Counter(),
)
if self._shots is not None:
if ppcirc is not None:
Expand Down
6 changes: 6 additions & 0 deletions pytket/tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ def test_postprocess_4() -> None:
assert all(readout[0] == 1 for readout in counts.keys())


def test_empty_backenresult() -> None:
# https://github.com/CQCL/tket/issues/961
r = BackendResult(counts=Counter(), c_bits=[Bit(name="A", index=0)])
assert r.get_counts() == Counter()


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

0 comments on commit 76aab64

Please sign in to comment.