Skip to content

Commit

Permalink
Added a check to raise an error in the sampler if there are no measur…
Browse files Browse the repository at this point in the history
…ements in the circuit.
  • Loading branch information
PabloAndresCQ committed Jul 30, 2024
1 parent d7a72b8 commit 206fd71
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,17 @@ def sample(
scratch_fraction: Optional. Fraction of free memory on GPU to allocate as
scratch space.
Raises:
ValueError: If the circuit contains no measurements.
MemoryError: If there is insufficient workspace on GPU.
Returns:
A pytket ``BackendResult`` with the data from the shots.
"""

num_measurements = len(self._measurements)
if num_measurements == 0:
raise ValueError(
"Cannot sample from the circuit, it contains no measurements."
)
# We will need both a list of the qubits and a list of the classical bits
# and it is essential that the elements in the same index of either list
# match according to the self._measurements map. We guarantee this here.
Expand Down

0 comments on commit 206fd71

Please sign in to comment.