Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josephleekl committed Nov 8, 2024
1 parent 10a18bb commit 82b0b85
Show file tree
Hide file tree
Showing 2 changed files with 430 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,64 @@ TEMPLATE_TEST_CASE("StateVectorKokkos::applyOperation non-param "
}
}

TEMPLATE_TEST_CASE("StateVectorKokkos::applyOperation non-param "
"two-qubit with multiple-controls",
"[StateVectorKokkos_NonParam]", float, double) {
SECTION("2-controlled SWAP") {
using ComplexT = StateVectorKokkos<TestType>::ComplexT;
const std::size_t num_qubits = 4;

std::vector<ComplexT> ini_st{ComplexT{0.33377149, 0.2511291},
ComplexT{0.33013572, -0.14778699},
ComplexT{0.17288832, -0.041744},
ComplexT{0.11004883, -0.15105962},
ComplexT{0.17120967, 0.04376507},
ComplexT{0.33010645, 0.20088901},
ComplexT{-0.12770624, -0.17329647},
ComplexT{-0.34301996, 0.11944278},
ComplexT{0.0195779, -0.03687076},
ComplexT{0.34155068, 0.07464519},
ComplexT{0.00730597, 0.03670807},
ComplexT{0.08876188, -0.18019018},
ComplexT{-0.04946055, -0.10383813},
ComplexT{0.0715367, 0.04895361},
ComplexT{-0.12377521, -0.04781011},
ComplexT{-0.14509767, 0.2102171}};

std::vector<ComplexT> expected{ComplexT{0.33377149, 0.2511291},
ComplexT{0.33013572, -0.14778699},
ComplexT{0.17288832, -0.041744},
ComplexT{0.11004883, -0.15105962},
ComplexT{0.17120967, 0.04376507},
ComplexT{0.33010645, 0.20088901},
ComplexT{-0.12770624, -0.17329647},
ComplexT{-0.34301996, 0.11944278},
ComplexT{0.0195779, -0.03687076},
ComplexT{-0.04946055, -0.10383813},
ComplexT{0.00730597, 0.03670807},
ComplexT{0.08876188, -0.18019018},
ComplexT{0.34155068, 0.07464519},
ComplexT{0.0715367, 0.04895361},
ComplexT{-0.12377521, -0.04781011},
ComplexT{-0.14509767, 0.2102171}};

SECTION("Apply using dispatcher") {
StateVectorKokkos<TestType> kokkos_sv{num_qubits};
std::vector<ComplexT> result_sv(kokkos_sv.getLength(), {0, 0});

kokkos_sv.HostToDevice(ini_st.data(), ini_st.size());
kokkos_sv.applyOperation("SWAP", {0, 2}, {true, false}, {1, 3},
false);
kokkos_sv.DeviceToHost(result_sv.data(), result_sv.size());

for (std::size_t j = 0; j < exp2(num_qubits); j++) {
CHECK(imag(expected[j]) == Approx(imag(result_sv[j])));
CHECK(real(expected[j]) == Approx(real(result_sv[j])));
}
}
}
}

TEMPLATE_TEST_CASE("StateVectorKokkos::SetStateVector",
"[StateVectorKokkos_Nonparam]", float, double) {
using PrecisionT = TestType;
Expand Down
Loading

0 comments on commit 82b0b85

Please sign in to comment.