Skip to content

Commit

Permalink
restore namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
josephleekl committed Dec 9, 2024
1 parent 0e5e47d commit d1d919c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compat-docker-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Docker latest - Linux::x86_64
uses: ./.github/workflows/docker_linux_x86_64.yml
with:
lightning-version: master
lightning-version: fix_lk_rocm_unused
pennylane-version: master
push-to-dockerhub: false
secrets: inherit # pass all secrets
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ using Pennylane::LightningKokkos::Util::generateBitPatterns;
using Pennylane::LightningKokkos::Util::parity_2_offset;
using Pennylane::LightningKokkos::Util::reverseWires;
using Pennylane::LightningKokkos::Util::vector2view;
using Pennylane::Util::exp2;
} // namespace
/// @endcond

Expand All @@ -59,9 +58,9 @@ template <class PrecisionT, class FuncT> class applyNCNFunctor {
const std::vector<bool> &controlled_values,
const std::vector<std::size_t> &wires, FuncT core_function_)
: arr(arr_), core_function(core_function_) {
const std::size_t two2N =
exp2(num_qubits - wires.size() - controlled_wires.size());
dim = exp2(wires.size());
const std::size_t two2N = Pennylane::Util::exp2(
num_qubits - wires.size() - controlled_wires.size());
dim = Pennylane::Util::exp2(wires.size());
const auto &[parity_, rev_wires_] =
reverseWires(num_qubits, wires, controlled_wires);
parity = parity_;
Expand Down Expand Up @@ -116,7 +115,8 @@ class applyNC1Functor<PrecisionT, FuncT, true> {
indices = vector2view(indices_);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(
0, exp2(num_qubits - controlled_wires.size() - wires.size())),
0, Pennylane::Util::exp2(num_qubits - controlled_wires.size() -
wires.size())),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
Expand Down Expand Up @@ -148,9 +148,9 @@ class applyNC1Functor<PrecisionT, FuncT, false> {
rev_wire_shift((static_cast<std::size_t>(1U) << rev_wire)),
wire_parity(fillTrailingOnes(rev_wire)),
wire_parity_inv(fillLeadingOnes(rev_wire + 1)) {
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits - 1)),
*this);
Kokkos::parallel_for(Kokkos::RangePolicy<ExecutionSpace>(
0, Pennylane::Util::exp2(num_qubits - 1)),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
std::size_t i0 = ((k << 1U) & wire_parity_inv) | (wire_parity & k);
Expand Down Expand Up @@ -645,7 +645,8 @@ class applyNC2Functor<PrecisionT, FuncT, true> {
indices = vector2view(indices_);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(
0, exp2(num_qubits - controlled_wires.size() - wires.size())),
0, Pennylane::Util::exp2(num_qubits - controlled_wires.size() -
wires.size())),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
Expand Down Expand Up @@ -693,9 +694,9 @@ class applyNC2Functor<PrecisionT, FuncT, false> {
parity_high(fillLeadingOnes(rev_wire_max + 1)),
parity_middle(fillLeadingOnes(rev_wire_min + 1) &
fillTrailingOnes(rev_wire_max)) {
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits - 2)),
*this);
Kokkos::parallel_for(Kokkos::RangePolicy<ExecutionSpace>(
0, Pennylane::Util::exp2(num_qubits - 2)),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
std::size_t i00 = ((k << 2U) & parity_high) |
Expand Down Expand Up @@ -1268,9 +1269,9 @@ template <class PrecisionT, class FuncT> class applyNC3Functor {
fillLeadingOnes(rev_wire_min + 1) & fillTrailingOnes(rev_wire_mid);
parity_hmiddle =
fillLeadingOnes(rev_wire_mid + 1) & fillTrailingOnes(rev_wire_max);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits - 3)),
*this);
Kokkos::parallel_for(Kokkos::RangePolicy<ExecutionSpace>(
0, Pennylane::Util::exp2(num_qubits - 3)),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
std::size_t i000 = ((k << 3U) & parity_high) |
Expand Down Expand Up @@ -1365,7 +1366,8 @@ class applyNC4Functor<PrecisionT, FuncT, true> {
indices = vector2view(indices_);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(
0, exp2(num_qubits - controlled_wires.size() - wires.size())),
0, Pennylane::Util::exp2(num_qubits - controlled_wires.size() -
wires.size())),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
Expand Down Expand Up @@ -1474,9 +1476,9 @@ class applyNC4Functor<PrecisionT, FuncT, false> {
fillTrailingOnes(rev_wire_max);
parity_middle = fillLeadingOnes(rev_wire_min_mid + 1) &
fillTrailingOnes(rev_wire_max_mid);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits - 4)),
*this);
Kokkos::parallel_for(Kokkos::RangePolicy<ExecutionSpace>(
0, Pennylane::Util::exp2(num_qubits - 4)),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
std::size_t i0000 = ((k << 4U) & parity_high) |
Expand Down Expand Up @@ -1700,7 +1702,8 @@ void applyMultiRZ(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
(static_cast<std::size_t>(1U) << (num_qubits - wire - 1));
}
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits)),
Kokkos::RangePolicy<ExecutionSpace>(0,
Pennylane::Util::exp2(num_qubits)),
KOKKOS_LAMBDA(std::size_t k) {
arr_(k) *= (Kokkos::Impl::bit_count(k & wires_parity) % 2 == 0)
? shift_0
Expand Down Expand Up @@ -1778,7 +1781,8 @@ void applyPauliRot(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
get_mask([&word](const int a) { return word[a] == 'Z'; });
const auto count_mask_y = std::popcount(mask_y);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits)),
Kokkos::RangePolicy<ExecutionSpace>(0,
Pennylane::Util::exp2(num_qubits)),
KOKKOS_LAMBDA(std::size_t i0) {
std::size_t i1 = i0 ^ mask_xy;
if (i0 <= i1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace {
using namespace Pennylane::Util;
using Kokkos::kokkos_swap;
using Pennylane::Gates::GeneratorOperation;
using Pennylane::Util::exp2;
} // namespace
/// @endcond

Expand Down Expand Up @@ -347,10 +346,11 @@ void applyGenMultiRZ(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
[[maybe_unused]] bool inverse = false) {
std::size_t wires_parity = static_cast<std::size_t>(0U);
for (std::size_t wire : wires) {
wires_parity |= exp2(num_qubits - wire - 1);
wires_parity |= Pennylane::Util::exp2(num_qubits - wire - 1);
}
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits)),
Kokkos::RangePolicy<ExecutionSpace>(0,
Pennylane::Util::exp2(num_qubits)),
KOKKOS_LAMBDA(std::size_t k) {
arr_(k) *= static_cast<PrecisionT>(
1 - 2 * int(Kokkos::Impl::bit_count(k & wires_parity) % 2));
Expand Down Expand Up @@ -412,7 +412,8 @@ template <class PrecisionT, class FuncT> class applyNCGenerator1Functor {
indices = vector2view(indices_);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(
0, exp2(num_qubits - controlled_wires.size() - wires.size())),
0, Pennylane::Util::exp2(num_qubits - controlled_wires.size() -
wires.size())),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
Expand Down Expand Up @@ -588,7 +589,8 @@ template <class PrecisionT, class FuncT> class applyNCGenerator2Functor {
indices = vector2view(indices_);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(
0, exp2(num_qubits - controlled_wires.size() - wires.size())),
0, Pennylane::Util::exp2(num_qubits - controlled_wires.size() -
wires.size())),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
Expand Down Expand Up @@ -802,7 +804,8 @@ template <class PrecisionT, class FuncT> class applyNCGenerator4Functor {
indices = vector2view(indices_);
Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(
0, exp2(num_qubits - controlled_wires.size() - wires.size())),
0, Pennylane::Util::exp2(num_qubits - controlled_wires.size() -
wires.size())),
*this);
}
KOKKOS_FUNCTION void operator()(std::size_t k) const {
Expand Down Expand Up @@ -899,16 +902,17 @@ void applyNCGenMultiRZ(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
std::size_t ctrls_parity = std::accumulate(
controlled_wires.begin(), controlled_wires.end(), std::size_t{0},
[num_qubits](std::size_t acc, std::size_t wire) {
return acc | exp2(num_qubits - wire - 1);
return acc | Pennylane::Util::exp2(num_qubits - wire - 1);
});
std::size_t wires_parity = std::accumulate(
wires.begin(), wires.end(), std::size_t{0},
[num_qubits](std::size_t acc, std::size_t wire) {
return acc | Pennylane::Util::exp2(num_qubits - wire - 1);
});
std::size_t wires_parity =
std::accumulate(wires.begin(), wires.end(), std::size_t{0},
[num_qubits](std::size_t acc, std::size_t wire) {
return acc | exp2(num_qubits - wire - 1);
});

Kokkos::parallel_for(
Kokkos::RangePolicy<ExecutionSpace>(0, exp2(num_qubits)),
Kokkos::RangePolicy<ExecutionSpace>(0,
Pennylane::Util::exp2(num_qubits)),
KOKKOS_LAMBDA(std::size_t k) {
if (ctrls_mask == (ctrls_parity & k)) {
arr_(k) *= static_cast<PrecisionT>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ using Pennylane::LightningKokkos::Util::parity_2_offset;
using Pennylane::LightningKokkos::Util::reverseWires;
using Pennylane::LightningKokkos::Util::vector2view;
using Pennylane::LightningKokkos::Util::wires2Parity;
using Pennylane::Util::exp2;
} // namespace
/// @endcond

Expand Down Expand Up @@ -61,7 +60,7 @@ template <class Precision> struct multiQubitOpFunctor {
const KokkosComplexVector &matrix_,
const std::vector<std::size_t> &wires_) {
wires = vector2view(wires_);
dim = exp2(wires_.size());
dim = Pennylane::Util::exp2(wires_.size());
num_qubits = num_qubits_;
arr = arr_;
matrix = matrix_;
Expand Down Expand Up @@ -138,7 +137,7 @@ template <class Precision> struct NCMultiQubitOpFunctor {
const std::vector<std::size_t> &controlled_wires_,
const std::vector<bool> &controlled_values_,
const std::vector<std::size_t> &wires_) {
dim = exp2(wires_.size());
dim = Pennylane::Util::exp2(wires_.size());
arr = arr_;
matrix = matrix_;
num_qubits = num_qubits_;
Expand Down Expand Up @@ -203,7 +202,7 @@ template <class PrecisionT> struct apply1QubitOpFunctor {
num_qubits = num_qubits_;

rev_wire = num_qubits - wires_[0] - 1;
rev_wire_shift = exp2(rev_wire);
rev_wire_shift = Pennylane::Util::exp2(rev_wire);
wire_parity = fillTrailingOnes(rev_wire);
wire_parity_inv = fillLeadingOnes(rev_wire + 1);
}
Expand Down

0 comments on commit d1d919c

Please sign in to comment.