diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 6a03c14fa5..cbaf15d250 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -35,6 +35,9 @@

Internal changes ⚙️

+- Update Catch2 testing framework to v3.11. + [(#1350)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1350) + - Update internal dependencies versions for Nanobind (2.11), cmake (3.26), sphinxcontrib-htmlhelp (2.1.0) [(#1347)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1347) diff --git a/.github/workflows/tests_lgpumpi_cpp.yml b/.github/workflows/tests_lgpumpi_cpp.yml index dab42477bf..ea16fa04b2 100644 --- a/.github/workflows/tests_lgpumpi_cpp.yml +++ b/.github/workflows/tests_lgpumpi_cpp.yml @@ -167,7 +167,7 @@ jobs: mkdir -p ./tests/results test_status=0 for file in *runner ; do ./$file --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; - for file in *runner_mpi ; do mpirun -np 2 ./$file --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; + for file in *runner_mpi ; do mpirun -np 2 ./$file --order decl --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; if [ $test_status -ne 0 ]; then echo "Tests failed. Exiting with error code." exit 1 diff --git a/.github/workflows/tests_lkmpi_cuda_cpp.yml b/.github/workflows/tests_lkmpi_cuda_cpp.yml index f7f6be67b7..c8782b4e6a 100644 --- a/.github/workflows/tests_lkmpi_cuda_cpp.yml +++ b/.github/workflows/tests_lkmpi_cuda_cpp.yml @@ -193,8 +193,8 @@ jobs: mkdir -p ./tests/results test_status=0 for file in *runner ; do ./$file --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; - for file in lightning_kokkos*runner_mpi ; do mpirun -np 4 ./$file --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; - for file in utils_*runner_mpi ; do mpirun -np 2 ./$file --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; + for file in lightning_kokkos*runner_mpi ; do mpirun -np 4 ./$file --order decl --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; + for file in utils_*runner_mpi ; do mpirun -np 2 ./$file --order decl --reporter junit --out ./tests/results/report_$file.xml && echo "Test $file Success!" || { cat ./tests/results/report_$file.xml; test_status=1; } done; if [ $test_status -ne 0 ]; then echo "Tests failed. Exiting with error code." exit 1 diff --git a/Makefile b/Makefile index c0cd20b034..39733050d6 100644 --- a/Makefile +++ b/Makefile @@ -156,23 +156,23 @@ test-cpp-mpi: $(OPTIONS) ifdef target cmake --build ./BuildTests $(VERBOSE) --target $(target) - mpirun -np 2 ./BuildTests/$(target) + mpirun -np 2 ./BuildTests/$(target) --order decl else cmake --build ./BuildTests $(VERBOSE) - + if [ "$(PL_BACKEND)" = "lightning_gpu" ]; then \ for file in ./BuildTests/*_test_runner_mpi; do \ echo "Running $$file"; \ - mpirun -np 2 $$file ; \ + mpirun -np 2 $$file --order decl ; \ done ; \ elif [ "$(PL_BACKEND)" = "lightning_kokkos" ]; then \ for file in ./BuildTests/lightning_kokkos*test_runner_mpi; do \ echo "Running $$file"; \ - mpirun -np 4 $$file ; \ + mpirun -np 4 $$file --order decl ; \ done ; \ for file in ./BuildTests/utils_test_runner_mpi; do \ echo "Running $$file"; \ - mpirun -np 2 $$file ; \ + mpirun -np 2 $$file --order decl ; \ done; \ fi endif diff --git a/cmake/support_tests.cmake b/cmake/support_tests.cmake index 827d050c9d..793df71f54 100644 --- a/cmake/support_tests.cmake +++ b/cmake/support_tests.cmake @@ -13,7 +13,7 @@ macro(FetchAndIncludeCatch) FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.13.10 + GIT_TAG v3.11.0 ) FetchContent_MakeAvailable(Catch2) @@ -22,7 +22,7 @@ macro(FetchAndIncludeCatch) set_target_properties(Catch2 PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CATCH2_IID}") # Required for catch_discover_tests() and include(Catch) - list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib) + list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) include(Catch) endmacro() @@ -48,4 +48,4 @@ macro(ProcessTestOptions target_name) message(STATUS "ENABLE_NATIVE is ON. Use -march=native for cpptests.") target_compile_options(${target_name} INTERFACE -march=native) endif() -endmacro() \ No newline at end of file +endmacro() diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index fa40379eb5..2e003b71ba 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.45.0-dev25" +__version__ = "0.45.0-dev26" diff --git a/pennylane_lightning/core/algorithms/tests/Test_AdjointJacobian.cpp b/pennylane_lightning/core/algorithms/tests/Test_AdjointJacobian.cpp index a18221c145..6d01341d73 100644 --- a/pennylane_lightning/core/algorithms/tests/Test_AdjointJacobian.cpp +++ b/pennylane_lightning/core/algorithms/tests/Test_AdjointJacobian.cpp @@ -11,7 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include +#include #include "Error.hpp" // LightningException #include "JacobianData.hpp" diff --git a/pennylane_lightning/core/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp b/pennylane_lightning/core/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp index 6b8cf7e44a..650eb73ded 100644 --- a/pennylane_lightning/core/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp +++ b/pennylane_lightning/core/algorithms/tests/mpi/Test_AdjointJacobianMPI.cpp @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "JacobianData.hpp" #include "TestHelpers.hpp" //PLApprox diff --git a/pennylane_lightning/core/algorithms/tests/mpi/runner_algorithms_mpi.cpp b/pennylane_lightning/core/algorithms/tests/mpi/runner_algorithms_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/algorithms/tests/mpi/runner_algorithms_mpi.cpp +++ b/pennylane_lightning/core/algorithms/tests/mpi/runner_algorithms_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/algorithms/tests/runner_algorithms.cpp b/pennylane_lightning/core/algorithms/tests/runner_algorithms.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/algorithms/tests/runner_algorithms.cpp +++ b/pennylane_lightning/core/algorithms/tests/runner_algorithms.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/bindings/BindingsMPI.hpp b/pennylane_lightning/core/bindings/BindingsMPI.hpp index d0332a80d5..a7023fc205 100644 --- a/pennylane_lightning/core/bindings/BindingsMPI.hpp +++ b/pennylane_lightning/core/bindings/BindingsMPI.hpp @@ -427,7 +427,7 @@ void registerBackendAgnosticAlgorithmsMPI(nb::module_ &m) { * * @param m Nanobind module */ -inline void registerInfoMPI(nb::module_ &m) { +inline void registerInfoMPI([[maybe_unused]] nb::module_ &m) { // This function is now empty - MPI manager registration moved to // backend-specific } diff --git a/pennylane_lightning/core/catalyst/tests/Test_LightningDriver.cpp b/pennylane_lightning/core/catalyst/tests/Test_LightningDriver.cpp index d355dbf875..8389fbe380 100644 --- a/pennylane_lightning/core/catalyst/tests/Test_LightningDriver.cpp +++ b/pennylane_lightning/core/catalyst/tests/Test_LightningDriver.cpp @@ -13,8 +13,9 @@ // limitations under the License. #include "TestHelpers.hpp" -#include "catch2/catch.hpp" #include +#include +#include #include #include @@ -162,7 +163,7 @@ TEST_CASE("Check an unsupported operation", "[Driver]") { REQUIRE_THROWS_WITH( Lightning::lookup_gates(Lightning::simulator_gate_info, "UnsupportedGateName"), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The given operation is not supported by the simulator")); } @@ -447,8 +448,9 @@ TEST_CASE("Cannot reuse entangled qubit when allocating", "[Driver]") { REQUIRE_THROWS_WITH( sim->AllocateQubit(), - Catch::Contains("Cannot reuse qubit: qubit is entangled with remaining " - "qubits. Release qubits must be disentangled.")); + Catch::Matchers::ContainsSubstring( + "Cannot reuse qubit: qubit is entangled with remaining " + "qubits. Release qubits must be disentangled.")); } TEST_CASE("Release one qubit from entangled qubits", "[Driver]") { @@ -478,8 +480,9 @@ TEST_CASE("Release one qubit from entangled qubits", "[Driver]") { REQUIRE_THROWS_WITH( sim->PartialProbs(probs_view, {static_qubits[0], static_qubits[1]}), - Catch::Contains("Cannot release qubits: released qubits are entangled " - "with remaining qubits")); + Catch::Matchers::ContainsSubstring( + "Cannot release qubits: released qubits are entangled " + "with remaining qubits")); } TEST_CASE("Release all entangled qubits", "[Driver]") { diff --git a/pennylane_lightning/core/catalyst/tests/Test_LightningQubitManager.cpp b/pennylane_lightning/core/catalyst/tests/Test_LightningQubitManager.cpp index 04c2134811..ff8516adcb 100644 --- a/pennylane_lightning/core/catalyst/tests/Test_LightningQubitManager.cpp +++ b/pennylane_lightning/core/catalyst/tests/Test_LightningQubitManager.cpp @@ -16,7 +16,8 @@ #include #include -#include "catch2/catch.hpp" +#include +#include #include "LightningQubitManager.hpp" @@ -98,12 +99,14 @@ TEST_CASE("Test lightning qubit manager invalid IDs", "[Utils]") { size_t device_qubit_id = 0; QubitIdType q = manager.Allocate(device_qubit_id); - REQUIRE_THROWS_WITH(manager.getProgramId(device_qubit_id + 42), - Catch::Contains("Invalid device qubit ID")); - REQUIRE_THROWS_WITH(manager.getDeviceId(q + 42), - Catch::Contains("Invalid program qubit ID")); - REQUIRE_THROWS_WITH( - manager.Release(q + 42), - Catch::Contains("Cannot release qubit, the given ID is invalid")); + manager.getProgramId(device_qubit_id + 42), + Catch::Matchers::ContainsSubstring("Invalid device qubit ID")); + REQUIRE_THROWS_WITH( + manager.getDeviceId(q + 42), + Catch::Matchers::ContainsSubstring("Invalid program qubit ID")); + + REQUIRE_THROWS_WITH(manager.Release(q + 42), + Catch::Matchers::ContainsSubstring( + "Cannot release qubit, the given ID is invalid")); } diff --git a/pennylane_lightning/core/catalyst/tests/runner_catalyst.cpp b/pennylane_lightning/core/catalyst/tests/runner_catalyst.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/catalyst/tests/runner_catalyst.cpp +++ b/pennylane_lightning/core/catalyst/tests/runner_catalyst.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/measurements/tests/Test_MeasurementsBase.cpp b/pennylane_lightning/core/measurements/tests/Test_MeasurementsBase.cpp index e8ff3bdff4..efba57ff7e 100644 --- a/pennylane_lightning/core/measurements/tests/Test_MeasurementsBase.cpp +++ b/pennylane_lightning/core/measurements/tests/Test_MeasurementsBase.cpp @@ -12,7 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "TestHelpers.hpp" -#include +#include +#include +#include +#include /// @cond DEV namespace { @@ -129,8 +132,9 @@ template void testProbabilities() { << StateVectorToName::name) { for (const auto &term : input) { probabilities = Measurer.probs(term.first); - REQUIRE_THAT(term.second, - Catch::Approx(probabilities).margin(1e-6)); + REQUIRE_THAT( + term.second, + Catch::Matchers::Approx(probabilities).margin(1e-6)); } } @@ -179,7 +183,7 @@ template void testProbabilitiesShots() { std::size_t num_shots = 10000; probabilities = Measurer.probs(num_shots); REQUIRE_THAT(input[0].second, - Catch::Approx(probabilities).margin(5e-2)); + Catch::Matchers::Approx(probabilities).margin(5e-2)); } DYNAMIC_SECTION( @@ -188,8 +192,9 @@ template void testProbabilitiesShots() { for (const auto &term : input) { std::size_t num_shots = 10000; probabilities = Measurer.probs(term.first, num_shots); - REQUIRE_THAT(term.second, - Catch::Approx(probabilities).margin(5e-2)); + REQUIRE_THAT( + term.second, + Catch::Matchers::Approx(probabilities).margin(5e-2)); } } @@ -232,7 +237,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -250,7 +256,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -265,7 +272,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -282,7 +290,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -297,7 +306,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -322,7 +332,7 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(*obs); auto prob = Measurer.probs(std::vector({0, 1, 2})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, Catch::Matchers::Approx(prob).margin(1e-6)); } DYNAMIC_SECTION("Test TensorProd YHI" @@ -347,7 +357,7 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(*obs); auto prob = Measurer.probs(std::vector({0, 1, 2})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, Catch::Matchers::Approx(prob).margin(1e-6)); } testProbabilitiesObs(); @@ -396,7 +406,8 @@ template void testProbabilitiesObsShots() { auto prob = Measurer.probs(std::vector({0, 1, 2})); - REQUIRE_THAT(prob_obs_shots, Catch::Approx(prob).margin(5e-2)); + REQUIRE_THAT(prob_obs_shots, + Catch::Matchers::Approx(prob).margin(5e-2)); } DYNAMIC_SECTION("Test TensorProd YHI" @@ -422,7 +433,8 @@ template void testProbabilitiesObsShots() { auto prob_obs_shots = Measurer_obs_shots.probs(*obs, num_shots); auto prob = Measurer.probs(std::vector({0, 1, 2})); - REQUIRE_THAT(prob_obs_shots, Catch::Approx(prob).margin(5e-2)); + REQUIRE_THAT(prob_obs_shots, + Catch::Matchers::Approx(prob).margin(5e-2)); } testProbabilitiesObsShots(); @@ -1290,8 +1302,9 @@ void testSamples(const std::optional &seed = std::nullopt) { DYNAMIC_SECTION("No wires provided - " << StateVectorToName::name) { - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } testSamples(seed); } @@ -1419,8 +1432,9 @@ template void testSamplesCountsObs() { probabilities[i] = counts[i] / (PrecisionT)num_samples; } - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } DYNAMIC_SECTION("counts() without obs" @@ -1453,8 +1467,9 @@ template void testSamplesCountsObs() { probabilities[i] = counts[i] / (PrecisionT)num_samples; } - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } testSamplesCountsObs(); @@ -1700,18 +1715,19 @@ template void testSparseHObsMeasureShot() { std::vector shots_range = {}; REQUIRE_THROWS_WITH( Measurer.expval(*sparseH, num_shots, shots_range), - Catch::Matchers::Contains("SparseHamiltonian observables do " - "not support shot measurement.")); + Catch::Matchers::ContainsSubstring( + "SparseHamiltonian observables do " + "not support shot measurement.")); } DYNAMIC_SECTION("Failed for var " << StateVectorToName::name) { std::size_t num_shots = 1000; std::vector shots_range = {}; - REQUIRE_THROWS_WITH( - Measurer.var(*sparseH, num_shots), - Catch::Matchers::Contains("SparseHamiltonian observables do " - "not support shot measurement.")); + REQUIRE_THROWS_WITH(Measurer.var(*sparseH, num_shots), + Catch::Matchers::ContainsSubstring( + "SparseHamiltonian observables do " + "not support shot measurement.")); } testSparseHObsMeasureShot(); diff --git a/pennylane_lightning/core/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp b/pennylane_lightning/core/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp index ab9640677f..bd1d7fc474 100644 --- a/pennylane_lightning/core/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp +++ b/pennylane_lightning/core/measurements/tests/mpi/Test_MeasurementsBaseMPI.cpp @@ -11,7 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include +#include #include "TestHelpers.hpp" @@ -105,8 +106,9 @@ template void testProbabilities() { << StateVectorMPIToName::name) { for (const auto &term : input) { auto probabilities = Measurer.probs(term.first); - REQUIRE_THAT(prob_local, - Catch::Approx(probabilities).margin(1e-6)); + REQUIRE_THAT( + prob_local, + Catch::Matchers::Approx(probabilities).margin(1e-6)); } } @@ -115,7 +117,7 @@ template void testProbabilities() { std::size_t num_shots = 1000; auto probabilities = Measurer.probs(num_shots); REQUIRE_THAT(expected_prob, - Catch::Approx(probabilities).margin(5e-2)); + Catch::Matchers::Approx(probabilities).margin(5e-2)); } DYNAMIC_SECTION( @@ -129,7 +131,7 @@ template void testProbabilities() { auto probabilities = Measurer.probs(wires, num_shots); REQUIRE_THAT(expected_probs, - Catch::Approx(probabilities).margin(5e-2)); + Catch::Matchers::Approx(probabilities).margin(5e-2)); } testProbabilities(); @@ -197,7 +199,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -215,7 +218,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -230,7 +234,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -247,7 +252,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -262,7 +268,8 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(obs); auto prob = Measurer.probs(std::vector({i})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, + Catch::Matchers::Approx(prob).margin(1e-6)); } } @@ -287,7 +294,7 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(*obs); auto prob = Measurer.probs(std::vector({0, 1, 2})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, Catch::Matchers::Approx(prob).margin(1e-6)); } DYNAMIC_SECTION("Test TensorProd YHI" @@ -312,7 +319,7 @@ template void testProbabilitiesObs() { auto prob_obs = Measurer_obs.probs(*obs); auto prob = Measurer.probs(std::vector({0, 1, 2})); - REQUIRE_THAT(prob_obs, Catch::Approx(prob).margin(1e-6)); + REQUIRE_THAT(prob_obs, Catch::Matchers::Approx(prob).margin(1e-6)); } testProbabilitiesObs(); @@ -389,7 +396,8 @@ template void testProbabilitiesObsShots() { auto prob_obs_shots = Measurer_obs_shots.probs(*obs, num_shots); auto prob = Measurer.probs(std::vector({0, 1, 2})); auto prob_all = mpi_manager.allgather(prob); - REQUIRE_THAT(prob_obs_shots, Catch::Approx(prob_all).margin(5e-2)); + REQUIRE_THAT(prob_obs_shots, + Catch::Matchers::Approx(prob_all).margin(5e-2)); } DYNAMIC_SECTION("Test TensorProd YHI" @@ -415,7 +423,8 @@ template void testProbabilitiesObsShots() { auto prob_obs_shots = Measurer_obs_shots.probs(*obs, num_shots); auto prob = Measurer.probs(std::vector({2, 1, 0})); auto prob_all = mpi_manager.allgather(prob); - REQUIRE_THAT(prob_obs_shots, Catch::Approx(prob_all).margin(5e-2)); + REQUIRE_THAT(prob_obs_shots, + Catch::Matchers::Approx(prob_all).margin(5e-2)); } testProbabilitiesObsShots(); @@ -1243,8 +1252,9 @@ template void testSamples() { DYNAMIC_SECTION("No wires provided - " << StateVectorMPIToName::name) { - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } testSamples(); } @@ -1387,8 +1397,9 @@ template void testSamplesCountsObs() { probabilities[i] = counts[i] / (PrecisionT)num_samples; } - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } DYNAMIC_SECTION("counts() without obs" @@ -1420,8 +1431,9 @@ template void testSamplesCountsObs() { probabilities[i] = counts[i] / (PrecisionT)num_samples; } - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } testSamplesCountsObs(); diff --git a/pennylane_lightning/core/measurements/tests/mpi/runner_measurements_mpi.cpp b/pennylane_lightning/core/measurements/tests/mpi/runner_measurements_mpi.cpp index b75b719a2c..757dbc9e5a 100644 --- a/pennylane_lightning/core/measurements/tests/mpi/runner_measurements_mpi.cpp +++ b/pennylane_lightning/core/measurements/tests/mpi/runner_measurements_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/measurements/tests/runner_measurements.cpp b/pennylane_lightning/core/measurements/tests/runner_measurements.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/measurements/tests/runner_measurements.cpp +++ b/pennylane_lightning/core/measurements/tests/runner_measurements.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/observables/tests/Test_Observables.cpp b/pennylane_lightning/core/observables/tests/Test_Observables.cpp index b8aa79646d..91a9d90a4e 100644 --- a/pennylane_lightning/core/observables/tests/Test_Observables.cpp +++ b/pennylane_lightning/core/observables/tests/Test_Observables.cpp @@ -17,7 +17,8 @@ #include "TypeList.hpp" #include "Util.hpp" // TestVector -#include +#include +#include #include #include @@ -135,7 +136,7 @@ template void testNamedObsBase() { REQUIRE_THROWS_WITH( obs.applyInPlaceShots(state_vector, eigenValues, ob_wires), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "Provided NamedObs does not support shot measurement.")); auto ob = obs.getObs(); @@ -223,8 +224,9 @@ template void testHermitianObsBase() { REQUIRE_THROWS_WITH( obs.applyInPlaceShots(state_vector, eigenValues, ob_wires), - Catch::Matchers::Contains("The matrix passed to HermitianObs " - "is not a Hermitian matrix.")); + Catch::Matchers::ContainsSubstring( + "The matrix passed to HermitianObs " + "is not a Hermitian matrix.")); } testHermitianObsBase(); @@ -668,8 +670,9 @@ template void testSparseHamiltonianBase() { REQUIRE_THROWS_WITH( sparseH->applyInPlaceShots(state_vector, eigenValues, ob_wires), - Catch::Matchers::Contains("SparseHamiltonian observables do " - "not support shot measurement.")); + Catch::Matchers::ContainsSubstring( + "SparseHamiltonian observables do " + "not support shot measurement.")); } testSparseHamiltonianBase(); diff --git a/pennylane_lightning/core/observables/tests/mpi/Test_ObservablesMPI.cpp b/pennylane_lightning/core/observables/tests/mpi/Test_ObservablesMPI.cpp index 5ee28d9083..3ae657ef30 100644 --- a/pennylane_lightning/core/observables/tests/mpi/Test_ObservablesMPI.cpp +++ b/pennylane_lightning/core/observables/tests/mpi/Test_ObservablesMPI.cpp @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include diff --git a/pennylane_lightning/core/observables/tests/mpi/runner_observables_mpi.cpp b/pennylane_lightning/core/observables/tests/mpi/runner_observables_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/observables/tests/mpi/runner_observables_mpi.cpp +++ b/pennylane_lightning/core/observables/tests/mpi/runner_observables_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/observables/tests/runner_observables.cpp b/pennylane_lightning/core/observables/tests/runner_observables.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/observables/tests/runner_observables.cpp +++ b/pennylane_lightning/core/observables/tests/runner_observables.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/base/tests/Test_StateVectorBase.cpp b/pennylane_lightning/core/simulators/base/tests/Test_StateVectorBase.cpp index 405fcdc757..8180ba1d3b 100644 --- a/pennylane_lightning/core/simulators/base/tests/Test_StateVectorBase.cpp +++ b/pennylane_lightning/core/simulators/base/tests/Test_StateVectorBase.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include "TestHelpers.hpp" // createZeroState, createRandomStateVectorData #include "TypeList.hpp" diff --git a/pennylane_lightning/core/simulators/base/tests/runner_base.cpp b/pennylane_lightning/core/simulators/base/tests/runner_base.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/base/tests/runner_base.cpp +++ b/pennylane_lightning/core/simulators/base/tests/runner_base.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/Test_AdjointJacobianGPU.cpp b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/Test_AdjointJacobianGPU.cpp index 29dad3318b..c9dcd7500b 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/Test_AdjointJacobianGPU.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/Test_AdjointJacobianGPU.cpp @@ -4,7 +4,8 @@ #include #include -#include +#include +#include #include "AdjointJacobianGPU.hpp" #include "JacobianData.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp index 703bcab491..bda91fff83 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/Test_AdjointJacobianGPUMPI.cpp @@ -18,7 +18,8 @@ #include #include -#include +#include +#include #include "AdjointJacobianGPU.hpp" #include "JacobianData.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/runner_lightning_gpu_algorithms_mpi.cpp b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/runner_lightning_gpu_algorithms_mpi.cpp index b75b719a2c..757dbc9e5a 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/runner_lightning_gpu_algorithms_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/mpi/runner_lightning_gpu_algorithms_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/runner_lightning_gpu_algorithms.cpp b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/runner_lightning_gpu_algorithms.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/runner_lightning_gpu_algorithms.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/algorithms/tests/runner_lightning_gpu_algorithms.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUGradient.cpp b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUGradient.cpp index f914770522..1364a58547 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUGradient.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUGradient.cpp @@ -13,7 +13,10 @@ // limitations under the License. #include "LightningGPUSimulator.hpp" -#include "catch2/catch.hpp" +#include +#include +#include +using Catch::Approx; /// @cond DEV namespace { @@ -76,13 +79,13 @@ TEST_CASE("Test Gradient with Var", "[Gradient]") { auto pz = sim->Observable(ObsId::PauliZ, {}, {q}); sim->Var(pz); - REQUIRE_THROWS_WITH( - sim->Gradient(gradients, trainParams), - Catch::Contains("Unsupported measurements to compute gradient")); + REQUIRE_THROWS_WITH(sim->Gradient(gradients, trainParams), + Catch::Matchers::ContainsSubstring( + "Unsupported measurements to compute gradient")); - REQUIRE_THROWS_WITH( - sim->Gradient(gradients, {}), - Catch::Contains("Unsupported measurements to compute gradient")); + REQUIRE_THROWS_WITH(sim->Gradient(gradients, {}), + Catch::Matchers::ContainsSubstring( + "Unsupported measurements to compute gradient")); sim->StopTapeRecording(); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUMeasures.cpp b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUMeasures.cpp index 0d1f2a720c..8525b21d7d 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUMeasures.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUMeasures.cpp @@ -19,7 +19,10 @@ #include "QuantumDevice.hpp" #include "Types.h" #include "Utils.hpp" -#include "catch2/catch.hpp" +#include +#include +#include +using Catch::Approx; #include "cmath" /// @cond DEV @@ -41,8 +44,9 @@ using LGPUSimulator = LightningGPUSimulator; TEST_CASE("NameObs test with invalid number of wires", "[Measures]") { std::unique_ptr sim = std::make_unique(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::PauliX, {}, {1}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::PauliX, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); } TEST_CASE("NameObs test with invalid given wires for NamedObs", "[Measures]") { @@ -50,15 +54,17 @@ TEST_CASE("NameObs test with invalid given wires for NamedObs", "[Measures]") { sim->AllocateQubit(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::PauliX, {}, {1}), - Catch::Contains("Invalid given wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::PauliX, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid given wires")); } TEST_CASE("HermitianObs test with invalid number of wires", "[Measures]") { std::unique_ptr sim = std::make_unique(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::Hermitian, {}, {1}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::Hermitian, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); } TEST_CASE("HermitianObs test with invalid given wires for HermitianObs", @@ -66,15 +72,16 @@ TEST_CASE("HermitianObs test with invalid given wires for HermitianObs", std::unique_ptr sim = std::make_unique(); sim->AllocateQubit(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::Hermitian, {}, {1}), - Catch::Contains("Invalid given wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::Hermitian, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid given wires")); } TEST_CASE("Check an unsupported observable", "[Measures]") { REQUIRE_THROWS_WITH( Lightning::lookup_obs( Lightning::simulator_observable_support, static_cast(10)), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The given observable is not supported by the simulator")); } @@ -187,8 +194,8 @@ TEST_CASE("Mid-circuit measurement test with invalid postselect value", sim->NamedOperation("Hadamard", {}, {q}, false); - REQUIRE_THROWS_WITH(sim->Measure(q, 2), - Catch::Contains("Invalid postselect value")); + REQUIRE_THROWS_WITH(sim->Measure(q, 2), Catch::Matchers::ContainsSubstring( + "Invalid postselect value")); } TEST_CASE("Expval(ObsT) test with invalid key for cached observables", @@ -196,7 +203,8 @@ TEST_CASE("Expval(ObsT) test with invalid key for cached observables", std::unique_ptr sim = std::make_unique(); REQUIRE_THROWS_WITH(sim->Expval(0), - Catch::Contains("Invalid key for cached observables")); + Catch::Matchers::ContainsSubstring( + "Invalid key for cached observables")); } TEST_CASE("Expval(NamedObs) test", "[Measures]") { @@ -406,9 +414,9 @@ TEST_CASE("Expval(TensorProd(NamedObs[])) test", "[Measures]") { ObsIdType tpxy = sim->TensorObservable({px, py}); ObsIdType tpxz = sim->TensorObservable({px, pz}); - REQUIRE_THROWS_WITH( - sim->TensorObservable({px, py, pz}), - Catch::Contains("All wires in observables must be disjoint.")); + REQUIRE_THROWS_WITH(sim->TensorObservable({px, py, pz}), + Catch::Matchers::ContainsSubstring( + "All wires in observables must be disjoint.")); CHECK(sim->Expval(tpxy) == Approx(0.0).margin(1e-5)); CHECK(sim->Expval(tpxz) == Approx(-1.0).margin(1e-5)); @@ -1296,9 +1304,9 @@ TEST_CASE("State test with incorrect size", "[Measures]") { std::vector> state(1U << (n - 1)); DataView, 1> view(state); - REQUIRE_THROWS_WITH( - sim->State(view), - Catch::Contains("Invalid size for the pre-allocated state vector")); + REQUIRE_THROWS_WITH(sim->State(view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated state vector")); } TEST_CASE("State test with numWires=4", "[Measures]") { @@ -1345,21 +1353,23 @@ TEST_CASE("PartialProbs test with incorrect numWires and numAlloc", REQUIRE_THROWS_WITH( sim->PartialProbs(probs_view, {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialProbs(probs_view, {Qs[0]}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "Invalid size for the pre-allocated partial-probabilities")); REQUIRE_THROWS_WITH( sim->Probs(probs_view), - Catch::Contains("Invalid size for the pre-allocated probabilities")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated probabilities")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialProbs(probs_view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialProbs(probs_view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("Probs and PartialProbs tests with numWires=0-4", "[Measures]") { @@ -1506,20 +1516,22 @@ TEST_CASE("PartialSample test with incorrect numWires and numAlloc", REQUIRE_THROWS_WITH( sim->PartialSample(view, {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialSample(view, {Qs[0], Qs[1]}), - Catch::Contains("Invalid size for the pre-allocated partial-samples")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated partial-samples")); - REQUIRE_THROWS_WITH( - sim->Sample(view), - Catch::Contains("Invalid size for the pre-allocated samples")); + REQUIRE_THROWS_WITH(sim->Sample(view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated samples")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialSample(view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialSample(view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("PartialCounts test with incorrect numWires and numAlloc", @@ -1541,22 +1553,25 @@ TEST_CASE("PartialCounts test with incorrect numWires and numAlloc", std::vector counts_vec(1); DataView counts_view(counts_vec); - REQUIRE_THROWS_WITH(sim->PartialCounts(eigvals_view, counts_view, - {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->PartialCounts(eigvals_view, counts_view, + {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), - Catch::Contains("Invalid size for the pre-allocated partial-counts")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated partial-counts")); - REQUIRE_THROWS_WITH( - sim->Counts(eigvals_view, counts_view), - Catch::Contains("Invalid size for the pre-allocated counts")); + REQUIRE_THROWS_WITH(sim->Counts(eigvals_view, counts_view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated counts")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("Sample and PartialSample tests with numWires=0-4 shots=100", diff --git a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUSimulator.cpp b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUSimulator.cpp index 05c446498d..a543210da1 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUSimulator.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUSimulator.cpp @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "LightningGPUSimulator.hpp" #include "QuantumDevice.hpp" @@ -78,13 +79,13 @@ TEST_CASE("LightningGPUSimulator::unit_tests", "[unit tests]") { std::make_unique(); std::vector Qs = LGPUsim->AllocateQubits(1); REQUIRE_NOTHROW(LGPUsim->StartTapeRecording()); - REQUIRE_THROWS_WITH( - LGPUsim->StartTapeRecording(), - Catch::Matchers::Contains("Cannot re-activate the cache manager")); + REQUIRE_THROWS_WITH(LGPUsim->StartTapeRecording(), + Catch::Matchers::ContainsSubstring( + "Cannot re-activate the cache manager")); REQUIRE_NOTHROW(LGPUsim->StopTapeRecording()); REQUIRE_THROWS_WITH( LGPUsim->StopTapeRecording(), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "Cannot stop an already stopped cache manager")); } } @@ -753,14 +754,15 @@ TEST_CASE("LightningGPUSimulator::GateSet", "[GateSet]") { constexpr std::size_t n_qubits = 2; std::vector Qs = LGPUsim->AllocateQubits(n_qubits); - REQUIRE_THROWS_WITH( - LGPUsim->NamedOperation("Hadamard", {}, {Qs[0]}, false, {Qs[1]}, - {}), - Catch::Contains("Controlled wires/values size mismatch")); + REQUIRE_THROWS_WITH(LGPUsim->NamedOperation("Hadamard", {}, {Qs[0]}, + false, {Qs[1]}, {}), + Catch::Matchers::ContainsSubstring( + "Controlled wires/values size mismatch")); std::vector> matrix(4, {0.0, 0.0}); REQUIRE_THROWS_WITH( LGPUsim->MatrixOperation(matrix, {Qs[0]}, false, {Qs[1]}, {}), - Catch::Contains("Controlled wires/values size mismatch")); + Catch::Matchers::ContainsSubstring( + "Controlled wires/values size mismatch")); } SECTION("Controlled GlobalPhase (multi-qubit)") { @@ -873,14 +875,15 @@ TEST_CASE("LightningGPUSimulator::GateSet", "[GateSet]") { constexpr std::size_t n_qubits = 2; std::vector Qs = LGPUsim->AllocateQubits(n_qubits); - REQUIRE_THROWS_WITH( - LGPUsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, false, {}, {}, - {"X", "Y"}), - Catch::Contains("PauliRot operation requires one string")); + REQUIRE_THROWS_WITH(LGPUsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, + false, {}, {}, {"X", "Y"}), + Catch::Matchers::ContainsSubstring( + "PauliRot operation requires one string")); - REQUIRE_THROWS_WITH( - LGPUsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, false, {Qs[1]}, - {false}, {"XY"}), - Catch::Contains("Controlled PauliRot is not supported")); + REQUIRE_THROWS_WITH(LGPUsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, + false, {Qs[1]}, {false}, + {"XY"}), + Catch::Matchers::ContainsSubstring( + "Controlled PauliRot is not supported")); } } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/runner_lightning_gpu_catalyst.cpp b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/runner_lightning_gpu_catalyst.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/runner_lightning_gpu_catalyst.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/catalyst/tests/runner_lightning_gpu_catalyst.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Generators.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Generators.cpp index d8c2a66ff6..393a58f4a6 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Generators.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Generators.cpp @@ -17,7 +17,8 @@ #include #include -#include +#include +#include #include "StateVectorCudaManaged.hpp" #include "TestHelpers.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_NonParam.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_NonParam.cpp index 725539e699..afa134d83f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_NonParam.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_NonParam.cpp @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "StateVectorCudaManaged.hpp" #include "cuGateCache.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp index 39de53ac1c..ce4a07b56a 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "Gates.hpp" #include "TestHelpers.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp index 164fed7f01..aee834b5e1 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Generators.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include "MPIManagerGPU.hpp" #include "StateVectorCudaMPI.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp index 672975ea86..f7996ba3e5 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_NonParam.cpp @@ -20,7 +20,8 @@ #include #include -#include +#include +#include #include #include "DevTag.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp index db8f0ef4b5..e969114a62 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/Test_StateVectorCudaMPI_Param.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include #include "cuGateCache.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/mpi_runner_lightning_gpu_gates.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/mpi_runner_lightning_gpu_gates.cpp index b75b719a2c..1dfe3b5032 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/mpi_runner_lightning_gpu_gates.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/mpi/mpi_runner_lightning_gpu_gates.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { @@ -7,4 +7,4 @@ int main(int argc, char *argv[]) { int result = Catch::Session().run(argc, argv); MPI_Finalize(); return result; -} \ No newline at end of file +} diff --git a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/runner_lightning_gpu_gates.cpp b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/runner_lightning_gpu_gates.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/runner_lightning_gpu_gates.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/gates/tests/runner_lightning_gpu_gates.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Expval.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Expval.cpp index 6539d34116..3904d8e334 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Expval.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Expval.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Measure.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Measure.cpp index 4f3efaade5..63fc464b68 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Measure.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Measure.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "MeasurementsGPU.hpp" #include "StateVectorCudaManaged.hpp" @@ -74,17 +75,20 @@ TEMPLATE_TEST_CASE("Expected Values", "[Measurements]", float, double) { operations_list = {PauliX, PauliX, PauliX}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } SECTION("Testing list of operators defined by its name:") { @@ -96,17 +100,20 @@ TEMPLATE_TEST_CASE("Expected Values", "[Measurements]", float, double) { operations_list = {"PauliX", "PauliX", "PauliX"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } SECTION("Catch failures caused by unsupported named gates") { @@ -217,17 +224,20 @@ TEMPLATE_TEST_CASE("Variances", "[Measurements]", float, double) { operations_list = {PauliX, PauliX, PauliX}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } SECTION("Testing list of operators defined by its name:") { @@ -239,17 +249,20 @@ TEMPLATE_TEST_CASE("Variances", "[Measurements]", float, double) { operations_list = {"PauliX", "PauliX", "PauliX"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } } @@ -271,7 +284,7 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) { for (const auto &term : input) { auto probabilities = m.probs(term.first); REQUIRE_THAT(term.second, - Catch::Approx(probabilities).margin(1e-6)); + Catch::Matchers::Approx(probabilities).margin(1e-6)); } } } \ No newline at end of file diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Var.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Var.cpp index deccedee0c..3bcf99c315 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Var.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/Test_StateVectorCudaManaged_Var.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +using Catch::Approx; #include "MeasurementsGPU.hpp" #include "ObservablesGPU.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp index 739e24da94..9af30449dc 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Expval.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp index 8df30cb776..35d92692a5 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Measure.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "MPIManagerGPU.hpp" #include "MeasurementsGPU.hpp" @@ -119,17 +120,20 @@ TEMPLATE_TEST_CASE("Expected Values", "[MeasurementsMPI]", float, double) { operations_list = {PauliX, PauliX, PauliX}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } SECTION("Testing list of operators defined by its name:") { @@ -148,17 +152,20 @@ TEMPLATE_TEST_CASE("Expected Values", "[MeasurementsMPI]", float, double) { operations_list = {"PauliX", "PauliX", "PauliX"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } SECTION("Catch failures caused by unsupported named gates") { @@ -369,17 +376,20 @@ TEMPLATE_TEST_CASE("Variances", "[MeasurementsMPI]", double) { operations_list = {PauliX, PauliX, PauliX}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } SECTION("Testing list of operators defined by its name:") { @@ -393,17 +403,20 @@ TEMPLATE_TEST_CASE("Variances", "[MeasurementsMPI]", double) { operations_list = {"PauliX", "PauliX", "PauliX"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } } @@ -453,7 +466,8 @@ TEMPLATE_TEST_CASE("Probabilities", "[MeasuresMPI]", double) { auto m = MeasurementsMPI(sv); for (const auto &term : input) { auto probabilities = m.probs(term.first); - REQUIRE_THAT(prob_local, Catch::Approx(probabilities).margin(1e-6)); + REQUIRE_THAT(prob_local, + Catch::Matchers::Approx(probabilities).margin(1e-6)); } } } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp index 2a521bcdba..9a36c8162f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/Test_StateVectorCudaMPI_Var.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +using Catch::Approx; #include "MeasurementsGPU.hpp" #include "MeasurementsGPUMPI.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/runner_lightning_gpu_measurements_mpi.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/runner_lightning_gpu_measurements_mpi.cpp index b75b719a2c..757dbc9e5a 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/runner_lightning_gpu_measurements_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/mpi/runner_lightning_gpu_measurements_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/runner_lightning_gpu_measurements.cpp b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/runner_lightning_gpu_measurements.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/runner_lightning_gpu_measurements.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/measurements/tests/runner_lightning_gpu_measurements.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/Test_ObservablesGPU.cpp b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/Test_ObservablesGPU.cpp index f8850ef3ff..0ac9a34dc9 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/Test_ObservablesGPU.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/Test_ObservablesGPU.cpp @@ -14,7 +14,7 @@ #include "ObservablesGPU.hpp" #include "TestHelpers.hpp" -#include +#include /// @cond DEV namespace { diff --git a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp index 0e1e1788be..ddfe0bd105 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/Test_ObservablesGPUMPI.cpp @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "MPIManagerGPU.hpp" #include "ObservablesGPU.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/runner_lightning_gpu_observables_mpi.cpp b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/runner_lightning_gpu_observables_mpi.cpp index b75b719a2c..757dbc9e5a 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/runner_lightning_gpu_observables_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/mpi/runner_lightning_gpu_observables_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/runner_lightning_gpu_observables.cpp b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/runner_lightning_gpu_observables.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/runner_lightning_gpu_observables.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/observables/tests/runner_lightning_gpu_observables.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/tests/Test_StateVectorCudaManaged.cpp b/pennylane_lightning/core/simulators/lightning_gpu/tests/Test_StateVectorCudaManaged.cpp index a50c791926..369cbaa5e2 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/tests/Test_StateVectorCudaManaged.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/tests/Test_StateVectorCudaManaged.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +#include #include "StateVectorCudaManaged.hpp" #include "TestHelpers.hpp" // createRandomStateVectorData @@ -104,7 +106,7 @@ TEMPLATE_PRODUCT_TEST_CASE( st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0, 1}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } @@ -118,7 +120,7 @@ TEMPLATE_PRODUCT_TEST_CASE( st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } } @@ -140,8 +142,9 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorCudaManaged::applyMatrix with a pointer", StateVectorT state_vector(reinterpret_cast(st_data.data()), st_data.size()); - REQUIRE_THROWS_WITH(state_vector.applyMatrix(m.data(), {}), - Catch::Contains("must be larger than 0")); + REQUIRE_THROWS_WITH( + state_vector.applyMatrix(m.data(), {}), + Catch::Matchers::ContainsSubstring("must be larger than 0")); } SECTION("Test a matrix represent PauliX") { @@ -316,7 +319,8 @@ TEMPLATE_TEST_CASE("StateVectorCudaManaged::collapse error", REQUIRE_THROWS_WITH( sv.collapse(wire, branch), - Catch::Contains("Chosen branch has vector norm close to zero and " - "cannot be normalized")); + Catch::Matchers::ContainsSubstring( + "Chosen branch has vector norm close to zero and " + "cannot be normalized")); } } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/Test_StateVectorCudaMPI.cpp b/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/Test_StateVectorCudaMPI.cpp index d35bd57d9d..e86d7cf604 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/Test_StateVectorCudaMPI.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/Test_StateVectorCudaMPI.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "DevTag.hpp" #include "MPIManagerGPU.hpp" @@ -155,7 +156,7 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorCudaMPI::applyMatrix with a std::vector", state_vector.CopyHostDataToGpu(local_state, false); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0, 1}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } SECTION("Test wrong number of wires") { @@ -166,7 +167,7 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorCudaMPI::applyMatrix with a std::vector", state_vector.CopyHostDataToGpu(local_state, false); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } } @@ -212,8 +213,9 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorCudaMPI::applyMatrix with a pointer", StateVectorT state_vector(mpi_manager, dt_local, mpi_buffersize, nGlobalIndexBits, nLocalIndexBits); state_vector.CopyHostDataToGpu(local_state, false); - REQUIRE_THROWS_WITH(state_vector.applyMatrix(m.data(), {}), - Catch::Contains("must be larger than 0")); + REQUIRE_THROWS_WITH( + state_vector.applyMatrix(m.data(), {}), + Catch::Matchers::ContainsSubstring("must be larger than 0")); } SECTION("Test a matrix represent PauliX") { diff --git a/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/runner_lightning_gpu_mpi.cpp b/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/runner_lightning_gpu_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/runner_lightning_gpu_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/tests/mpi/runner_lightning_gpu_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_gpu/tests/runner_lightning_gpu.cpp b/pennylane_lightning/core/simulators/lightning_gpu/tests/runner_lightning_gpu.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/tests/runner_lightning_gpu.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/tests/runner_lightning_gpu.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/Test_LinearAlgebra.cpp b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/Test_LinearAlgebra.cpp index 95b2299699..9c831b0c88 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/Test_LinearAlgebra.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/Test_LinearAlgebra.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include "DataBuffer.hpp" #include "LinearAlg.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp index 4dc5e81fdd..7c6658f850 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_CSRMatrix.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "CSRMatrix.hpp" #include "MPIManagerGPU.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp index 86367e9598..eddb6814a6 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_LinearAlgebraMPI.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "DataBuffer.hpp" #include "MPILinearAlg.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManagerGPU.cpp b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManagerGPU.cpp index e35bef2248..496aa1bcdb 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManagerGPU.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/Test_MPIManagerGPU.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "MPIManagerGPU.hpp" @@ -54,8 +55,9 @@ TEST_CASE("MPIManagerGPU::getMPIDatatype", "[MPIManagerGPU]") { SECTION("Test invalid type") { // This should throw an exception - REQUIRE_THROWS_WITH(mpi_manager.getMPIDatatype(), - Catch::Matchers::Contains("Type not supported")); + REQUIRE_THROWS_WITH( + mpi_manager.getMPIDatatype(), + Catch::Matchers::ContainsSubstring("Type not supported")); } } @@ -242,7 +244,7 @@ TEMPLATE_TEST_CASE("MPIManagerGPU::Reduce", "[MPIManagerGPU]", float, double) { std::vector recvBuf(1, {0, 0}); REQUIRE_THROWS_WITH( mpi_manager.Reduce(sendBuf, recvBuf, 0, "SUM"), - Catch::Matchers::Contains("Op not supported")); + Catch::Matchers::ContainsSubstring("Op not supported")); } SECTION("Catch failures caused by unsupported ops") { @@ -250,7 +252,7 @@ TEMPLATE_TEST_CASE("MPIManagerGPU::Reduce", "[MPIManagerGPU]", float, double) { std::vector recvBuf(1, "test"); REQUIRE_THROWS_WITH( mpi_manager.Reduce(sendBuf, recvBuf, 0, "SUM"), - Catch::Matchers::Contains("Type not supported")); + Catch::Matchers::ContainsSubstring("Type not supported")); } } diff --git a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/runner_lightning_gpu_utils_mpi.cpp b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/runner_lightning_gpu_utils_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/runner_lightning_gpu_utils_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/mpi/runner_lightning_gpu_utils_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/runner_lightning_gpu_utils.cpp b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/runner_lightning_gpu_utils.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/runner_lightning_gpu_utils.cpp +++ b/pennylane_lightning/core/simulators/lightning_gpu/utils/tests/runner_lightning_gpu_utils.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/Test_AdjointJacobianKokkos.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/Test_AdjointJacobianKokkos.cpp index 4b0426f4ee..7c657b68ad 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/Test_AdjointJacobianKokkos.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/Test_AdjointJacobianKokkos.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include "AdjointJacobianKokkos.hpp" #include "ObservablesKokkos.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/Test_AdjointJacobianKokkosMPI.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/Test_AdjointJacobianKokkosMPI.cpp index aaaaa90f32..7f1dd53165 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/Test_AdjointJacobianKokkosMPI.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/Test_AdjointJacobianKokkosMPI.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "AdjointJacobianKokkosMPI.hpp" #include "MPIManagerKokkos.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/runner_lightning_kokkos_algorithms_mpi.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/runner_lightning_kokkos_algorithms_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/runner_lightning_kokkos_algorithms_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/mpi/runner_lightning_kokkos_algorithms_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/runner_lightning_kokkos_algorithms.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/runner_lightning_kokkos_algorithms.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/runner_lightning_kokkos_algorithms.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/algorithms/tests/runner_lightning_kokkos_algorithms.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/bindings/LKokkosBindingsMPI.hpp b/pennylane_lightning/core/simulators/lightning_kokkos/bindings/LKokkosBindingsMPI.hpp index 0bd3423eef..cca19fbff5 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/bindings/LKokkosBindingsMPI.hpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/bindings/LKokkosBindingsMPI.hpp @@ -257,8 +257,6 @@ void registerBackendSpecificObservablesMPI(nb::module_ &m) { std::is_same_v ? "64" : "128"; using ArrayComplexT = nb::ndarray, nb::c_contig>; - using SparseIndexT = std::size_t; - using ArrSparseIndT = nb::ndarray; std::string class_name = "SparseHamiltonianC" + bitsize; auto sparse_hamiltonian_class = @@ -304,7 +302,7 @@ void registerBackendSpecificObservablesMPI(nb::module_ &m) { * @param m Nanobind module */ template -void registerBackendSpecificAlgorithmsMPI(nb::module_ &m) { +void registerBackendSpecificAlgorithmsMPI([[maybe_unused]] nb::module_ &m) { // This function is intentionally left empty as there are no // backend-specific algorithms for Kokkos MPI } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosGradient.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosGradient.cpp index 40ebd95b48..9d1cfa8a18 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosGradient.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosGradient.cpp @@ -13,7 +13,10 @@ // limitations under the License. #include "LightningKokkosSimulator.hpp" -#include "catch2/catch.hpp" +#include +#include +#include +using Catch::Approx; /// @cond DEV namespace { @@ -76,13 +79,13 @@ TEST_CASE("Test Gradient with Var", "[Gradient]") { auto pz = sim->Observable(ObsId::PauliZ, {}, {q}); sim->Var(pz); - REQUIRE_THROWS_WITH( - sim->Gradient(gradients, trainParams), - Catch::Contains("Unsupported measurements to compute gradient")); + REQUIRE_THROWS_WITH(sim->Gradient(gradients, trainParams), + Catch::Matchers::ContainsSubstring( + "Unsupported measurements to compute gradient")); - REQUIRE_THROWS_WITH( - sim->Gradient(gradients, {}), - Catch::Contains("Unsupported measurements to compute gradient")); + REQUIRE_THROWS_WITH(sim->Gradient(gradients, {}), + Catch::Matchers::ContainsSubstring( + "Unsupported measurements to compute gradient")); sim->StopTapeRecording(); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp index 735fcfb6d0..175e135be7 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp @@ -19,7 +19,10 @@ #include "QuantumDevice.hpp" #include "Types.h" #include "Utils.hpp" -#include "catch2/catch.hpp" +#include +#include +#include +using Catch::Approx; #include "cmath" /// @cond DEV @@ -40,8 +43,9 @@ using LKSimulator = LightningKokkosSimulator; TEST_CASE("NameObs test with invalid number of wires", "[Measures]") { std::unique_ptr sim = std::make_unique(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::PauliX, {}, {1}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::PauliX, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); } TEST_CASE("NameObs test with invalid given wires for NamedObs", "[Measures]") { @@ -49,15 +53,17 @@ TEST_CASE("NameObs test with invalid given wires for NamedObs", "[Measures]") { sim->AllocateQubit(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::PauliX, {}, {1}), - Catch::Contains("Invalid given wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::PauliX, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid given wires")); } TEST_CASE("HermitianObs test with invalid number of wires", "[Measures]") { std::unique_ptr sim = std::make_unique(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::Hermitian, {}, {1}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::Hermitian, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); } TEST_CASE("HermitianObs test with invalid given wires for HermitianObs", @@ -65,15 +71,16 @@ TEST_CASE("HermitianObs test with invalid given wires for HermitianObs", std::unique_ptr sim = std::make_unique(); sim->AllocateQubit(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::Hermitian, {}, {1}), - Catch::Contains("Invalid given wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::Hermitian, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid given wires")); } TEST_CASE("Check an unsupported observable", "[Measures]") { REQUIRE_THROWS_WITH( Lightning::lookup_obs( Lightning::simulator_observable_support, static_cast(10)), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The given observable is not supported by the simulator")); } @@ -186,8 +193,8 @@ TEST_CASE("Mid-circuit measurement test with invalid postselect value", sim->NamedOperation("Hadamard", {}, {q}, false); - REQUIRE_THROWS_WITH(sim->Measure(q, 2), - Catch::Contains("Invalid postselect value")); + REQUIRE_THROWS_WITH(sim->Measure(q, 2), Catch::Matchers::ContainsSubstring( + "Invalid postselect value")); } TEST_CASE("Expval(ObsT) test with invalid key for cached observables", @@ -195,7 +202,8 @@ TEST_CASE("Expval(ObsT) test with invalid key for cached observables", std::unique_ptr sim = std::make_unique(); REQUIRE_THROWS_WITH(sim->Expval(0), - Catch::Contains("Invalid key for cached observables")); + Catch::Matchers::ContainsSubstring( + "Invalid key for cached observables")); } TEST_CASE("Expval(NamedObs) test", "[Measures]") { @@ -406,9 +414,9 @@ TEST_CASE("Expval(TensorProd(NamedObs[])) test", "[Measures]") { ObsIdType tpxy = sim->TensorObservable({px, py}); ObsIdType tpxz = sim->TensorObservable({px, pz}); - REQUIRE_THROWS_WITH( - sim->TensorObservable({px, py, pz}), - Catch::Contains("All wires in observables must be disjoint.")); + REQUIRE_THROWS_WITH(sim->TensorObservable({px, py, pz}), + Catch::Matchers::ContainsSubstring( + "All wires in observables must be disjoint.")); CHECK(sim->Expval(tpxy) == Approx(0.0).margin(1e-5)); CHECK(sim->Expval(tpxz) == Approx(-1.0).margin(1e-5)); @@ -1296,9 +1304,9 @@ TEST_CASE("State test with incorrect size", "[Measures]") { std::vector> state(1U << (n - 1)); DataView, 1> view(state); - REQUIRE_THROWS_WITH( - sim->State(view), - Catch::Contains("Invalid size for the pre-allocated state vector")); + REQUIRE_THROWS_WITH(sim->State(view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated state vector")); } TEST_CASE("State test with numWires=4", "[Measures]") { @@ -1345,21 +1353,23 @@ TEST_CASE("PartialProbs test with incorrect numWires and numAlloc", REQUIRE_THROWS_WITH( sim->PartialProbs(probs_view, {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialProbs(probs_view, {Qs[0]}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "Invalid size for the pre-allocated partial-probabilities")); REQUIRE_THROWS_WITH( sim->Probs(probs_view), - Catch::Contains("Invalid size for the pre-allocated probabilities")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated probabilities")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialProbs(probs_view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialProbs(probs_view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("Probs and PartialProbs tests with numWires=0-4", "[Measures]") { @@ -1506,20 +1516,22 @@ TEST_CASE("PartialSample test with incorrect numWires and numAlloc", REQUIRE_THROWS_WITH( sim->PartialSample(view, {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialSample(view, {Qs[0], Qs[1]}), - Catch::Contains("Invalid size for the pre-allocated partial-samples")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated partial-samples")); - REQUIRE_THROWS_WITH( - sim->Sample(view), - Catch::Contains("Invalid size for the pre-allocated samples")); + REQUIRE_THROWS_WITH(sim->Sample(view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated samples")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialSample(view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialSample(view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("PartialCounts test with incorrect numWires and numAlloc", @@ -1541,22 +1553,25 @@ TEST_CASE("PartialCounts test with incorrect numWires and numAlloc", std::vector counts_vec(1); DataView counts_view(counts_vec); - REQUIRE_THROWS_WITH(sim->PartialCounts(eigvals_view, counts_view, - {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->PartialCounts(eigvals_view, counts_view, + {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), - Catch::Contains("Invalid size for the pre-allocated partial-counts")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated partial-counts")); - REQUIRE_THROWS_WITH( - sim->Counts(eigvals_view, counts_view), - Catch::Contains("Invalid size for the pre-allocated counts")); + REQUIRE_THROWS_WITH(sim->Counts(eigvals_view, counts_view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated counts")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("Sample and PartialSample tests with numWires=0-4 shots=100", diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp index 29d0358be0..13c8bd5a22 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosSimulator.cpp @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "LightningKokkosSimulator.hpp" #include "QuantumDevice.hpp" @@ -77,13 +78,13 @@ TEST_CASE("LightningKokkosSimulator::unit_tests", "[unit tests]") { std::unique_ptr LKsim = std::make_unique(); std::vector Qs = LKsim->AllocateQubits(1); REQUIRE_NOTHROW(LKsim->StartTapeRecording()); - REQUIRE_THROWS_WITH( - LKsim->StartTapeRecording(), - Catch::Matchers::Contains("Cannot re-activate the cache manager")); + REQUIRE_THROWS_WITH(LKsim->StartTapeRecording(), + Catch::Matchers::ContainsSubstring( + "Cannot re-activate the cache manager")); REQUIRE_NOTHROW(LKsim->StopTapeRecording()); REQUIRE_THROWS_WITH( LKsim->StopTapeRecording(), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "Cannot stop an already stopped cache manager")); } } @@ -732,7 +733,8 @@ TEST_CASE("LightningKokkosSimulator::GateSet", "[GateSet]") { REQUIRE_THROWS_WITH( LKsim->NamedOperation("Hadamard", {}, {Qs[0]}, false, {Qs[1]}, {}), - Catch::Contains("Controlled wires/values size mismatch")); + Catch::Matchers::ContainsSubstring( + "Controlled wires/values size mismatch")); std::vector> matrix{ {-0.6709485262524046, -0.6304426335363695}, {-0.14885403153998722, 0.3608498832392019}, @@ -741,7 +743,8 @@ TEST_CASE("LightningKokkosSimulator::GateSet", "[GateSet]") { }; REQUIRE_THROWS_WITH( LKsim->MatrixOperation(matrix, {Qs[0]}, false, {Qs[1]}, {}), - Catch::Contains("Controlled wires/values size mismatch")); + Catch::Matchers::ContainsSubstring( + "Controlled wires/values size mismatch")); } SECTION("Controlled GlobalPhase (multi-qubit)") { @@ -848,14 +851,15 @@ TEST_CASE("LightningKokkosSimulator::GateSet", "[GateSet]") { constexpr std::size_t n_qubits = 2; std::vector Qs = LKsim->AllocateQubits(n_qubits); - REQUIRE_THROWS_WITH( - LKsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, false, {}, {}, - {"X", "Y"}), - Catch::Contains("PauliRot operation requires one string")); + REQUIRE_THROWS_WITH(LKsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, + false, {}, {}, {"X", "Y"}), + Catch::Matchers::ContainsSubstring( + "PauliRot operation requires one string")); - REQUIRE_THROWS_WITH( - LKsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, false, {Qs[1]}, - {false}, {"XY"}), - Catch::Contains("Controlled PauliRot is not supported")); + REQUIRE_THROWS_WITH(LKsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, + false, {Qs[1]}, {false}, + {"XY"}), + Catch::Matchers::ContainsSubstring( + "Controlled PauliRot is not supported")); } } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/runner_lightning_kokkos_catalyst.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/runner_lightning_kokkos_catalyst.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/runner_lightning_kokkos_catalyst.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/catalyst/tests/runner_lightning_kokkos_catalyst.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Generator.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Generator.cpp index beb1734ac6..ee3742d769 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Generator.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Generator.cpp @@ -20,7 +20,8 @@ #include #include -#include +#include +#include #include "BasicGeneratorFunctors.hpp" #include "Constant.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp index 34972fc12c..f46c619914 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_NonParam.cpp @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "Gates.hpp" // getHadamard #include "StateVectorKokkos.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp index f1e8b3389f..7661d5c9d4 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/Test_StateVectorKokkos_Param.cpp @@ -21,7 +21,9 @@ #include #include -#include +#include +#include +#include #include "ConstantUtil.hpp" #include "Error.hpp" @@ -2644,8 +2646,9 @@ TEMPLATE_TEST_CASE("Sample", "[StateVectorKokkosManaged_Param]", float, // compare estimated probabilities to real probabilities SECTION("No wires provided:") { - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Generator.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Generator.cpp index 6d634bae24..3f1c3ec239 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Generator.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Generator.cpp @@ -20,7 +20,8 @@ #include #include -#include +#include +#include #include "StateVectorKokkosMPI.hpp" #include "TestHelpers.hpp" // createRandomStateVectorData diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_NonParam.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_NonParam.cpp index 64a8cd52d4..cc4d0f1145 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_NonParam.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_NonParam.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +#include #include "StateVectorKokkosMPI.hpp" #include "TestHelpers.hpp" // createRandomStateVectorData @@ -52,12 +54,14 @@ TEMPLATE_TEST_CASE("Apply op with wires more than local wires", "[LKMPI]", StateVectorKokkosMPI sv(mpi_manager, num_qubits); REQUIRE_THROWS_WITH( sv.applyOperation("XXX", {0, 1, 2}), - Catch::Contains("smaller than or equal to the number of local wires.")); + Catch::Matchers::ContainsSubstring( + "smaller than or equal to the number of local wires.")); std::vector> matrix(64, {0.0, 0.0}); REQUIRE_THROWS_WITH( sv.applyMatrix(matrix, {0, 1, 2}), - Catch::Contains("smaller than or equal to the number of local wires.")); + Catch::Matchers::ContainsSubstring( + "smaller than or equal to the number of local wires.")); } TEMPLATE_TEST_CASE("Apply non-trivial op", "[LKMPI]", double, float) { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Param.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Param.cpp index 8523ab5838..acbed2fbcc 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Param.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/Test_StateVectorKokkosMPI_Param.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "StateVectorKokkosMPI.hpp" #include "TestHelpers.hpp" // createRandomStateVectorData diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/runner_lightning_kokkos_gates_mpi.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/runner_lightning_kokkos_gates_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/runner_lightning_kokkos_gates_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/mpi/runner_lightning_kokkos_gates_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/runner_lightning_kokkos_gates.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/runner_lightning_kokkos_gates.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/runner_lightning_kokkos_gates.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/gates/tests/runner_lightning_kokkos_gates.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Expval.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Expval.cpp index 59be17ed5e..c81fdc5a48 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Expval.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Expval.cpp @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Measure.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Measure.cpp index 1d9b575e29..69e0cd0303 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Measure.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Measure.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +#include #include "MeasurementsKokkos.hpp" #include "StateVectorKokkos.hpp" @@ -81,32 +83,38 @@ TEMPLATE_PRODUCT_TEST_CASE("Expected Values", "[Measurements]", operations_list = {Identity, Identity, Identity}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {1.0, 1.0, 1.0}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {Identity2, Identity2}; exp_values = Measurer.expval(operations_list, {{0, 1}, {1, 2}}); exp_values_ref = {1.0, 1.0}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliX, PauliX, PauliX}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {Hadamard, Hadamard, Hadamard}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.7620549436, 0.8420840225, 0.8449848566}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } SECTION("Testing list of operators defined by its name:") { @@ -118,27 +126,32 @@ TEMPLATE_PRODUCT_TEST_CASE("Expected Values", "[Measurements]", operations_list = {"Identity", "Identity", "Identity"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {1.0, 1.0, 1.0}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliX", "PauliX", "PauliX"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"Hadamard", "Hadamard", "Hadamard"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.7620549436, 0.8420840225, 0.8449848566}; - REQUIRE_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + REQUIRE_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } SECTION("Testing error cases for expectation values of Pauli Strings") { @@ -544,17 +557,20 @@ TEMPLATE_PRODUCT_TEST_CASE("Variances", "[Measurements]", (StateVectorKokkos), operations_list = {PauliX, PauliX, PauliX}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } SECTION("Testing list of operators defined by its name:") { @@ -566,17 +582,20 @@ TEMPLATE_PRODUCT_TEST_CASE("Variances", "[Measurements]", (StateVectorKokkos), operations_list = {"PauliX", "PauliX", "PauliX"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - REQUIRE_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + REQUIRE_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } } @@ -608,7 +627,7 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) { for (const auto &term : input) { auto probabilities = m.probs(term.first); REQUIRE_THAT(term.second, - Catch::Approx(probabilities).margin(1e-6)); + Catch::Matchers::Approx(probabilities).margin(1e-6)); } } SECTION("21 qubits") { @@ -625,7 +644,8 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) { std::size_t target = GENERATE(0, num_qubits / 2, num_qubits - 1); statevector.applyOperation("Hadamard", {target}, false); auto probs = Measurer.probs({target}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector(2, 1.0 / 2)) + CHECK_THAT(probs, Catch::Matchers::Approx( + std::vector(2, 1.0 / 2)) .margin(1e-7)); } SECTION("2 targets") { @@ -634,31 +654,35 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) { if (target0 != target1) { statevector.applyOperation("Hadamard", {target0}, false); auto probs = Measurer.probs({target0, target1}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0}) - .margin(1e-7)); - probs = Measurer.probs({target1, target0}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0}) - .margin(1e-7)); - statevector.applyOperation("Hadamard", {target1}, false); - probs = Measurer.probs({target0, target1}, device_wires); CHECK_THAT(probs, - Catch::Approx(std::vector(4, 1.0 / 4.0)) + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0}) .margin(1e-7)); probs = Measurer.probs({target1, target0}, device_wires); CHECK_THAT(probs, - Catch::Approx(std::vector(4, 1.0 / 4.0)) + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0}) .margin(1e-7)); - statevector.applyOperation("Hadamard", {target0}, false); + statevector.applyOperation("Hadamard", {target1}, false); probs = Measurer.probs({target0, target1}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0}) + CHECK_THAT(probs, Catch::Matchers::Approx( + std::vector(4, 1.0 / 4.0)) .margin(1e-7)); probs = Measurer.probs({target1, target0}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0}) + CHECK_THAT(probs, Catch::Matchers::Approx( + std::vector(4, 1.0 / 4.0)) .margin(1e-7)); + statevector.applyOperation("Hadamard", {target0}, false); + probs = Measurer.probs({target0, target1}, device_wires); + CHECK_THAT(probs, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0}) + .margin(1e-7)); + probs = Measurer.probs({target1, target0}, device_wires); + CHECK_THAT(probs, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0}) + .margin(1e-7)); } } SECTION("Many targets Hadamard(n)") { @@ -675,7 +699,7 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) { std::vector ref(1UL << n_targets, 0.0); ref[0] = 0.5; ref[1] = 0.5; - CHECK_THAT(probs, Catch::Approx(ref).margin(1e-7)); + CHECK_THAT(probs, Catch::Matchers::Approx(ref).margin(1e-7)); } SECTION("3-6 targets Hadamard(all)") { for (std::size_t t = 0; t < num_qubits; t++) { @@ -685,7 +709,7 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) { std::vector targets(ntarget); std::iota(targets.begin(), targets.end(), 0); auto probs = Measurer.probs(targets, device_wires); - CHECK_THAT(probs, Catch::Approx( + CHECK_THAT(probs, Catch::Matchers::Approx( std::vector( (1UL << ntarget), 1.0 / (1UL << ntarget))) .margin(1e-7)); @@ -701,7 +725,7 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) { Pennylane::LightningKokkos::Functors::probs_bitshift_generic< typename StateVectorT::KokkosExecSpace, PrecisionT>( statevector.getView(), num_qubits, targets); - CHECK_THAT(probs, Catch::Approx( + CHECK_THAT(probs, Catch::Matchers::Approx( std::vector( (1UL << ntarget), 1.0 / (1UL << ntarget))) .margin(1e-7)); diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Var.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Var.cpp index 6b87606942..2cb1563531 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Var.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/Test_StateVectorKokkos_Var.cpp @@ -18,7 +18,9 @@ #include #include -#include +#include +#include +using Catch::Approx; #include "MeasurementsKokkos.hpp" #include "ObservablesKokkos.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/Test_StateVectorKokkosMPI_Measure.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/Test_StateVectorKokkosMPI_Measure.cpp index d5f5b2726a..b895b95370 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/Test_StateVectorKokkosMPI_Measure.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/Test_StateVectorKokkosMPI_Measure.cpp @@ -19,7 +19,10 @@ #include #include -#include +#include +#include +#include +#include #include "MeasurementsKokkosMPI.hpp" #include "ObservablesKokkosMPI.hpp" @@ -66,7 +69,8 @@ TEMPLATE_TEST_CASE("Expval - raise error", "[LKMPI_Expval]", float, double) { REQUIRE_THROWS_WITH( m.expval(mat_ob, {0, 1, 2}), - Catch::Contains("Not enough local wires to swap with global wires.")); + Catch::Matchers::ContainsSubstring( + "Not enough local wires to swap with global wires.")); } TEMPLATE_TEST_CASE("Expval - named string", "[LKMPI_Expval]", float, double) { @@ -594,7 +598,8 @@ TEMPLATE_TEST_CASE("probs - 1 wires", "[LKMPI_Expval]", float, double) { displacements); if (sv.getMPIManager().getRank() == 0) { - CHECK_THAT(res_gather, Catch::Approx(res_ref).margin(1e-7)); + CHECK_THAT(res_gather, + Catch::Matchers::Approx(res_ref).margin(1e-7)); } } } @@ -635,7 +640,8 @@ TEMPLATE_TEST_CASE("probs - 2 wires", "[LKMPI_Expval]", float, double) { displacements); if (sv.getMPIManager().getRank() == 0) { - CHECK_THAT(res_gather, Catch::Approx(res_ref).margin(1e-7)); + CHECK_THAT(res_gather, + Catch::Matchers::Approx(res_ref).margin(1e-7)); } } } @@ -677,7 +683,8 @@ TEMPLATE_TEST_CASE("probs - 3 wires", "[LKMPI_Expval]", float, double) { displacements); if (sv.getMPIManager().getRank() == 0) { - CHECK_THAT(res_gather, Catch::Approx(res_ref).margin(1e-7)); + CHECK_THAT(res_gather, + Catch::Matchers::Approx(res_ref).margin(1e-7)); } } } @@ -721,7 +728,8 @@ TEMPLATE_TEST_CASE("probs - 4 wires", "[LKMPI_Expval]", float, double) { displacements); if (sv.getMPIManager().getRank() == 0) { - CHECK_THAT(res_gather, Catch::Approx(res_ref).margin(1e-7)); + CHECK_THAT(res_gather, + Catch::Matchers::Approx(res_ref).margin(1e-7)); } } } @@ -767,7 +775,8 @@ TEMPLATE_TEST_CASE("probs - 5 wires", "[LKMPI_Expval]", float, double) { displacements); if (sv.getMPIManager().getRank() == 0) { - CHECK_THAT(res_gather, Catch::Approx(res_ref).margin(1e-7)); + CHECK_THAT(res_gather, + Catch::Matchers::Approx(res_ref).margin(1e-7)); } } } @@ -780,8 +789,8 @@ TEMPLATE_TEST_CASE("probs - raise wire error", "[LKMPI_Expval]", float, auto [sv, sv_ref] = initializeLKTestSV(num_qubits); auto m = MeasurementsMPI(sv); - REQUIRE_THROWS_WITH(m.probs({0, 3, 2}), - Catch::Contains("out-of-order wire")); + REQUIRE_THROWS_WITH(m.probs({0, 3, 2}), Catch::Matchers::ContainsSubstring( + "out-of-order wire")); } TEMPLATE_TEST_CASE("probs - all wires", "[LKMPI_Expval]", float, double) { @@ -800,7 +809,7 @@ TEMPLATE_TEST_CASE("probs - all wires", "[LKMPI_Expval]", float, double) { sv.getMPIManager().Gather(res, res_gather, 0); if (sv.getMPIManager().getRank() == 0) { - CHECK_THAT(res_gather, Catch::Approx(res_ref).margin(1e-7)); + CHECK_THAT(res_gather, Catch::Matchers::Approx(res_ref).margin(1e-7)); } } @@ -846,5 +855,5 @@ TEMPLATE_TEST_CASE("Generate Samples", "[LKMPI_Expval]", float, double) { for (std::size_t i = 0; i < counts.size(); i++) { probabilities[i] = counts[i] / (TestType)num_samples; } - REQUIRE_THAT(probabilities, Catch::Approx(prob_ref).margin(.05)); + REQUIRE_THAT(probabilities, Catch::Matchers::Approx(prob_ref).margin(.05)); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/runner_lightning_kokkos_measurements_mpi.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/runner_lightning_kokkos_measurements_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/runner_lightning_kokkos_measurements_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/mpi/runner_lightning_kokkos_measurements_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/runner_lightning_kokkos_measurements.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/runner_lightning_kokkos_measurements.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/runner_lightning_kokkos_measurements.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/measurements/tests/runner_lightning_kokkos_measurements.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/Test_ObservablesKokkos.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/Test_ObservablesKokkos.cpp index f7e90f7bf5..a46a89cb92 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/Test_ObservablesKokkos.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/Test_ObservablesKokkos.cpp @@ -14,7 +14,7 @@ #include "ObservablesKokkos.hpp" #include "TestHelpers.hpp" -#include +#include /// @cond DEV namespace { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/Test_ObservablesKokkosMPI.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/Test_ObservablesKokkosMPI.cpp index bea597010b..3f2750f7e7 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/Test_ObservablesKokkosMPI.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/Test_ObservablesKokkosMPI.cpp @@ -11,7 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include +#include #include "MPIManagerKokkos.hpp" #include "ObservablesKokkos.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/runner_lightning_kokkos_observables_mpi.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/runner_lightning_kokkos_observables_mpi.cpp index b75b719a2c..757dbc9e5a 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/runner_lightning_kokkos_observables_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/mpi/runner_lightning_kokkos_observables_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/runner_lightning_kokkos_observables.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/runner_lightning_kokkos_observables.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/runner_lightning_kokkos_observables.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/observables/tests/runner_lightning_kokkos_observables.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/tests/Test_StateVectorLKokkos.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/tests/Test_StateVectorLKokkos.cpp index 3fd9b7e89c..b29f1e8f1c 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/tests/Test_StateVectorLKokkos.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/tests/Test_StateVectorLKokkos.cpp @@ -18,7 +18,9 @@ #include #include -#include +#include +#include +#include #include "StateVectorKokkos.hpp" #include "TestHelpers.hpp" // createRandomStateVectorData @@ -61,7 +63,8 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorKokkos::Constructibility", std::vector st_data(14, 0.0); REQUIRE_THROWS_WITH( StateVectorT(st_data.data(), st_data.size()), - Catch::Contains("The size of provided data must be a power of 2.")); + Catch::Matchers::ContainsSubstring( + "The size of provided data must be a power of 2.")); } SECTION( "StateVectorBackend {const StateVectorBackend&}") { @@ -93,7 +96,7 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorKokkos::applyMatrix with a std::vector", st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0, 1}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } @@ -107,7 +110,7 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorKokkos::applyMatrix with a std::vector", st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } @@ -155,34 +158,36 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorKokkos::setState", "[errors]", StateVectorT sv(num_qubits); SECTION("setBasisState incompatible dimensions") { - REQUIRE_THROWS_WITH( - sv.setBasisState({0}, {0, 1}), - Catch::Contains("state and wires must have equal dimensions.")); + REQUIRE_THROWS_WITH(sv.setBasisState({0}, {0, 1}), + Catch::Matchers::ContainsSubstring( + "state and wires must have equal dimensions.")); } SECTION("setBasisState high wire index") { REQUIRE_THROWS_WITH( sv.setBasisState({0, 0, 0}, {0, 1, 2}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "wires must take values lower than the number of qubits.")); } SECTION("setStateVector incompatible dimensions indices & values") { REQUIRE_THROWS_WITH( sv.setStateVector({0, 1}, std::vector(4, 0.0)), - Catch::Contains("Inconsistent indices and values dimensions.")); + Catch::Matchers::ContainsSubstring( + "Inconsistent indices and values dimensions.")); } SECTION("setStateVector incompatible dimensions state & wires") { REQUIRE_THROWS_WITH( sv.setStateVector(std::vector(2, 0.0), {0, 1}), - Catch::Contains("Inconsistent state and wires dimensions.")); + Catch::Matchers::ContainsSubstring( + "Inconsistent state and wires dimensions.")); } SECTION("setStateVector high wire index") { REQUIRE_THROWS_WITH( sv.setStateVector(std::vector(8, 0.0), {0, 1, 2}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "wires must take values lower than the number of qubits.")); } } @@ -208,8 +213,9 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorKokkos::applyMatrix with a pointer", StateVectorT state_vector(reinterpret_cast(st_data.data()), st_data.size()); - REQUIRE_THROWS_WITH(state_vector.applyMatrix(m.data(), {}), - Catch::Contains("must be larger than 0")); + REQUIRE_THROWS_WITH( + state_vector.applyMatrix(m.data(), {}), + Catch::Matchers::ContainsSubstring("must be larger than 0")); } SECTION("Test with different number of wires") { @@ -267,7 +273,7 @@ TEMPLATE_PRODUCT_TEST_CASE( st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyControlledMatrix(m, {2}, {true}, {0, 1}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } @@ -281,7 +287,7 @@ TEMPLATE_PRODUCT_TEST_CASE( st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyControlledMatrix(m, {2}, {true}, {0}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } @@ -349,7 +355,7 @@ TEMPLATE_PRODUCT_TEST_CASE( st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyControlledMatrix(m.data(), {0}, {true}, {}), - Catch::Contains("must be larger than 0")); + Catch::Matchers::ContainsSubstring("must be larger than 0")); } SECTION("Test with different number of wires") { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/Test_StateVectorKokkosMPI.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/Test_StateVectorKokkosMPI.cpp index 0cf7fdf1ae..74f8e49886 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/Test_StateVectorKokkosMPI.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/Test_StateVectorKokkosMPI.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +#include #include "StateVectorKokkosMPI.hpp" #include "TestHelpers.hpp" // createRandomStateVectorData @@ -568,15 +570,15 @@ TEMPLATE_TEST_CASE("setStateVector error", "[LKMPI]", double, float) { StateVectorKokkosMPI sv(mpi_manager, num_qubits); SECTION("setBasisState incompatible dimensions") { - REQUIRE_THROWS_WITH( - sv.setBasisState({0}, {0, 1}), - Catch::Contains("state and wires must have equal dimensions.")); + REQUIRE_THROWS_WITH(sv.setBasisState({0}, {0, 1}), + Catch::Matchers::ContainsSubstring( + "state and wires must have equal dimensions.")); } SECTION("setBasisState high wire index") { REQUIRE_THROWS_WITH( sv.setBasisState({0, 0, 0}, {0, 1, 6}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "wires must take values lower than the number of qubits.")); } @@ -584,14 +586,15 @@ TEMPLATE_TEST_CASE("setStateVector error", "[LKMPI]", double, float) { REQUIRE_THROWS_WITH( sv.setStateVector(std::vector>(2, 0.0), {0, 1}), - Catch::Contains("Inconsistent state and wires dimensions.")); + Catch::Matchers::ContainsSubstring( + "Inconsistent state and wires dimensions.")); } SECTION("setStateVector high wire index") { REQUIRE_THROWS_WITH( sv.setStateVector(std::vector>(8, 0.0), {0, 1, 6}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "wires must take values lower than the number of qubits.")); } } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/runner_lightning_kokkos_mpi.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/runner_lightning_kokkos_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/runner_lightning_kokkos_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/tests/mpi/runner_lightning_kokkos_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/tests/runner_lightning_kokkos.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/tests/runner_lightning_kokkos.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/tests/runner_lightning_kokkos.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/tests/runner_lightning_kokkos.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/Test_LinearAlgebra.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/Test_LinearAlgebra.cpp index 2a9e61afb4..9dbd971336 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/Test_LinearAlgebra.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/Test_LinearAlgebra.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include "LinearAlgebraKokkos.hpp" #include "StateVectorKokkos.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/Test_MPIManagerKokkos.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/Test_MPIManagerKokkos.cpp index 8c9230eaf8..2a8c49f024 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/Test_MPIManagerKokkos.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/Test_MPIManagerKokkos.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "MPIManagerKokkos.hpp" #include "UtilKokkos.hpp" @@ -55,8 +56,9 @@ TEST_CASE("MPIManagerKokkos::getMPIDatatype", "[MPIManagerKokkos]") { SECTION("Test invalid type") { // This should throw an exception - REQUIRE_THROWS_WITH(mpi_manager.getMPIDatatype(), - Catch::Matchers::Contains("Type not supported")); + REQUIRE_THROWS_WITH( + mpi_manager.getMPIDatatype(), + Catch::Matchers::ContainsSubstring("Type not supported")); } } diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/runner_lightning_kokkos_utils_mpi.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/runner_lightning_kokkos_utils_mpi.cpp index 1e414b80fe..f62d1009b8 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/runner_lightning_kokkos_utils_mpi.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/mpi/runner_lightning_kokkos_utils_mpi.cpp @@ -1,6 +1,6 @@ #define CATCH_CONFIG_RUNNER #include -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/runner_lightning_kokkos_utils.cpp b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/runner_lightning_kokkos_utils.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/runner_lightning_kokkos_utils.cpp +++ b/pennylane_lightning/core/simulators/lightning_kokkos/utils/tests/runner_lightning_kokkos_utils.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_AdjointJacobianLQubit.cpp b/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_AdjointJacobianLQubit.cpp index aa4884b6a6..7a28a641be 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_AdjointJacobianLQubit.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_AdjointJacobianLQubit.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include "AdjointJacobianLQubit.hpp" #include "ObservablesLQubit.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_VectorJacobianProduct.cpp b/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_VectorJacobianProduct.cpp index 02f9cee251..651f7e8f8e 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_VectorJacobianProduct.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/Test_VectorJacobianProduct.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include "AdjointJacobianLQubit.hpp" #include "ConstantUtil.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/runner_lightning_qubit_algorithms.cpp b/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/runner_lightning_qubit_algorithms.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/runner_lightning_qubit_algorithms.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/algorithms/tests/runner_lightning_qubit_algorithms.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningGradient.cpp b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningGradient.cpp index 70981cb933..9b19dbf7db 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningGradient.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningGradient.cpp @@ -13,7 +13,10 @@ // limitations under the License. #include "LightningSimulator.hpp" -#include "catch2/catch.hpp" +#include +#include +#include +using Catch::Approx; /// @cond DEV namespace { @@ -76,13 +79,13 @@ TEST_CASE("Test Gradient with Var", "[Gradient]") { auto pz = sim->Observable(ObsId::PauliZ, {}, {q}); sim->Var(pz); - REQUIRE_THROWS_WITH( - sim->Gradient(gradients, trainParams), - Catch::Contains("Unsupported measurements to compute gradient")); + REQUIRE_THROWS_WITH(sim->Gradient(gradients, trainParams), + Catch::Matchers::ContainsSubstring( + "Unsupported measurements to compute gradient")); - REQUIRE_THROWS_WITH( - sim->Gradient(gradients, {}), - Catch::Contains("Unsupported measurements to compute gradient")); + REQUIRE_THROWS_WITH(sim->Gradient(gradients, {}), + Catch::Matchers::ContainsSubstring( + "Unsupported measurements to compute gradient")); sim->StopTapeRecording(); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningMeasures.cpp b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningMeasures.cpp index e29d4e8686..cf67092cf9 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningMeasures.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningMeasures.cpp @@ -20,7 +20,10 @@ #include "QuantumDevice.hpp" #include "Types.h" #include "Utils.hpp" -#include "catch2/catch.hpp" +#include +#include +#include +using Catch::Approx; #include "cmath" /// @cond DEV @@ -41,8 +44,9 @@ using LQSimulator = LightningSimulator; TEST_CASE("NameObs test with invalid number of wires", "[Measures]") { std::unique_ptr sim = std::make_unique(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::PauliX, {}, {1}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::PauliX, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); } TEST_CASE("NameObs test with invalid given wires for NamedObs", "[Measures]") { @@ -50,15 +54,17 @@ TEST_CASE("NameObs test with invalid given wires for NamedObs", "[Measures]") { sim->AllocateQubit(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::PauliX, {}, {1}), - Catch::Contains("Invalid given wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::PauliX, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid given wires")); } TEST_CASE("HermitianObs test with invalid number of wires", "[Measures]") { std::unique_ptr sim = std::make_unique(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::Hermitian, {}, {1}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::Hermitian, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); } TEST_CASE("HermitianObs test with invalid given wires for HermitianObs", @@ -66,15 +72,16 @@ TEST_CASE("HermitianObs test with invalid given wires for HermitianObs", std::unique_ptr sim = std::make_unique(); sim->AllocateQubit(); - REQUIRE_THROWS_WITH(sim->Observable(ObsId::Hermitian, {}, {1}), - Catch::Contains("Invalid given wires")); + REQUIRE_THROWS_WITH( + sim->Observable(ObsId::Hermitian, {}, {1}), + Catch::Matchers::ContainsSubstring("Invalid given wires")); } TEST_CASE("Check an unsupported observable", "[Measures]") { REQUIRE_THROWS_WITH( Lightning::lookup_obs( Lightning::simulator_observable_support, static_cast(10)), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The given observable is not supported by the simulator")); } @@ -187,8 +194,8 @@ TEST_CASE("Mid-circuit measurement test with invalid postselect value", sim->NamedOperation("Hadamard", {}, {q}, false); - REQUIRE_THROWS_WITH(sim->Measure(q, 2), - Catch::Contains("Invalid postselect value")); + REQUIRE_THROWS_WITH(sim->Measure(q, 2), Catch::Matchers::ContainsSubstring( + "Invalid postselect value")); } TEST_CASE("Expval(ObsT) test with invalid key for cached observables", @@ -196,7 +203,8 @@ TEST_CASE("Expval(ObsT) test with invalid key for cached observables", std::unique_ptr sim = std::make_unique(); REQUIRE_THROWS_WITH(sim->Expval(0), - Catch::Contains("Invalid key for cached observables")); + Catch::Matchers::ContainsSubstring( + "Invalid key for cached observables")); } TEST_CASE("Expval(NamedObs) test", "[Measures]") { @@ -406,9 +414,9 @@ TEST_CASE("Expval(TensorProd(NamedObs[])) test", "[Measures]") { ObsIdType tpxy = sim->TensorObservable({px, py}); ObsIdType tpxz = sim->TensorObservable({px, pz}); - REQUIRE_THROWS_WITH( - sim->TensorObservable({px, py, pz}), - Catch::Contains("All wires in observables must be disjoint.")); + REQUIRE_THROWS_WITH(sim->TensorObservable({px, py, pz}), + Catch::Matchers::ContainsSubstring( + "All wires in observables must be disjoint.")); CHECK(sim->Expval(tpxy) == Approx(0.0).margin(1e-5)); CHECK(sim->Expval(tpxz) == Approx(-1.0).margin(1e-5)); @@ -1296,9 +1304,9 @@ TEST_CASE("State test with incorrect size", "[Measures]") { std::vector> state(1U << (n - 1)); DataView, 1> view(state); - REQUIRE_THROWS_WITH( - sim->State(view), - Catch::Contains("Invalid size for the pre-allocated state vector")); + REQUIRE_THROWS_WITH(sim->State(view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated state vector")); } TEST_CASE("State test with numWires=4", "[Measures]") { @@ -1345,21 +1353,23 @@ TEST_CASE("PartialProbs test with incorrect numWires and numAlloc", REQUIRE_THROWS_WITH( sim->PartialProbs(probs_view, {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialProbs(probs_view, {Qs[0]}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "Invalid size for the pre-allocated partial-probabilities")); REQUIRE_THROWS_WITH( sim->Probs(probs_view), - Catch::Contains("Invalid size for the pre-allocated probabilities")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated probabilities")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialProbs(probs_view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialProbs(probs_view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("Probs and PartialProbs tests with numWires=0-4", "[Measures]") { @@ -1506,20 +1516,22 @@ TEST_CASE("PartialSample test with incorrect numWires and numAlloc", REQUIRE_THROWS_WITH( sim->PartialSample(view, {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialSample(view, {Qs[0], Qs[1]}), - Catch::Contains("Invalid size for the pre-allocated partial-samples")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated partial-samples")); - REQUIRE_THROWS_WITH( - sim->Sample(view), - Catch::Contains("Invalid size for the pre-allocated samples")); + REQUIRE_THROWS_WITH(sim->Sample(view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated samples")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialSample(view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialSample(view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("PartialCounts test with incorrect numWires and numAlloc", @@ -1541,22 +1553,25 @@ TEST_CASE("PartialCounts test with incorrect numWires and numAlloc", std::vector counts_vec(1); DataView counts_view(counts_vec); - REQUIRE_THROWS_WITH(sim->PartialCounts(eigvals_view, counts_view, - {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), - Catch::Contains("Invalid number of wires")); + REQUIRE_THROWS_WITH( + sim->PartialCounts(eigvals_view, counts_view, + {Qs[0], Qs[1], Qs[2], Qs[3], Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid number of wires")); REQUIRE_THROWS_WITH( sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), - Catch::Contains("Invalid size for the pre-allocated partial-counts")); + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated partial-counts")); - REQUIRE_THROWS_WITH( - sim->Counts(eigvals_view, counts_view), - Catch::Contains("Invalid size for the pre-allocated counts")); + REQUIRE_THROWS_WITH(sim->Counts(eigvals_view, counts_view), + Catch::Matchers::ContainsSubstring( + "Invalid size for the pre-allocated counts")); sim->ReleaseQubit(Qs[0]); - REQUIRE_THROWS_WITH(sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), - Catch::Contains("Invalid given wires to measure")); + REQUIRE_THROWS_WITH( + sim->PartialCounts(eigvals_view, counts_view, {Qs[0]}), + Catch::Matchers::ContainsSubstring("Invalid given wires to measure")); } TEST_CASE("Sample and PartialSample tests with numWires=0-4 shots=100", diff --git a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningSimulator.cpp b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningSimulator.cpp index 193968e26a..edc3607362 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningSimulator.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/Test_LightningSimulator.cpp @@ -21,7 +21,8 @@ #include #include -#include +#include +#include #include "LightningSimulator.hpp" #include "QuantumDevice.hpp" @@ -77,13 +78,13 @@ TEST_CASE("LightningSimulator::unit_tests", "[unit tests]") { std::unique_ptr LQsim = std::make_unique(); std::vector Qs = LQsim->AllocateQubits(1); REQUIRE_NOTHROW(LQsim->StartTapeRecording()); - REQUIRE_THROWS_WITH( - LQsim->StartTapeRecording(), - Catch::Matchers::Contains("Cannot re-activate the cache manager")); + REQUIRE_THROWS_WITH(LQsim->StartTapeRecording(), + Catch::Matchers::ContainsSubstring( + "Cannot re-activate the cache manager")); REQUIRE_NOTHROW(LQsim->StopTapeRecording()); REQUIRE_THROWS_WITH( LQsim->StopTapeRecording(), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "Cannot stop an already stopped cache manager")); } } @@ -815,14 +816,15 @@ TEST_CASE("LightningSimulator::GateSet", "[GateSet]") { constexpr std::size_t n_qubits = 2; std::vector Qs = LQsim->AllocateQubits(n_qubits); - REQUIRE_THROWS_WITH( - LQsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, false, {}, {}, - {"X", "Y"}), - Catch::Contains("PauliRot operation requires one string")); + REQUIRE_THROWS_WITH(LQsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, + false, {}, {}, {"X", "Y"}), + Catch::Matchers::ContainsSubstring( + "PauliRot operation requires one string")); - REQUIRE_THROWS_WITH( - LQsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, false, {Qs[1]}, - {false}, {"XY"}), - Catch::Contains("Controlled PauliRot is not supported")); + REQUIRE_THROWS_WITH(LQsim->NamedOperation("PauliRot", {0.5}, {Qs[0]}, + false, {Qs[1]}, {false}, + {"XY"}), + Catch::Matchers::ContainsSubstring( + "Controlled PauliRot is not supported")); } } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/runner_lightning_qubit_catalyst.cpp b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/runner_lightning_qubit_catalyst.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/runner_lightning_qubit_catalyst.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/catalyst/tests/runner_lightning_qubit_catalyst.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXSingleQubitGateHelpers.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXSingleQubitGateHelpers.cpp index d6db3836c5..21b884d2b8 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXSingleQubitGateHelpers.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXSingleQubitGateHelpers.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "cpu_kernels/avx_common/SingleQubitGateHelper.hpp" -#include +#include #include /// @cond DEV diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXTwoQubitGateHelpers.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXTwoQubitGateHelpers.cpp index 2c282d73c9..8cf50aa377 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXTwoQubitGateHelpers.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_AVXTwoQubitGateHelpers.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "cpu_kernels/avx_common/TwoQubitGateHelper.hpp" -#include +#include #include /// @cond DEV diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_DynamicDispatcher.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_DynamicDispatcher.cpp index c3b8f29b61..1c7721032d 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_DynamicDispatcher.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_DynamicDispatcher.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "CPUMemoryModel.hpp" #include "DynamicDispatcher.hpp" @@ -95,13 +96,13 @@ TEMPLATE_TEST_CASE("DynamicDispatcher::applyOperation", "[DynamicDispatcher]", REQUIRE_THROWS_WITH(dispatcher.applyOperation( Pennylane::Gates::KernelType::None, st.data(), num_qubits, "Toffoli", {0, 1, 2}, false), - Catch::Contains("Cannot find")); + Catch::Matchers::ContainsSubstring("Cannot find")); REQUIRE_THROWS_WITH( dispatcher.applyOperation( Pennylane::Gates::KernelType::None, st.data(), num_qubits, Pennylane::Gates::GateOperation::Toffoli, {0, 1, 2}, false), - Catch::Contains("Cannot find")); + Catch::Matchers::ContainsSubstring("Cannot find")); } SECTION("Test some gate operations") { @@ -155,13 +156,13 @@ TEMPLATE_TEST_CASE("DynamicDispatcher::applyGenerator", "[DynamicDispatcher]", REQUIRE_THROWS_WITH(dispatcher.applyGenerator( Pennylane::Gates::KernelType::None, st.data(), num_qubits, "RX", {0, 1, 2}, false), - Catch::Contains("Cannot find")); + Catch::Matchers::ContainsSubstring("Cannot find")); REQUIRE_THROWS_WITH( dispatcher.applyGenerator(Pennylane::Gates::KernelType::None, st.data(), num_qubits, GeneratorOperation::RX, {0, 1, 2}, false), - Catch::Contains("Cannot find")); + Catch::Matchers::ContainsSubstring("Cannot find")); } } @@ -178,11 +179,12 @@ TEMPLATE_TEST_CASE("DynamicDispatcher::applyMatrix", "[DynamicDispatcher]", std::vector> matrix(4, 0.0); - REQUIRE_THROWS_WITH(dispatcher.applyMatrix( - Pennylane::Gates::KernelType::None, st.data(), - num_qubits, matrix.data(), {0}, false), - Catch::Contains("is not registered") && - Catch::Contains("SingleQubitOp")); + REQUIRE_THROWS_WITH( + dispatcher.applyMatrix(Pennylane::Gates::KernelType::None, + st.data(), num_qubits, matrix.data(), {0}, + false), + Catch::Matchers::ContainsSubstring("is not registered") && + Catch::Matchers::ContainsSubstring("SingleQubitOp")); } } @@ -201,12 +203,12 @@ TEMPLATE_TEST_CASE("DynamicDispatcher::applySparseMatrix", std::vector col_idx(4, 0.0); std::vector row_map(5, 0.0); - REQUIRE_THROWS_WITH(dispatcher.applySparseMatrix( - Pennylane::Gates::KernelType::None, st.data(), - num_qubits, row_map.data(), col_idx.data(), - values.data(), {0}, false), - Catch::Contains("is not registered") && - Catch::Contains("SparseMultiQubitOp")); + REQUIRE_THROWS_WITH( + dispatcher.applySparseMatrix( + Pennylane::Gates::KernelType::None, st.data(), num_qubits, + row_map.data(), col_idx.data(), values.data(), {0}, false), + Catch::Matchers::ContainsSubstring("is not registered") && + Catch::Matchers::ContainsSubstring("SparseMultiQubitOp")); } } @@ -225,11 +227,12 @@ TEMPLATE_TEST_CASE("DynamicDispatcher::applyControlledSparseMatrix", std::vector col_idx(4, 0.0); std::vector row_map(5, 0.0); - REQUIRE_THROWS_WITH(dispatcher.applyControlledSparseMatrix( - Pennylane::Gates::KernelType::None, st.data(), - num_qubits, row_map.data(), col_idx.data(), - values.data(), {1}, {true}, {0}, false), - Catch::Contains("is not registered") && - Catch::Contains("NCSparseMultiQubitOp")); + REQUIRE_THROWS_WITH( + dispatcher.applyControlledSparseMatrix( + Pennylane::Gates::KernelType::None, st.data(), num_qubits, + row_map.data(), col_idx.data(), values.data(), {1}, {true}, {0}, + false), + Catch::Matchers::ContainsSubstring("is not registered") && + Catch::Matchers::ContainsSubstring("NCSparseMultiQubitOp")); } } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_CompareKernels.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_CompareKernels.cpp index 46ed631278..746dc929b5 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_CompareKernels.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_CompareKernels.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "ConstantUtil.hpp" // lookup, array_has_elem #include "DynamicDispatcher.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Generator.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Generator.cpp index 71681edc7d..b457a202d1 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Generator.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Generator.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include "ConstantUtil.hpp" // lookup, array_has_elem, prepend_to_tuple, tuple_to_array #include "DynamicDispatcher.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Inverse.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Inverse.cpp index 3419ed116b..4e2a1595a7 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Inverse.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Inverse.cpp @@ -19,7 +19,7 @@ #include "TestKernels.hpp" #include "Util.hpp" -#include +#include #include #include diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Matrix.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Matrix.cpp index bbe0158abf..2fe828743b 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Matrix.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Matrix.cpp @@ -13,7 +13,8 @@ // limitations under the License. #include -#include +#include +#include #include "ConstantUtil.hpp" // array_has_elem #include "Gates.hpp" // getPauliX, getPauliY diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Nonparam.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Nonparam.cpp index 1c20709926..fd3ef555f0 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Nonparam.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Nonparam.cpp @@ -18,7 +18,8 @@ #include #include -#include +#include +#include #include "Gates.hpp" #include "StateVectorLQubitManaged.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Param.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Param.cpp index 44d748e096..7ee563a3af 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Param.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Param.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +#include #include "CPUMemoryModel.hpp" #include "Gates.hpp" @@ -2499,9 +2501,10 @@ void testApplyPCPhase() { REQUIRE_THROWS_WITH( GateImplementation::applyPCPhase(st.data(), num_qubits, {0, 1}, inverse, angle, wrong_dim), - Catch::Contains("The dimension of the PCPhase gate must be a " - "positive integer and less than or equal to " - "statevector size.")); + Catch::Matchers::ContainsSubstring( + "The dimension of the PCPhase gate must be a " + "positive integer and less than or equal to " + "statevector size.")); } SECTION("Testing multiples dimensions") { diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Sparse_Matrix.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Sparse_Matrix.cpp index 82c04be7e6..907c11487e 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Sparse_Matrix.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateImplementations_Sparse_Matrix.cpp @@ -11,7 +11,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include +#include +#include +#include #include "ConstantUtil.hpp" // array_has_elem #include "Gates.hpp" // getPauliX, getPauliY @@ -57,11 +60,12 @@ TEST_CASE("GateImplementationsLM::applyNCMultiQubitSparseOp throws if inverse " std::vector col_idx = {0, 1, 2, 3}; std::vector values = {1.0, 1.0, 1.0, 1.0}; - REQUIRE_THROWS_WITH( - GateImplementationsLM::applyNCMultiQubitSparseOp( - state.data(), num_qubits, row_map.data(), col_idx.data(), - values.data(), controlled_wires, controlled_values, wires, inverse), - Catch::Matchers::Contains("Inverse not implemented for sparse ops.")); + REQUIRE_THROWS_WITH(GateImplementationsLM::applyNCMultiQubitSparseOp( + state.data(), num_qubits, row_map.data(), + col_idx.data(), values.data(), controlled_wires, + controlled_values, wires, inverse), + Catch::Matchers::ContainsSubstring( + "Inverse not implemented for sparse ops.")); } // Gate operation as a parameter diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateIndices.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateIndices.cpp index 89c3c3ca46..c0436185ea 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateIndices.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_GateIndices.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "GateIndices.hpp" -#include +#include #include diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_Internal.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_Internal.cpp index 00fa3b2ffd..07b83788cf 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_Internal.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_Internal.cpp @@ -14,7 +14,7 @@ #include "TestHelpers.hpp" // createProductState, createZeroState #include "TestHelpersWires.hpp" // CombinationGenerator, PermutationGenerator -#include +#include #include #include diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_KernelMap.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_KernelMap.cpp index a42cb5118c..78fb00c293 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_KernelMap.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_KernelMap.cpp @@ -19,7 +19,8 @@ #include "TestHelpers.hpp" #include "Util.hpp" // for_each_enum -#include +#include +#include /// @cond DEV namespace { @@ -27,7 +28,7 @@ using namespace Pennylane::LightningQubit; using namespace Pennylane::LightningQubit::KernelMap; using namespace Pennylane::Util; -using Catch::Matchers::Contains; +using Catch::Matchers::ContainsSubstring; using Pennylane::Util::for_each_enum; using Pennylane::Util::LightningException; } // namespace diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_OpToMemberFuncPtr.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_OpToMemberFuncPtr.cpp index dcc77ccf9b..a3f0754b57 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_OpToMemberFuncPtr.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/Test_OpToMemberFuncPtr.cpp @@ -17,7 +17,7 @@ #include "OpToMemberFuncPtr.hpp" #include "Util.hpp" -#include +#include #include /// @cond DEV diff --git a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/runner_lightning_qubit_gates.cpp b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/runner_lightning_qubit_gates.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/runner_lightning_qubit_gates.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/gates/tests/runner_lightning_qubit_gates.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubit.cpp b/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubit.cpp index 92af57d7d3..af1a05b55d 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubit.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubit.cpp @@ -17,7 +17,10 @@ #include #include "TestHelpers.hpp" -#include +#include +#include +#include +#include #include "MeasurementsLQubit.hpp" #include "ObservablesLQubit.hpp" @@ -60,9 +63,9 @@ TEMPLATE_PRODUCT_TEST_CASE("Expected Values", "[Measurements]", std::vector matrix = {0, 1}; // Should be 2x2 std::vector wires = {0, 1}; - REQUIRE_THROWS_WITH( - Measurer.expval(matrix, wires), - Catch::Contains("The size of matrix does not match")); + REQUIRE_THROWS_WITH(Measurer.expval(matrix, wires), + Catch::Matchers::ContainsSubstring( + "The size of matrix does not match")); } SECTION("Testing single operation defined by a matrix:") { @@ -76,9 +79,9 @@ TEMPLATE_PRODUCT_TEST_CASE("Expected Values", "[Measurements]", SECTION("Test expval with wrong named observable:") { std::vector wires = {0, 1}; - REQUIRE_THROWS_WITH( - Measurer.expval("huh", wires), - Catch::Contains("Expval does not exist for named observable")); + REQUIRE_THROWS_WITH(Measurer.expval("huh", wires), + Catch::Matchers::ContainsSubstring( + "Expval does not exist for named observable")); } SECTION("Testing single operation defined by its name:") { @@ -101,17 +104,20 @@ TEMPLATE_PRODUCT_TEST_CASE("Expected Values", "[Measurements]", operations_list = {PauliX, PauliX, PauliX}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } // For the following tests, the results are generated using the following @@ -143,27 +149,32 @@ TEMPLATE_PRODUCT_TEST_CASE("Expected Values", "[Measurements]", operations_list = {"Identity", "Identity", "Identity"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {1.0, 1.0, 1.0}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliX", "PauliX", "PauliX"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.49272486, 0.42073549, 0.28232124}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {-0.64421768, -0.47942553, -0.29552020}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.58498357, 0.77015115, 0.91266780}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); operations_list = {"Hadamard", "Hadamard", "Hadamard"}; exp_values = Measurer.expval(operations_list, wires_list); exp_values_ref = {0.7620549436, 0.8420840225, 0.8449848566}; - CHECK_THAT(exp_values, Catch::Approx(exp_values_ref).margin(1e-6)); + CHECK_THAT(exp_values, + Catch::Matchers::Approx(exp_values_ref).margin(1e-6)); } // For the following tests, the results are generated using the following @@ -478,17 +489,20 @@ TEMPLATE_PRODUCT_TEST_CASE("Variances", "[Measurements]", operations_list = {PauliX, PauliX, PauliX}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - CHECK_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + CHECK_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliY, PauliY, PauliY}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - CHECK_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + CHECK_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {PauliZ, PauliZ, PauliZ}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - CHECK_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + CHECK_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } SECTION("Testing list of operators defined by its name:") { @@ -500,17 +514,20 @@ TEMPLATE_PRODUCT_TEST_CASE("Variances", "[Measurements]", operations_list = {"PauliX", "PauliX", "PauliX"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.7572222, 0.8229816, 0.9202947}; - CHECK_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + CHECK_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliY", "PauliY", "PauliY"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.5849835, 0.7701511, 0.9126678}; - CHECK_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + CHECK_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); operations_list = {"PauliZ", "PauliZ", "PauliZ"}; variances = Measurer.var(operations_list, wires_list); variances_ref = {0.6577942, 0.4068672, 0.1670374}; - CHECK_THAT(variances, Catch::Approx(variances_ref).margin(1e-6)); + CHECK_THAT(variances, + Catch::Matchers::Approx(variances_ref).margin(1e-6)); } } @@ -533,11 +550,11 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", auto p1 = Measurer.probs(); CHECK_THAT( - p0, - Catch::Approx(std::vector{1.0, 0.0}).margin(1e-7)); + p0, Catch::Matchers::Approx(std::vector{1.0, 0.0}) + .margin(1e-7)); CHECK_THAT( - p1, - Catch::Approx(std::vector{0.5, 0.5}).margin(1e-7)); + p1, Catch::Matchers::Approx(std::vector{0.5, 0.5}) + .margin(1e-7)); } SECTION("Testing probs(NamedObs)") { const auto obs1 = Observables::NamedObs( @@ -550,45 +567,48 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", auto p0_obs2 = Measurer.probs(obs2); auto p0_obs3 = Measurer.probs(obs3); - CHECK_THAT( - p0_obs1, - Catch::Approx(std::vector{0.5, 0.5}).margin(1e-7)); - CHECK_THAT( - p0_obs2, - Catch::Approx(std::vector{1.0, 0.0}).margin(1e-7)); - CHECK_THAT(p0_obs3, Catch::Approx(std::vector{ - 0.85355339, 0.14644661}) + CHECK_THAT(p0_obs1, Catch::Matchers::Approx( + std::vector{0.5, 0.5}) .margin(1e-7)); + CHECK_THAT(p0_obs2, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_obs3, + Catch::Matchers::Approx( + std::vector{0.85355339, 0.14644661}) + .margin(1e-7)); statevector.applyOperation("Hadamard", {0}, false); auto p1_obs1 = Measurer.probs(obs1); auto p1_obs2 = Measurer.probs(obs2); auto p1_obs3 = Measurer.probs(obs3); - CHECK_THAT( - p1_obs1, - Catch::Approx(std::vector{1.0, 0.0}).margin(1e-7)); - CHECK_THAT( - p1_obs2, - Catch::Approx(std::vector{0.5, 0.5}).margin(1e-7)); - CHECK_THAT(p1_obs3, Catch::Approx(std::vector{ - 0.85355339, 0.14644661}) + CHECK_THAT(p1_obs1, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_obs2, Catch::Matchers::Approx( + std::vector{0.5, 0.5}) .margin(1e-7)); + CHECK_THAT(p1_obs3, + Catch::Matchers::Approx( + std::vector{0.85355339, 0.14644661}) + .margin(1e-7)); statevector.applyOperation("Hadamard", {0}, false); auto p2_obs1 = Measurer.probs(obs1); auto p2_obs2 = Measurer.probs(obs2); auto p2_obs3 = Measurer.probs(obs3); - CHECK_THAT( - p0_obs1, - Catch::Approx(std::vector{0.5, 0.5}).margin(1e-7)); - CHECK_THAT( - p0_obs2, - Catch::Approx(std::vector{1.0, 0.0}).margin(1e-7)); - CHECK_THAT(p0_obs3, Catch::Approx(std::vector{ - 0.85355339, 0.14644661}) + CHECK_THAT(p0_obs1, Catch::Matchers::Approx( + std::vector{0.5, 0.5}) + .margin(1e-7)); + CHECK_THAT(p0_obs2, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) .margin(1e-7)); + CHECK_THAT(p0_obs3, + Catch::Matchers::Approx( + std::vector{0.85355339, 0.14644661}) + .margin(1e-7)); } } SECTION("n-qubit") { @@ -609,38 +629,42 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", auto p0_1 = Measurer.probs({1}, device_wires); auto p0_perm0 = Measurer.probs({1, 0}, device_wires); - CHECK_THAT(p0_full, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_0, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p0_full, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p0_1, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p0_0, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_1, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + + CHECK_THAT(p0_perm0, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p0_perm0, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); - statevector.applyOperation("Hadamard", {0}, false); auto p1_full = Measurer.probs(); auto p1_0 = Measurer.probs({0}, device_wires); auto p1_1 = Measurer.probs({1}, device_wires); auto p1_perm0 = Measurer.probs({1, 0}, device_wires); - CHECK_THAT(p1_full, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_0, - Catch::Approx(std::vector{0.5, 0.5}) + CHECK_THAT(p1_full, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0}) .margin(1e-7)); - CHECK_THAT(p1_1, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p1_0, Catch::Matchers::Approx( + std::vector{0.5, 0.5}) + .margin(1e-7)); + CHECK_THAT(p1_1, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_perm0, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p1_perm0, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0}) - .margin(1e-7)); statevector.applyOperation("Hadamard", {1}, false); auto p2_full = Measurer.probs(); @@ -648,18 +672,20 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", auto p2_1 = Measurer.probs({1}, device_wires); auto p2_perm0 = Measurer.probs({1, 0}, device_wires); - CHECK_THAT(p2_full, Catch::Approx(std::vector{ - 0.25, 0.25, 0.25, 0.25}) - .margin(1e-7)); - CHECK_THAT(p2_0, - Catch::Approx(std::vector{0.5, 0.5}) + CHECK_THAT(p2_full, + Catch::Matchers::Approx( + std::vector{0.25, 0.25, 0.25, 0.25}) .margin(1e-7)); - CHECK_THAT(p2_1, - Catch::Approx(std::vector{0.5, 0.5}) + CHECK_THAT(p2_0, Catch::Matchers::Approx( + std::vector{0.5, 0.5}) + .margin(1e-7)); + CHECK_THAT(p2_1, Catch::Matchers::Approx( + std::vector{0.5, 0.5}) + .margin(1e-7)); + CHECK_THAT(p2_perm0, + Catch::Matchers::Approx( + std::vector{0.25, 0.25, 0.25, 0.25}) .margin(1e-7)); - CHECK_THAT(p2_perm0, Catch::Approx(std::vector{ - 0.25, 0.25, 0.25, 0.25}) - .margin(1e-7)); } } SECTION("3 qubits") { @@ -694,65 +720,78 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", auto p0_201 = Measurer.probs({2, 0, 1}, device_wires); auto p0_210 = Measurer.probs({2, 1, 0}, device_wires); - CHECK_THAT(p0_full, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_0, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p0_full, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p0_1, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p0_0, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_1, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_2, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + + CHECK_THAT(p0_01, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p0_2, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p0_02, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_12, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p0_01, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_02, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_12, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(p0_10, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_20, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_21, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) + .margin(1e-7)); - CHECK_THAT(p0_10, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_20, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_21, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(p0_012, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_021, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_102, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); - CHECK_THAT(p0_012, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_021, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_102, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - - CHECK_THAT(p0_120, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_201, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p0_210, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(p0_120, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_201, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p0_210, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); statevector.applyOperation("Hadamard", {0}, false); @@ -776,65 +815,78 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", auto p1_201 = Measurer.probs({2, 0, 1}, device_wires); auto p1_210 = Measurer.probs({2, 1, 0}, device_wires); - CHECK_THAT(p1_full, Catch::Approx(std::vector{ - 0.5, 0.0, 0.0, 0.0, 0.5, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_0, - Catch::Approx(std::vector{0.5, 0.5}) + CHECK_THAT(p1_full, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.0, 0.0, 0.5, + 0.0, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p1_1, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p1_0, Catch::Matchers::Approx( + std::vector{0.5, 0.5}) + .margin(1e-7)); + CHECK_THAT(p1_1, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_2, Catch::Matchers::Approx( + std::vector{1.0, 0.0}) + .margin(1e-7)); + + CHECK_THAT(p1_01, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0}) .margin(1e-7)); - CHECK_THAT(p1_2, - Catch::Approx(std::vector{1.0, 0.0}) + CHECK_THAT(p1_02, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_12, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) .margin(1e-7)); - CHECK_THAT(p1_01, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_02, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_12, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(p1_10, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_20, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_21, + Catch::Matchers::Approx( + std::vector{1.0, 0.0, 0.0, 0.0}) + .margin(1e-7)); - CHECK_THAT(p1_10, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_20, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_21, Catch::Approx(std::vector{ - 1.0, 0.0, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(p1_012, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.0, 0.0, 0.5, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_021, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.0, 0.0, 0.5, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_102, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); - CHECK_THAT(p1_012, Catch::Approx(std::vector{ - 0.5, 0.0, 0.0, 0.0, 0.5, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_021, Catch::Approx(std::vector{ - 0.5, 0.0, 0.0, 0.0, 0.5, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_102, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - - CHECK_THAT(p1_120, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_201, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); - CHECK_THAT(p1_210, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(p1_120, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_201, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); + CHECK_THAT(p1_210, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0}) + .margin(1e-7)); } } SECTION("5 qubits") { @@ -850,9 +902,9 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", std::size_t target = GENERATE(0, 1, 2, 3, 4); statevector.applyOperation("Hadamard", {target}, false); auto probs = Measurer.probs({target}, device_wires); - CHECK_THAT(probs, - Catch::Approx(std::vector(2, 1.0 / 2)) - .margin(1e-7)); + CHECK_THAT(probs, Catch::Matchers::Approx( + std::vector(2, 1.0 / 2)) + .margin(1e-7)); } SECTION("2 targets") { std::size_t target0 = GENERATE(0, 1, 2, 3, 4); @@ -861,31 +913,35 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", statevector.applyOperation("Hadamard", {target0}, false); auto probs = Measurer.probs({target0, target1}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0}) - .margin(1e-7)); + CHECK_THAT(probs, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0}) + .margin(1e-7)); probs = Measurer.probs({target1, target0}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(probs, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0}) + .margin(1e-7)); statevector.applyOperation("Hadamard", {target1}, false); probs = Measurer.probs({target0, target1}, device_wires); - CHECK_THAT(probs, Catch::Approx( + CHECK_THAT(probs, Catch::Matchers::Approx( std::vector(4, 1.0 / 4.0)) .margin(1e-7)); probs = Measurer.probs({target1, target0}, device_wires); - CHECK_THAT(probs, Catch::Approx( + CHECK_THAT(probs, Catch::Matchers::Approx( std::vector(4, 1.0 / 4.0)) .margin(1e-7)); statevector.applyOperation("Hadamard", {target0}, false); probs = Measurer.probs({target0, target1}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.5, 0.0, 0.0}) - .margin(1e-7)); + CHECK_THAT(probs, + Catch::Matchers::Approx( + std::vector{0.5, 0.5, 0.0, 0.0}) + .margin(1e-7)); probs = Measurer.probs({target1, target0}, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector{ - 0.5, 0.0, 0.5, 0.0}) - .margin(1e-7)); + CHECK_THAT(probs, + Catch::Matchers::Approx( + std::vector{0.5, 0.0, 0.5, 0.0}) + .margin(1e-7)); } } SECTION("Many targets Hadamard(n)") { @@ -900,7 +956,7 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", std::vector ref(1UL << num_qubits, 0.0); ref[0] = 0.5; ref[1] = 0.5; - CHECK_THAT(probs, Catch::Approx(ref).margin(1e-7)); + CHECK_THAT(probs, Catch::Matchers::Approx(ref).margin(1e-7)); } SECTION("Many targets Hadamard(all)") { for (std::size_t t = 0; t < num_qubits; t++) { @@ -910,10 +966,11 @@ TEMPLATE_PRODUCT_TEST_CASE("Probabilities", "[Measurements]", std::vector targets(ntarget); std::iota(targets.begin(), targets.end(), 0); auto probs = Measurer.probs(targets, device_wires); - CHECK_THAT(probs, Catch::Approx(std::vector( - (1UL << ntarget), - 1.0 / (1UL << ntarget))) - .margin(1e-7)); + CHECK_THAT(probs, + Catch::Matchers::Approx( + std::vector((1UL << ntarget), + 1.0 / (1UL << ntarget))) + .margin(1e-7)); } } } @@ -977,6 +1034,6 @@ TEMPLATE_PRODUCT_TEST_CASE("Sample with Metropolis (Local Kernel)", // compare estimated probabilities to real probabilities SECTION("No wires provided:") { CHECK_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.05)); + Catch::Matchers::Approx(expected_probabilities).margin(.05)); } } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubitSparse.cpp b/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubitSparse.cpp index f7f5a5d9db..f02f0f11dd 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubitSparse.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/Test_MeasurementsLQubitSparse.cpp @@ -24,7 +24,7 @@ #include "TestHelpers.hpp" #include "TestHelpersSparse.hpp" // write_CSR_vectors -#include +#include #if defined(_MSC_VER) #pragma warning(disable : 4305) diff --git a/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/runner_lightning_qubit_measurements.cpp b/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/runner_lightning_qubit_measurements.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/runner_lightning_qubit_measurements.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/measurements/tests/runner_lightning_qubit_measurements.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/Test_ObservablesLQubit.cpp b/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/Test_ObservablesLQubit.cpp index 1358a07f41..6ec877bae0 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/Test_ObservablesLQubit.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/Test_ObservablesLQubit.cpp @@ -15,7 +15,7 @@ #include "ObservablesLQubit.hpp" #include "TestHelpers.hpp" -#include +#include // using namespace Pennylane; /// @cond DEV diff --git a/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/runner_lightning_qubit_observables.cpp b/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/runner_lightning_qubit_observables.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/runner_lightning_qubit_observables.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/observables/tests/runner_lightning_qubit_observables.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubit.cpp b/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubit.cpp index 6a11bc4a0d..fd11a122b4 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubit.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubit.cpp @@ -18,7 +18,9 @@ #include #include -#include +#include +#include +#include #include "LinearAlgebra.hpp" //randomUnitary #include "StateVectorLQubitManaged.hpp" @@ -190,7 +192,8 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorLQubit::Constructibility", std::vector st_data(14, 0.0); REQUIRE_THROWS_WITH( StateVectorT(st_data.data(), st_data.size()), - Catch::Contains("The size of provided data must be a power of 2.")); + Catch::Matchers::ContainsSubstring( + "The size of provided data must be a power of 2.")); } SECTION( "StateVectorBackend {const StateVectorBackend&}") { @@ -220,7 +223,7 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorLQubit::applyMatrix with a std::vector", StateVectorT state_vector(st_data.data(), st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0, 1}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } @@ -233,7 +236,7 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorLQubit::applyMatrix with a std::vector", StateVectorT state_vector(st_data.data(), st_data.size()); REQUIRE_THROWS_WITH( state_vector.applyMatrix(m, {0}), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "The size of matrix does not match with the given")); } } @@ -255,8 +258,9 @@ TEMPLATE_PRODUCT_TEST_CASE("StateVectorLQubit::applyMatrix with a pointer", createRandomStateVectorData(re, num_qubits); StateVectorT state_vector(st_data.data(), st_data.size()); - REQUIRE_THROWS_WITH(state_vector.applyMatrix(m.data(), {}), - Catch::Contains("must be larger than 0")); + REQUIRE_THROWS_WITH( + state_vector.applyMatrix(m.data(), {}), + Catch::Matchers::ContainsSubstring("must be larger than 0")); } } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubitManaged.cpp b/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubitManaged.cpp index 896ceed4e9..703a77b1c0 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubitManaged.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/tests/Test_StateVectorLQubitManaged.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +#include #include "CPUMemoryModel.hpp" // getBestAllocator #include "LinearAlgebra.hpp" //randomUnitary @@ -180,7 +182,7 @@ TEMPLATE_TEST_CASE("StateVectorLQubitManaged::normalize", init_state.size()}; REQUIRE_THROWS_WITH( sv.normalize(), - Catch::Contains( + Catch::Matchers::ContainsSubstring( "Vector has norm close to zero and cannot be normalized")); } } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/tests/runner_lightning_qubit.cpp b/pennylane_lightning/core/simulators/lightning_qubit/tests/runner_lightning_qubit.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/tests/runner_lightning_qubit.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/tests/runner_lightning_qubit.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_LinearAlgebra.cpp b/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_LinearAlgebra.cpp index 5d9c477f5f..267d52fec5 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_LinearAlgebra.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_LinearAlgebra.cpp @@ -15,7 +15,8 @@ #include #include -#include +#include +#include #include "LinearAlgebra.hpp" #include "TestHelpers.hpp" @@ -202,7 +203,7 @@ TEMPLATE_TEST_CASE("Transpose", "[Util][LinearAlgebra]", float, double) { std::invalid_argument); CHECK_THROWS_WITH( Util::Transpose(mat, 2, 2), - Contains( + ContainsSubstring( "Invalid number of rows and columns for the input matrix")); } } @@ -255,7 +256,7 @@ TEMPLATE_TEST_CASE("Transpose", "[Util][LinearAlgebra]", float, double) { CHECK_THROWS_AS(Util::Transpose(mat, 2, 2), std::invalid_argument); CHECK_THROWS_WITH( Util::Transpose(mat, 2, 2), - Contains( + ContainsSubstring( "Invalid number of rows and columns for the input matrix")); } } diff --git a/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_SparseLinAlg.cpp b/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_SparseLinAlg.cpp index 273767825e..3ac9e92706 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_SparseLinAlg.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/Test_SparseLinAlg.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "SparseLinAlg.hpp" #include "Util.hpp" // exp2 diff --git a/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/runner_lightning_qubit_utils.cpp b/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/runner_lightning_qubit_utils.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/runner_lightning_qubit_utils.cpp +++ b/pennylane_lightning/core/simulators/lightning_qubit/utils/tests/runner_lightning_qubit_utils.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/Tests_TensorCuda.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/Tests_TensorCuda.cpp index f44daf2bad..6db244add1 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/Tests_TensorCuda.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/Tests_TensorCuda.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include "DevTag.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/runner_lightning_tensor_TensorCuda.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/runner_lightning_tensor_TensorCuda.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/runner_lightning_tensor_TensorCuda.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tensor/tncuda/tests/runner_lightning_tensor_TensorCuda.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/Tests_TNCudaBase.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/Tests_TNCudaBase.cpp index a05159d642..812d262ba9 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/Tests_TNCudaBase.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/Tests_TNCudaBase.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include "TypeList.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/runner_lightning_tensor_TNCudaBase.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/runner_lightning_tensor_TNCudaBase.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/runner_lightning_tensor_TNCudaBase.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/base/tests/runner_lightning_tensor_TNCudaBase.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_MPO.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_MPO.cpp index ff79a770dc..c54e7f8cba 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_MPO.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_MPO.cpp @@ -15,7 +15,8 @@ #include #include -#include +#include +#include #include "DevTag.hpp" #include "MPSTNCuda.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_NonParam.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_NonParam.cpp index e5aa545d7f..2e99de103d 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_NonParam.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_NonParam.cpp @@ -15,7 +15,8 @@ #include #include -#include +#include +#include #include "DevTag.hpp" #include "ExactTNCuda.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_Param.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_Param.cpp index 947876180f..fe77710453 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_Param.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/Test_TNCuda_Param.cpp @@ -15,7 +15,8 @@ #include #include -#include +#include +#include #include "DevTag.hpp" #include "ExactTNCuda.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/runner_lightning_tensor_gates.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/runner_lightning_tensor_gates.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/runner_lightning_tensor_gates.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/gates/tests/runner_lightning_tensor_gates.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Expval.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Expval.cpp index 87bc06e35a..4f69653e67 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Expval.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Expval.cpp @@ -20,7 +20,11 @@ #include #include -#include +#include +#include +#include +#include +using Catch::Approx; #include "DevTag.hpp" #include "ExactTNCuda.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Measure.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Measure.cpp index 12fe3cc601..a39077d67b 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Measure.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Measure.cpp @@ -21,7 +21,9 @@ #include #include -#include +#include +#include +#include #include "DevTag.hpp" #include "ExactTNCuda.hpp" @@ -81,7 +83,7 @@ TEMPLATE_LIST_TEST_CASE("Probabilities", "[Measures]", TestTNBackends) { for (const auto &term : input) { auto probabilities = measure.probs(term.first); REQUIRE_THAT(term.second, - Catch::Approx(probabilities).margin(1e-6)); + Catch::Matchers::Approx(probabilities).margin(1e-6)); } } @@ -156,8 +158,9 @@ TEMPLATE_LIST_TEST_CASE("Samples", "[TNCUDA_Measures]", TestTNBackends) { // compare estimated probabilities to real probabilities SECTION("No wires provided:") { - REQUIRE_THAT(probabilities, - Catch::Approx(expected_probabilities).margin(.1)); + REQUIRE_THAT( + probabilities, + Catch::Matchers::Approx(expected_probabilities).margin(.1)); } } } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Var.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Var.cpp index 337653fe8a..2b910d8334 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Var.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/Test_TNCuda_Var.cpp @@ -21,7 +21,10 @@ #include #include -#include +#include +#include +#include +using Catch::Approx; #include "DevTag.hpp" #include "ExactTNCuda.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/runner_lightning_tensor_measurements.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/runner_lightning_tensor_measurements.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/runner_lightning_tensor_measurements.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/measurements/tests/runner_lightning_tensor_measurements.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCuda.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCuda.cpp index a62a3a5a99..80231895ba 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCuda.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCuda.cpp @@ -13,7 +13,8 @@ // limitations under the License. #include -#include +#include +#include #include "MPSTNCuda.hpp" #include "ObservablesTNCuda.hpp" @@ -96,8 +97,9 @@ TEMPLATE_TEST_CASE("[Hermitian]", "[Observables]", float, double) { REQUIRE_THROWS_WITH( HermitianObsT(std::vector(16, ComplexT{0.0, 0.0}), {0, 1}), - Catch::Matchers::Contains("The number of Hermitian target wires " - "must be 1 for Lightning-Tensor.")); + Catch::Matchers::ContainsSubstring( + "The number of Hermitian target wires " + "must be 1 for Lightning-Tensor.")); } SECTION("Test get obs name") { diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCudaOperators.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCudaOperators.cpp index 0ff0d40013..67d08f132a 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCudaOperators.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/Test_Observables_TNCudaOperators.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include -#include +#include #include "MPSTNCuda.hpp" #include "ObservablesTNCuda.hpp" diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/runner_lightning_tensor_observables.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/runner_lightning_tensor_observables.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/runner_lightning_tensor_observables.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/observables/tests/runner_lightning_tensor_observables.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/Tests_MPSTNCuda.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/Tests_MPSTNCuda.cpp index 9fc4572e23..7350bcad6b 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/Tests_MPSTNCuda.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/Tests_MPSTNCuda.cpp @@ -19,7 +19,9 @@ #include #include -#include +#include +#include +#include #include "DevTag.hpp" #include "MPOTNCuda.hpp" @@ -72,7 +74,7 @@ TEMPLATE_TEST_CASE("MPSTNCuda::setIthMPSSite", "[MPSTNCuda]", float, double) { REQUIRE_THROWS_WITH( mps_state.updateSiteData(siteIdx, site_data.data(), site_data.size()), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "The site index should be less than the number of qubits.")); } @@ -85,11 +87,11 @@ TEMPLATE_TEST_CASE("MPSTNCuda::setIthMPSSite", "[MPSTNCuda]", float, double) { std::vector> site_data(1, {0.0, 0.0}); - REQUIRE_THROWS_WITH( - mps_state.updateSiteData(siteIdx, site_data.data(), - site_data.size()), - Catch::Matchers::Contains("The length of the host data should " - "match its copy on the device.")); + REQUIRE_THROWS_WITH(mps_state.updateSiteData(siteIdx, site_data.data(), + site_data.size()), + Catch::Matchers::ContainsSubstring( + "The length of the host data should " + "match its copy on the device.")); } SECTION("Set MPS sites") { @@ -133,10 +135,10 @@ TEMPLATE_TEST_CASE("MPSTNCuda::SetBasisStates() & reset()", "[MPSTNCuda]", MPSTNCuda mps_state{num_qubits, maxBondDim}; - REQUIRE_THROWS_WITH( - mps_state.setBasisState(basisState), - Catch::Matchers::Contains("The size of a basis state should be " - "equal to the number of qubits.")); + REQUIRE_THROWS_WITH(mps_state.setBasisState(basisState), + Catch::Matchers::ContainsSubstring( + "The size of a basis state should be " + "equal to the number of qubits.")); } SECTION("Failure for wrong basisState input") { @@ -146,10 +148,10 @@ TEMPLATE_TEST_CASE("MPSTNCuda::SetBasisStates() & reset()", "[MPSTNCuda]", MPSTNCuda mps_state{num_qubits, maxBondDim}; - REQUIRE_THROWS_WITH( - mps_state.setBasisState(basisState), - Catch::Matchers::Contains("Please ensure all elements of a basis " - "state should be either 0 or 1.")); + REQUIRE_THROWS_WITH(mps_state.setBasisState(basisState), + Catch::Matchers::ContainsSubstring( + "Please ensure all elements of a basis " + "state should be either 0 or 1.")); } SECTION("Set reset on device with data on the host") { @@ -236,7 +238,7 @@ TEMPLATE_TEST_CASE("MPSTNCuda::WorksizePref", "[MPSTNCuda]", float, double) { MPSTNCuda mps_state{num_qubits, maxBondDim, dev_tag}; REQUIRE_THROWS_WITH( mps_state.setWorksizePref("invalid_pref"), - Catch::Matchers::Contains("Invalid workspace preference")); + Catch::Matchers::ContainsSubstring("Invalid workspace preference")); } SECTION("Set and get workspace preference") { @@ -290,7 +292,7 @@ TEMPLATE_TEST_CASE("MPSTNCuda::getDataVector()", "[MPSTNCuda]", float, double) { REQUIRE_THROWS_WITH( mps_state.getData(results.data(), length), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "State tensor size exceeds the available GPU memory!")); } @@ -305,7 +307,7 @@ TEMPLATE_TEST_CASE("MPSTNCuda::getDataVector()", "[MPSTNCuda]", float, double) { std::vector results(1); REQUIRE_THROWS_WITH(mps_state.getData(results.data(), length), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "The size of the result vector should be equal " "to the dimension of the quantum state.")); } @@ -317,7 +319,7 @@ TEMPLATE_TEST_CASE("MPSTNCuda::getDataVector()", "[MPSTNCuda]", float, double) { REQUIRE_THROWS_WITH( MPSTNCuda(num_qubits, maxBondDim, dev_tag), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "The number of qubits should be greater than 1.")); } } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/runner_lightning_tensor_MPSTNCuda.cpp b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/runner_lightning_tensor_MPSTNCuda.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/runner_lightning_tensor_MPSTNCuda.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/tncuda/tests/runner_lightning_tensor_MPSTNCuda.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/Test_TNCuda_utils.cpp b/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/Test_TNCuda_utils.cpp index 72372bf03f..4fbce36610 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/Test_TNCuda_utils.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/Test_TNCuda_utils.cpp @@ -16,7 +16,8 @@ #include #include -#include +#include +#include #include "tncuda_helpers.hpp" @@ -44,10 +45,10 @@ TEST_CASE("MPSShapeCheck", "[TNCuda_utils]") { std::vector> incorrect_MPS_shape{ {2, 2}, {2, 2, 2}, {2, 2, 2}, {2, 2}}; - REQUIRE_THROWS_WITH( - MPSShapeCheck(MPS_shape_dest, incorrect_MPS_shape), - Catch::Matchers::Contains("The incoming MPS does not have the " - "correct layout for lightning.tensor")); + REQUIRE_THROWS_WITH(MPSShapeCheck(MPS_shape_dest, incorrect_MPS_shape), + Catch::Matchers::ContainsSubstring( + "The incoming MPS does not have the " + "correct layout for lightning.tensor")); } SECTION("Incorrect incoming MPS shape, physical dimension") { std::vector> MPS_shape_dest{ @@ -56,10 +57,10 @@ TEST_CASE("MPSShapeCheck", "[TNCuda_utils]") { std::vector> incorrect_shape{ {4, 2}, {2, 4, 4}, {4, 4, 2}, {2, 4}}; - REQUIRE_THROWS_WITH( - MPSShapeCheck(MPS_shape_dest, incorrect_shape), - Catch::Matchers::Contains("The incoming MPS does not have the " - "correct layout for lightning.tensor")); + REQUIRE_THROWS_WITH(MPSShapeCheck(MPS_shape_dest, incorrect_shape), + Catch::Matchers::ContainsSubstring( + "The incoming MPS does not have the " + "correct layout for lightning.tensor")); } SECTION("Incorrect incoming MPS shape, number sites") { std::vector> MPS_shape_dest{ @@ -68,9 +69,9 @@ TEST_CASE("MPSShapeCheck", "[TNCuda_utils]") { std::vector> incorrect_shape{ {2, 2}, {2, 2, 2}, {2, 2}}; - REQUIRE_THROWS_WITH( - MPSShapeCheck(MPS_shape_dest, incorrect_shape), - Catch::Matchers::Contains("The incoming MPS does not have the " - "correct layout for lightning.tensor")); + REQUIRE_THROWS_WITH(MPSShapeCheck(MPS_shape_dest, incorrect_shape), + Catch::Matchers::ContainsSubstring( + "The incoming MPS does not have the " + "correct layout for lightning.tensor")); } } diff --git a/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/runner_lightning_tensor_tncuda_utils.cpp b/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/runner_lightning_tensor_tncuda_utils.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/runner_lightning_tensor_tncuda_utils.cpp +++ b/pennylane_lightning/core/simulators/lightning_tensor/utils/tncuda_utils/tests/runner_lightning_tensor_tncuda_utils.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/utils/TestHelpers.hpp b/pennylane_lightning/core/utils/TestHelpers.hpp index 337ffae231..cbfbceebcb 100644 --- a/pennylane_lightning/core/utils/TestHelpers.hpp +++ b/pennylane_lightning/core/utils/TestHelpers.hpp @@ -25,7 +25,11 @@ #include #include -#include +#include +#include +#include + +using Catch::Approx; #include "CPUMemoryModel.hpp" // getBestAllocator #include "Error.hpp" // PL_ABORT @@ -637,10 +641,11 @@ inline auto samples_to_decimal(const std::vector &samples, #define PL_REQUIRE_THROWS_MATCHES(expr, type, message_match) \ REQUIRE_THROWS_AS(expr, type); \ - REQUIRE_THROWS_WITH(expr, Catch::Matchers::Contains(message_match)); + REQUIRE_THROWS_WITH(expr, \ + Catch::Matchers::ContainsSubstring(message_match)); #define PL_CHECK_THROWS_MATCHES(expr, type, message_match) \ CHECK_THROWS_AS(expr, type); \ - CHECK_THROWS_WITH(expr, Catch::Matchers::Contains(message_match)); + CHECK_THROWS_WITH(expr, Catch::Matchers::ContainsSubstring(message_match)); } // namespace Pennylane::Util /// @endcond diff --git a/pennylane_lightning/core/utils/TestHelpersSparse.hpp b/pennylane_lightning/core/utils/TestHelpersSparse.hpp index d9cb3aa2b8..9654049f4c 100644 --- a/pennylane_lightning/core/utils/TestHelpersSparse.hpp +++ b/pennylane_lightning/core/utils/TestHelpersSparse.hpp @@ -19,7 +19,7 @@ */ #pragma once -#include +#include #include #include #include diff --git a/pennylane_lightning/core/utils/cuda_utils/tests/Test_LinearAlgebra.cpp b/pennylane_lightning/core/utils/cuda_utils/tests/Test_LinearAlgebra.cpp index 95b2299699..9c831b0c88 100644 --- a/pennylane_lightning/core/utils/cuda_utils/tests/Test_LinearAlgebra.cpp +++ b/pennylane_lightning/core/utils/cuda_utils/tests/Test_LinearAlgebra.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include "DataBuffer.hpp" #include "LinearAlg.hpp" diff --git a/pennylane_lightning/core/utils/cuda_utils/tests/runner_cuda_utils.cpp b/pennylane_lightning/core/utils/cuda_utils/tests/runner_cuda_utils.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/utils/cuda_utils/tests/runner_cuda_utils.cpp +++ b/pennylane_lightning/core/utils/cuda_utils/tests/runner_cuda_utils.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); } diff --git a/pennylane_lightning/core/utils/tests/Test_BitUtil.cpp b/pennylane_lightning/core/utils/tests/Test_BitUtil.cpp index 6d043b3ed7..08db5fdd64 100644 --- a/pennylane_lightning/core/utils/tests/Test_BitUtil.cpp +++ b/pennylane_lightning/core/utils/tests/Test_BitUtil.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "BitUtil.hpp" #include "TestHelpers.hpp" -#include +#include #include /// @cond DEV diff --git a/pennylane_lightning/core/utils/tests/Test_ConstantUtil.cpp b/pennylane_lightning/core/utils/tests/Test_ConstantUtil.cpp index ac8798d815..7f89071807 100644 --- a/pennylane_lightning/core/utils/tests/Test_ConstantUtil.cpp +++ b/pennylane_lightning/core/utils/tests/Test_ConstantUtil.cpp @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "ConstantTestHelpers.hpp" #include "ConstantUtil.hpp" diff --git a/pennylane_lightning/core/utils/tests/Test_Error.cpp b/pennylane_lightning/core/utils/tests/Test_Error.cpp index d8b44578ad..aa3390d770 100644 --- a/pennylane_lightning/core/utils/tests/Test_Error.cpp +++ b/pennylane_lightning/core/utils/tests/Test_Error.cpp @@ -14,7 +14,8 @@ #include #include -#include +#include +#include #include "Error.hpp" @@ -28,19 +29,19 @@ TEST_CASE("Error.hpp", "[Error]") { auto e_mut = Pennylane::Util::LightningException("Test exception e_mut"); - REQUIRE_THROWS_WITH(throw e, - Catch::Matchers::Contains("Test exception e")); + REQUIRE_THROWS_WITH( + throw e, Catch::Matchers::ContainsSubstring("Test exception e")); REQUIRE_THROWS_AS(throw e, Pennylane::Util::LightningException); // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) const Pennylane::Util::LightningException e_copy(e); - REQUIRE_THROWS_WITH(throw e_copy, - Catch::Matchers::Contains("Test exception e")); + REQUIRE_THROWS_WITH(throw e_copy, Catch::Matchers::ContainsSubstring( + "Test exception e")); REQUIRE_THROWS_AS(throw e_copy, Pennylane::Util::LightningException); Pennylane::Util::LightningException e_move(std::move(e_mut)); - REQUIRE_THROWS_WITH(throw e_move, - Catch::Matchers::Contains("Test exception e_mut")); + REQUIRE_THROWS_WITH(throw e_move, Catch::Matchers::ContainsSubstring( + "Test exception e_mut")); REQUIRE_THROWS_AS(throw e_move, Pennylane::Util::LightningException); REQUIRE(std::strcmp(e.what(), "Test exception e") == 0); @@ -50,13 +51,13 @@ TEST_CASE("Error.hpp", "[Error]") { SECTION("Abort") { REQUIRE_THROWS_WITH( Pennylane::Util::Abort("Test abort", __FILE__, __LINE__, __func__), - Catch::Matchers::Contains("Test abort")); + Catch::Matchers::ContainsSubstring("Test abort")); REQUIRE_THROWS_AS( Pennylane::Util::Abort("Test abort", __FILE__, __LINE__, __func__), Pennylane::Util::LightningException); REQUIRE_THROWS_WITH(PL_ABORT("Test abort"), - Catch::Matchers::Contains("Test abort")); + Catch::Matchers::ContainsSubstring("Test abort")); REQUIRE_THROWS_AS(PL_ABORT("Test abort"), Pennylane::Util::LightningException); } diff --git a/pennylane_lightning/core/utils/tests/Test_RuntimeInfo.cpp b/pennylane_lightning/core/utils/tests/Test_RuntimeInfo.cpp index e3efb44a54..2b0770e759 100644 --- a/pennylane_lightning/core/utils/tests/Test_RuntimeInfo.cpp +++ b/pennylane_lightning/core/utils/tests/Test_RuntimeInfo.cpp @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "Macros.hpp" #include "RuntimeInfo.hpp" diff --git a/pennylane_lightning/core/utils/tests/Test_TestHelpersSparse.cpp b/pennylane_lightning/core/utils/tests/Test_TestHelpersSparse.cpp index 8ad0e02a51..7f0c5c8351 100644 --- a/pennylane_lightning/core/utils/tests/Test_TestHelpersSparse.cpp +++ b/pennylane_lightning/core/utils/tests/Test_TestHelpersSparse.cpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include +#include #include #include "TestHelpers.hpp" @@ -87,20 +88,20 @@ TEMPLATE_TEST_CASE("SparseMatrixCSR data structure", "[SparseMatrixCSR]", float, SECTION("SparseMatrixCSR: makeSparseUnitary dimension check") { SparseMatrixCSR matrix; - REQUIRE_THROWS_WITH( - matrix.makeSparseUnitary(gen, 0, 0.5), - Catch::Matchers::Contains("Dimension must be greater than 0.")); + REQUIRE_THROWS_WITH(matrix.makeSparseUnitary(gen, 0, 0.5), + Catch::Matchers::ContainsSubstring( + "Dimension must be greater than 0.")); } SECTION("SparseMatrixCSR: makeSparseUnitary sparsity check") { SparseMatrixCSR matrix; - REQUIRE_THROWS_WITH( - matrix.makeSparseUnitary(gen, 4, -0.1), - Catch::Matchers::Contains("Sparsity must be between 0 and 1.")); - REQUIRE_THROWS_WITH( - matrix.makeSparseUnitary(gen, 4, 1.1), - Catch::Matchers::Contains("Sparsity must be between 0 and 1.")); + REQUIRE_THROWS_WITH(matrix.makeSparseUnitary(gen, 4, -0.1), + Catch::Matchers::ContainsSubstring( + "Sparsity must be between 0 and 1.")); + REQUIRE_THROWS_WITH(matrix.makeSparseUnitary(gen, 4, 1.1), + Catch::Matchers::ContainsSubstring( + "Sparsity must be between 0 and 1.")); } SECTION("SparseMatrixCSR: Make sparse unitary") { diff --git a/pennylane_lightning/core/utils/tests/Test_TypeTraits.cpp b/pennylane_lightning/core/utils/tests/Test_TypeTraits.cpp index 45a43636df..1984832112 100644 --- a/pennylane_lightning/core/utils/tests/Test_TypeTraits.cpp +++ b/pennylane_lightning/core/utils/tests/Test_TypeTraits.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "TypeTraits.hpp" -#include +#include #include #include diff --git a/pennylane_lightning/core/utils/tests/Test_Util.cpp b/pennylane_lightning/core/utils/tests/Test_Util.cpp index f23b908df1..cd8475608e 100644 --- a/pennylane_lightning/core/utils/tests/Test_Util.cpp +++ b/pennylane_lightning/core/utils/tests/Test_Util.cpp @@ -18,7 +18,8 @@ #include "TestHelpers.hpp" #include "Util.hpp" -#include +#include +#include /// @cond DEV namespace { @@ -262,7 +263,7 @@ TEST_CASE("Util::createRandomWiresSubset", "[createRandomWiresSubset]") { REQUIRE_THROWS_WITH( createRandomWiresSubset(re, sv_num_qubits, unitary_num_qubits), - Catch::Matchers::Contains( + Catch::Matchers::ContainsSubstring( "If unitary_num_qubits > sv_num_qubits, the " "internal while loop will go on forever.")); } diff --git a/pennylane_lightning/core/utils/tests/Test_UtilLinearAlg.cpp b/pennylane_lightning/core/utils/tests/Test_UtilLinearAlg.cpp index 3e8faa284b..c6e3555655 100644 --- a/pennylane_lightning/core/utils/tests/Test_UtilLinearAlg.cpp +++ b/pennylane_lightning/core/utils/tests/Test_UtilLinearAlg.cpp @@ -19,7 +19,7 @@ #include "TestHelpers.hpp" #include "UtilLinearAlg.hpp" -#include +#include /// @cond DEV namespace { diff --git a/pennylane_lightning/core/utils/tests/mpi/Test_MPIManager.cpp b/pennylane_lightning/core/utils/tests/mpi/Test_MPIManager.cpp index e4b853ca4a..22041f180e 100644 --- a/pennylane_lightning/core/utils/tests/mpi/Test_MPIManager.cpp +++ b/pennylane_lightning/core/utils/tests/mpi/Test_MPIManager.cpp @@ -19,7 +19,8 @@ #include #include -#include +#include +#include #include "MPIManager.hpp" @@ -55,8 +56,9 @@ TEMPLATE_TEST_CASE("MPIManager::getMPIDatatype", "[MPIManager]", float, SECTION("Test invalid type") { // This should throw an exception - REQUIRE_THROWS_WITH(mpi_manager.getMPIDatatype(), - Catch::Matchers::Contains("Type not supported")); + REQUIRE_THROWS_WITH( + mpi_manager.getMPIDatatype(), + Catch::Matchers::ContainsSubstring("Type not supported")); } } @@ -187,7 +189,7 @@ TEMPLATE_TEST_CASE("MPIManager::Reduce", "[MPIManager]", float, double) { std::vector recvBuf(1, {0, 0}); REQUIRE_THROWS_WITH( mpi_manager.Reduce(sendBuf, recvBuf, 0, "SUM"), - Catch::Matchers::Contains("Op not supported")); + Catch::Matchers::ContainsSubstring("Op not supported")); } SECTION("Catch failures caused by unsupported ops") { @@ -195,7 +197,7 @@ TEMPLATE_TEST_CASE("MPIManager::Reduce", "[MPIManager]", float, double) { std::vector recvBuf(1, "test"); REQUIRE_THROWS_WITH( mpi_manager.Reduce(sendBuf, recvBuf, 0, "SUM"), - Catch::Matchers::Contains("not supported")); + Catch::Matchers::ContainsSubstring("not supported")); } } diff --git a/pennylane_lightning/core/utils/tests/mpi/runner_utils_mpi.cpp b/pennylane_lightning/core/utils/tests/mpi/runner_utils_mpi.cpp index 3bed64f9d3..1dfe3b5032 100644 --- a/pennylane_lightning/core/utils/tests/mpi/runner_utils_mpi.cpp +++ b/pennylane_lightning/core/utils/tests/mpi/runner_utils_mpi.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include +#include #include int main(int argc, char *argv[]) { diff --git a/pennylane_lightning/core/utils/tests/runner_utils.cpp b/pennylane_lightning/core/utils/tests/runner_utils.cpp index 4ed06df1f7..64ba13906f 100644 --- a/pennylane_lightning/core/utils/tests/runner_utils.cpp +++ b/pennylane_lightning/core/utils/tests/runner_utils.cpp @@ -1,2 +1,3 @@ -#define CATCH_CONFIG_MAIN -#include +#include + +int main(int argc, char *argv[]) { return Catch::Session().run(argc, argv); }