Skip to content

Commit 10dc3a9

Browse files
Update kokkos files from catalyst repo to support MCM seeding (#819)
### Before submitting Please complete the following checklist when submitting a PR: - [x] All new features must include a unit test. If you've fixed a bug or added code that should be tested, add a test to the [`tests`](../tests) directory! - [x] All new functions and code must be clearly commented and documented. If you do make documentation changes, make sure that the docs build and render correctly by running `make docs`. - [x] Ensure that the test suite passes, by running `make test`. - [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing the change, and including a link back to the PR. - [x] Ensure that code is properly formatted by running `make format`. When all the above are checked, delete everything above the dashed line and fill in the pull request template. ------------------------------------------------------------------------------------------------------------ **Context:** The lightning kokkos files in the Catalyst repo has changed since #770. We make a small update to track these changes. The Catalyst PR that made the changes added seeding to qjit: PennyLaneAI/catalyst#936 **Description of the Change:** The `lightning_kokkos/catalyst` files now has the MCM seeding support added in catalyst PennyLaneAI/catalyst#936 **Benefits:** unblocks kokkos with catalyst **Possible Drawbacks:** None **Related GitHub Issues:** None --------- Co-authored-by: ringo-but-quantum <[email protected]>
1 parent d1b4007 commit 10dc3a9

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

.github/CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515

1616
### Improvements
1717

18+
* Update the Catalyst-specific wrapping class for Lightning Kokkos to track Catalyst's new support for MCM seeding.
19+
[(#819)](https://github.com/PennyLaneAI/pennylane-lightning/pull/819)
20+
1821
* Shot batching is made more efficient by executing all the shots in one go on LightningQubit.
19-
[#814](https://github.com/PennyLaneAI/pennylane-lightning/pull/814)
22+
[(#814)](https://github.com/PennyLaneAI/pennylane-lightning/pull/814)
2023

2124
* LightningQubit calls `generate_samples(wires)` on a minimal subset of wires when executing in finite-shot mode.
2225
[(#813)](https://github.com/PennyLaneAI/pennylane-lightning/pull/813)
@@ -74,7 +77,7 @@
7477

7578
This release contains contributions from (in alphabetical order):
7679

77-
Ali Asadi, Amintor Dusko, Vincent Michaud-Rioux, Shuli Shu
80+
Ali Asadi, Amintor Dusko, Vincent Michaud-Rioux, Shuli Shu, Paul Haochen Wang
7881

7982
---
8083

pennylane_lightning/core/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.38.0-dev17"
19+
__version__ = "0.38.0-dev18"

pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ auto LightningKokkosSimulator::GetDeviceShots() const -> std::size_t {
106106
return this->device_shots;
107107
}
108108

109+
void LightningKokkosSimulator::SetDevicePRNG(std::mt19937 *gen) {
110+
this->gen = gen;
111+
}
112+
109113
/// LCOV_EXCL_START
110114
void LightningKokkosSimulator::PrintState() {
111115
using std::cout;
@@ -480,7 +484,7 @@ auto LightningKokkosSimulator::Measure(QubitIdType wire,
480484
SetDeviceShots(device_shots);
481485

482486
// It represents the measured result, true for 1, false for 0
483-
bool mres = Lightning::simulateDraw(probs, postselect);
487+
bool mres = Lightning::simulateDraw(probs, postselect, this->gen);
484488
auto dev_wires = getDeviceWires(wires);
485489
this->device_sv->collapse(dev_wires[0], mres ? 1 : 0);
486490
return mres ? this->One() : this->Zero();

pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <iostream>
2727
#include <limits>
2828
#include <optional>
29+
#include <random>
2930
#include <span>
3031
#include <stdexcept>
3132
#include <unordered_map>
@@ -63,6 +64,8 @@ class LightningKokkosSimulator final : public Catalyst::Runtime::QuantumDevice {
6364

6465
std::size_t device_shots;
6566

67+
std::mt19937 *gen{nullptr};
68+
6669
std::unique_ptr<StateVectorT> device_sv = std::make_unique<StateVectorT>(0);
6770
LightningKokkosObsManager<double> obs_manager{};
6871

@@ -116,6 +119,7 @@ class LightningKokkosSimulator final : public Catalyst::Runtime::QuantumDevice {
116119
void StartTapeRecording() override;
117120
void StopTapeRecording() override;
118121
void SetDeviceShots(size_t shots) override;
122+
void SetDevicePRNG(std::mt19937 *) override;
119123
[[nodiscard]] auto GetDeviceShots() const -> size_t override;
120124
void PrintState() override;
121125
[[nodiscard]] auto Zero() const -> Result override;

pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <random>
16+
1517
#include "CacheManager.hpp"
1618
#include "LightningKokkosSimulator.hpp"
1719
#include "QuantumDevice.hpp"
@@ -1750,3 +1752,28 @@ TEST_CASE("Counts and PartialCounts tests with numWires=0-4 shots=100",
17501752
CHECK(sum3 == shots);
17511753
CHECK(sum4 == shots);
17521754
}
1755+
1756+
TEST_CASE("Measurement with a seeded device", "[Measures]") {
1757+
for (size_t _ = 0; _ < 5; _++) {
1758+
std::unique_ptr<LKSimulator> sim = std::make_unique<LKSimulator>();
1759+
std::unique_ptr<LKSimulator> sim1 = std::make_unique<LKSimulator>();
1760+
1761+
std::mt19937 gen(37);
1762+
sim->SetDevicePRNG(&gen);
1763+
std::vector<intptr_t> Qs;
1764+
Qs.reserve(1);
1765+
Qs.push_back(sim->AllocateQubit());
1766+
sim->NamedOperation("Hadamard", {}, {Qs[0]}, false);
1767+
auto m = sim->Measure(Qs[0]);
1768+
1769+
std::mt19937 gen1(37);
1770+
sim1->SetDevicePRNG(&gen1);
1771+
std::vector<intptr_t> Qs1;
1772+
Qs1.reserve(1);
1773+
Qs1.push_back(sim1->AllocateQubit());
1774+
sim1->NamedOperation("Hadamard", {}, {Qs1[0]}, false);
1775+
auto m1 = sim1->Measure(Qs1[0]);
1776+
1777+
CHECK(*m == *m1);
1778+
}
1779+
}

0 commit comments

Comments
 (0)