diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 1509f65b3..c09d84436 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -26,6 +26,9 @@ ### Improvements +* Catalyst device interfaces support dynamic shots, and no longer parses the device init op's attribute dictionary for a static shots literal. + [(#1017)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1017) + * Reduce flaky test and increase test shots count. [(#1015)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1015) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index f748fa2b7..8eb04fefb 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.40.0-dev29" +__version__ = "0.40.0-dev30" diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/catalyst/LightningGPUSimulator.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/catalyst/LightningGPUSimulator.hpp index 1c9238a5b..117e46b66 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/catalyst/LightningGPUSimulator.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/catalyst/LightningGPUSimulator.hpp @@ -61,7 +61,7 @@ class LightningGPUSimulator final : public Catalyst::Runtime::QuantumDevice { Catalyst::Runtime::CacheManager> cache_manager{}; bool tape_recording{false}; - std::size_t device_shots; + std::size_t device_shots{0}; std::mt19937 *gen{nullptr}; @@ -108,9 +108,6 @@ class LightningGPUSimulator final : public Catalyst::Runtime::QuantumDevice { public: explicit LightningGPUSimulator(const std::string &kwargs = "{}") { auto &&args = Catalyst::Runtime::parse_kwargs(kwargs); - device_shots = args.contains("shots") - ? static_cast(std::stoll(args["shots"])) - : 0; } ~LightningGPUSimulator() = default; diff --git a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.hpp b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.hpp index dd162569f..f11144765 100644 --- a/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.hpp @@ -109,9 +109,6 @@ class LightningKokkosSimulator final : public Catalyst::Runtime::QuantumDevice { explicit LightningKokkosSimulator( const std::string &kwargs = "{}") noexcept { auto &&args = Catalyst::Runtime::parse_kwargs(kwargs); - device_shots = args.contains("shots") - ? static_cast(std::stoll(args["shots"])) - : 0; } ~LightningKokkosSimulator() noexcept = default; diff --git a/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/LightningSimulator.hpp b/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/LightningSimulator.hpp index c4edb70db..d47fdd4a6 100644 --- a/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/LightningSimulator.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/LightningSimulator.hpp @@ -50,7 +50,7 @@ class LightningSimulator final : public Catalyst::Runtime::QuantumDevice { Catalyst::Runtime::QubitManager qubit_manager{}; Catalyst::Runtime::CacheManager> cache_manager{}; bool tape_recording{false}; - size_t device_shots; + size_t device_shots{0}; std::mt19937 *gen = nullptr; @@ -101,9 +101,6 @@ class LightningSimulator final : public Catalyst::Runtime::QuantumDevice { const std::string &kwargs = "{}") // NOLINT(hicpp-member-init) { auto &&args = Catalyst::Runtime::parse_kwargs(kwargs); - device_shots = args.contains("shots") - ? static_cast(std::stoll(args["shots"])) - : 0; mcmc = args.contains("mcmc") ? args["mcmc"] == "True" : false; num_burnin = args.contains("num_burnin") ? static_cast(std::stoll(args["num_burnin"])) diff --git a/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningDriver.cpp b/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningDriver.cpp index 41ab41738..81f08deb3 100644 --- a/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningDriver.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningDriver.cpp @@ -26,9 +26,9 @@ TEST_CASE("Test parse_kwargs coverage", "[Utils]") { std::string case1; CHECK(parse_kwargs(case1).empty()); - std::string case2{"{shots : 1000}"}; - std::string case3{"shots : 1000"}; - std::string case4{"'shots':'1000'"}; + std::string case2{"{my_attr : 1000}"}; + std::string case3{"my_attr : 1000"}; + std::string case4{"'my_attr':'1000'"}; CHECK(parse_kwargs(case2) == parse_kwargs(case3)); CHECK(parse_kwargs(case3) == parse_kwargs(case4)); @@ -40,13 +40,12 @@ TEST_CASE("Test parse_kwargs coverage", "[Utils]") { CHECK((res5.contains("E") && res5["E"] == "F")); std::string case6{ - "device_type : braket.aws.qubit,{'shots': 0, 'device_arn': 'sv1', " + "device_type : braket.aws.qubit,{'device_arn': 'sv1', " "'s3_destination_folder': \"('catalyst-op3-s3', 'prefix')\"}"}; auto res6 = parse_kwargs(case6); - CHECK(res6.size() == 4); + CHECK(res6.size() == 3); CHECK((res6.contains("device_type") && res6["device_type"] == "braket.aws.qubit")); - CHECK((res6.contains("shots") && res6["shots"] == "0")); CHECK((res6.contains("device_arn") && res6["device_arn"] == "sv1")); CHECK((res6.contains("s3_destination_folder") && res6["s3_destination_folder"] == "('catalyst-op3-s3', 'prefix')"));