From a2816809d90487da77d0f35f03b792f2e5f76b18 Mon Sep 17 00:00:00 2001 From: Erick Ochoa Lopez Date: Mon, 5 Aug 2024 10:32:40 -0400 Subject: [PATCH 1/4] Add SetBasisState and SetState to lightning.kokkos --- .../catalyst/LightningKokkosSimulator.cpp | 13 ++++++++++ .../tests/Test_LightningKokkosSimulator.cpp | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp index 14f2d54c35..44abb07e5d 100644 --- a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp @@ -137,6 +137,19 @@ void LightningKokkosSimulator::PrintState() { } /// LCOV_EXCL_STOP +void LightningKokkosSimulator::SetState(DataView, 1> &data_view) +{ + std::vector> data_vector(data_view.begin(), data_view.end()); + std::vector count(data_vector.size()); + std::iota(std::begin(count), std::end(count), 0); + this->device_sv->setStateVector(count, data_vector); +} + +void LightningKokkosSimulator::SetBasisState(const std::size_t index) +{ + this->device_sv->setBasisState(index); +} + auto LightningKokkosSimulator::Zero() const -> Result { return const_cast(&GLOBAL_RESULT_FALSE_CONST); } diff --git a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp index 4df813266d..fc5cd24935 100644 --- a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp @@ -659,4 +659,30 @@ TEST_CASE("LightningKokkosSimulator::GateSet", "[GateSet]") { expected{3, 0, 1, {"Hadamard", "Hadamard", "IsingZZ"}, {}}; REQUIRE(LKsim->CacheManagerInfo() == expected); } + + SECTION("setBasisState") + { + const size_t num_qubits = 1; + std::unique_ptr sv1 = std::make_unique(); + std::vector Qs = sv1->AllocateQubits(num_qubits); + sv1->setBasisState(0); + std::vector> expected({{1.0, 0.0}, {0.0, 0.0}}); + CHECK(sv1->getDataVector() == expected); + sv1->setBasisState(1); + std::vector> expected2({{0.0, 0.0}, {1.0, 0.0}}); + CHECK(sv1->getDataVector() == expected2); + } + + SECTION("setStateVector") + { + const size_t num_qubits = 1; + std::unique_ptr sv1 = std::make_unique(); + std::vector Qs = sv1->AllocateQubits(num_qubits); + sv1->setStateVector({0}, {{0.5, 0.5}}); + std::vector> expected({{0.5, 0.5}, {0.0, 0.0}}); + CHECK(sv1->getDataVector() == expected); + sv1->setStateVector({1}, {{0.5, 0.5}}); + std::vector> expected2({{0.5, 0.5}, {0.5, 0.5}}); + CHECK(sv1->getDataVector() == expected2); + } } From dab8ffb78630cc16174a3000d627a0a19c02ffe7 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Mon, 5 Aug 2024 14:35:46 +0000 Subject: [PATCH 2/4] Auto update version from '0.38.0-dev25' to '0.38.0-dev26' --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 3961045c01..444de99a58 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.38.0-dev25" +__version__ = "0.38.0-dev26" From 52e930640b8efa6ba4bea8fd885d6c5e8a058e80 Mon Sep 17 00:00:00 2001 From: Erick Ochoa Lopez Date: Mon, 5 Aug 2024 10:44:17 -0400 Subject: [PATCH 3/4] Style --- .../catalyst/LightningKokkosSimulator.cpp | 10 +++++----- .../tests/Test_LightningKokkosSimulator.cpp | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp index 44abb07e5d..4e9a0bd134 100644 --- a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp @@ -137,16 +137,16 @@ void LightningKokkosSimulator::PrintState() { } /// LCOV_EXCL_STOP -void LightningKokkosSimulator::SetState(DataView, 1> &data_view) -{ - std::vector> data_vector(data_view.begin(), data_view.end()); +void LightningKokkosSimulator::SetState( + DataView, 1> &data_view) { + std::vector> data_vector(data_view.begin(), + data_view.end()); std::vector count(data_vector.size()); std::iota(std::begin(count), std::end(count), 0); this->device_sv->setStateVector(count, data_vector); } -void LightningKokkosSimulator::SetBasisState(const std::size_t index) -{ +void LightningKokkosSimulator::SetBasisState(const std::size_t index) { this->device_sv->setBasisState(index); } diff --git a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp index fc5cd24935..00f8a933cf 100644 --- a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp @@ -660,29 +660,31 @@ TEST_CASE("LightningKokkosSimulator::GateSet", "[GateSet]") { REQUIRE(LKsim->CacheManagerInfo() == expected); } - SECTION("setBasisState") - { + SECTION("setBasisState") { const size_t num_qubits = 1; std::unique_ptr sv1 = std::make_unique(); std::vector Qs = sv1->AllocateQubits(num_qubits); sv1->setBasisState(0); - std::vector> expected({{1.0, 0.0}, {0.0, 0.0}}); + std::vector> expected( + {{1.0, 0.0}, {0.0, 0.0}}); CHECK(sv1->getDataVector() == expected); sv1->setBasisState(1); - std::vector> expected2({{0.0, 0.0}, {1.0, 0.0}}); + std::vector> expected2( + {{0.0, 0.0}, {1.0, 0.0}}); CHECK(sv1->getDataVector() == expected2); } - SECTION("setStateVector") - { + SECTION("setStateVector") { const size_t num_qubits = 1; std::unique_ptr sv1 = std::make_unique(); std::vector Qs = sv1->AllocateQubits(num_qubits); sv1->setStateVector({0}, {{0.5, 0.5}}); - std::vector> expected({{0.5, 0.5}, {0.0, 0.0}}); + std::vector> expected( + {{0.5, 0.5}, {0.0, 0.0}}); CHECK(sv1->getDataVector() == expected); sv1->setStateVector({1}, {{0.5, 0.5}}); - std::vector> expected2({{0.5, 0.5}, {0.5, 0.5}}); + std::vector> expected2( + {{0.5, 0.5}, {0.5, 0.5}}); CHECK(sv1->getDataVector() == expected2); } } From 3a92870c2e80f05bbe1b67cf9011cb30184e4422 Mon Sep 17 00:00:00 2001 From: Erick Ochoa Lopez Date: Mon, 5 Aug 2024 10:46:07 -0400 Subject: [PATCH 4/4] Changelog --- .github/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index c0e20d79f8..aeebada5bf 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -63,8 +63,9 @@ * Add a Catalyst-specific wrapping class for Lightning Kokkos. [(#770)](https://github.com/PennyLaneAI/pennylane-lightning/pull/770) -* Add `initial_state_prep` option to Catalyst TOML file. +* Add `initial_state_prep` option to TOML files and Lightning Kokkos. [(#826)](https://github.com/PennyLaneAI/pennylane-lightning/pull/826) + [(#838)](https://github.com/PennyLaneAI/pennylane-lightning/pull/838) ### Documentation