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

Change to tox for tests #86

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
97 changes: 42 additions & 55 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,53 @@ name: Testing
on: [push, pull_request]

jobs:
build:

test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.8, 3.9]
steps:
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.py }}
auto-update-conda: true
channels: conda-forge,defaults
channel-priority: strict
show-channel-urls: true

- name: install reqs
run: |
conda install pip compilers pytest pytest-cov pyccl cython
pip install cobaya
include:

- name: install extra reqs
run: |
pip install cosmopower
- name: latest supported versions
os: ubuntu-latest
python-version: '3.10'
toxenv: python3.10-test-all-latest-cov
toxposargs: --cov-report=xml:${GITHUB_WORKSPACE}/coverage.xml

env:
MATRIX_OS: ${{ matrix.os }}
- name: oldest supported versions
os: ubuntu-latest
python-version: '3.7'
toxenv: python3.7-test-oldest

- name: Install classy
run: |
if [[ ${MATRIX_OS} == "macos-latest" ]]; then
. ci_scripts/install_class_osx.sh
else
. ci_scripts/install_class_linux.sh
fi
python -c "import classy; print(classy)"
env:
MATRIX_OS: ${{ matrix.os }}
- name: macOS 11
os: macos-11
python-version: '3.10'
toxenv: python3.10-test-latest

- name: install
run: |
pip install .

- name: install test data
run: |
export COBAYA_PACKAGES_PATH="../packages"
cobaya-install planck_2018_highl_plik.TTTEEE_lite_native

- name: Unit tests
run: |
pytest -vv soliket --cov=soliket --cov-report=xml:coverage.xml --cov-config=setup.cfg
env:
PYTEST_ADDOPTS: "--color=yes"

- name: Report Coverage (codecov)
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v2
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Conda w/ Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: soliket-tests
environment-file: soliket-tests.yml
auto-activate-base: false
python-version: ${{ matrix.python-version }}
use-mamba: true
miniforge-variant: Mambaforge
- if: contains(matrix.os, 'ubuntu')
name: Install class
shell: bash -el {0}
run: |
pip install classy
env:
MATRIX_OS: ${{ matrix.os }}
- name: Run Tests
shell: bash -el {0}
run: |
tox -e ${{ matrix.toxenv }} ${{ matrix.toxargs }} -- ${{ matrix.toxposargs }}
- if: contains(matrix.toxenv, '-cov')
name: Report Coverage
uses: codecov/codecov-action@v1
19 changes: 12 additions & 7 deletions ci_scripts/install_class_osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ export CONDA_BUILD_SYSROOT=/
rm -rf class_public
git clone --depth=1000 https://github.com/lesgourg/class_public.git
cd class_public
git checkout v2.7.2

# if you are running on macos 11.6 and higher, uncomment the following line
sed -i.bak -e 's/gcc/gcc-9/g' Makefile
echo "----------------------------------"
env
echo "----------------------------------"

# if you are running on macos 10.15 and lower, uncomment the following 4 lines
#sed -i.bak -e 's/^CC/#CC/g' Makefile
#sed -i.bak -e 's/^OPTFLAG =/OPTFLAG = ${CFLAGS} ${LDFLAGS}/g' Makefile
#sed -i.bak -e 's/^#CCFLAG +=/CCFLAG +=/g' Makefile
#sed -i.bak -e 's/^#CCFLAG =/CCFLAG =/g' Makefile
sed -i.bak -e 's/^CC/#CC/g' Makefile
sed -i.bak -e 's/^OPTFLAG =/OPTFLAG = ${CFLAGS} ${LDFLAGS}/g' Makefile
sed -i.bak -e 's/^#CCFLAG +=/CCFLAG +=/g' Makefile
sed -i.bak -e 's/^#CCFLAG =/CCFLAG =/g' Makefile

echo "----------------------------------"
cat Makefile
echo "----------------------------------"

make -j4

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]

requires = ["setuptools",
"setuptools_scm",
"wheel"]

build-backend = 'setuptools.build_meta'
21 changes: 21 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
tox
numpy
scipy
pandas
scikit-learn
pyyaml
py-bobyqa
packaging
tqdm
portalocker
dill
fuzzywuzzy
astropy
camb
cosmopower
getdist
cobaya
pyccl
sacc
fgspectra @ git+https://github.com/simonsobs/fgspectra@act_sz_x_cib#egg=fgspectra
mflike @ git+https://github.com/simonsobs/lat_mflike@master
29 changes: 24 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
[flake8]
select = E713,E704,E703,E714,E741,E10,E11,E20,E22,E23,E25,E27,E301,E302,E304,E9,
F405,F406,F5,F6,F7,F8,W1,W2,W3,W6,E501
max-line-length = 90
exclude = .tox,build
[metadata]
name = soliket
version = 0.0
description = "SO Likelihoods & Theories"

[options]
zip_safe = False
packages = find:
python_requires = >=3.7
setup_requires = setuptools_scm
install_requires =

[options.extras_require]

[options.package_data]
soliket = *.yaml,*.bibtex,clusters/data/*,clusters/data/selFn_equD56/*,lensing/data/*.txt,mflike/*.yaml
testpaths = "soliket"
text_file_format = rst

[coverage:run]
omit =
Expand All @@ -27,3 +40,9 @@ exclude_lines =
pragma: py{ignore_python_version}
# Don't complain about IPython completion helper
def _ipython_key_completions_

[flake8]
select = E713,E704,E703,E714,E741,E10,E11,E20,E22,E23,E25,E27,E301,E302,E304,E9,
F405,F406,F5,F6,F7,F8,W1,W2,W3,W6,E501
max-line-length = 90
exclude = .tox,build
108 changes: 75 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,78 @@
# example cobaya-compliant SO likelihood package;
# adapted from github.com/cobayasampler/example_external_likelihood
#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst

# NOTE: The configuration for the package, including the name, version, and
# other information are set in the setup.cfg file.

import os
import sys

from setuptools import setup

setup(
name="soliket",
version="0.0",
description="SO Likelihoods & Theories",
zip_safe=False,
packages=["soliket", "soliket.tests", "soliket.clusters"],
package_data={
"soliket": [
"*.yaml",
"*.bibtex",
# "data/simulated*/*.txt",
"clusters/data/*",
"clusters/data/selFn_equD56/*",
"lensing/data/*.txt",
]
},
install_requires=[
"astropy",
"scikit-learn",
"cobaya",
"sacc",
"pyccl",
"fgspectra @ git+https://github.com/simonsobs/fgspectra@act_sz_x_cib#egg=fgspectra", # noqa E501
"mflike @ git+https://github.com/simonsobs/lat_mflike@master"
],
extras_requires=[
"cosmopower"
],
test_suite="soliket.tests",
include_package_data=True,
)

# First provide helpful messages if contributors try and run legacy commands
# for tests or docs.

TEST_HELP = """
Note: running tests is no longer done using 'python setup.py test'. Instead
you will need to run:

tox -e test

If you don't already have tox installed, you can install it with:

pip install tox

If you only want to run part of the test suite, you can also use pytest
directly with::

pip install -e .[test]
pytest

For more information, see:

http://docs.astropy.org/en/latest/development/testguide.html#running-tests
"""

if 'test' in sys.argv:
print(TEST_HELP)
sys.exit(1)

DOCS_HELP = """
Note: building the documentation is no longer done using
'python setup.py build_docs'. Instead you will need to run:

tox -e build_docs

If you don't already have tox installed, you can install it with:

pip install tox

You can also build the documentation with Sphinx directly using::

pip install -e .[docs]
cd docs
make html

For more information, see:

http://docs.astropy.org/en/latest/install.html#builddocs
"""

if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv:
print(DOCS_HELP)
sys.exit(1)

VERSION_TEMPLATE = """
# Note that we need to fall back to the hard-coded version if either
# setuptools_scm can't be imported or setuptools_scm can't determine the
# version, so we catch the generic 'Exception'.
try:
from setuptools_scm import get_version
version = get_version(root='..', relative_to=__file__)
except Exception:
version = '{version}'
""".lstrip()

setup(use_scm_version={'write_to': os.path.join('soliket', 'version.py'),
'write_to_template': VERSION_TEMPLATE})
16 changes: 16 additions & 0 deletions soliket-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: soliket-tests
channels:

dependencies:
- python<=3.10
- pip
- compilers
- cmake
- gsl
- fftw
- cython
- mpi4py
- pytest
- pytest-forked
- pip:
- -r requirements.txt
17 changes: 11 additions & 6 deletions soliket/tests/test_cosmopower.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@
"theory": {
"soliket.CosmoPower": {
# "soliket_data_path": os.path.normpath(
# os.path.join(os.getcwd(), "../data/CosmoPower")
# os.path.join(os.getcwd(), "soliket/data/CosmoPower")
# ),
"soliket_data_path": "soliket/data/CosmoPower",
# "soliket_data_path": "soliket/data/CosmoPower",
"stop_at_error": True,
}
},
}


@pytest.mark.skipif(not HAS_COSMOPOWER, reason='test requires cosmopower')
def test_cosmopower_theory():
def test_cosmopower_theory(request):
info_dict['theory']['soliket.CosmoPower']['soliket_data_path'] = \
os.path.join(request.config.rootdir, 'soliket/data/CosmoPower')
model_fiducial = get_model(info_dict) # noqa F841


@pytest.mark.skipif(not HAS_COSMOPOWER, reason='test requires cosmopower')
def test_cosmopower_loglike():
def test_cosmopower_loglike(request):
info_dict['theory']['soliket.CosmoPower']['soliket_data_path'] = \
os.path.join(request.config.rootdir, 'soliket/data/CosmoPower')
model_cp = get_model(info_dict)

logL_cp = float(model_cp.loglikes({})[0])
Expand All @@ -55,7 +59,7 @@ def test_cosmopower_loglike():


@pytest.mark.skipif(not HAS_COSMOPOWER, reason='test requires cosmopower')
def test_cosmopower_against_camb():
def test_cosmopower_against_camb(request):

info_dict['theory'] = {'camb': {'stop_at_error': True}}
model_camb = get_model(info_dict)
Expand All @@ -64,7 +68,8 @@ def test_cosmopower_against_camb():

info_dict['theory'] = {
"soliket.CosmoPower": {
"soliket_data_path": "soliket/data/CosmoPower",
"soliket_data_path": os.path.join(request.config.rootdir,
'soliket/data/CosmoPower'),
"stop_at_error": True,
"extra_args": {'lmax': camb_cls['ell'].max() + 1}}
}
Expand Down
Loading