diff --git a/pennylane_lightning/core/src/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp b/pennylane_lightning/core/src/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp index 51888c1b37..117d1dc980 100644 --- a/pennylane_lightning/core/src/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp +++ b/pennylane_lightning/core/src/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp @@ -58,6 +58,7 @@ template void testAdjointJacobian() { using ComplexT = typename StateVectorT::ComplexT; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); const std::vector param{-M_PI / 7, M_PI / 5, 2 * M_PI / 3}; @@ -81,6 +82,7 @@ template void testAdjointJacobian() { int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -131,6 +133,7 @@ template void testAdjointJacobian() { int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -181,6 +184,7 @@ template void testAdjointJacobian() { int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -293,6 +297,7 @@ template void testAdjointJacobian() { int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -344,6 +349,7 @@ template void testAdjointJacobian() { int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp b/pennylane_lightning/core/src/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp index 54a5d299ed..733b8a5743 100644 --- a/pennylane_lightning/core/src/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp +++ b/pennylane_lightning/core/src/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp @@ -68,6 +68,7 @@ template void testProbabilities() { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -77,6 +78,7 @@ template void testProbabilities() { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -127,6 +129,7 @@ template void testNamedObsExpval() { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -136,6 +139,7 @@ template void testNamedObsExpval() { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -197,6 +201,7 @@ template void testHermitianObsExpval() { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -206,6 +211,7 @@ template void testHermitianObsExpval() { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -294,6 +300,7 @@ template void testNamedObsVar() { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -303,6 +310,7 @@ template void testNamedObsVar() { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -365,6 +373,7 @@ template void testHermitianObsVar() { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -374,6 +383,7 @@ template void testHermitianObsVar() { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -470,6 +480,7 @@ template void testSamples() { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -479,6 +490,7 @@ template void testSamples() { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/observables/tests/mpi/Test_ObservablesMPI.cpp b/pennylane_lightning/core/src/observables/tests/mpi/Test_ObservablesMPI.cpp index dee6e37532..20f8466e09 100644 --- a/pennylane_lightning/core/src/observables/tests/mpi/Test_ObservablesMPI.cpp +++ b/pennylane_lightning/core/src/observables/tests/mpi/Test_ObservablesMPI.cpp @@ -422,20 +422,6 @@ template void testHamiltonianBase() { REQUIRE(ham1->getWires() == std::vector{0, 5, 9}); } - - /* - DYNAMIC_SECTION("applyInPlace must fail - " - << StateVectorMPIToName::name) { - auto ham = - HamiltonianT::create({PrecisionT{1.0}, h, h}, {zz, x1, x2}); - auto st_data = createZeroState(2); - - StateVectorT state_vector(st_data.data(), st_data.size()); - - REQUIRE_THROWS_AS(ham->applyInPlace(state_vector), - LightningException); - } - */ } testHamiltonianBase(); } diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp index 8503efe570..32981cd48b 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp @@ -1867,6 +1867,7 @@ class StateVectorCudaMPI // LCOV_EXCL_STOP cuDoubleComplex expect_; + // compute expectation PL_CUSTATEVEC_IS_SUCCESS(custatevecComputeExpectation( /* custatevecHandle_t */ handle_.get(), diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp index b9c4eba70c..26a13bd203 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp @@ -47,6 +47,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobianMPI Op=RX, Obs=[Z,Z]", using StateVectorT = StateVectorCudaMPI; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); AdjointJacobianMPI adj; std::vector param{-M_PI / 7, M_PI / 5, 2 * M_PI / 3}; @@ -66,6 +67,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobianMPI Op=RX, Obs=[Z,Z]", int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -104,6 +106,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobianMPI Op=[QubitStateVector, " using StateVectorT = StateVectorCudaMPI; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); AdjointJacobianMPI adj; std::vector param{-M_PI / 7, M_PI / 5, 2 * M_PI / 3}; @@ -124,6 +127,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobianMPI Op=[QubitStateVector, " int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -167,6 +171,7 @@ TEST_CASE( std::vector jacobian_serial(num_obs * tp.size(), 0); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -177,6 +182,7 @@ TEST_CASE( int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -234,6 +240,7 @@ TEST_CASE( std::vector jacobian_serial(num_obs * tp.size(), 0); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -244,6 +251,7 @@ TEST_CASE( int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -297,6 +305,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobian Op=[RX,RX,RX], Obs=[ZZZ]", std::vector jacobian_serial(num_obs * tp.size(), 0); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -307,6 +316,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobian Op=[RX,RX,RX], Obs=[ZZZ]", int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -358,6 +368,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobian Op=Mixed, Obs=[XXX]", std::vector jacobian_serial(num_obs * tp.size(), 0); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -368,6 +379,7 @@ TEST_CASE("AdjointJacobianGPUMPI::adjointJacobian Op=Mixed, Obs=[XXX]", int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -436,6 +448,7 @@ TEST_CASE("AdjointJacobianGPU::AdjointJacobianGPUMPI Op=[RX,RX,RX], " std::vector jacobian_serial(num_obs * tp.size(), 0); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -446,6 +459,7 @@ TEST_CASE("AdjointJacobianGPU::AdjointJacobianGPUMPI Op=[RX,RX,RX], " int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -504,6 +518,7 @@ TEST_CASE("AdjointJacobianGPU::AdjointJacobianGPU Test HermitianObs", std::vector jacobian2_serial(num_obs * tp.size(), 0); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -514,6 +529,7 @@ TEST_CASE("AdjointJacobianGPU::AdjointJacobianGPU Test HermitianObs", int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp index 6dbd1f70f6..511e181d1b 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp @@ -64,6 +64,7 @@ using namespace Pennylane::LightningGPU::MPI; using cp_t = std::complex; \ using PrecisionT = TestType; \ MPIManager mpi_manager(MPI_COMM_WORLD); \ + CHECK(mpi_manager.getSize() == 2); \ size_t mpi_buffersize = 1; \ size_t nGlobalIndexBits = \ std::bit_width(static_cast(mpi_manager.getSize())) - 1; \ @@ -82,6 +83,7 @@ using namespace Pennylane::LightningGPU::MPI; mpi_manager.Barrier(); \ int nDevices = 0; \ cudaGetDeviceCount(&nDevices); \ + CHECK(nDevices >= 2); \ int deviceId = mpi_manager.getRank() % nDevices; \ cudaSetDevice(deviceId); \ DevTag dt_local(deviceId, 0); \ diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp index b8985e6642..fd8882769a 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp @@ -90,6 +90,7 @@ TEMPLATE_TEST_CASE("StateVectorCudaMPI::SetStateVector", using PrecisionT = TestType; using cp_t = std::complex; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -132,6 +133,7 @@ TEMPLATE_TEST_CASE("StateVectorCudaMPI::SetStateVector", int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -165,6 +167,7 @@ TEMPLATE_TEST_CASE("StateVectorCudaMPI::SetIthStates", using PrecisionT = TestType; using cp_t = std::complex; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -193,6 +196,7 @@ TEMPLATE_TEST_CASE("StateVectorCudaMPI::SetIthStates", int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -219,6 +223,7 @@ TEMPLATE_TEST_CASE("StateVectorCudaMPI::SetIthStates", using cp_t = std::complex; \ using PrecisionT = TestType; \ MPIManager mpi_manager(MPI_COMM_WORLD); \ + CHECK(mpi_manager.getSize() == 2); \ size_t mpi_buffersize = 1; \ size_t nGlobalIndexBits = \ std::bit_width(static_cast(mpi_manager.getSize())) - 1; \ @@ -237,6 +242,7 @@ TEMPLATE_TEST_CASE("StateVectorCudaMPI::SetIthStates", mpi_manager.Barrier(); \ int nDevices = 0; \ cudaGetDeviceCount(&nDevices); \ + CHECK(nDevices >= 2); \ int deviceId = mpi_manager.getRank() % nDevices; \ cudaSetDevice(deviceId); \ DevTag dt_local(deviceId, 0); \ diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp index d30115d4a9..4f00345d8f 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp @@ -63,6 +63,7 @@ using namespace Pennylane::LightningGPU::MPI; using cp_t = std::complex; \ using PrecisionT = TestType; \ MPIManager mpi_manager(MPI_COMM_WORLD); \ + CHECK(mpi_manager.getSize() == 2); \ size_t mpi_buffersize = 1; \ size_t nGlobalIndexBits = \ std::bit_width(static_cast(mpi_manager.getSize())) - 1; \ @@ -81,6 +82,7 @@ using namespace Pennylane::LightningGPU::MPI; mpi_manager.Barrier(); \ int nDevices = 0; \ cudaGetDeviceCount(&nDevices); \ + CHECK(nDevices >= 2); \ int deviceId = mpi_manager.getRank() % nDevices; \ cudaSetDevice(deviceId); \ DevTag dt_local(deviceId, 0); \ diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp index 1a1a62c924..582eec1e2d 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp @@ -53,6 +53,7 @@ TEMPLATE_TEST_CASE("[Identity]", "[StateVectorCudaMPI_Expval]", float, double) { auto ONE = TestType(1); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -62,6 +63,7 @@ TEMPLATE_TEST_CASE("[Identity]", "[StateVectorCudaMPI_Expval]", float, double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -91,6 +93,7 @@ TEMPLATE_TEST_CASE("[PauliX]", "[StateVectorCudaMPI_Expval]", float, double) { auto ONE = TestType(1); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -100,6 +103,7 @@ TEMPLATE_TEST_CASE("[PauliX]", "[StateVectorCudaMPI_Expval]", float, double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -162,6 +166,7 @@ TEMPLATE_TEST_CASE("[PauliY]", "[StateVectorCudaMPI_Expval]", float, double) { auto PI = TestType(M_PI); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -171,6 +176,7 @@ TEMPLATE_TEST_CASE("[PauliY]", "[StateVectorCudaMPI_Expval]", float, double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -228,6 +234,7 @@ TEMPLATE_TEST_CASE("[PauliZ]", "[StateVectorCudaMPI_Expval]", float, double) { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -237,6 +244,7 @@ TEMPLATE_TEST_CASE("[PauliZ]", "[StateVectorCudaMPI_Expval]", float, double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -266,6 +274,7 @@ TEMPLATE_TEST_CASE("[Hadamard]", "[StateVectorCudaMPI_Expval]", float, double) { auto INVSQRT2 = TestType(0.707106781186547524401); MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -275,6 +284,7 @@ TEMPLATE_TEST_CASE("[Hadamard]", "[StateVectorCudaMPI_Expval]", float, double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -299,6 +309,7 @@ TEMPLATE_TEST_CASE("Test expectation value of HamiltonianObs", using ComplexT = StateVectorT::ComplexT; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t num_qubits = 3; size_t mpi_buffersize = 1; @@ -309,6 +320,7 @@ TEMPLATE_TEST_CASE("Test expectation value of HamiltonianObs", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -345,6 +357,7 @@ TEMPLATE_TEST_CASE("Test expectation value of TensorProdObs", using ComplexT = StateVectorT::ComplexT; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t num_qubits = 3; size_t mpi_buffersize = 1; @@ -355,6 +368,7 @@ TEMPLATE_TEST_CASE("Test expectation value of TensorProdObs", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -384,11 +398,12 @@ TEMPLATE_TEST_CASE("Test expectation value of TensorProdObs", } TEMPLATE_TEST_CASE("StateVectorCudaMPI::Hamiltonian_expval_Sparse", - "[StateVectorCudaMPI_Expval]", double) { + "[StateVectorCudaMPI_Expval]", float, double) { using StateVectorT = StateVectorCudaMPI; using ComplexT = StateVectorT::ComplexT; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t num_qubits = 3; size_t mpi_buffersize = 1; @@ -399,6 +414,7 @@ TEMPLATE_TEST_CASE("StateVectorCudaMPI::Hamiltonian_expval_Sparse", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp index ca19aae90e..5ca6b7684b 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp @@ -37,7 +37,7 @@ using Pennylane::Util::createNonTrivialState; }; // namespace /// @endcond -TEMPLATE_TEST_CASE("Expected Values", "[MeasurementsMPI]", double) { +TEMPLATE_TEST_CASE("Expected Values", "[MeasurementsMPI]", float, double) { using StateVectorT = StateVectorCudaMPI; using PrecisionT = typename StateVectorT::PrecisionT; using ComplexT = typename StateVectorT::ComplexT; @@ -49,6 +49,7 @@ TEMPLATE_TEST_CASE("Expected Values", "[MeasurementsMPI]", double) { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -58,6 +59,7 @@ TEMPLATE_TEST_CASE("Expected Values", "[MeasurementsMPI]", double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -190,12 +192,15 @@ TEMPLATE_TEST_CASE("Expected Values", "[MeasurementsMPI]", double) { } } -TEMPLATE_TEST_CASE("Pauliwords base on expval", "[MeasurementsMPI]", double) { +TEMPLATE_TEST_CASE("Pauliwords base on expval", "[MeasurementsMPI]", float, + double) { using PrecisionT = TestType; using cp_t = std::complex; using StateVectorT = StateVectorCudaMPI; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); + size_t numqubits = 4; size_t mpi_buffersize = 1; @@ -225,6 +230,7 @@ TEMPLATE_TEST_CASE("Pauliwords base on expval", "[MeasurementsMPI]", double) { int nDevices = 0; // Number of GPU devices per node cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -294,7 +300,7 @@ TEMPLATE_TEST_CASE("Pauliwords base on expval", "[MeasurementsMPI]", double) { } } -TEMPLATE_TEST_CASE("Variances", "[MeasurementsMPI]", double) { +TEMPLATE_TEST_CASE("Variances", "[MeasurementsMPI]", float, double) { using StateVectorT = StateVectorCudaMPI; using PrecisionT = typename StateVectorT::PrecisionT; using ComplexT = typename StateVectorT::ComplexT; @@ -306,6 +312,7 @@ TEMPLATE_TEST_CASE("Variances", "[MeasurementsMPI]", double) { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -315,6 +322,7 @@ TEMPLATE_TEST_CASE("Variances", "[MeasurementsMPI]", double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -404,7 +412,7 @@ TEMPLATE_TEST_CASE("Variances", "[MeasurementsMPI]", double) { } } -TEMPLATE_TEST_CASE("Probabilities", "[MeasuresMPI]", double) { +TEMPLATE_TEST_CASE("Probabilities", "[MeasuresMPI]", float, double) { using StateVectorT = StateVectorCudaMPI; // Probabilities calculated with Pennylane default.qubit: std::vector, std::vector>> input = { @@ -420,6 +428,7 @@ TEMPLATE_TEST_CASE("Probabilities", "[MeasuresMPI]", double) { size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -429,6 +438,7 @@ TEMPLATE_TEST_CASE("Probabilities", "[MeasuresMPI]", double) { int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp index 141b987cb0..caea1e0d03 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp @@ -41,6 +41,7 @@ TEMPLATE_TEST_CASE("Test variance of NamedObs", "[StateVectorCudaMPI_Var]", const std::size_t num_qubits = 2; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -50,6 +51,7 @@ TEMPLATE_TEST_CASE("Test variance of NamedObs", "[StateVectorCudaMPI_Var]", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -108,12 +110,13 @@ TEMPLATE_TEST_CASE("Test variance of NamedObs", "[StateVectorCudaMPI_Var]", } TEMPLATE_TEST_CASE("Test variance of HermitianObs", "[StateVectorCudaMPI_Var]", - double) { + float, double) { const std::size_t num_qubits = 3; using StateVectorT = StateVectorCudaMPI; using ComplexT = typename StateVectorT::ComplexT; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -123,6 +126,7 @@ TEMPLATE_TEST_CASE("Test variance of HermitianObs", "[StateVectorCudaMPI_Var]", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -160,11 +164,12 @@ TEMPLATE_TEST_CASE("Test variance of HermitianObs", "[StateVectorCudaMPI_Var]", } TEMPLATE_TEST_CASE("Test variance of TensorProdObs", "[StateVectorCudaMPI_Var]", - double) { + float, double) { using StateVectorT = StateVectorCudaMPI; const std::size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -174,6 +179,7 @@ TEMPLATE_TEST_CASE("Test variance of TensorProdObs", "[StateVectorCudaMPI_Var]", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); @@ -203,11 +209,12 @@ TEMPLATE_TEST_CASE("Test variance of TensorProdObs", "[StateVectorCudaMPI_Var]", } TEMPLATE_TEST_CASE("Test variance of HamiltonianObs", - "[StateVectorCudaMPI_Var]", double) { + "[StateVectorCudaMPI_Var]", float, double) { using StateVectorT = StateVectorCudaMPI; const std::size_t num_qubits = 3; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); size_t mpi_buffersize = 1; @@ -217,6 +224,7 @@ TEMPLATE_TEST_CASE("Test variance of HamiltonianObs", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp index e757fb4b84..a39f9f5f7e 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp @@ -172,6 +172,8 @@ TEMPLATE_PRODUCT_TEST_CASE("HamiltonianMPI::ApplyInPlace", "[Observables]", using Hamiltonian = Hamiltonian>; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); + size_t num_qubits = 8; size_t mpi_buffersize = 1; size_t nGlobalIndexBits = @@ -191,6 +193,7 @@ TEMPLATE_PRODUCT_TEST_CASE("HamiltonianMPI::ApplyInPlace", "[Observables]", int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp index a7be042ce3..3cc508fb98 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp @@ -42,6 +42,7 @@ TEMPLATE_TEST_CASE("CRSMatrix::Split", "[CRSMatrix]", float, double) { int64_t>::type; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); int rank = mpi_manager.getRank(); int size = mpi_manager.getSize(); diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp index 4a3892b4fd..43abf11c62 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp @@ -42,6 +42,7 @@ TEMPLATE_TEST_CASE("Linear Algebra::SparseMV", "[Linear Algebra]", float, using CFP_t = StateVectorT::CFP_t; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); std::size_t num_qubits = 3; @@ -79,6 +80,7 @@ TEMPLATE_TEST_CASE("Linear Algebra::SparseMV", "[Linear Algebra]", float, int nDevices = 0; cudaGetDeviceCount(&nDevices); + CHECK(nDevices >= 2); int deviceId = mpi_manager.getRank() % nDevices; cudaSetDevice(deviceId); DevTag dt_local(deviceId, 0); diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManager.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManager.cpp index 549be55b85..da21c9028e 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManager.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManager.cpp @@ -36,6 +36,7 @@ TEMPLATE_TEST_CASE("MPIManager::Scatter", "[MPIManager]", float, double) { using cp_t = std::complex; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); int rank = mpi_manager.getRank(); int size = mpi_manager.getSize(); @@ -79,6 +80,8 @@ TEMPLATE_TEST_CASE("MPIManager::Allgather", "[MPIManager]", float, double) { using cp_t = std::complex; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); + int rank = mpi_manager.getRank(); int size = mpi_manager.getSize(); @@ -132,6 +135,8 @@ TEMPLATE_TEST_CASE("MPIManager::Reduce", "[MPIManager]", float, double) { using cp_t = std::complex; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); + int rank = mpi_manager.getRank(); int size = mpi_manager.getSize(); @@ -170,6 +175,8 @@ TEMPLATE_TEST_CASE("MPIManager::Allreduce", "[MPIManager]", float, double) { using cp_t = std::complex; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); + int rank = mpi_manager.getRank(); int size = mpi_manager.getSize(); @@ -216,6 +223,8 @@ TEMPLATE_TEST_CASE("MPIManager::Bcast", "[MPIManager]", float, double) { using cp_t = std::complex; MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); + int rank = mpi_manager.getRank(); SECTION("Apply Bcast scalar") { @@ -265,6 +274,7 @@ TEMPLATE_TEST_CASE("MPIManager::Sendrecv", "[MPIManager]", float, double) { TEST_CASE("MPIManager::split") { MPIManager mpi_manager(MPI_COMM_WORLD); + CHECK(mpi_manager.getSize() == 2); int rank = mpi_manager.getRank(); int color = rank % 2; int key = rank;