Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove parsing catalyst device attribute dictionary for shots #1017

Merged
merged 14 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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.40.0-dev29"
__version__ = "0.40.0-dev30"
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class LightningGPUSimulator final : public Catalyst::Runtime::QuantumDevice {
Catalyst::Runtime::CacheManager<std::complex<double>> cache_manager{};
bool tape_recording{false};

std::size_t device_shots;
std::size_t device_shots{0};

std::mt19937 *gen{nullptr};

Expand Down Expand Up @@ -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::size_t>(std::stoll(args["shots"]))
: 0;
}
~LightningGPUSimulator() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::size_t>(std::stoll(args["shots"]))
: 0;
}
~LightningKokkosSimulator() noexcept = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LightningSimulator final : public Catalyst::Runtime::QuantumDevice {
Catalyst::Runtime::QubitManager<QubitIdType, size_t> qubit_manager{};
Catalyst::Runtime::CacheManager<std::complex<double>> cache_manager{};
bool tape_recording{false};
size_t device_shots;
size_t device_shots{0};

std::mt19937 *gen = nullptr;

Expand Down Expand Up @@ -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<size_t>(std::stoll(args["shots"]))
: 0;
mcmc = args.contains("mcmc") ? args["mcmc"] == "True" : false;
num_burnin = args.contains("num_burnin")
? static_cast<size_t>(std::stoll(args["num_burnin"]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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')"));
Expand Down
Loading