Skip to content

Commit c975ef3

Browse files
committed
Split analysis into matrix jobs
1 parent 40374d8 commit c975ef3

File tree

2 files changed

+79
-24
lines changed

2 files changed

+79
-24
lines changed

.github/workflows/analysis.yml

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,71 @@ on:
77
- 'analysis/**'
88

99
jobs:
10-
build:
10+
read_algorithms:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Read algorithms
15+
id: read_algorithms
16+
run: |
17+
algorithms=$(cat tests/IVIMmodels/unit_tests/algorithms.json)
18+
echo "::set-output name=algorithms::$algorithms"
1119
20+
build:
1221
runs-on: ubuntu-latest
22+
needs: read_algorithms
1323
continue-on-error: false
1424
strategy:
1525
fail-fast: false
26+
matrix:
27+
algorithm: ${{ fromJson(needs.read_algorithms.outputs.algorithms).algorithms }}
28+
SNR: [10 30 50 100 200]
1629
steps:
1730
- uses: actions/checkout@v3
1831
- name: Set up Python
19-
uses: actions/setup-python@v4
20-
with:
21-
python-version: "3.11"
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: "3.11"
2235
- name: Install dependencies
2336
run: |
2437
python -m pip install --upgrade pip
2538
pip install -r requirements.txt
39+
- name: Generate fitting data
40+
run: |
41+
pip install pytest
42+
python -m pytest -m slow --selectAlgorithm ${{ matrix.algorithm }} --saveFileName test_output.csv --SNR ${{ matrix.SNR }} --fitCount 300 --saveDurationFileName test_duration.csv
43+
- name: Upload raw data
44+
uses: actions/upload-artifact@v3
45+
with:
46+
name: RawData/raw_data_${{ matrix.algorithm }}_${{ matrix.SNR }}
47+
path: |
48+
test_output.csv
49+
test_duration.csv
50+
merge:
51+
runs-on: ubuntu-latest
52+
needs: build
53+
steps:
54+
- name: Download artifacts
55+
uses: actions/download-artifact@v3
56+
with:
57+
path: artifacts
58+
- name: Merge fitting results
59+
run: |
60+
cat artifacts/raw_data_*/test_output.csv > test_output.csv
61+
- name: Merge timing results
62+
run: |
63+
cat artifacts/raw_data_*/test_duration.csv > test_duration.csv
64+
- name: Upload merged artifacts
65+
uses: actions/upload-artifacts@v3
66+
with:
67+
name: Raw Data
68+
path: |
69+
test_output.csv
70+
test_duration.csv
71+
analyze:
72+
runs-on: ubuntu-latest
73+
needs: merge
74+
steps:
2675
- name: Set up R
2776
uses: r-lib/actions/setup-r@v2
2877
with:
@@ -36,23 +85,16 @@ jobs:
3685
any::tidyverse
3786
any::data.table
3887
any::ggplot2
39-
- name: Generate fitting data
40-
run: |
41-
pip install pytest
42-
python -m pytest -m slow --saveFileName test_output.csv --SNR 10 30 50 100 200 --fitCount 300 --saveDurationFileName test_duration.csv
88+
- name: Download artifacts
89+
uses: actions/download-artifact@v3
90+
with:
91+
name: Raw Data
4392
- name: Generate figures
4493
run: Rscript --vanilla tests/IVIMmodels/unit_tests/analyze.r test_output.csv test_duration.csv
45-
- name: Upload raw data
46-
uses: actions/upload-artifact@v3
47-
with:
48-
name: Raw data
49-
path: |
50-
test_output.csv
51-
test_duration.csv
5294
- name: Upload figures
5395
uses: actions/upload-artifact@v3
5496
with:
55-
name: Fit figures
97+
name: Fit Figures
5698
path: |
5799
D.pdf
58100
f.pdf

conftest.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ def pytest_addoption(parser):
6767
type=str,
6868
help="Saved duration results file name",
6969
)
70+
parser.addoption(
71+
"--selectAlgorithm",
72+
default=[""],
73+
nargs="+",
74+
type=str,
75+
help="Drop all algorithms except for these from the list"
76+
)
77+
parser.addoption(
78+
"--dropAlgorithm",
79+
default=[""],
80+
nargs="+",
81+
type=str,
82+
help="Drop this algorithm from the list"
83+
)
7084

7185

7286
@pytest.fixture(scope="session")
@@ -115,7 +129,6 @@ def save_duration_file(request):
115129
def rtol(request):
116130
return request.config.getoption("--rtol")
117131

118-
119132
@pytest.fixture(scope="session")
120133
def atol(request):
121134
return request.config.getoption("--atol")
@@ -137,23 +150,23 @@ def pytest_generate_tests(metafunc):
137150
if "SNR" in metafunc.fixturenames:
138151
metafunc.parametrize("SNR", metafunc.config.getoption("SNR"))
139152
if "ivim_algorithm" in metafunc.fixturenames:
140-
algorithms = algorithm_list(metafunc.config.getoption("algorithmFile"))
153+
algorithms = algorithm_list(metafunc.config.getoption("algorithmFile"), metafunc.config.getoption("selectAlgorithm"), metafunc.config.getoption("dropAlgorithm"))
141154
metafunc.parametrize("ivim_algorithm", algorithms)
142-
if "algorithm_file" in metafunc.fixturenames:
143-
metafunc.parametrize("algorithm_file", metafunc.config.getoption("algorithmFile"))
144155
if "ivim_data" in metafunc.fixturenames:
145156
data = data_list(metafunc.config.getoption("dataFile"))
146157
metafunc.parametrize("ivim_data", data)
147-
if "data_file" in metafunc.fixturenames:
148-
metafunc.parametrize("data_file", metafunc.config.getoption("dataFile"))
149158

150159

151-
def algorithm_list(filename):
160+
def algorithm_list(filename, selected, dropped):
152161
current_folder = pathlib.Path.cwd()
153162
algorithm_path = current_folder / filename
154163
with algorithm_path.open() as f:
155164
algorithm_information = json.load(f)
156-
return algorithm_information["algorithms"]
165+
algorithms = set(algorithm_information["algorithms"])
166+
algorithms = algorithms - set(dropped)
167+
if len(selected) > 0 and selected[0]:
168+
algorithms = algorithms & set(selected)
169+
return list(algorithms)
157170

158171
def data_list(filename):
159172
current_folder = pathlib.Path.cwd()

0 commit comments

Comments
 (0)