diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index a55ef60238..a522237ffe 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -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. diff --git a/.github/workflows/tests_lgpu_python.yml b/.github/workflows/tests_lgpu_python.yml index ab49c7b141..5ab6975fd0 100644 --- a/.github/workflows/tests_lgpu_python.yml +++ b/.github/workflows/tests_lgpu_python.yml @@ -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/** diff --git a/.github/workflows/tests_lgpumpi_python.yml b/.github/workflows/tests_lgpumpi_python.yml index 7f9a5e431f..3b3cecdec9 100644 --- a/.github/workflows/tests_lgpumpi_python.yml +++ b/.github/workflows/tests_lgpumpi_python.yml @@ -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/** diff --git a/.github/workflows/tests_lkcpu_python.yml b/.github/workflows/tests_lkcpu_python.yml index 5d405753c7..340e4e5c93 100644 --- a/.github/workflows/tests_lkcpu_python.yml +++ b/.github/workflows/tests_lkcpu_python.yml @@ -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: diff --git a/.github/workflows/tests_lkcuda_python.yml b/.github/workflows/tests_lkcuda_python.yml index a7daef4cf1..878a1051e5 100644 --- a/.github/workflows/tests_lkcuda_python.yml +++ b/.github/workflows/tests_lkcuda_python.yml @@ -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/** diff --git a/.github/workflows/tests_lqcpu_python.yml b/.github/workflows/tests_lqcpu_python.yml index 89a3869b98..7124b3f0d5 100644 --- a/.github/workflows/tests_lqcpu_python.yml +++ b/.github/workflows/tests_lqcpu_python.yml @@ -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/** diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index b46423dcc8..b3b4b3174c 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.37.0-dev4" +__version__ = "0.37.0-dev5" diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py index 4a9eede8ef..e17f317707 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py @@ -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): @@ -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): diff --git a/pennylane_lightning/lightning_qubit/_measurements.py b/pennylane_lightning/lightning_qubit/_measurements.py index 52d3c154b4..31a9f18179 100644 --- a/pennylane_lightning/lightning_qubit/_measurements.py +++ b/pennylane_lightning/lightning_qubit/_measurements.py @@ -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 ):