Skip to content

Commit

Permalink
Make wires2Parity inline.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentmr committed Oct 10, 2023
1 parent 8e3deb7 commit dcf9ad6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
/// @cond DEV
namespace {
using namespace Pennylane::Util;
using namespace Pennylane::LightningKokkos::Util; // one
using Kokkos::Experimental::swap;
using Pennylane::LightningKokkos::Util::one;
using Pennylane::LightningKokkos::Util::wires2Parity;
using std::size_t;
} // namespace
/// @endcond
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ target_link_libraries(lightning_kokkos_gates_tests INTERFACE Catch2::Catch2
lightning_kokkos_measurements
lightning_kokkos_observables
lightning_kokkos
lightning_kokkos_utils
)

ProcessTestOptions(lightning_kokkos_gates_tests)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
/// @cond DEV
namespace {
using namespace Pennylane::Util;
using namespace Pennylane::LightningKokkos::Util; // one
using Pennylane::LightningKokkos::Util::one;
using Pennylane::LightningKokkos::Util::wires2Parity;
} // namespace
/// @endcond

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,26 @@ using KokkosIntVector = Kokkos::View<std::size_t *>;

namespace Pennylane::LightningKokkos::Util {

inline constexpr std::size_t one{1};
constexpr std::size_t one{1};

/**
* @brief Faster log2 when the value is a power of 2.
* @brief Compute the parities and shifts for multi-qubit operations.
*
* @param val Size of the state vector. Expected to be a power of 2.
* @return size_t Log2(val), or the state vector's number of qubits.
* @param num_qubits Number of qubits in the state vector.
* @param wires List of target wires.
* @return std::pair<KokkosIntVector, KokkosIntVector> Parities and shifts for
* multi-qubit operations.
*/
std::pair<KokkosIntVector, KokkosIntVector>
wires2Parity(const std::size_t num_qubits,
const std::vector<std::size_t> &wires_) {
constexpr std::size_t one{1};
inline auto wires2Parity(const std::size_t num_qubits,
const std::vector<std::size_t> &wires)
-> std::pair<KokkosIntVector, KokkosIntVector> {
KokkosIntVector parity;
KokkosIntVector rev_wire_shifts;

std::vector<std::size_t> rev_wires_(wires_.size());
std::vector<std::size_t> rev_wire_shifts_(wires_.size());
for (std::size_t k = 0; k < wires_.size(); k++) {
rev_wires_[k] = (num_qubits - 1) - wires_[(wires_.size() - 1) - k];
std::vector<std::size_t> rev_wires_(wires.size());
std::vector<std::size_t> rev_wire_shifts_(wires.size());
for (std::size_t k = 0; k < wires.size(); k++) {
rev_wires_[k] = (num_qubits - 1) - wires[(wires.size() - 1) - k];
rev_wire_shifts_[k] = (one << rev_wires_[k]);
}
const std::vector<std::size_t> parity_ = revWireParity(rev_wires_);
Expand Down

0 comments on commit dcf9ad6

Please sign in to comment.