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

ci: Add tests in pyhf-validation-root-base Docker image #9

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,46 @@ jobs:
file: ./coverage.xml
flags: unittests

test-ROOT-6_22-Py-3_8:

runs-on: ubuntu-latest
container: pyhf/pyhf-validation-root-base:root6.22.02-python3.8

steps:
- uses: actions/checkout@master
- name: Install utilities
# git init done as the .git directory seems
# to be missing after the checkout
run: |
apt-get -qq -y update
apt-get -qq -y install shellcheck
git init .
- name: Lint with Shellcheck
run: |
shellcheck tests/*.sh
shellcheck scripts/*.sh
- name: Install dependencies
run: |
python -m pip install --upgrade --no-cache-dir pip setuptools wheel
python -m pip install --quiet --no-cache-dir --editable .[complete]
python -m pip list
- name: Test with pytest
run: |
python -m pytest -r sx tests
matthewfeickert marked this conversation as resolved.
Show resolved Hide resolved
- name: Generate ROOT workspace from JSON
run: |
bash scripts/JSON_to_workspace.sh \
sbottom-pallet \
https://www.hepdata.net/record/resource/1408070?view=true \
RegionA/BkgOnly.json \
sbottom_1300_205_60 \
RegionA/workspace_sbottom_1300_205_60.json
- name: Test workspace comparison
run: |
bash tests/test_suite.sh \
sbottom-pallet/xml/config/FitConfig_combined_NormalMeasurement_model.root \
sbottom-pallet/RegionA/workspace_sbottom_1300_205_60.json

docker:

runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
repository: pyhf/pyhf-validation
dockerfile: docker/Dockerfile
tags: latest,root6.20.00,root6.20.00-python3.7
tags: latest,root6.22.02,root6.22.02-python3.8
- name: Build and Publish to Registry with Release Tag
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v1
Expand All @@ -31,5 +31,5 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
repository: pyhf/pyhf-validation
dockerfile: docker/Dockerfile
tags: latest,latest-stable,root6.20.00,root6.20.00-python3.7
tags: latest,latest-stable,root6.22.02,root6.22.02-python3.8
tag_with_ref: true
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM pyhf/pyhf-validation-root-base:root6.20.00-python3.7 as base
FROM pyhf/pyhf-validation-root-base:root6.22.02-python3.8 as base

FROM base as builder
COPY . /code
Expand Down
59 changes: 59 additions & 0 deletions scripts/JSON_to_workspace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

function JSON_to_workspace() {
# 1: the analysis pallet name
# 2: the url of the JSON workspaces
# 3: the background only workspace
# 4: the name of the signal patch
# 5: the patched background + signal workspace
local PALLET_NAME=$1
local HEPDATA_URL=$2
local BACKGROUND_ONLY=$3
local PATCH_NAME=$4
local JSON_WORKSPACE=$5

# Download from HEPData
pyhf contrib download "${HEPDATA_URL}" "${PALLET_NAME}"

# Create a full signal+background workspace
workspace_dir="${BACKGROUND_ONLY%/*}"
pyhf patchset extract \
--name "${PATCH_NAME}" \
--output-file "${PALLET_NAME}/${workspace_dir}/${PATCH_NAME}.json" \
"${PALLET_NAME}/${workspace_dir}/patchset.json"
jsonpatch \
"${PALLET_NAME}/${BACKGROUND_ONLY}" \
"${PALLET_NAME}/${workspace_dir}/${PATCH_NAME}.json" > \
"${PALLET_NAME}/${JSON_WORKSPACE}"

# Convert to ROOT + XML
if [[ -d "${PALLET_NAME}/xml" ]]; then
rm -rf "${PALLET_NAME}/xml"
fi
mkdir "${PALLET_NAME}/xml"
pyhf json2xml \
--output-dir "${PALLET_NAME}/xml" \
"${PALLET_NAME}/${JSON_WORKSPACE}"

# Generate ROOT workspace
hist2workspace "${PALLET_NAME}/xml/FitConfig.xml"
}

function main() {
# 1: the analysis pallet name
# 2: the url of the JSON workspaces
# 3: the background only workspace
# 4: the name of the signal patch
# 5: the patched background + signal workspace
local PALLET_NAME=$1
local HEPDATA_URL=$2
local BACKGROUND_ONLY=$3
local PATCH_NAME=$4
local JSON_WORKSPACE=$5

JSON_to_workspace "${PALLET_NAME}" "${HEPDATA_URL}" "${BACKGROUND_ONLY}" "${PATCH_NAME}" "${JSON_WORKSPACE}"
}

main "$@" || exit 1
2 changes: 1 addition & 1 deletion scripts/compare_fitted_nuisance.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def exhaust_argset(s):
pyhf_param = (
param.replace("alpha_", "")
.replace("gamma_stat_", "staterror_")
.replace("lumi", "Lumi")
.replace("Lumi", "lumi")
.replace("_bin", "")
)

Expand Down
3 changes: 1 addition & 2 deletions scripts/compare_nuisance.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def exhaust_argset(s):
pars_root = [
sub.replace("alpha_", "")
.replace("gamma_stat_", "staterror_")
.replace("gamma_stat_", "staterror_")
.replace("lumi", "Lumi")
.replace("Lumi", "lumi")
.replace("_bin", "")
for sub in pars
]
Expand Down