diff --git a/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp b/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp index bdb950300..58721cb72 100644 --- a/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp @@ -1177,64 +1177,6 @@ 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::ComplexT; - const std::size_t num_qubits = 4; - - std::vector 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 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 kokkos_sv{num_qubits}; - std::vector 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; diff --git a/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp b/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp index 5d6d3aa4c..2bdca68bc 100644 --- a/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp @@ -706,260 +706,6 @@ TEMPLATE_TEST_CASE( } } -TEMPLATE_TEST_CASE("StateVectorKokkos::applyOperation param " - "two-qubit with multiple-controls", - "[StateVectorKokkos_Param]", float, double) { - using ComplexT = StateVectorKokkos::ComplexT; - const bool inverse = false; - const std::size_t num_qubits = 4; - StateVectorKokkos kokkos_sv{num_qubits}; - - kokkos_sv.applyOperations( - {{"Hadamard"}, {"Hadamard"}, {"Hadamard"}, {"Hadamard"}}, - {{0}, {1}, {2}, {3}}, {{false}, {false}, {false}, {false}}); - - auto ini_sv = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, - kokkos_sv.getView()); - StateVectorKokkos sv_gate{num_qubits}; - StateVectorKokkos expected_result{num_qubits}; - - SECTION("2-controlled IsingXX") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 2}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 3}; - const TestType param = 0.234; - sv_gate.applyOperation("IsingXX", control_wires, control_values, - target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result{// Generated using Pennylane - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled IsingXY") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 2}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 3}; - const TestType param = 0.234; - sv_gate.applyOperation("IsingXY", control_wires, control_values, - target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result{// Generated using Pennylane - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled IsingYY") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 2}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 3}; - const TestType param = 0.234; - sv_gate.applyOperation("IsingYY", control_wires, control_values, - target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result{// Generated using Pennylane - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled IsingZZ") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 2}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 3}; - const TestType param = 0.234; - sv_gate.applyOperation("IsingZZ", control_wires, control_values, - target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result{// Generated using Pennylane - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled SingleExcitation") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 2}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 3}; - const TestType param = 0.234; - sv_gate.applyOperation("SingleExcitation", control_wires, - control_values, target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result{ - // Generated using Pennylane - ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, - ComplexT{0.21910751, 0.0}, ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, - ComplexT{0.27747414, 0.0}, ComplexT{0.25, 0.0}, ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled SingleExcitationPlus") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 2}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 3}; - const TestType param = 0.234; - sv_gate.applyOperation("SingleExcitationPlus", control_wires, - control_values, target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result{// Generated using Pennylane - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.21910751, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.27747414, 0.0}, - ComplexT{0.24829083, 0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled SingleExcitationMinus") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 2}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 3}; - const TestType param = 0.234; - sv_gate.applyOperation("SingleExcitationMinus", control_wires, - control_values, target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result{// Generated using Pennylane - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.21910751, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}, - ComplexT{0.27747414, 0.0}, - ComplexT{0.24829083, -0.02918331}, - ComplexT{0.25, 0.0}, - ComplexT{0.25, 0.0}}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } -} - TEMPLATE_TEST_CASE( "StateVectorKokkos::applyOperation param four-qubit with controls", "[StateVectorKokkos_Operation]", float, double) { @@ -1086,124 +832,6 @@ TEMPLATE_TEST_CASE( } } -TEMPLATE_TEST_CASE("StateVectorKokkos::applyOperation param " - "four-qubit with multiple-controls", - "[StateVectorKokkos_Param]", float, double) { - using ComplexT = StateVectorKokkos::ComplexT; - const bool inverse = false; - const std::size_t num_qubits = 6; - StateVectorKokkos kokkos_sv{num_qubits}; - - kokkos_sv.applyOperations( - {{"Hadamard"}, - {"Hadamard"}, - {"Hadamard"}, - {"Hadamard"}, - {"Hadamard"}, - {"Hadamard"}}, - {{0}, {1}, {2}, {3}, {4}, {5}}, - {{false}, {false}, {false}, {false}, {false}, {false}}); - - auto ini_sv = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, - kokkos_sv.getView()); - StateVectorKokkos sv_gate{num_qubits}; - StateVectorKokkos expected_result{num_qubits}; - - SECTION("2-controlled DoubleExcitation") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 3}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 2, 4, 5}; - const TestType param = 0.234; - sv_gate.applyOperation("DoubleExcitation", control_wires, - control_values, target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result( - 64, ComplexT{0.125, 0.0}); // Generated using Pennylane - expected_result[35] = ComplexT{0.10955376, 0.0}; - expected_result[56] = ComplexT{0.13873707, 0.0}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled DoubleExcitationPlus") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 3}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 2, 4, 5}; - const TestType param = 0.234; - sv_gate.applyOperation("DoubleExcitationPlus", control_wires, - control_values, target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result( - 64, ComplexT{0.125, 0.0}); // Generated using Pennylane - expected_result[32] = ComplexT{0.12414541, 0.01459166}; - expected_result[33] = ComplexT{0.12414541, 0.01459166}; - expected_result[34] = ComplexT{0.12414541, 0.01459166}; - expected_result[35] = ComplexT{0.10955376, 0.0}; - expected_result[40] = ComplexT{0.12414541, 0.01459166}; - expected_result[41] = ComplexT{0.12414541, 0.01459166}; - expected_result[42] = ComplexT{0.12414541, 0.01459166}; - expected_result[43] = ComplexT{0.12414541, 0.01459166}; - expected_result[48] = ComplexT{0.12414541, 0.01459166}; - expected_result[49] = ComplexT{0.12414541, 0.01459166}; - expected_result[50] = ComplexT{0.12414541, 0.01459166}; - expected_result[51] = ComplexT{0.12414541, 0.01459166}; - expected_result[56] = ComplexT{0.13873707, 0.0}; - expected_result[57] = ComplexT{0.12414541, 0.01459166}; - expected_result[58] = ComplexT{0.12414541, 0.01459166}; - expected_result[59] = ComplexT{0.12414541, 0.01459166}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } - - SECTION("2-controlled DoubleExcitationMinus") { - Kokkos::deep_copy(sv_gate.getView(), ini_sv); - - const std::vector control_wires = {0, 3}; - const std::vector control_values = {true, false}; - const std::vector target_wire = {1, 2, 4, 5}; - const TestType param = 0.234; - sv_gate.applyOperation("DoubleExcitationMinus", control_wires, - control_values, target_wire, inverse, {param}); - auto sv_gate_host = Kokkos::create_mirror_view_and_copy( - Kokkos::HostSpace{}, sv_gate.getView()); - - std::vector expected_result( - 64, ComplexT{0.125, 0.0}); // Generated using Pennylane - expected_result[32] = ComplexT{0.12414541, -0.01459166}; - expected_result[33] = ComplexT{0.12414541, -0.01459166}; - expected_result[34] = ComplexT{0.12414541, -0.01459166}; - expected_result[35] = ComplexT{0.10955376, 0.0}; - expected_result[40] = ComplexT{0.12414541, -0.01459166}; - expected_result[41] = ComplexT{0.12414541, -0.01459166}; - expected_result[42] = ComplexT{0.12414541, -0.01459166}; - expected_result[43] = ComplexT{0.12414541, -0.01459166}; - expected_result[48] = ComplexT{0.12414541, -0.01459166}; - expected_result[49] = ComplexT{0.12414541, -0.01459166}; - expected_result[50] = ComplexT{0.12414541, -0.01459166}; - expected_result[51] = ComplexT{0.12414541, -0.01459166}; - expected_result[56] = ComplexT{0.13873707, 0.0}; - expected_result[57] = ComplexT{0.12414541, -0.01459166}; - expected_result[58] = ComplexT{0.12414541, -0.01459166}; - expected_result[59] = ComplexT{0.12414541, -0.01459166}; - for (std::size_t j = 0; j < exp2(num_qubits); j++) { - CHECK(imag(sv_gate_host[j]) == Approx(imag(expected_result[j]))); - CHECK(real(sv_gate_host[j]) == Approx(real(expected_result[j]))); - } - } -} - TEMPLATE_TEST_CASE("StateVectorKokkosManaged::applyIsingXY", "[StateVectorKokkosManaged_Param]", float, double) { {