Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Event rate CI #40

Open
wants to merge 65 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
99af6f5
Test commit to see if we can find TDR era inputs
Jan 27, 2025
d6f6acf
Update event rates yaml
Jan 27, 2025
2c2e277
Attempt to mount CVMFS to container
Jan 27, 2025
2f65c6b
Shuffles around CVFMs to let the container mount it
Jan 27, 2025
d4d3f07
remove T2K command we don't need
Jan 27, 2025
8356efa
make -> make install
Jan 27, 2025
d5e3fe2
Use EventRates in src not bin
Jan 27, 2025
84f3926
Move environment setup
Jan 27, 2025
c8592f6
Update baseline error to be 1 rather than -1
Jan 27, 2025
8322a0d
Debugging commit as symlink isn't working
Jan 27, 2025
945056c
Re-arrange workflow (thanks Prof. Chat GPT)
Jan 27, 2025
431eec1
Add ubuntu container as CVMFS runner requires some ubuntu specific in…
Jan 27, 2025
c663e61
Second debugging commit, this will build an ubuntu container for use …
Jan 27, 2025
858e414
Add more debug info
Jan 27, 2025
44578b0
remove debugging info from CI workflow
Jan 27, 2025
67518da
more rearranging
Jan 27, 2025
4df26c0
Use ubuntu container
Jan 27, 2025
a9e2d3d
Properly mount CVMFS (hopefully...)
Jan 27, 2025
470f9f3
More playing around with the container
Jan 27, 2025
cdf19f5
Docker build->docker run
Jan 27, 2025
5933177
More moving of docker options
Jan 27, 2025
11349c7
docker build needed directory path
Jan 27, 2025
18a49c2
Attempt to neaten workflow to work out why ROOT doesn't mount properly
Jan 27, 2025
4f31ada
hyper hack, move everything into the same workflow...
Jan 27, 2025
e7e3ea5
Add more instructions to repo, possibly useful to have single script …
Jan 28, 2025
012d3d1
Almost there, workflow just needed some more bugs fixed
Jan 28, 2025
cec6f2f
Another debug, this will fail to build
Jan 28, 2025
4db3ae8
More debugging to work out where the container has put ROOT
Jan 28, 2025
ec05737
Another attempt to run this workflow
Jan 28, 2025
da3f71e
Workflow now works, removes debugging code
Jan 28, 2025
0fe9093
Was overzealous with env paths
Jan 28, 2025
ec4e51d
Accidentally broke the yaml...
Jan 28, 2025
13df171
Agggh ubuntu
Jan 28, 2025
8959254
By default Ubuntu doesnt ues a bash shell, this should fix that
Jan 28, 2025
d0135f6
tweaks to dockerfile to (hopefully) use bash
Jan 28, 2025
f99011f
Move around shell
Jan 28, 2025
ef2b87d
debugging
Jan 28, 2025
1961c07
lets try alma9 instead
Jan 28, 2025
494af4b
AGHHH
Jan 28, 2025
1a718a7
specifies shell
Jan 28, 2025
2ada4a7
fix bug in baseline
Jan 28, 2025
1bd464e
Remove unecessary root source
Jan 28, 2025
d61c906
wrong branch being pulled
Jan 28, 2025
3dc1dfc
Event rates now runs BUT uses the wrong oscillator
Jan 28, 2025
4b7ed40
Also needed the docker image...
Jan 28, 2025
2a7b9cf
Small typo
Jan 28, 2025
d91dc81
Attmpt to avoid using CUDA
Jan 28, 2025
7d9337e
I'm so dumb, oscillator is set in the configs now
Jan 28, 2025
a06d5d9
DEBUG: reduces number of samples briefly
Jan 28, 2025
77af813
remove debugging from workflow, set config file back to normal
Jan 28, 2025
ab65757
Adds event rates CI and example test result for beam sample
Jan 29, 2025
d2c6da1
oops, forgot to actually make it run checks
Jan 29, 2025
fd55175
Update the YAML to point to correct folders
Jan 29, 2025
c7b00ee
More updates to yaml
Jan 29, 2025
78c2f92
Small updates to test code as output format wasnt quite correct
Jan 29, 2025
567e9f1
DEBUG: Check files are being linked correctly (sorry for more spam)
Jan 29, 2025
c0de0be
Attempt workflow with TDR V1 as V2 files seem to not work with action…
henry-wallace-phys Jan 29, 2025
080220f
More debugging
henry-wallace-phys Jan 29, 2025
a81a354
Very dumb bug, didn't remove mkdir from workflow
henry-wallace-phys Jan 29, 2025
a9f7da6
Hopefully works, from re-running https://github.com/DUNE/MaCh3_DUNE/a…
Jan 30, 2025
e6d0d43
Remove debugging
Jan 30, 2025
7881570
Merge branch 'develop' into hwallace/feature/event_rate_bot
henry-wallace-phys Jan 30, 2025
f8e990e
Git pointing to wrong branch when CI called on PRs
Jan 30, 2025
f1db3cf
Final commit to event rates CI just to make it even more flexible
henry-wallace-phys Feb 3, 2025
6449c06
merge
Mar 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/CDImage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
# Update MaCh3 container image registry with newest updates
name: Image CD

Expand Down Expand Up @@ -66,4 +65,4 @@ jobs:
package-name: 'mach3'
package-type: 'container'
min-versions-to-keep: 5
delete-only-untagged-versions: 'true'
delete-only-untagged-versions: 'true'
1 change: 0 additions & 1 deletion .github/workflows/CIBuild.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
# Check if MaCh3 compiles correctly

name: Build CI
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/EventRates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Event Rates Beam

# To add additional run-time tests add (to matrix)
# - name: <your test>
# test_exe: /test/<your exe>
# test_config: path/to/tconfiguration
# repo_linking_command: ln -sf /path/to/files/ (usually CAFs + splines)


on:
pull_request:
branches: [develop]

permissions:
contents: read
packages: write

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: Beam Event Rate Validation
test_exe: /test/TestEventRates
test_config: test/test_configs/EventRates_Beam_TEST.yaml
repo_linking_command: |
ln -s \
/cvmfs/dune.osgstorage.org/pnfs/fnal.gov/usr/dune/persistent/stash/MaCh3/inputs/TDR/v2/DUNE_2021_FD_splines inputs/DUNE_spline_files
ln -s \
/cvmfs/dune.osgstorage.org/pnfs/fnal.gov/usr/dune/persistent/stash/MaCh3/inputs/TDR/v2/DUNE_2023_FD_CAFs inputs/DUNE_CAF_files



name: Run Test ${{matrix.name}}

steps:
# Set up CVMFS
- name: Set up CVMFS
uses: cvmfs-contrib/github-action-cvmfs@v4


# Checkout the repository code
- uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: start docker container with bind mount cvmfs
run: |
docker build . \
--file doc/MaCh3DockerFiles/Alma9/Dockerfile \
--tag ghcr.io/dune/mach3:alma9test \
--build-arg MACH3_DUNE_VERSION=${{ github.head_ref }} \
--build-arg MACH3_DUNE_BUILD_ARGS="-DCUDAProb3Linear_ENABLED=ON -DMACH3_BUILD_TESTS=ON"


# Run event rates
- name: Run Event Rates
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/dune/mach3:alma9test
shell: bash
options: -v /cvmfs:/cvmfs:shared
run: |
${{matrix.repo_linking_command}}
source ./bin/setup.MaCh3.sh
source ./bin/setup.NuOscillator.sh
source ./bin/setup.MaCh3DUNE.sh
.${{matrix.test_exe}} ${{matrix.test_config}}
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ add_subdirectory(splines)
add_subdirectory(samplePDFDUNE)
add_subdirectory(src)


# Do we want to build our integration tests?
if(DEFINED MACH3_BUILD_TESTS AND MACH3_BUILD_TESTS)
add_subdirectory(tests)
endif()


add_library(MaCh3DUNEAll INTERFACE)
set_target_properties(MaCh3DUNEAll PROPERTIES EXPORT_NAME All)
target_link_libraries(MaCh3DUNEAll INTERFACE SamplePDFDUNE splinesDUNE MaCh3DUNECompilerOptions)
Expand Down
4 changes: 1 addition & 3 deletions configs/CovObjs/OscCov_PDG2021_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ Systematics:
Names:
FancyName: baseline
ParameterName: baseline


DetID: 984
Error: -1.0
Error: 1.0
FlatPrior: true
ParameterBounds: [0, 999]
ParameterGroup: Osc
Expand Down
3 changes: 2 additions & 1 deletion doc/MaCh3DockerFiles/Alma9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ENV MACH3_DUNE_VERSION=${MACH3_DUNE_VERSION:-develop}
ENV MACH3_DUNE_WORK_DIR=/opt/MaCh3DUNE/
ENV MACH3_DUNE_INSTALL_DIR=${MACH3_DUNE_WORK_DIR}/build

ARG MACH3_DUNE_BUILD_ARGS

RUN git clone https://github.com/DUNE/MaCh3_DUNE.git ${MACH3_DUNE_WORK_DIR}

Expand All @@ -17,6 +18,6 @@ RUN git checkout ${MACH3_DUNE_VERSION}
RUN mkdir -p ${MACH3_DUNE_INSTALL_DIR}
WORKDIR ${MACH3_DUNE_INSTALL_DIR}

RUN cmake ../
RUN cmake ../ ${MACH3_DUNE_BUILD_ARGS}

RUN make -j && make install
11 changes: 11 additions & 0 deletions doc/MaCh3DockerFiles/Ubuntu22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#To run use: docker build --secret id=tokens,src=tokens.txt -t mach3dune .
FROM rootproject/root:6.32.02-ubuntu22.04 AS mach3_dune_build

# Let's be smart and use bash...
SHELL ["/bin/bash", "-c"]

# Add a label for the author
LABEL maintainer="The MaCh3 Collaboration"
LABEL website="https://dune.github.io/MaCh3_DUNE/"
LABEL compiler="GNU 11.4.0"
LABEL root_version="v6.32.02"
LABEL org.opencontainers.image.description="Official MaCh3 DUNE container"


RUN apt update && apt upgrade -y
RUN apt-get install -y nlohmann-json3-dev
#MISC_SW
Expand Down
49 changes: 49 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
add_custom_target(MaCh3DUNETests)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the entire tests directory if you use the github workflow text comparison script that I use in NuOscillator: https://github.com/dbarrow257/NuOscillator/blob/01bee0dfcee824524b81147853faea6be4a77f65/.github/workflows/CIValidations2.yml#L100-L106

Then you don't need the Comparison.{cpp,h} stuff. We should also force event rate CI checks, not allow them to be skipable


# Wet up utils lib
set(HEADERS
Comparison.h
)

add_library(
MaCh3DuneTestUtils SHARED
Comparison.cpp
)

set_target_properties(MaCh3DuneTestUtils PROPERTIES
PUBLIC_HEADER "${HEADERS}"
EXPORT_NAME MaCh3DuneTestUtils
)

target_link_libraries(MaCh3DuneTestUtils PUBLIC MaCh3::All MaCh3DUNECompilerOptions)

target_include_directories(MaCh3DuneTestUtils PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>
$<INSTALL_INTERFACE:include>)

install(TARGETS MaCh3DuneTestUtils
EXPORT mach3dune-targets
LIBRARY DESTINATION lib/
PUBLIC_HEADER DESTINATION include/MaCh3DuneTestUtils)

add_library(MACH3DUNE::MaCh3DuneTestUtils ALIAS MaCh3DuneTestUtils)


# Now we set up test apps
foreach(app
TestEventRates
)

add_executable(${app} ${app}.cpp)
target_link_libraries(${app} MaCh3DUNE::All MaCh3DuneTestUtils Minuit)
add_dependencies(MaCh3DUNEApps ${app})
install(TARGETS ${app} DESTINATION test)

endforeach(app)


# Now copy remaining stuff
install(DIRECTORY test_configs DESTINATION test)
install(DIRECTORY test_results DESTINATION test)


50 changes: 50 additions & 0 deletions tests/Comparison.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// MaCh3 spline includes
#include "tests/Comparison.h"

bool CompareTwoFiles(const std::string& File1, const std::string& File2) {
std::ifstream file1(File1);
std::ifstream file2(File2);

// Check if both files opened successfully
if (!file1.is_open()) {
MACH3LOG_ERROR("Error opening file: {}", File1);
throw MaCh3Exception(__FILE__ , __LINE__ );
}
if (!file2.is_open()) {
MACH3LOG_ERROR("Error opening file: {}", File2);
throw MaCh3Exception(__FILE__ , __LINE__ );
}

std::string line1, line2;
bool sameFiles = true;
int lineNumber = 1;

// Read and compare line by line
while (std::getline(file1, line1) && std::getline(file2, line2)) {
if (line1 != line2) {
MACH3LOG_WARN("Difference found on line {}:", lineNumber);
MACH3LOG_WARN("File1: {}", line1);
MACH3LOG_WARN("File2: {}", line2);
sameFiles = false;
}
++lineNumber;
}

// Check if one file has extra lines
while (std::getline(file1, line1)) {
MACH3LOG_WARN("Extra line in {} on line {}: {}", File1, lineNumber, line1);
sameFiles = false;
++lineNumber;
}
while (std::getline(file2, line2)) {
MACH3LOG_WARN("Extra line in {} on line {}: {}", File2, lineNumber, line2);
sameFiles = false;
++lineNumber;
}

// Close files
file1.close();
file2.close();

return sameFiles;
}
5 changes: 5 additions & 0 deletions tests/Comparison.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "manager/manager.h"

bool CompareTwoFiles(const std::string& File1, const std::string& File2);
111 changes: 111 additions & 0 deletions tests/TestEventRates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <iostream>
#include <chrono>
#include <iomanip>
#include <vector>
#include <string>

#include <TH1D.h>
#include <THStack.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TRint.h>
#include <TLegend.h>
#include <TColor.h>
#include <TMath.h>

#include "samplePDFDUNE/MaCh3DUNEFactory.h"
#include "samplePDFDUNE/StructsDUNE.h"
#include "tests/Comparison.h"


int main(int argc, char * argv[]) {
MaCh3Utils::MaCh3Usage(argc, argv);

auto fitMan = std::unique_ptr<manager>(new manager(argv[1]));

bool skip_checks = false;

if (CheckNodeExists(fitMan->raw(), "General", "Tests", "SkipChecks") ){
skip_checks = fitMan->raw()["General"]["Tests"]["SkipChecks"].as<bool>();
}

//###############################################################################################################################
//Create samplePDFFD objects

covarianceXsec* xsec = nullptr;
covarianceOsc* osc = nullptr;

std::vector<samplePDFFDBase*> DUNEPdfs;
MakeMaCh3DuneInstance(fitMan.get(), DUNEPdfs, xsec, osc);


//###############################################################################################################################
//Perform reweight and print total integral
//###############################################################################################################################
//Make oscillation channel breakdown
// Initialise output file
std::ofstream outFile("TestNewSampleOut.txt");


for(auto Sample : DUNEPdfs) {
int nOscChannels = Sample->getNMCSamples();
for (int iOscChan=0;iOscChan<nOscChannels;iOscChan++) {
std::vector< std::vector<double> > SelectionVec;

std::vector<double> SelecChannel(3);
SelecChannel[0] = Sample->ReturnKinematicParameterFromString("OscChannel");
SelecChannel[1] = iOscChan;
SelecChannel[2] = iOscChan+1;
SelectionVec.push_back(SelecChannel);

TH1* Hist = Sample->get1DVarHist("TrueNeutrinoEnergy",SelectionVec);
outFile<<Sample->GetName()<<" "<<Sample->getFlavourName(iOscChan)<<" "<<Hist->Integral()<<" ";
}

TH1* Hist = Sample->get1DVarHist("TrueNeutrinoEnergy");
outFile<<Sample->GetName()<<" "<<Hist->Integral()<<" ";
}

//###############################################################################################################################
//Make interaction channel breakdown

for(auto Sample : DUNEPdfs) {
int nModeChannels = kMaCh3_nModes;
for (int iModeChan=0;iModeChan<nModeChannels;iModeChan++) {
std::vector< std::vector<double> > SelectionVec;

std::vector<double> SelecChannel(3);
SelecChannel[0] = Sample->ReturnKinematicParameterFromString("Mode");
SelecChannel[1] = iModeChan;
SelecChannel[2] = iModeChan+1;
SelectionVec.push_back(SelecChannel);

TH1* Hist = Sample->get1DVarHist("TrueNeutrinoEnergy",SelectionVec);
outFile<<Sample->GetName()<<" "<<MaCh3mode_ToDUNEString((MaCh3_Mode)iModeChan)<<" "<<Hist->Integral()<<" ";
}

TH1* Hist = Sample->get1DVarHist("TrueNeutrinoEnergy");
outFile<<Sample->GetName()<<" "<<Hist->Integral()<<" ";
}

// Do you want to gener
if(skip_checks){
return 0;
}

std::string results_file = fitMan->raw()["General"]["Tests"]["TestResultsFile"].as<std::string>();


// Okay now we've written we need to compare
bool TheSame = CompareTwoFiles(results_file, "TestNewSampleOut.txt");

// Are we right?
if(!TheSame) {
MACH3LOG_CRITICAL("Different event rates detected");
throw MaCh3Exception(__FILE__ , __LINE__ );
} else {
MACH3LOG_INFO("Event rates match");
}

return 0;
}
Loading