Skip to content

Commit

Permalink
Merge pull request #1871 from NNPDF/test_python_installation
Browse files Browse the repository at this point in the history
Test python installation with dedicated workflow
  • Loading branch information
scarlehoff committed Jan 19, 2024
2 parents aac4ec9 + df627ba commit 48e8535
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/python_installation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test the python installation

on: [push]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10", "3.11"]
include:
- os: ubuntu-latest
CONDA_OS: linux-64
fail-fast: false
runs-on: ${{ matrix.os }}
env:
NETRC_FILE: ${{ secrets.NETRC_FILE }}
NNPDF_SSH_KEY: ${{ secrets.NNPDF_SSH_KEY }}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
- name: Setup conda and install LHAPDF and pandoc
shell: bash -l {0}
run: |
echo "$NETRC_FILE" | base64 --decode > ~/.netrc
conda install -n base conda-libmamba-solver
conda config --set solver libmamba
conda config --append channels conda-forge
conda config --prepend channels https://packages.nnpdf.science/public
conda config --set show_channel_urls true
conda install lhapdf pandoc
conda activate test
- name: Install nnpdf with testing and qed extras
shell: bash -l {0}
run: |
conda activate test
pip install .[qed,tests]
- name: Test n3fit and validphys
shell: bash -l {0}
run: |
conda activate test
pytest --pyargs --mpl validphys n3fit
2 changes: 1 addition & 1 deletion n3fit/src/n3fit/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def test_preprocessing():
]
]
prefactors = prepro(test_x)
np.testing.assert_allclose(test_prefactors, prefactors)
np.testing.assert_allclose(test_prefactors, prefactors, rtol=1e-6)
36 changes: 23 additions & 13 deletions validphys2/src/validphys/tests/test_plots.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,67 @@
import matplotlib
#This is to fix a weird bug in LHAPDF

# This is to fix a weird bug in LHAPDF
matplotlib.use('agg')

import pytest

from validphys.api import API
from validphys.tests.conftest import PDF, THEORYID, DATA

TOLERANCE_VALUE = 12


@pytest.mark.linux
@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(tolerance=TOLERANCE_VALUE)
def test_plotpdfs():
pdfs = [PDF]
Q = 10
flavours = ['g']
#plot_pdfs returns a generator with (figure, name_hint)
# plot_pdfs returns a generator with (figure, name_hint)
return next(API.plot_pdfs(pdfs=pdfs, Q=Q, flavours=flavours))[0]


@pytest.mark.linux
@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(tolerance=TOLERANCE_VALUE)
def test_dataspecschi2():
dsinpts = [
{'dataset': 'NMC'},
{'dataset': 'ATLASTTBARTOT', 'cfac':['QCD']},
{'dataset': 'CMSZDIFF12', 'cfac':('QCD', 'NRM'), 'sys':10}
{'dataset': 'ATLASTTBARTOT', 'cfac': ['QCD']},
{'dataset': 'CMSZDIFF12', 'cfac': ('QCD', 'NRM'), 'sys': 10},
]
dataspecs = [
{'pdf': PDF, 'theoryid': THEORYID, 'speclabel': 'no t0'},
{'pdf': PDF, 'theoryid': THEORYID, 'use_t0': False, 'speclabel': 'with t0'}
{'pdf': PDF, 'theoryid': THEORYID, 'use_t0': False, 'speclabel': 'with t0'},
]
return API.plot_dataspecs_datasets_chi2(
dataset_inputs=dsinpts,
dataspecs=dataspecs,
use_cuts='internal',
metadata_group='experiment'
metadata_group='experiment',
)


@pytest.mark.linux
@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(tolerance=TOLERANCE_VALUE)
def test_plot_smpdf(single_data_internal_cuts_config):
return next(API.plot_smpdf(**single_data_internal_cuts_config))


@pytest.mark.linux
@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(tolerance=TOLERANCE_VALUE)
def test_plot_smpdf_categorical(single_data_categorical_internal_cuts_config):
return next(API.plot_smpdf(**single_data_categorical_internal_cuts_config))


@pytest.mark.linux
@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(tolerance=TOLERANCE_VALUE)
def test_plot_obscorrs(single_data_internal_cuts_config):
corrpair = [{"corrpair": (i["dataset"],)} for i in DATA[:2]]
return API.plot_obscorrs(**single_data_internal_cuts_config, corrpair=corrpair)


@pytest.mark.linux
@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(tolerance=TOLERANCE_VALUE)
def test_plot_xq2():
theoryid = THEORYID
use_cuts = "nocuts"
Expand All @@ -74,8 +83,9 @@ def test_plot_xq2():
metadata_group=metadata_group,
)


@pytest.mark.linux
@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare(tolerance=TOLERANCE_VALUE)
def test_plot_xq2_custom():
theoryid = THEORYID
use_cuts = "nocuts"
Expand Down

0 comments on commit 48e8535

Please sign in to comment.