diff --git a/CIValidations/Benchmark/CMakeLists.txt b/CIValidations/Benchmark/CMakeLists.txt new file mode 100644 index 0000000..0e5a87c --- /dev/null +++ b/CIValidations/Benchmark/CMakeLists.txt @@ -0,0 +1,8 @@ +foreach(TEST + MaCh3Benchmark + ) + + add_executable(${TEST} ${TEST}.cpp) + target_link_libraries(${TEST} PRIVATE Catch2::Catch2WithMain MaCh3::All MaCh3Tutorial::samplePDFTutorial) + catch_discover_tests(${TEST}) +endforeach() diff --git a/CIValidations/Benchmark/MaCh3Benchmark.cpp b/CIValidations/Benchmark/MaCh3Benchmark.cpp new file mode 100755 index 0000000..6460e30 --- /dev/null +++ b/CIValidations/Benchmark/MaCh3Benchmark.cpp @@ -0,0 +1,38 @@ +// MaCh3 spline includes +#include "mcmc/MaCh3Factory.h" +#include "samplePDF/samplePDFTutorial.h" + +#include "catch2/catch_test_macros.hpp" +#include "catch2/benchmark/catch_benchmark.hpp" + +TEST_CASE("Benchmark MaCh3") { + // Initialise manger responsible for config handling + auto FitManager = std::make_unique("Inputs/FitterConfig.yaml"); + + // Initialise covariance class reasonable for Systematics + covarianceXsec* xsec = MaCh3CovarianceFactory(FitManager.get(), "Xsec"); + covarianceOsc* osc = MaCh3CovarianceFactory(FitManager.get(), "Osc"); + + // Initialise samplePDF + auto SampleConfig = FitManager->raw()["General"]["TutorialSamples"].as>(); + auto mySamples = MaCh3SamplePDFFactory(SampleConfig, xsec, osc); + + // Create MCMC Class + std::unique_ptr MaCh3Fitter = MaCh3FitterFactory(FitManager.get()); + // Add covariance to MCM + MaCh3Fitter->addSystObj(xsec); + MaCh3Fitter->addSystObj(osc); + for (size_t i = 0; i < SampleConfig.size(); ++i) { + MaCh3Fitter->addSamplePDF(mySamples[i]); + } + // Benchmark + BENCHMARK("MaCh3Fitter::DragRace") { + MaCh3Fitter->DragRace(1); + }; + + delete xsec; + delete osc; + for (size_t i = 0; i < SampleConfig.size(); ++i) { + delete mySamples[i]; + } +} diff --git a/CIValidations/CMakeLists.txt b/CIValidations/CMakeLists.txt index 9de8b3b..0e20ec0 100755 --- a/CIValidations/CMakeLists.txt +++ b/CIValidations/CMakeLists.txt @@ -39,3 +39,7 @@ install(DIRECTORY if(MaCh3Tutorial_UNITTESTS_ENABLED) add_subdirectory(UnitTests) endif() + +if(MaCh3Tutorial_Benchmark_ENABLED) + add_subdirectory(Benchmark) +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index b7972b3..5862819 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ file( ) include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake) +include(CIValidations) + ################################## MaCh3 ###################################### # KS: Here we try to find tag matching tutorial version. If we can't find one then use develop # This will allow to grab tutorial for tagged MaCh3 version without a need of manually changing version @@ -67,13 +69,30 @@ if(NOT DEFINED PYTHON_ENABLED) SET(PYTHON_ENABLED false) endif() if(NOT MaCh3_FOUND) + + set(MaCh3_OPTIONS + "MaCh3_PYTHON_ENABLED ${PYTHON_ENABLED}" + ) + + # KS: For benchmark we turn off logger to not interfere with output messages. + # Also to have code compile let's turn off Werror + if (MaCh3Tutorial_Benchmark_ENABLED) + list(APPEND MaCh3_OPTIONS "MaCh3_WERROR_ENABLED OFF") + set(LOG_LEVEL "OFF") + endif() + + # Add LOG_LEVEL if defined + if (DEFINED LOG_LEVEL) + list(APPEND MaCh3_OPTIONS "LOG_LEVEL ${LOG_LEVEL}") + endif() + CPMAddPackage( NAME MaCh3 GIT_TAG ${MaCh3_Branch} GIT_SHALLOW YES GITHUB_REPOSITORY mach3-software/MaCh3 OPTIONS - "MaCh3_PYTHON_ENABLED ${PYTHON_ENABLED}" + ${MaCh3_OPTIONS} "Prob3ppLinear_ENABLED ON" "NuFastLinear_ENABLED ON" ) @@ -92,8 +111,6 @@ if(MaCh3_VERSION GREATER MaCh3Tutorial_VERSION) cmessage(WARNING "MaCh3Tutorial_VERSION (${MaCh3Tutorial_VERSION}) is smaller than MaCh3_VERSION (${MaCh3_VERSION}), this most likely will not work") endif() -include(CIValidations) - ############################ C++ Compiler #################################### get_property(MACH3_CXX_STANDARD GLOBAL PROPERTY MACH3_CXX_STANDARD) if(NOT DEFINED MACH3_CXX_STANDARD) diff --git a/cmake/Modules/CIValidations.cmake b/cmake/Modules/CIValidations.cmake index ce7f232..5af2b61 100755 --- a/cmake/Modules/CIValidations.cmake +++ b/cmake/Modules/CIValidations.cmake @@ -1,5 +1,6 @@ option(MaCh3Tutorial_UNITTESTS_ENABLED "Whether to build MaCh3 Unit Tests" OFF) -option(MaCh3Tutorial_Coverage_ENABLED "Whether to build MaCh3 Coverage " OFF) +option(MaCh3Tutorial_Coverage_ENABLED "Whether to build MaCh3 Coverage" OFF) +option(MaCh3Tutorial_Benchmark_ENABLED "Enable benchmarking" ON) # WARNING FIXME CPMAddPackage( NAME NuMCMCTools @@ -14,7 +15,7 @@ install(DIRECTORY DESTINATION ${CMAKE_BINARY_DIR}/NuMCMCTools) ############################ Catch2/CTest #################################### -if(MaCh3Tutorial_UNITTESTS_ENABLED) +if(MaCh3Tutorial_UNITTESTS_ENABLED OR MaCh3Tutorial_Benchmark_ENABLED) find_package(Catch2 QUIET) if(NOT Catch2_FOUND) CPMAddPackage("gh:catchorg/Catch2@3.5.2")