Skip to content

Commit

Permalink
fix a bunch of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daviesje committed Aug 14, 2024
1 parent 6f5c991 commit 71ff0f4
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 17 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/test_suite_nointegration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Tests (No Integration Tests)

# Test on all pushes, except when the push is literally just a tag (because we
# tag automatically via CI, and therefore there's no extra code in that push).
# Also, only test on pull requests into master/production.
on:
push:
tags-ignore:
- 'v*'
pull_request:
branches:
- 'v4-prep'


jobs:
tests:
if: "!contains(github.event.pull_request.labels.*.name, 'auto-pr')"
env:
ENV_NAME: tests
PYTHON: ${{ matrix.python-version }}
OS: ${{ matrix.os }}
CC: gcc
name: Testing
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.9, "3.10", "3.11", "3.12"]
defaults:
run:
# Adding -l {0} ensures conda can be found properly in each step
shell: bash -l {0}
steps:
- uses: actions/checkout@master
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Print head git commit message
id: get_head_commit_message
run: echo "commit_message=$(git show -s --format=%s)" >> "$GITHUB_ENV"

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
# auto-update-conda: true
mamba-version: "*"
channels: conda-forge,defaults
python-version: ${{ matrix.python-version }}
environment-file: ci/${{ matrix.os }}-env.yml
activate-environment: tests
channel-priority: true

- name: Conda Info
run: |
conda info -a
conda list
conda config --show-sources
conda config --show
printenv | sort
- name: Make it a Debug Run
if: "contains(env.commit_message, 'ci debug')"
run: |
echo "log_level=ULTRA_DEBUG" >> $GITHUB_ENV
echo "extra_pytest_args=-s --log-level-21=DEBUG" >> $GITHUB_ENV
- name: Make it a Normal Run
if: "!contains(env.commit_message, 'ci debug')"
run: |
echo "log_level=INFO" >> $GITHUB_ENV
echo "extra_pytest_args=" >> $GITHUB_ENV
- name: Get C Libraries Linux
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install libfftw3-dev
sudo apt-get install libgsl0-dev
- name: Setup GCC
uses: Dup4/actions-setup-gcc@v1
with:
version: latest

- name: Install 21cmFAST Linux
if: matrix.os == 'ubuntu-latest'
run: |
LOG_LEVEL=${{ env.log_level }} pip install .
- name: Install 21cmFAST MacOS
if: matrix.os == 'macos-latest'
run: |
LOG_LEVEL=${{ env.log_level }} CFLAGS="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" pip install .
- name: Run Tests
run: |
python -m pytest -n 2 -l ${{ env.extra_pytest_args }} --ignore tests/test_integration_features.py --cov=py21cmfast --cov-config=.coveragerc -vv --cov-report xml:./coverage.xml --durations=25 --plots=testplots
- name: Archive Integration Test Plots
if: always()
uses: actions/upload-artifact@v3
with:
name: integration-test-plots-${{ matrix.os }}-${{ matrix.python-version }}
path: |
testplots/*.pdf
- uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-latest' && success() && !contains(github.event.pull_request.labels.*.name, 'auto-pr')
with:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion src/py21cmfast/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def __init__(
self,
*,
desc_redshift: float | None = None,
buffer_size: int = 0.0,
buffer_size: int = 0,
**kwargs,
):
self.desc_redshift = desc_redshift
Expand Down
14 changes: 8 additions & 6 deletions src/py21cmfast/photoncons.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
lib.adjust_redshifts_for_photoncons()
lib.determine_deltaz_for_photoncons() (first time only) --> calculates the deltaz array with some smoothing
--> does more smoothing and returns the adjusted redshift
ELIF PHOTON_CONS_TYPE==1:
ELIF PHOTON_CONS_TYPE==2:
photoncons_alpha() --> computes and stores ALPHA_ESC shift vs global neutral fraction
lib.ComputeIonizedBox()
get_fesc_fit() --> applies the fit to the current redshift
ELIF PHOTON_CONS_TYPE==2:
ELIF PHOTON_CONS_TYPE==3:
photoncons_fesc() --> computes and stores F_ESC10 shift vs global neutral fraction
lib.ComputeIonizedBox()
get_fesc_fit() --> applies the fit to the current redshift
Expand Down Expand Up @@ -327,11 +327,13 @@ def calibrate_photon_cons(
astro_params_photoncons = deepcopy(astro_params)
astro_params_photoncons._R_BUBBLE_MAX = astro_params.R_BUBBLE_MAX

flag_options_photoncons = FlagOptions(
USE_MASS_DEPENDENT_ZETA=flag_options.USE_MASS_DEPENDENT_ZETA,
M_MIN_in_Mass=flag_options.M_MIN_in_Mass,
flag_options_photoncons = flag_options.clone(
USE_TS_FLUCT=False,
INHOMO_RECO=False,
USE_MINI_HALOS=False,
HALO_STOCHASTICITY=False,
PHOTON_CONS_TYPE=0,
)

ib = None
prev_perturb = None

Expand Down
2 changes: 1 addition & 1 deletion src/py21cmfast/src/_functionprototypes_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int ComputePerturbField(float redshift, UserParams *user_params, CosmoParams *

int ComputeHaloField(float redshift_desc, float redshift, UserParams *user_params, CosmoParams *cosmo_params,
AstroParams *astro_params, FlagOptions *flag_options,
InitialConditions *boxes, int random_seed, HaloField * halos_desc, HaloField *halos);
InitialConditions *boxes, unsigned long long int random_seed, HaloField * halos_desc, HaloField *halos);

int ComputePerturbHaloField(float redshift, UserParams *user_params, CosmoParams *cosmo_params,
AstroParams *astro_params, FlagOptions *flag_options,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_c_interpolation_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def test_SFRD_z_tables(name, plt):
lib.init_ps()

if up.INTEGRATION_METHOD_ATOMIC == 1 or up.INTEGRATION_METHOD_MINI == 1:
lib.initialise_GL(100, np.log(M_min), np.log(M_max))
lib.initialise_GL(np.log(M_min), np.log(M_max))

Mlim_Fstar = 1e10 * (10**ap.F_STAR10) ** (-1.0 / ap.ALPHA_STAR)
Mlim_Fstar_MINI = 1e7 * (10**ap.F_STAR7_MINI) ** (-1.0 / ap.ALPHA_STAR_MINI)
Expand Down Expand Up @@ -732,7 +732,7 @@ def test_Nion_z_tables(name, plt):
lib.init_ps()

if up.INTEGRATION_METHOD_ATOMIC == 1 or up.INTEGRATION_METHOD_MINI == 1:
lib.initialise_GL(100, np.log(M_min), np.log(M_max))
lib.initialise_GL(np.log(M_min), np.log(M_max))

Mlim_Fstar = 1e10 * (10**ap.F_STAR10) ** (-1.0 / ap.ALPHA_STAR)
Mlim_Fesc = 1e10 * (10**ap.F_ESC10) ** (-1.0 / ap.ALPHA_ESC)
Expand Down Expand Up @@ -881,7 +881,7 @@ def test_Nion_conditional_tables(name, R, mini, intmethod, plt):
lib.init_ps()

if up.INTEGRATION_METHOD_ATOMIC == 1 or up.INTEGRATION_METHOD_MINI == 1:
lib.initialise_GL(100, np.log(M_min), np.log(M_max))
lib.initialise_GL(np.log(M_min), np.log(M_max))

growth_out = lib.dicke(redshift)
cond_mass = (
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def test_SFRD_conditional_table(name, R, intmethod, plt):
lib.init_ps()

if up.INTEGRATION_METHOD_ATOMIC == 1 or up.INTEGRATION_METHOD_MINI == 1:
lib.initialise_GL(100, np.log(M_min), np.log(M_max))
lib.initialise_GL(np.log(M_min), np.log(M_max))

growth_out = lib.dicke(redshift)
cond_mass = (
Expand Down Expand Up @@ -1230,7 +1230,7 @@ def test_conditional_integral_methods(R, name, integrand, plt):
lib.init_ps()

if up.INTEGRATION_METHOD_ATOMIC == 1 or up.INTEGRATION_METHOD_MINI == 1:
lib.initialise_GL(100, np.log(M_min), np.log(M_max))
lib.initialise_GL(np.log(M_min), np.log(M_max))

growth_out = lib.dicke(redshift)
cond_mass = (
Expand Down
2 changes: 2 additions & 0 deletions tests/test_halo_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ def test_halo_scaling_relations():
# NOTE: Not using upper turnover, this test should be extended
fo = FlagOptions(
USE_MINI_HALOS=True,
INHOMO_RECO=True,
USE_TS_FLUCT=True,
USE_HALO_FIELD=True,
FIXED_HALO_GRIDS=False,
HALO_STOCHASTICITY=True,
Expand Down
28 changes: 24 additions & 4 deletions tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ def test_run_lf():
redshifts=[7, 8, 9],
nbins=100,
component=0,
flag_options={"USE_MINI_HALOS": True},
flag_options={
"USE_MINI_HALOS": True,
"INHOMO_RECO": True,
"USE_TS_FLUCT": True,
},
mturnovers=[7.0, 7.0, 7.0],
mturnovers_mini=[5.0, 5.0, 5.0],
)
Expand Down Expand Up @@ -465,7 +469,11 @@ def test_run_coeval_bad_inputs():
):
wrapper.run_coeval(
redshift=6.0,
flag_options={"USE_MINI_HALOS": True},
flag_options={
"USE_MINI_HALOS": True,
"INHOMO_RECO": True,
"USE_TS_FLUCT": True,
},
use_interp_perturb_field=True,
)

Expand Down Expand Up @@ -588,12 +596,24 @@ def test_lc_pass_redshift_deprecation(rectlcn, ic):
def test_coeval_lowerz_than_photon_cons(ic):
with pytest.raises(ValueError, match="You have passed a redshift"):
wrapper.run_coeval(
init_box=ic, redshift=2.0, flag_options={"PHOTON_CONS_TYPE": 1}
init_box=ic,
redshift=2.0,
flag_options={
"PHOTON_CONS_TYPE": 1,
"USE_HALO_FIELD": False,
"HALO_STOCHASTICITY": False,
},
)


def test_lc_lowerz_than_photon_cons(rectlcn, ic):
with pytest.raises(ValueError, match="You have passed a redshift"):
wrapper.run_lightcone(
init_box=ic, redshift=2.0, flag_options={"PHOTON_CONS_TYPE": 1}
init_box=ic,
redshift=2.0,
flag_options={
"PHOTON_CONS_TYPE": 1,
"USE_HALO_FIELD": False,
"HALO_STOCHASTICITY": False,
},
)

0 comments on commit 71ff0f4

Please sign in to comment.