Skip to content

Commit

Permalink
Include the changes introduced in #814 for measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisAlfredoNu committed Jul 26, 2024
1 parent 2a31aaf commit 72faa2f
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions pennylane_lightning/lightning_kokkos/_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,39 +388,6 @@ def _process_single_shot(samples):

return tuple(processed)

Check warning on line 389 in pennylane_lightning/lightning_kokkos/_measurements.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/_measurements.py#L389

Added line #L389 was not covered by tests

# if there is a shot vector, build a list containing results for each shot entry
if shots.has_partitioned_shots:
processed_samples = []
for s in shots:
# currently we call sample_state for each shot entry, but it may be
# better to call sample_state just once with total_shots, then use
# the shot_range keyword argument
try:
# ----------------------------------------
# Original:
# if self._mcmc:
# samples = self._measurement_lightning.generate_mcmc_samples(
# len(wires), self._kernel_name, self._num_burnin, s
# ).astype(int, copy=False)
# else:
# samples = self._measurement_lightning.generate_samples(
# list(wires), s
# ).astype(int, copy=False)

# Specific for Kokkos:
samples = self._measurement_lightning.generate_samples(len(wires), s).astype(
int, copy=False
)
# ----------------------------------------
except ValueError as e:
if str(e) != "probabilities contain NaN":
raise e
samples = qml.math.full((s, len(wires)), 0)

processed_samples.append(_process_single_shot(samples))
self._apply_diagonalizing_gates(mps, adjoint=True)
return tuple(zip(*processed_samples))

try:

Check warning on line 391 in pennylane_lightning/lightning_kokkos/_measurements.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/_measurements.py#L391

Added line #L391 was not covered by tests
# ----------------------------------------
# Original:
Expand All @@ -446,7 +413,16 @@ def _process_single_shot(samples):

self._apply_diagonalizing_gates(mps, adjoint=True)

Check warning on line 414 in pennylane_lightning/lightning_kokkos/_measurements.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/_measurements.py#L414

Added line #L414 was not covered by tests

return _process_single_shot(samples)
# if there is a shot vector, use the shots.bins generator to
# split samples w.r.t. the shots
processed_samples = []
for lower, upper in shots.bins():
result = _process_single_shot(samples[..., lower:upper, :])
processed_samples.append(result)

Check warning on line 421 in pennylane_lightning/lightning_kokkos/_measurements.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/_measurements.py#L418-L421

Added lines #L418 - L421 were not covered by tests

return (

Check warning on line 423 in pennylane_lightning/lightning_kokkos/_measurements.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/lightning_kokkos/_measurements.py#L423

Added line #L423 was not covered by tests
tuple(zip(*processed_samples)) if shots.has_partitioned_shots else processed_samples[0]
)

def _measure_hamiltonian_with_samples(
self,
Expand Down

0 comments on commit 72faa2f

Please sign in to comment.