Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
79 changes: 25 additions & 54 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,32 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Miniforge
uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1

- name: Install uv and set the python version
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
with:
miniforge-version: latest
activate-environment: anaconda-client-env
python-version: ${{ matrix.python }}
python-version: ${{ inputs.python-version }}
version: "0.10.0"

- name: Get Date
id: get-date
run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT
shell: bash
- name: Cache Conda env
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ env.CONDA }}/envs
key:
conda-${{ runner.os }}--python-${{ matrix.python }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
hashFiles('treerec/tests/environment.yml') }}-${{ env.CACHE_NUMBER}}
env:
# Increase this value to reset cache if
# treerec/tests/environment.yml has not changed
CACHE_NUMBER: 0
id: cache
- name: Update environment
run: conda env update -n anaconda-client-env -f treerec/tests/environment.yml
if: steps.cache.outputs.cache-hit != 'true'

- name: Workaround for gcc-11
if: startsWith(matrix.os, 'ubuntu') && matrix.gcc == 11
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update -y

- name: Set up default GCC (in Ubuntu)
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} && \
sudo update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc }} 100 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${{ matrix.gcc }}

- name: Build and test (Debug)
run: |
mkdir Debug && \
Expand All @@ -108,6 +96,7 @@ jobs:
make -j 2 && \
# Show any output from the test program whenever the test fails
env CTEST_OUTPUT_ON_FAILURE=1 make test

- name: Build and test (Release)
run: |
mkdir Release && \
Expand All @@ -116,13 +105,13 @@ jobs:
make -j 2 && \
# Show any output from the test program whenever the test fails
env CTEST_OUTPUT_ON_FAILURE=1 make test

- name: Treesequence tests
shell: bash -el {0}
run: |
conda activate anaconda-client-env && \
export PATH=$PATH:$PWD/Release && \
echo $PATH && \
cd treerec/tests && python -m pytest -xv
cd treerec/tests && uv run pytest -xv

tests-Windows-CLI:
if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository == 'messerlab/slim')
Expand All @@ -137,8 +126,10 @@ jobs:
run:
shell: msys2 {0}
steps:

- name: Check out repository code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup MSYS2 ${{matrix.sys}}
uses: msys2/setup-msys2@66cd2cce69caa17b53920067426061ca1de3a884 # v2.32.0
with:
Expand All @@ -150,40 +141,19 @@ jobs:
msys2-devel
mingw-w64-${{matrix.env}}-toolchain
mingw-w64-${{matrix.env}}-cmake
- name: Setup Miniforge
uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
with:
miniforge-version: latest
activate-environment: anaconda-client-env
auto-update-conda: true
python-version: ${{ matrix.python }}

- name: Get Date
id: get-date
run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT
shell: bash
- name: Cache Conda env
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
env:
# Increase this value to reset cache if treerec/tests/environment.yml has not changed
CACHE_NUMBER: 0
with:
# Use faster GNU tar
enableCrossOsArchive: true
path: D:\conda_pkgs_dir
key:
conda-${{ runner.os }}--python-${{ matrix.python }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
hashFiles('treerec/tests/environment.yml') }}-${{ env.CACHE_NUMBER}}
id: cache
- uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
with:
activate-environment: anaconda-client-env
environment-file: treerec/tests/environment.yml
pkgs-dirs: D:\conda_pkgs_dir
- name: Update environment

- name: Install uv and set the python version
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
shell: bash -el {0}
run: conda env update -n anaconda-client-env -f treerec/tests/environment.yml
if: steps.cache.outputs.cache-hit != 'true'
with:
python-version: ${{ inputs.python-version }}
version: "0.10.0"

- name: Build and test (Debug)
run: |
cd windows_compat/gnulib && \
Expand All @@ -195,6 +165,7 @@ jobs:
make -j 2 && \
# Show any output from the test program whenever the test fails
env CTEST_OUTPUT_ON_FAILURE=1 make test

- name: Build and test (Release)
run: |
cd windows_compat/gnulib && \
Expand All @@ -206,13 +177,13 @@ jobs:
make -j 2 && \
# Show any output from the test program whenever the test fails
env CTEST_OUTPUT_ON_FAILURE=1 make test

- name: Treesequence tests
shell: bash -el {0}
run: |
conda activate anaconda-client-env && \
export PATH=$PATH:$PWD/Release && \
echo $PATH && \
cd treerec/tests && python -m pytest -xv
cd treerec/tests && uv run pytest -xv

tests-Unix-GUI:
if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository == 'messerlab/slim')
Expand Down
3 changes: 3 additions & 0 deletions treerec/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@ To add a new test:
add individuals to the saved list by calling `addIndividuals(individuals)` at any point
in the simulation.

* Ensure that tree sequences are written to subdirectories! If there are no subdirectories
then nothing will happen.


To temporarily turn off a test just comment out the appropriate line in `recipe_specs.py`
7 changes: 4 additions & 3 deletions treerec/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ def get_ts(self):
# binary
print("******** Binary input.")
bin_ts = load_file_or_dir(os.path.join(self.dir, "test_output.trees"))
yield bin_ts
# and nonsimplified binary
print("******** Unsimplified binary.")
bin_nonsimp_ts = load_file_or_dir(
os.path.join(self.dir, "test_output.unsimplified.trees"))
yield bin_nonsimp_ts
return (bin_ts, bin_nonsimp_ts)

@staticmethod
def get_slim_ids(ts):
Expand Down Expand Up @@ -154,11 +153,13 @@ def make_result(run_dir):
SLiM recipes are expected to output their results into a set of directories
within the run_dir: return a list of results, one for each subdirectory
"""
return [
out = [
OutputResult(os.path.join(run_dir, f.name))
for f in os.scandir(run_dir)
if f.is_dir()
]
assert len(out) > 0
return out

def run_slim(recipe, run_dir, recipe_dir="test_recipes"):
"""
Expand Down
13 changes: 13 additions & 0 deletions treerec/tests/init.slim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ function (void)initializeMarks(i$ num_marks)
return;
}

function (void)saveTreeSeqTraits(void) {
MD = Dictionary();
for (mt in sim.mutationTypes) {
MD.setValue("m" + mt.id, Dictionary(
"convertToSubstitution", mt.convertToSubstitution
));
}
sim.demandPhenotype(sim.subpopulations);
setwdForGen();
sim.treeSeqOutput("test_output.trees", metadata=Dictionary("mutation_types", MD));
sim.treeSeqOutput("test_output.unsimplified.trees", simplify=F);
}

function (void)saveTreeSeq(void) {
// create tree seq representation in various formats: this could overwrite any
// existing ones output in the same cycle, but they should be identical
Expand Down
4 changes: 2 additions & 2 deletions treerec/tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
"filelock>=3.32.4",
"msprime>=1.2.0",
"msprime>=1.4.4",
"numpy>=2.5.2",
"pyslim>=1.0.4",
"pyslim @ git+https://github.com/tskit-dev/pyslim@main",
"pytest>=9.1.1",
"pytest-xdist>=3.8.0",
"setuptools>=84.0.0",
Expand Down
15 changes: 15 additions & 0 deletions treerec/tests/recipe_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@
"test_836_output from multiple-chromosome models.slim": {"mutations": True, "individuals": True},
"test_169_complex multi-chromosome inheritance.slim": {"mutations": True, "individuals": True},
"test_1610_modeling pseudo-autosomal regions.slim": {"mutations": True, "individuals": True},
"recipe_WF.slim": {"traits": True},
"recipe_WF_adds.slim": {"traits": True},
"recipe_WF_no_substitutions.slim": {"traits": True},
"recipe_WF_H.slim": {"traits": True},
"recipe_WF_HF.slim": {"traits": True},
"recipe_WF_HM.slim": {"traits": True},
"recipe_WF_W.slim": {"traits": True},
"recipe_WF_X.slim": {"traits": True},
"recipe_WF_Y.slim": {"traits": True},
"recipe_WF_Z.slim": {"traits": True},
"recipe_nonWF.slim": {"traits": True},
"recipe_nonWF_substitutions.slim": {"traits": True},
"recipe_nonWF_H.slim": {"traits": True},
"recipe_nonWF_X.slim": {"traits": True},
"recipe_nonWF_Y.slim": {"traits": True},
}


Expand Down
24 changes: 24 additions & 0 deletions treerec/tests/test_recipes/recipe_WF.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
initialize()
{
setSeed(23);
initializeSLiMOptions(keepPedigrees=T);
initializeTreeSeq(timeUnit="generations");
source("init.slim");
initializeSex();
initializeChromosome(1, 100, "A", "A");
initializeMutationRate(1e-2);
initializeMutationType("m1", 0.5, "f", -0.1);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, 99);
initializeRecombinationRate(1e-2);
}

1 early() {
sim.addSubpop("p1", 10);
}

30 late() {
saveTreeSeqTraits();
catn("Done.");
sim.simulationFinished();
}
23 changes: 23 additions & 0 deletions treerec/tests/test_recipes/recipe_WF_H.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
initialize()
{
setSeed(23);
initializeSLiMOptions(keepPedigrees=T);
initializeTreeSeq(timeUnit="generations");
source("init.slim");
initializeChromosome(1, 100, "A", "A");
initializeMutationRate(1e-2);
initializeMutationType("m1", 0.5, "f", -0.1);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, 99);
initializeRecombinationRate(1e-2);
}

1 early() {
sim.addSubpop("p1", 10);
}

30 late() {
saveTreeSeqTraits();
catn("Done.");
sim.simulationFinished();
}
24 changes: 24 additions & 0 deletions treerec/tests/test_recipes/recipe_WF_HF.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
initialize()
{
setSeed(23);
initializeSLiMOptions(keepPedigrees=T);
initializeTreeSeq(timeUnit="generations");
source("init.slim");
initializeSex();
initializeChromosome(1, 100, "A", "A");
initializeMutationRate(1e-2);
initializeMutationType("m1", 0.5, "f", -0.1);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, 99);
initializeRecombinationRate(1e-2);
}

1 early() {
sim.addSubpop("p1", 10);
}

30 late() {
saveTreeSeqTraits();
catn("Done.");
sim.simulationFinished();
}
24 changes: 24 additions & 0 deletions treerec/tests/test_recipes/recipe_WF_HM.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
initialize()
{
setSeed(23);
initializeSLiMOptions(keepPedigrees=T);
initializeTreeSeq(timeUnit="generations");
source("init.slim");
initializeSex();
initializeChromosome(1, 100, "A", "A");
initializeMutationRate(1e-2);
initializeMutationType("m1", 0.5, "f", -0.1);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, 99);
initializeRecombinationRate(1e-2);
}

1 early() {
sim.addSubpop("p1", 10);
}

30 late() {
saveTreeSeqTraits();
catn("Done.");
sim.simulationFinished();
}
24 changes: 24 additions & 0 deletions treerec/tests/test_recipes/recipe_WF_W.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
initialize()
{
setSeed(23);
initializeSLiMOptions(keepPedigrees=T);
initializeTreeSeq(timeUnit="generations");
source("init.slim");
initializeSex();
initializeChromosome(1, 100, "A", "A");
initializeMutationRate(1e-2);
initializeMutationType("m1", 0.5, "f", -0.1);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, 99);
initializeRecombinationRate(1e-2);
}

1 early() {
sim.addSubpop("p1", 10);
}

30 late() {
saveTreeSeqTraits();
catn("Done.");
sim.simulationFinished();
}
Loading