Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accelerate sample to counts conversion. (#5145)
### Before submitting Please complete the following checklist when submitting a PR: - [x] All new features must include a unit test. If you've fixed a bug or added code that should be tested, add a test to the test directory! - [x] All new functions and code must be clearly commented and documented. If you do make documentation changes, make sure that the docs build and render correctly by running `make docs`. - [x] Ensure that the test suite passes, by running `make test`. - [x] Add a new entry to the `doc/releases/changelog-dev.md` file, summarizing the change, and including a link back to the PR. - [x] The PennyLane source code conforms to [PEP8 standards](https://www.python.org/dev/peps/pep-0008/). We check all of our code against [Pylint](https://www.pylint.org/). To lint modified files, simply `pip install pylint`, and then run `pylint pennylane/path/to/file.py`. When all the above are checked, delete everything above the dashed line and fill in the pull request template. ------------------------------------------------------------------------------------------------------------ **Context:** While doing work on mid-circuit measurements #5088 #5120 , I found `_samples_to_counts` to be a bottleneck in small circuits with a lot of shots (>1e5). For example, the circuit below spends: - 1.9 sec. in `_samples_to_counts` on `master` - 0.09 sec. in `_samples_to_counts` on `optim/_samples_to_counts` ``` import pennylane as qml import pennylane.numpy as np dev = qml.device("default.qubit", shots=100000) @qml.qnode(dev) @qml.defer_measurements def func2(x, y): qml.RX(x, wires=0) m0 = qml.measure(0) qml.RX(y, wires=1) m1 = qml.measure(1) return qml.counts(wires=[0, 1]) results2 = func2(np.pi / 4, np.pi / 4) ``` **Description of the Change:** Accelerate NaN pruning and int to str conversion in `_samples_to_counts`. **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: Matthew Silverman <[email protected]>
- Loading branch information