Skip to content

Commit

Permalink
Update MCM measurements as dynamic_one_shot handles post-selection (#720
Browse files Browse the repository at this point in the history
)

* Update LQ mcms

* Auto update version from '0.37.0-dev4' to '0.37.0-dev5'

* Remove mid_meas = -1 from LK.

* paths-ignore _version.py

---------

Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
  • Loading branch information
vincentmr and ringo-but-quantum authored May 9, 2024
1 parent 229359f commit 279f7e8
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Breaking changes

* `dynamic_one_shot` deals with post-selection during the post-processing phase, so Lightning-Qubit does not return `None`-valued measurements for mismatching samples anymore.
[(#720)](https://github.com/PennyLaneAI/pennylane-lightning/pull/720)

### Improvements

* The various OpenMP configurations of Lightning-Qubit are tested in parallel on different Github Actions runners.
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests_lgpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
paths-ignore:
- .github
- '!.github/workflows/tests_lgpu_python.yml'
- pennylane_lightning/core/_version.py
- pennylane_lightning/core/src/simulators/lightning_kokkos/**
- pennylane_lightning/core/src/simulators/lightning_qubit/**
- pennylane_lightning/lightning_kokkos/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests_lgpumpi_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
paths-ignore:
- .github
- '!.github/workflows/tests_lgpumpi_python.yml'
- pennylane_lightning/core/_version.py
- pennylane_lightning/core/src/simulators/lightning_kokkos/**
- pennylane_lightning/core/src/simulators/lightning_qubit/**
- pennylane_lightning/lightning_kokkos/**
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/tests_lkcpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ on:
paths-ignore:
- .github
- '!.github/workflows/tests_lkcpu_python.yml'
- pennylane_lightning/core/_version.py
- pennylane_lightning/core/src/simulators/lightning_gpu/**
- pennylane_lightning/lightning_gpu/**
- pennylane_lightning/core/src/simulators/lightning_qubit/**
- pennylane_lightning/lightning_gpu/**
- pennylane_lightning/lightning_qubit/**
push:
branches:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests_lkcuda_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
paths-ignore:
- .github
- '!.github/workflows/tests_lkcuda_python.yml'
- pennylane_lightning/core/_version.py
- pennylane_lightning/core/src/simulators/lightning_gpu/**
- pennylane_lightning/core/src/simulators/lightning_qubit/**
- pennylane_lightning/lightning_gpu/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests_lqcpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
paths-ignore:
- .github
- '!.github/workflows/tests_lqcpu_python.yml'
- pennylane_lightning/core/_version.py
- pennylane_lightning/core/src/simulators/lightning_gpu/**
- pennylane_lightning/lightning_gpu/**
- pennylane_lightning/core/src/simulators/lightning_kokkos/**
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.37.0-dev4"
__version__ = "0.37.0-dev5"
5 changes: 0 additions & 5 deletions pennylane_lightning/lightning_kokkos/lightning_kokkos.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,6 @@ def _apply_lightning_midmeasure(self, operation: MidMeasureMP, mid_measurements:
wires = self.wires.indices(operation.wires)
wire = list(wires)[0]
sample = qml.math.reshape(self.generate_samples(shots=1), (-1,))[wire]
if operation.postselect is not None and sample != operation.postselect:
mid_measurements[operation] = -1
return
mid_measurements[operation] = sample
getattr(self.state_vector, "collapse")(wire, bool(sample))
if operation.reset and bool(sample):
Expand Down Expand Up @@ -482,8 +479,6 @@ def apply(self, operations, rotations=None, mid_measurements=None, **kwargs):
)

self.apply_lightning(operations, mid_measurements=mid_measurements)
if mid_measurements is not None and any(v == -1 for v in mid_measurements.values()):
self._apply_basis_state(np.zeros(self.num_wires), wires=self.wires)

# pylint: disable=protected-access
def expval(self, observable, shot_range=None, bin_size=None):
Expand Down
7 changes: 0 additions & 7 deletions pennylane_lightning/lightning_qubit/_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,10 @@ def measure_with_samples(
"""
# last N measurements are sampling MCMs in ``dynamic_one_shot`` execution mode
mps = measurements[0 : -len(mid_measurements)] if mid_measurements else measurements
skip_measure = (
any(v == -1 for v in mid_measurements.values()) if mid_measurements else False
)

groups, indices = _group_measurements(mps)

all_res = []
for group in groups:
if skip_measure:
all_res.extend([None] * len(group))
continue
if isinstance(group[0], (ExpectationMP, VarianceMP)) and isinstance(
group[0].obs, SparseHamiltonian
):
Expand Down

0 comments on commit 279f7e8

Please sign in to comment.