Skip to content

Commit 1177ae9

Browse files
update LQ generator vector insert order (#1009)
### Before submitting Please complete the following checklist when submitting a PR: - [ ] 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 [`tests`](../tests) directory! - [ ] 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 `.github/CHANGELOG.md` file, summarizing the change, and including a link back to the PR. - [X] Ensure that code is properly formatted by running `make format`. When all the above are checked, delete everything above the dashed line and fill in the pull request template. ------------------------------------------------------------------------------------------------------------ **Context:** Currently in `GateImplementationsLM.hpp` some generator functions performs two std::vector insertions to the same vector, both to the beginning of the destination vectors. **Description of the Change:** The order is swapped, and the second vector is inserted to the end of the vector. This should be more performant. **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** [sc-78933] --------- Co-authored-by: ringo-but-quantum <[email protected]>
1 parent db137bf commit 1177ae9

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
### Improvements
2525

26+
* Reverse Lightning Qubit generators vector insertion order.
27+
[(#1009)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1009)
28+
2629
* Update Kokkos version support to 4.4.1 and enable Lightning-Kokkos[CUDA] C++ tests on CI.
2730
[(#1000)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1000)
2831

pennylane_lightning/core/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.40.0-dev18"
19+
__version__ = "0.40.0-dev19"

pennylane_lightning/core/src/simulators/lightning_qubit/gates/cpu_kernels/GateImplementationsLM.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1946,9 +1946,10 @@ class GateImplementationsLM : public PauliGenerator<GateImplementationsLM> {
19461946

19471947
std::vector<std::size_t> all_wires;
19481948
all_wires.reserve(nw_tot);
1949-
all_wires.insert(all_wires.begin(), wires.begin(), wires.end());
19501949
all_wires.insert(all_wires.begin(), controlled_wires.begin(),
19511950
controlled_wires.end());
1951+
all_wires.insert(all_wires.begin() + n_contr, wires.begin(),
1952+
wires.end());
19521953
const auto revs = reverseWires(num_qubits, all_wires, {});
19531954
const auto &rev_wires = revs.first;
19541955
const std::vector<std::size_t> parity =
@@ -2166,9 +2167,10 @@ class GateImplementationsLM : public PauliGenerator<GateImplementationsLM> {
21662167

21672168
std::vector<std::size_t> all_wires;
21682169
all_wires.reserve(nw_tot);
2169-
all_wires.insert(all_wires.begin(), wires.begin(), wires.end());
21702170
all_wires.insert(all_wires.begin(), controlled_wires.begin(),
21712171
controlled_wires.end());
2172+
all_wires.insert(all_wires.begin() + n_contr, wires.begin(),
2173+
wires.end());
21722174
const auto revs = reverseWires(num_qubits, all_wires, {});
21732175
const auto &rev_wires = revs.first;
21742176
const std::vector<std::size_t> parity =
@@ -2448,9 +2450,10 @@ class GateImplementationsLM : public PauliGenerator<GateImplementationsLM> {
24482450

24492451
std::vector<std::size_t> all_wires;
24502452
all_wires.reserve(nw_tot);
2451-
all_wires.insert(all_wires.begin(), wires.begin(), wires.end());
24522453
all_wires.insert(all_wires.begin(), controlled_wires.begin(),
24532454
controlled_wires.end());
2455+
all_wires.insert(all_wires.begin() + n_contr, wires.begin(),
2456+
wires.end());
24542457
const auto revs = reverseWires(num_qubits, all_wires, {});
24552458
const auto &rev_wires = revs.first;
24562459
const std::vector<std::size_t> parity =

0 commit comments

Comments
 (0)