PennyLaneAI / PennyLaneAI/catalyst
Consider eliminating redundant "shots" parameters in device back end API
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 234
- Forks
- 84
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 66
Description
Issue description
As a general suggestion on your (C++ device back end) API, in Catalyst::Runtime::QuantumDevice, as someone implementing a simulator device back end over at pennylane-qrack, I notice that you require a "shots" parameter in certain methods that is redundant with the dimension required for DataView instances. Immediately at the top of such methods, you make sure that shots is exactly the same as the size of the DataView instance, and you raise exception if the two do not match.
Given that the DataView must already have the same size as the shots integer, why not remove the shots parameter and simply consider it implied by the size of the DataView? This way, there's never a case where it's necessary to reject on input validation.
Source code and tracebacks
For example,
void Sample(DataView<double, 2> &samples, size_t shots) override
{
RT_FAIL_IF(samples.size() != shots, "Invalid size for the pre-allocated samples");
[...]
}
Instead, the signature could simply be like this:
void Sample(DataView<double, 2> &samples) override
{
// "shots" parameter value is implied by just "samples.size()."
[...]
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Catalyst::Runtime::QuantumDevice and inspect the methods that accept both a DataView and a shots parameter, beginning with the Sample example in the issue. Trace the corresponding device back ends and callers to determine the full API impact. Done means the redundant parameters are consistently addressed across the API without mismatched validation or unresolved compatibility questions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100