Skip to content

Commit

Permalink
Packaging. (#6)
Browse files Browse the repository at this point in the history
* Added workflows.

* Added tests.

* Removed invalid flag in like.

* Added chi2 test.

* Flake8 compliance.

* URL line break error fix.
  • Loading branch information
HTJense authored Nov 10, 2023
1 parent eb75c96 commit 9272d03
Show file tree
Hide file tree
Showing 7 changed files with 1,093 additions and 904 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Code Style
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
flake8:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Conda w/ Python 3.8
uses: conda-incubator/setup-miniconda@v2
with:
auto-activate-base: false
python-version: '3.8'
channels: conda-forge

- name: Install Dependencies
shell: bash -el {0}
run: |
pip install flake8
- name: Check Code Style
shell: bash -el {0}
run: |
flake8
39 changes: 39 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Testing
on: [push, pull_request]
jobs:
test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Latest Version
os: ubuntu-latest
python-version: '3.12'

- name: Oldest Version
os: ubuntu-latest
python-version: '3.8'

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Dependencies
shell: bash -el {0}
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -e .
- name: Cache testing Dataset
shell: bash -el {0}
run: |
export COBAYA_PACKAGES_PATH=./cobaya_packages
cobaya-install wmaplike.WMAPLike
- name: Run Tests
shell: bash -el {0}
run: |
pytest -v
28 changes: 14 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from setuptools import find_packages, setup

setup(
name = "WMAPLike",
version = "0.1.0",
description = "WMAP DR5 likelihood for cobaya",
author = "Hidde Jense",
author_email = "JenseH@cardiff.ac.uk",
zip_safe = True,
packages = find_packages(),
python_requires = ">=3.7",
install_requires = [
"cobaya>=3.1.0",
"astropy"
],
package_data = { "wmaplike" : [ "WMAPLike.yaml" ] }
name="WMAPLike",
version="0.1.1",
description="WMAP DR5 likelihood for cobaya",
author="Hidde Jense",
author_email="JenseH@cardiff.ac.uk",

zip_safe=True,
packages=find_packages(),
python_requires=">=3.8",
install_requires=[
"cobaya>=3.3.0",
"astropy"
],
package_data={"wmaplike": ["*.yaml", "tests/*"]},
)
99 changes: 0 additions & 99 deletions test_wmap.py

This file was deleted.

2 changes: 1 addition & 1 deletion wmaplike/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .wmap import WMAPLike
from .wmap import WMAPLike, WMAPBestFitv5 # noqa F401
75 changes: 75 additions & 0 deletions wmaplike/tests/test_wmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import pytest # noqa F401
import numpy as np
from cobaya.model import get_model

info = {
"params": {
"cl_amp": 1.0
},
"theory": {
"wmaplike.WMAPBestFitv5": None
},
"likelihood": {
"wmaplike.WMAPLike": {
"use_lowl_TT": True,
"use_highl_TT": True,
"use_highl_TE": True,
"use_highl_TB": False,
"use_lowl_pol": False,
"use_lowl_TBEB": False,
"use_highl_TT_beam_ptsrc": False,
"use_sz": False,
}
},
"sampler": {"evaluate": None},
"debug": False
}

chisqr_expected = {
"lowl_TT_gibbs": -13.614869,
"MASTER_TTTT": 1200.005224,
"MASTER_TETE_chi2": 831.787122,
"MASTER_TETE_det": 3605.526233,
"MASTER_TBTB_chi2": 775.110063,
"MASTER_TBTB_det": 3610.385517,
}


def test_import():
import wmaplike # noqa F401


def test_model():
model = get_model(info) # noqa F841


def test_chi2():
info["likelihood"] = {
"wmaplike.WMAPLike": {
"use_lowl_TT": True,
"use_highl_TT": True,
"use_highl_TE": True,
"use_highl_TB": True,
"use_lowl_pol": False,
"use_lowl_TBEB": False,
"use_highl_TT_beam_ptsrc": False,
"use_sz": False,
}
}

model = get_model(info)
model.logposterior({"cl_amp": 1.0, "A_sz": 0.0})
like = model.likelihood["wmaplike.WMAPLike"]
chi2s = like.current_state["derived"]

for component in chisqr_expected:
if f"chi2_wmap_{component}" in chi2s:
assert np.isclose(chi2s[f"chi2_wmap_{component}"],
chisqr_expected[component])
print(f"{component} is fine.")


if __name__ == "__main__":
test_import()
test_model()
test_chi2()
Loading

0 comments on commit 9272d03

Please sign in to comment.