From d5955865c6fd05e9f8adaef56bfbb7bb3c89b1a7 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Fri, 6 Feb 2026 13:02:10 +0000 Subject: [PATCH 1/4] add benachmark for Parameter handler --- CIValidations/Benchmark/MaCh3Benchmark.cpp | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/CIValidations/Benchmark/MaCh3Benchmark.cpp b/CIValidations/Benchmark/MaCh3Benchmark.cpp index 5dd1316..f7d38ff 100755 --- a/CIValidations/Benchmark/MaCh3Benchmark.cpp +++ b/CIValidations/Benchmark/MaCh3Benchmark.cpp @@ -5,6 +5,39 @@ #include "catch2/catch_test_macros.hpp" #include "catch2/benchmark/catch_benchmark.hpp" +void CreateChungusYaml(const std::string& filename = "ChungusSystematics.yaml", + size_t nParams = 5000) +{ + std::ofstream out(filename); + if (!out.is_open()) { + throw std::runtime_error("Failed to open YAML file for writing"); + } + out << "Systematics:\n\n"; + + for (size_t i = 0; i < nParams; ++i) { + double error = 0.10; + double step_scale = 0.2; + out << "- Systematic:\n"; + out << " Names:\n"; + out << " FancyName: Norm_Param_" << i << "\n"; + out << " Error: " << error << "\n"; + out << " FlatPrior: false\n"; + out << " FixParam: false\n"; + out << " Mode: [ 1 ]\n"; + out << " ParameterBounds: [0, 999.]\n"; + out << " ParameterGroup: Xsec\n"; + out << " TargetNuclei: [12, 16]\n"; + out << " KinematicCuts:\n"; + out << " ParameterValues:\n"; + out << " Generated: 1.\n"; + out << " PreFitValue: 1.\n"; + out << " SampleNames: [\"Tutorial_*\", \"ND2137\"]\n"; + out << " StepScale:\n"; + out << " MCMC: "<< step_scale <<"\n"; + out << " Type: Norm\n\n"; + } +} + TEST_CASE("Benchmark MaCh3") { // Initialise manger responsible for config handling auto FitManager = std::make_unique("TutorialConfigs/FitterConfig.yaml"); @@ -63,6 +96,16 @@ TEST_CASE("Benchmark MaCh3") { } }; + + CreateChungusYaml("ChungusSystematics.yaml", 2000); + auto Chungus = std::make_unique(std::vector{"ChungusSystematics.yaml"}, "xsec_cov"); + + BENCHMARK("ParameterHandler Operations") { + Chungus->ProposeStep(); + Chungus->GetLikelihood(); + Chungus->AcceptStep(); + }; + for (size_t i = 0; i < NDSamples.size(); ++i) { delete NDSamples[i]; } From 8d287236b2f502ebc620b72f96a7ade6f1e8bce0 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Fri, 6 Feb 2026 22:04:19 +0000 Subject: [PATCH 2/4] add RAM tracker --- CIValidations/Benchmark/MaCh3Benchmark.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/CIValidations/Benchmark/MaCh3Benchmark.cpp b/CIValidations/Benchmark/MaCh3Benchmark.cpp index f7d38ff..dfa4fca 100755 --- a/CIValidations/Benchmark/MaCh3Benchmark.cpp +++ b/CIValidations/Benchmark/MaCh3Benchmark.cpp @@ -38,6 +38,42 @@ void CreateChungusYaml(const std::string& filename = "ChungusSystematics.yaml", } } +std::string FormatMB(double value, int precision) +{ + std::ostringstream ss; + ss << std::fixed << std::setprecision(precision) << value << " MB"; + return ss.str(); +} + +/// @brief This is super hacky but Catch2 doesn't support RAM printing only time... +void PrintRAMBenchmark(const std::string& name) +{ + double ram = MaCh3Utils::getValue("VmRSS") / 1024.0; + + std::cout << "\n"; + + // Main row + std::cout << std::left << std::setw(40) << name + << std::right << std::setw(10) << 100 + << std::right << std::setw(14) << 1 + << std::right << std::setw(11) << std::fixed << std::setprecision(3) + << ram << " MB\n"; + + // Mean row + std::cout << std::left << std::setw(40) << " " + << std::right << std::setw(10) << FormatMB(ram, 3) + << std::right << std::setw(14) << FormatMB(ram, 3) + << std::right << std::setw(11) << std::fixed << std::setprecision(3) + << ram << " MB\n"; + + // Std dev row + std::cout << std::left << std::setw(40) << " " + << std::right << std::setw(10) << FormatMB(0.0, 5) + << std::right << std::setw(14) << FormatMB(0.0, 5) + << std::right << std::setw(11) << std::fixed << std::setprecision(5) + << 0.00000 << " MB\n"; +} + TEST_CASE("Benchmark MaCh3") { // Initialise manger responsible for config handling auto FitManager = std::make_unique("TutorialConfigs/FitterConfig.yaml"); @@ -96,6 +132,8 @@ TEST_CASE("Benchmark MaCh3") { } }; + // Get RAM table BEFORE starting chungus + PrintRAMBenchmark("RAM tracker"); CreateChungusYaml("ChungusSystematics.yaml", 2000); auto Chungus = std::make_unique(std::vector{"ChungusSystematics.yaml"}, "xsec_cov"); From 900dc4969c37eb26d077ebfecdca9be117ed32c8 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Fri, 6 Feb 2026 22:10:24 +0000 Subject: [PATCH 3/4] simple test for low memory struct --- .github/workflows/CIValidations.yml | 44 +++++++++-------------------- CMakeLists.txt | 10 +++++++ 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/.github/workflows/CIValidations.yml b/.github/workflows/CIValidations.yml index df39744..52727d0 100644 --- a/.github/workflows/CIValidations.yml +++ b/.github/workflows/CIValidations.yml @@ -22,24 +22,24 @@ jobs: matrix: include: - name: Reweight Validations - test_1: MaCh3CLI --ReweightValidations - test_2: empty - test_3: empty + test: MaCh3CLI --ReweightValidations + compilation_flags: - name: Covariance Validations - test_1: MaCh3CLI --CovarianceValidations - test_2: empty - test_3: empty + test: MaCh3CLI --CovarianceValidations + compilation_flags: - name: Fitter Validations - test_1: MaCh3CLI --FitterValidations - test_2: empty - test_3: empty + test: MaCh3CLI --FitterValidations + compilation_flags: - name: NuMCMC Tools Validations - test_1: MaCh3CLI --NuMCMCToolsValidations - test_2: empty - test_3: empty + test: MaCh3CLI --NuMCMCToolsValidations + compilation_flags: + + - name: Fitter Validations Low Memory + test: MaCh3CLI --FitterValidations + compilation_flags: -DMaCh3Tutorial_DEBUG_ENABLED=ON -DMaCh3Tutorial_LOW_MEMORY_STRUCTS_ENABLED=ON container: image: ghcr.io/mach3-software/mach3:alma9v1.3.0 @@ -55,7 +55,7 @@ jobs: cd MaCh3Validations mkdir build cd build - cmake ../ -DMaCh3Tutorial_UNITTESTS_ENABLED=TRUE + cmake ../ -DMaCh3Tutorial_UNITTESTS_ENABLED=TRUE ${{ matrix.compilation_flags }} - name: Build MaCh3 Validations run: | @@ -68,20 +68,4 @@ jobs: source /opt/MaCh3Validations/build/bin/setup.MaCh3Tutorial.sh cd /opt/MaCh3Validations/build/CIValidations - ${{ matrix.test_1 }} - - #KS: GHA is stupid when it comes to arrays. I tried something fancy but it was crashing terribly - #If you know how to write this better please let me know - - # Run the second test if it is defined - if [[ "${{ matrix.test_2 }}" != "empty" ]]; then - echo " " - echo "Performing Second test" - ${{ matrix.test_2 }} - fi - # Run the third test if it is defined - if [[ "${{ matrix.test_3 }}" != "empty" ]]; then - echo " " - echo "Performing Third test" - ${{ matrix.test_3 }} - fi + ${{ matrix.test }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ee3a91..34877e1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,8 @@ include(CIValidations) option(MaCh3_CPM "Whether MaCh3 was obtained using CPM or find_package" OFF) option(MaCh3Tutorial_PROFILING_ENABLED "Will run with gperftools" OFF) option(Use_External_MaCh3 "Use an externally installed MaCh3 instead of CPM" OFF) +option(MaCh3Tutorial_DEBUG_ENABLED "Use debug options" OFF) +option(MaCh3Tutorial_LOW_MEMORY_STRUCTS_ENABLED "Use floats" OFF) # 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 @@ -93,6 +95,14 @@ if(NOT MaCh3_FOUND) list(APPEND MaCh3_OPTIONS "MaCh3_NATIVE_ENABLED ON") endif() + if (MaCh3Tutorial_DEBUG_ENABLED) + list(APPEND MaCh3_OPTIONS "MaCh3_DEBUG_ENABLED ON") + endif() + + if (MaCh3Tutorial_LOW_MEMORY_STRUCTS_ENABLED) + list(APPEND MaCh3_OPTIONS "MaCh3_LOW_MEMORY_STRUCTS_ENABLED ON") + endif() + CPMAddPackage( NAME MaCh3 GIT_TAG ${MaCh3_Branch} From 4a831fcfdd6d7b6919d2d88f4ba06f01a47d2cee Mon Sep 17 00:00:00 2001 From: Kamil <45295406+KSkwarczynski@users.noreply.github.com> Date: Fri, 6 Feb 2026 22:23:28 +0000 Subject: [PATCH 4/4] Update Fitter Validations compilation flags Removed debug flag from Fitter Validations Low Memory test. --- .github/workflows/CIValidations.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CIValidations.yml b/.github/workflows/CIValidations.yml index 52727d0..43de4d1 100644 --- a/.github/workflows/CIValidations.yml +++ b/.github/workflows/CIValidations.yml @@ -39,7 +39,7 @@ jobs: - name: Fitter Validations Low Memory test: MaCh3CLI --FitterValidations - compilation_flags: -DMaCh3Tutorial_DEBUG_ENABLED=ON -DMaCh3Tutorial_LOW_MEMORY_STRUCTS_ENABLED=ON + compilation_flags: -DMaCh3Tutorial_LOW_MEMORY_STRUCTS_ENABLED=ON container: image: ghcr.io/mach3-software/mach3:alma9v1.3.0