Skip to content

Commit 9203364

Browse files
paul0403ringo-but-quantum
authored andcommitted
Remove parsing catalyst device attribute dictionary for shots (#1017)
**Context:** As part of the work to support dynamic measurement shapes, PennyLaneAI/catalyst#1310 in Catalyst is allowing a quantum device to take in a dynamic number of shots at the mlir level. One of the changes involved is that the `DeviceInitOp` now takes in a proper SSA argument for shots, instead of having shots as just another entry in the `DeviceInitOp`'s attribute dictionary. Correspondingly, the backend devices' catalyst interfaces need to stop parsing the `DeviceInitOp`'s attribute dictionary for shots. **Description of the Change:** The backend devices' catalyst interfaces stop parsing the `DeviceInitOp`'s attribute dictionary for shots. **Benefits:** Agreement with Catalyst on how device shots, potentially dynamic, is handled. **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: ringo-but-quantum <[email protected]>
1 parent edcab29 commit 9203364

File tree

5 files changed

+10
-17
lines changed

5 files changed

+10
-17
lines changed

.github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
### Improvements
2828

29+
* Catalyst device interfaces support dynamic shots, and no longer parses the device init op's attribute dictionary for a static shots literal.
30+
[(#1017)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1017)
31+
2932
* Reduce flaky test and increase test shots count.
3033
[(#1015)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1015)
3134

pennylane_lightning/core/src/simulators/lightning_gpu/catalyst/LightningGPUSimulator.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class LightningGPUSimulator final : public Catalyst::Runtime::QuantumDevice {
6161
Catalyst::Runtime::CacheManager<std::complex<double>> cache_manager{};
6262
bool tape_recording{false};
6363

64-
std::size_t device_shots;
64+
std::size_t device_shots{0};
6565

6666
std::mt19937 *gen{nullptr};
6767

@@ -108,9 +108,6 @@ class LightningGPUSimulator final : public Catalyst::Runtime::QuantumDevice {
108108
public:
109109
explicit LightningGPUSimulator(const std::string &kwargs = "{}") {
110110
auto &&args = Catalyst::Runtime::parse_kwargs(kwargs);
111-
device_shots = args.contains("shots")
112-
? static_cast<std::size_t>(std::stoll(args["shots"]))
113-
: 0;
114111
}
115112
~LightningGPUSimulator() = default;
116113

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

-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ class LightningKokkosSimulator final : public Catalyst::Runtime::QuantumDevice {
109109
explicit LightningKokkosSimulator(
110110
const std::string &kwargs = "{}") noexcept {
111111
auto &&args = Catalyst::Runtime::parse_kwargs(kwargs);
112-
device_shots = args.contains("shots")
113-
? static_cast<std::size_t>(std::stoll(args["shots"]))
114-
: 0;
115112
}
116113
~LightningKokkosSimulator() noexcept = default;
117114

pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/LightningSimulator.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LightningSimulator final : public Catalyst::Runtime::QuantumDevice {
5050
Catalyst::Runtime::QubitManager<QubitIdType, size_t> qubit_manager{};
5151
Catalyst::Runtime::CacheManager<std::complex<double>> cache_manager{};
5252
bool tape_recording{false};
53-
size_t device_shots;
53+
size_t device_shots{0};
5454

5555
std::mt19937 *gen = nullptr;
5656

@@ -101,9 +101,6 @@ class LightningSimulator final : public Catalyst::Runtime::QuantumDevice {
101101
const std::string &kwargs = "{}") // NOLINT(hicpp-member-init)
102102
{
103103
auto &&args = Catalyst::Runtime::parse_kwargs(kwargs);
104-
device_shots = args.contains("shots")
105-
? static_cast<size_t>(std::stoll(args["shots"]))
106-
: 0;
107104
mcmc = args.contains("mcmc") ? args["mcmc"] == "True" : false;
108105
num_burnin = args.contains("num_burnin")
109106
? static_cast<size_t>(std::stoll(args["num_burnin"]))

pennylane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningDriver.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ TEST_CASE("Test parse_kwargs coverage", "[Utils]") {
2626
std::string case1;
2727
CHECK(parse_kwargs(case1).empty());
2828

29-
std::string case2{"{shots : 1000}"};
30-
std::string case3{"shots : 1000"};
31-
std::string case4{"'shots':'1000'"};
29+
std::string case2{"{my_attr : 1000}"};
30+
std::string case3{"my_attr : 1000"};
31+
std::string case4{"'my_attr':'1000'"};
3232
CHECK(parse_kwargs(case2) == parse_kwargs(case3));
3333
CHECK(parse_kwargs(case3) == parse_kwargs(case4));
3434

@@ -40,13 +40,12 @@ TEST_CASE("Test parse_kwargs coverage", "[Utils]") {
4040
CHECK((res5.contains("E") && res5["E"] == "F"));
4141

4242
std::string case6{
43-
"device_type : braket.aws.qubit,{'shots': 0, 'device_arn': 'sv1', "
43+
"device_type : braket.aws.qubit,{'device_arn': 'sv1', "
4444
"'s3_destination_folder': \"('catalyst-op3-s3', 'prefix')\"}"};
4545
auto res6 = parse_kwargs(case6);
46-
CHECK(res6.size() == 4);
46+
CHECK(res6.size() == 3);
4747
CHECK((res6.contains("device_type") &&
4848
res6["device_type"] == "braket.aws.qubit"));
49-
CHECK((res6.contains("shots") && res6["shots"] == "0"));
5049
CHECK((res6.contains("device_arn") && res6["device_arn"] == "sv1"));
5150
CHECK((res6.contains("s3_destination_folder") &&
5251
res6["s3_destination_folder"] == "('catalyst-op3-s3', 'prefix')"));

0 commit comments

Comments
 (0)