Skip to content

Commit

Permalink
[CI] Run calibration jobs on schedule instead of pushes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Nov 28, 2023
1 parent e7cb080 commit eca8220
Showing 1 changed file with 94 additions and 91 deletions.
185 changes: 94 additions & 91 deletions .github/workflows/calibration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ name: Calibration

on:
push:
branches: "master"
branches: "mg/nightly-calibration"
workflow_dispatch:
inputs:
commit:
description: 'Commit'
description: 'Commit hash (40 characters)'
required: true
default: ""
type: string
schedule:
- cron: 31 2 * * *

env:
REPO_PATH: /mnt/tlo/TLOmodel
Expand Down Expand Up @@ -44,6 +46,7 @@ jobs:
else
SHA=${{ github.sha }}
fi
SHA=e7cb080ca2b100c82b3d9c7063a6c91f73e63a25
ENV="/mnt/tlo/env-${SHA}"
WORKTREE_PATH="/mnt/tlo/${SHA}"
echo "SHA=${SHA}"
Expand All @@ -55,102 +58,102 @@ jobs:
echo "WORKTREE_PATH=${WORKTREE_PATH}" >> "${GITHUB_ENV}"
echo "worktree_path=${WORKTREE_PATH}" >> "${GITHUB_OUTPUT}"
- name: Clone remote TLO repository and fetch desired commit
run: |
# If the repository doesn't exist on disk, clone it.
if [[ ! -d "${REPO_PATH}" ]]; then
git clone --depth=1 --branch="${{ github.ref_name }}" "https://github.com/${{ github.repository }}.git" "${REPO_PATH}"
fi
# In any case, fetch the requested commit.
git -C "${REPO_PATH}" fetch --depth=1 origin "${SHA}"
# - name: Clone remote TLO repository and fetch desired commit
# run: |
# # If the repository doesn't exist on disk, clone it.
# if [[ ! -d "${REPO_PATH}" ]]; then
# git clone --depth=1 --branch="${{ github.ref_name }}" "https://github.com/${{ github.repository }}.git" "${REPO_PATH}"
# fi
# # In any case, fetch the requested commit.
# git -C "${REPO_PATH}" fetch --depth=1 origin "${SHA}"

- name: Create worktree
run: |
git -C "${REPO_PATH}" worktree add "${WORKTREE_PATH}" ${SHA}
# - name: Create worktree
# run: |
# git -C "${REPO_PATH}" worktree add "${WORKTREE_PATH}" ${SHA}

- name: Create virtual environment
run: |
python${PYTHON_VER} -m venv "${ENV}"
source "${ENV}/bin/activate"
pip install -r requirements/dev.txt
pip install -e .
working-directory: "${{ env.WORKTREE_PATH }}"
# - name: Create virtual environment
# run: |
# python${PYTHON_VER} -m venv "${ENV}"
# source "${ENV}/bin/activate"
# pip install -r requirements/dev.txt
# pip install -e .
# working-directory: "${{ env.WORKTREE_PATH }}"

- name: Generate output directory
id: out-dir
run: |
commit_dir=$(git show -s --date=format:'%Y-%m-%d_%H%M%S' --format=%cd_%h "${SHA}")
output_dir="${OUTPUT_ROOT}/${commit_dir}"
echo "output_dir=${output_dir}"
echo "output_dir=${output_dir}" >> "${GITHUB_OUTPUT}"
working-directory: "${{ env.WORKTREE_PATH }}"
# - name: Generate output directory
# id: out-dir
# run: |
# commit_dir=$(git show -s --date=format:'%Y-%m-%d_%H%M%S' --format=%cd_%h "${SHA}")
# output_dir="${OUTPUT_ROOT}/${commit_dir}"
# echo "output_dir=${output_dir}"
# echo "output_dir=${output_dir}" >> "${GITHUB_OUTPUT}"
# working-directory: "${{ env.WORKTREE_PATH }}"

- name: Generate list of tasks
id: tasks
run: |
RUNS="["
for run in $(seq 0 $((${RUNS_NUMBER} - 1))); do
RUNS="${RUNS}\"${run}\","
done
RUNS="${RUNS}]"
echo "tasks=${RUNS}"
echo "tasks=${RUNS}" >> "${GITHUB_OUTPUT}"
# - name: Generate list of tasks
# id: tasks
# run: |
# RUNS="["
# for run in $(seq 0 $((${RUNS_NUMBER} - 1))); do
# RUNS="${RUNS}\"${run}\","
# done
# RUNS="${RUNS}]"
# echo "tasks=${RUNS}"
# echo "tasks=${RUNS}" >> "${GITHUB_OUTPUT}"

# Run the tasks.
tasks:
needs: setup
name: Run task ${{ matrix.index }}
runs-on: [tlo-dev-vm-1, tasks] # Use only runners dedicated to running the tasks.
timeout-minutes: 5760 # = 4 * 24 * 60 minutes = 4 days
strategy:
fail-fast: false
matrix:
index: ${{ fromJSON(needs.setup.outputs.tasks) }}
steps:
- name: Run the task
run: |
source "${{ needs.setup.outputs.environment_path }}/bin/activate"
draw=0
task_output_dir="${{ needs.setup.outputs.output_dir }}/${RUN_NAME}/${draw}/${{ matrix.index }}"
mkdir -p "${task_output_dir}"
# # Run the tasks.
# tasks:
# needs: setup
# name: Run task ${{ matrix.index }}
# runs-on: [tlo-dev-vm-1, tasks] # Use only runners dedicated to running the tasks.
# timeout-minutes: 5760 # = 4 * 24 * 60 minutes = 4 days
# strategy:
# fail-fast: false
# matrix:
# index: ${{ fromJSON(needs.setup.outputs.tasks) }}
# steps:
# - name: Run the task
# run: |
# source "${{ needs.setup.outputs.environment_path }}/bin/activate"
# draw=0
# task_output_dir="${{ needs.setup.outputs.output_dir }}/${RUN_NAME}/${draw}/${{ matrix.index }}"
# mkdir -p "${task_output_dir}"

tlo scenario-run --output-dir "${task_output_dir}" --draw "${draw}" ${{ matrix.index }} "${{ needs.setup.outputs.worktree_path }}/src/scripts/calibration_analyses/scenarios/long_run_all_diseases.py"
working-directory: "${{ needs.setup.outputs.worktree_path }}"
# tlo scenario-run --output-dir "${task_output_dir}" --draw "${draw}" ${{ matrix.index }} "${{ needs.setup.outputs.worktree_path }}/src/scripts/calibration_analyses/scenarios/long_run_all_diseases.py"
# working-directory: "${{ needs.setup.outputs.worktree_path }}"

# Do the postprocessing
postprocess:
name: Post processing
needs: [setup, tasks]
runs-on: [tlo-dev-vm-1, postprocess] # Use only the runners dedicated to postprocessing
strategy:
fail-fast: false
steps:
- name: Run post-processing
run: |
source "${{ needs.setup.outputs.environment_path }}/bin/activate"
task_output_dir="${{ needs.setup.outputs.output_dir }}/${PROCESS_NAME}"
mkdir -p "${task_output_dir}"
# # Do the postprocessing
# postprocess:
# name: Post processing
# needs: [setup, tasks]
# runs-on: [tlo-dev-vm-1, postprocess] # Use only the runners dedicated to postprocessing
# strategy:
# fail-fast: false
# steps:
# - name: Run post-processing
# run: |
# source "${{ needs.setup.outputs.environment_path }}/bin/activate"
# task_output_dir="${{ needs.setup.outputs.output_dir }}/${PROCESS_NAME}"
# mkdir -p "${task_output_dir}"

python3 "${{ needs.setup.outputs.worktree_path }}/src/scripts/calibration_analyses/analysis_scripts/process.py" "${task_output_dir}" "${RUN_NAME}" "${{ needs.setup.outputs.worktree_path }}/resources"
working-directory: "${{ needs.setup.outputs.worktree_path }}"
# python3 "${{ needs.setup.outputs.worktree_path }}/src/scripts/calibration_analyses/analysis_scripts/process.py" "${task_output_dir}" "${RUN_NAME}" "${{ needs.setup.outputs.worktree_path }}/resources"
# working-directory: "${{ needs.setup.outputs.worktree_path }}"

# Cleanup stage, to remove temporary directories and such
cleanup:
name: Cleanup job
# It depends on all the previous jobs, but it always runs, regardless of
# their success (or maybe check that only `setup` was
# successful?)
if: ${{ always() }}
timeout-minutes: 10
needs: [setup, tasks, postprocess]
runs-on: [tlo-dev-vm-1]
strategy:
fail-fast: false
steps:
- name: Cleanup worktree
run: |
git -C "${REPO_PATH}" worktree remove -f "${{ needs.setup.outputs.worktree_path }}" || true
# # Cleanup stage, to remove temporary directories and such
# cleanup:
# name: Cleanup job
# # It depends on all the previous jobs, but it always runs, regardless of
# # their success (or maybe check that only `setup` was
# # successful?)
# if: ${{ always() }}
# timeout-minutes: 10
# needs: [setup, tasks, postprocess]
# runs-on: [tlo-dev-vm-1]
# strategy:
# fail-fast: false
# steps:
# - name: Cleanup worktree
# run: |
# git -C "${REPO_PATH}" worktree remove -f "${{ needs.setup.outputs.worktree_path }}" || true

- name: Cleanup virtual environment
run: |
rm -rvf "${{ needs.setup.outputs.environment_path }}"
# - name: Cleanup virtual environment
# run: |
# rm -rvf "${{ needs.setup.outputs.environment_path }}"

0 comments on commit eca8220

Please sign in to comment.