Speed up the algorithm analysis workflow #70
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Algorithm Analysis | ||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
- 'analysis/**' | ||
jobs: | ||
algorithms: | ||
runs-on: ubuntu-latest | ||
outputs: # here we use the outputs from steps, and set outputs for the job `configure` | ||
algorithms: ${{ steps.algorithms.outputs.algorithms }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Cache dependencies | ||
uses: actions/[email protected] | ||
id: cache | ||
with: | ||
path: ${{ runner.tool_cache }}/Python/3.11 | ||
key: ${{ runner.tool_cache }}/Python/$3.11/${{ runner.arch }}-${{ hashFiles('requirements.txt') }} | ||
- name: Set up Python | ||
id: setup_python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
- name: Read algorithms | ||
id: algorithms | ||
run: | | ||
echo 'algorithms<<EOF' >> $GITHUB_OUTPUT | ||
cat ./tests/IVIMmodels/unit_tests/algorithms.json >> $GITHUB_OUTPUT | ||
echo 'EOF' >> $GITHUB_OUTPUT | ||
- name: Log algorithms | ||
run: | | ||
echo "${{fromJson(steps.algorithms.outputs.algorithms)}}" | ||
echo "${{fromJson(steps.algorithms.outputs.algorithms).algorithms}}" | ||
- name: Log algorithms file | ||
run: cat ./tests/IVIMmodels/unit_tests/algorithms.json | ||
build: | ||
runs-on: ubuntu-latest | ||
needs: algorithms | ||
continue-on-error: false | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
algorithm: ${{fromJson(needs.algorithms.outputs.algorithms).algorithms}} | ||
SNR: [10, 30, 50, 100, 200] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Restore python cache | ||
uses: actions/[email protected] | ||
id: restore_cache | ||
with: | ||
path: ${{ runner.tool_cache }}/Python/3.11 | ||
key: ${{ runner.tool_cache }}/Python/$3.11/${{ runner.arch }}-${{ hashFiles('requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.tool_cache }}/Python/$3.11/${{ runner.arch }}- | ||
- name: Generate fitting data | ||
run: | | ||
python -m pytest -m slow --selectAlgorithm ${{ matrix.algorithm }} --saveFileName test_output_${{ matrix.algorithm }}_${{ matrix.SNR }}.csv --SNR ${{ matrix.SNR }} --fitCount 300 --saveDurationFileName test_duration_${{ matrix.algorithm }}_${{ matrix.SNR }}.csv | ||
- name: Upload raw data | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: Working_Data | ||
retention-days: 1 | ||
path: | | ||
test_output_${{ matrix.algorithm }}_${{ matrix.SNR }}.csv | ||
test_duration_${{ matrix.algorithm }}_${{ matrix.SNR }}.csv | ||
merge: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
path: artifacts | ||
- name: Merge fitting results | ||
run: | | ||
head -n 1 $(ls artifacts/Working_Data/test_output_*.csv | head -n 1) > test_output.csv | ||
tail -q -n +2 artifacts/Working_Data/test_output_*.csv >> test_output.csv | ||
- name: Merge timing results | ||
run: | | ||
head -n 1 $(ls artifacts/Working_Data/test_duration_*.csv | head -n 1) > test_duration.csv | ||
tail -q -n +2 artifacts/Working_Data/test_duration_*.csv >> test_duration.csv | ||
- name: Upload merged artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: Data | ||
path: | | ||
test_output.csv | ||
test_duration.csv | ||
analyze: | ||
runs-on: ubuntu-latest | ||
needs: merge | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up R | ||
uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
- name: Install R dependencies | ||
uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
packages: | | ||
any::plyr | ||
any::dplyr | ||
any::tidyverse | ||
any::data.table | ||
any::ggplot2 | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: Data | ||
- name: Generate figures | ||
run: Rscript --vanilla tests/IVIMmodels/unit_tests/analyze.r test_output.csv test_duration.csv | ||
- name: Upload figures | ||
uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: Figures | ||
path: | | ||
D.pdf | ||
f.pdf | ||
Dp.pdf | ||
D_limited.pdf | ||
f_limited.pdf | ||
Dp_limited.pdf | ||
durations.pdf | ||
curve_plot.pdf | ||
fitted_curves.pdf | ||
compare: | ||
runs-on: ubuntu-latest | ||
needs: merge | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up R | ||
uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
- name: Install R dependencies | ||
uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
packages: | | ||
any::tidyverse | ||
any::assertr | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: Data | ||
- name: Test against previous results | ||
run: Rscript --vanilla tests/IVIMmodels/unit_tests/compare.r test_output.csv test_reference.csv tests/IVIMmodels/unit_tests/reference_output.csv test_results.csv | ||
- name: Upload data | ||
uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: Comparison | ||
path: | | ||
test_reference.csv | ||
test_results.csv |