Skip to content

Commit

Permalink
Merge branch 'naive-tides' of https://github.com/TeamCOMPAS/COMPAS in…
Browse files Browse the repository at this point in the history
…to naive-tides
  • Loading branch information
jeffriley committed Nov 2, 2023
2 parents 2214788 + 2a2d7cd commit 5fb7988
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 18 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/compas-compile-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ jobs:
pip install --upgrade pip
pip install -e .[dev]
export COMPAS_ROOT_DIR=${GITHUB_WORKSPACE}
cd ${GITHUB_WORKSPACE}/misc/examples/methods_paper_plots/detailed_evolution
chmod 755 run.sh
cat run.sh
./run.sh
cd ${GITHUB_WORKSPACE}/py_tests/test_data/
echo "Run example COMPAS job using the config py_tests/test_data/fiducial_bbh_config.yaml"
compas_run_submit fiducial_bbh_config.yaml > example_bbh.log
cat example_bbh.log
echo "Generating detailed evolution plot"
compas_plot_detailed_evolution "./COMPAS_Output/Detailed_Output/BSE_Detailed_Output_0.h5" --dont-show >> example_bbh.log
echo "Out files:"
ls -l
mkdir test_artifacts
mv example_bbh.log test_artifacts/
- name: Run pytests
# Run tests and collect coverage data
Expand Down
17 changes: 10 additions & 7 deletions py_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os
from typing import Any, Dict

import subprocess
import h5py
import pytest
from compas_python_utils.cosmic_integration.binned_cosmic_integrator.bbh_population import \
generate_mock_bbh_population_file

HERE = os.path.dirname(__file__)
DETAILED_EVOLUTION_PATH = os.path.join(
HERE, "../misc/examples/methods_paper_plots/detailed_evolution"
)

TEST_CONFIG_DIR = os.path.join(HERE, "test_data")
TEST_CONFIG_FNAME = os.path.join(TEST_CONFIG_DIR, "fiducial_bbh_config.yaml")
TEST_ARCHIVE_DIR = os.path.join(HERE, "test_artifacts")


Expand All @@ -21,16 +20,20 @@ def example_compas_output_path(clean=False):
(This is a fixture so it can passed as a parameter to other tests)
"""
compas_data_path = os.path.join(
DETAILED_EVOLUTION_PATH, "COMPAS_Output/COMPAS_Output.h5"
TEST_CONFIG_DIR, "COMPAS_Output/COMPAS_Output.h5"
)

if not os.path.exists(compas_data_path) or clean: # Check if path exists
curr_dir = os.getcwd()
os.chdir(DETAILED_EVOLUTION_PATH)
os.system("python runSubmitDemo.py")
os.chdir(TEST_CONFIG_DIR)
cmd = f"compas_run_submit {TEST_CONFIG_FNAME}"
# run the command in shell "compas_run_submit {TEST_CONFIG_FNAME}" with subprocess
subprocess.run(cmd, shell=True, check=True)

os.chdir(curr_dir)
print("Generated COMPAS test data")


return compas_data_path


Expand Down
10 changes: 7 additions & 3 deletions py_tests/test_data/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Test Data

This folder contains all the COMPAS test data generated manually by running:
This folder contains COMPAS configs used for testing.
COMPAS is run from within the pytest environment and the output is cached for the remainder of the tests.

The pytest runs the following command:
```bash
bash generate_test_data.sh
compas_run_submit fiducial_bbh_configs.yaml
```

These files may need to be periodically updated if the COMPAS code changes.
The pytest cache is _not_ cleared locally (but will be cleared on the CI server).
Hence, this may need to be rerun locally if changes are made to COMPAS.
273 changes: 273 additions & 0 deletions py_tests/test_data/fiducial_bbh_config.yaml

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions py_tests/test_data/generate_test_data.sh

This file was deleted.

2 changes: 2 additions & 0 deletions py_tests/test_data/grid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--initial-mass-1 35.0 --initial-mass-2 31.0 --metallicity 0.001 --eccentricity 0.000000e+00 --semi-major-axis 3.5 --kick-magnitude-1 0 --kick-magnitude-2 0
--initial-mass-1 35.0 --initial-mass-2 31.0 --metallicity 0.001 --eccentricity 0.000000e+00 --semi-major-axis 3.5 --kick-magnitude-1 0 --kick-magnitude-2 0
11 changes: 11 additions & 0 deletions py_tests/test_fast_cosmic_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_fast_cosmic_integration(example_compas_output_path, test_archive_dir,
COMPAS,
) = FastCosmicIntegration.find_detection_rate(
path=example_compas_output_path,
merges_hubble_time=False,
)
runtime = time.time() - t0
assert runtime < 10
Expand All @@ -38,3 +39,13 @@ def test_fast_cosmic_integration(example_compas_output_path, test_archive_dir,
# check that the COMPAS object is a COMPASData object
assert isinstance(COMPAS, COMPASData)



def test_compas_output_has_dcos(example_compas_output_path):
"""Test that the COMPAS output has dco_type"""
COMPAS = COMPASData(path=example_compas_output_path, lazyData=False)
COMPAS.setCOMPASDCOmask(types='BBH', withinHubbleTime=False, pessimistic=True, noRLOFafterCEE=True)
COMPAS.setCOMPASData()
n_bin = len(COMPAS.seedsDCO)
assert n_bin > 1
assert sum(COMPAS.DCOmask) == n_bin

0 comments on commit 5fb7988

Please sign in to comment.