Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.5 2024 03 04 run #5

Merged
merged 3 commits into from
Mar 4, 2024
Merged
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
21 changes: 21 additions & 0 deletions .github/actions/install-cmdstan/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Epinowcast

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 53 additions & 0 deletions .github/actions/install-cmdstan/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# MIT Licensed action vendored from
# https://github.com/epinowcast/actions

name: 'Install CmdStan with caching'
description: 'Install CmdStan with caching'
inputs:
cmdstan-version:
description: 'CmdStan version to install (use "latest" for the latest version)'
required: false
default: 'latest'
num-cores:
description: 'Number of cores to use for building CmdStan'
required: false
default: '1'

runs:
using: 'composite'
steps:
- name: Determine CmdStan Version (Unix)
if: runner.os != 'Windows' && inputs.cmdstan-version == 'latest'
run: |
chmod +x ${{ github.action_path }}/scripts/get-latest-release.sh
${{ github.action_path }}/scripts/get-latest-release.sh
shell: bash

- name: Determine CmdStan Version (Windows)
if: runner.os == 'Windows' && inputs.cmdstan-version == 'latest'
run: ${{ github.action_path }}\scripts\get-latest-release.ps1
shell: pwsh

- name: Set CmdStan Version (Specified)
if: inputs.cmdstan-version != 'latest'
run: echo "CMDSTAN_VERSION=${{ inputs.cmdstan-version }}" >> $GITHUB_ENV
shell: bash

- name: Restore Cache
id: cache-cmdstan
uses: actions/cache@v4
with:
path: '~/.cmdstan/cmdstan-${{ env.CMDSTAN_VERSION }}'
key: ${{ runner.os }}-cmdstan-${{ env.CMDSTAN_VERSION }}

- name: Check the CmdStan toolchain and repair it if required
if: steps.cache-cmdstan.outputs.cache-hit != 'true'
run: |
Rscript -e 'cmdstanr::check_cmdstan_toolchain(fix = TRUE)'
shell: bash

- name: Install CmdStan using cmdstanr
if: steps.cache-cmdstan.outputs.cache-hit != 'true'
run: |
Rscript -e 'cmdstanr::install_cmdstan(version = "${{ env.CMDSTAN_VERSION }}", cores = ${{ inputs.num-cores }})'
shell: bash
27 changes: 27 additions & 0 deletions .github/actions/install-cmdstan/scripts/get-latest-release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# PowerShell script to fetch the latest CmdStan release version with retry logic

# Initialize retry parameters
$max_attempts = 5
$wait_time = 5 # seconds

for ($attempt = 1; $attempt -le $max_attempts; $attempt++) {
try {
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/stan-dev/cmdstan/releases/latest" -ErrorAction Stop
$version = $response.tag_name -replace '^v', ''

if (-not [string]::IsNullOrWhiteSpace($version)) {
"CMDSTAN_VERSION=$version" | Out-File -Append -FilePath $env:GITHUB_ENV
Write-Host "CmdStan latest version: $version"
break
}
} catch {
Write-Host "Attempt $attempt of $max_attempts failed. Retrying in $wait_time seconds..."
Start-Sleep -Seconds $wait_time
$wait_time = $wait_time * 2
}
}

if ([string]::IsNullOrWhiteSpace($version)) {
Write-Host "Failed to fetch CmdStan version after $max_attempts attempts."
exit 1
}
46 changes: 46 additions & 0 deletions .github/actions/install-cmdstan/scripts/get-latest-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# Detect the operating system and install jq
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get update
sudo apt-get install -y jq
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install jq
else
echo "Unsupported OS for this script"
exit 1
fi

# Function to get the latest CmdStan version using GitHub API
get_latest_version() {
local retries=3
local wait_time=5
local status=0
local version=""

for ((i=0; i<retries; i++)); do
version=$(curl -s https://api.github.com/repos/stan-dev/cmdstan/releases/latest | jq -r '.tag_name' | tr -d 'v')
status=$?
if [ $status -eq 0 ] && [ -n "$version" ]; then
echo $version
return 0
fi
sleep $wait_time
wait_time=$((wait_time*2))
done

return 1
}

# Fetch the latest release version of CmdStan
version=$(get_latest_version)

if [ $? -ne 0 ] || [ -z "$version" ]; then
echo "Failed to fetch the latest CmdStan version"
exit 1
fi

# Pass the version to the GitHub environment
echo "CMDSTAN_VERSION=$version" >> $GITHUB_ENV

echo "CmdStan latest version: $version"
27 changes: 27 additions & 0 deletions .github/workflows/r-cmd-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: R CMD check project package

on:
pull_request:
push:
branches: [main]

jobs:
build-and-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
r-version: 'release'
use-public-rspm: true
extra-repositories: 'https://mc-stan.org/r-packages/'
- uses: r-lib/actions/setup-r-dependencies@v2
with:
working-directory: cfaforecastrenewalww
needs: check
- name: "Install cmdstan via cmdstanr"
uses: ./.github/actions/install-cmdstan
- uses: r-lib/actions/check-r-package@v2
with:
working-directory: cfaforecastrenewalww
error-on: '"error"'
65 changes: 50 additions & 15 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,22 @@ list(
),

# Format data for the hub ----------------------------------------------------
tar_target(
name = loc_model_map_submission,
command = get_loc_model_map(
df_of_filepaths_id,
hosp_only_states
),
deployment = "main"
),
tar_target(
name = df_of_filepaths,
command = get_submission_filepath_df(
prod_model_type = prod_model_type,
hosp_only_states = hosp_only_states,
loc_model_map = loc_model_map_submission,
df_of_filepaths_inf_dyn = df_of_filepaths_id,
df_of_filepaths_agg = df_of_filepaths_us,
df_of_filepaths_hosp_only = df_of_filepaths_ho,
df_of_filepaths_hosp_only = df_of_filepaths_ho
),
deployment = "main"
),
Expand Down Expand Up @@ -797,11 +805,17 @@ list(
),
tar_target(
name = table_of_state_model_designations,
command = get_summarized_table(
hub_submission_df,
full_diagnostics_df,
hosp_only_states,
repo_file_path
command = do.call(
get_summarized_table,
c(
list(
hub_submission_df = hub_submission_df,
full_diagnostics_df = full_diagnostics_df,
hosp_only_states = hosp_only_states,
repo_file_path = repo_file_path
),
config_vars_id
)
),
deployment = "main"
),
Expand Down Expand Up @@ -876,14 +890,28 @@ list(
),

# Generate "would-be" submissions from each model type -----------------------
tar_target(
name = is_submitted_forecast,
command = FALSE,
deployment = "main"
),
tar_target(
name = loc_model_map_ho,
command = get_loc_model_map(
df_of_filepaths_ho |> dplyr::filter(location != "US"),
hosp_only_states,
us_model_type = "hospital admissions only"
),
deployment = "main"
),
tar_target(
name = df_of_filepaths_hosp_only,
command = get_submission_filepath_df(
prod_model_type = "hospital admissions only",
hosp_only_states = c(),
loc_model_map = loc_model_map_ho,
df_of_filepaths_inf_dyn = df_of_filepaths_id,
df_of_filepaths_agg = df_of_filepaths_us,
df_of_filepaths_hosp_only = df_of_filepaths_ho,
df_of_filepaths_hosp_only = df_of_filepaths_ho
),
deployment = "main"
),
Expand All @@ -896,8 +924,8 @@ list(
submitting_model_name = "cfa-wwrenewal_hosp_only",
submission_file_path = submission_file_path,
repo_file_path = repo_file_path, # We won't write to the repo
prod_run = FALSE, # This is not what we're submitting, even if it is part of a
# production run
prod_run = is_submitted_forecast, # This is not what we're submitting,
# even if it is part of a production run
is_for_public_repo = FALSE
)
),
Expand Down Expand Up @@ -938,14 +966,21 @@ list(
),
deployment = "main"
),
tar_target(
name = loc_model_map_ww,
command = get_loc_model_map(df_of_filepaths_id,
hosp_only_states = c()
),
deployment = "main"
),
tar_target(
name = df_of_filepaths_ww,
command = get_submission_filepath_df(
prod_model_type = prod_model_type,
hosp_only_states = c(),
loc_model_map = loc_model_map_ww,
df_of_filepaths_inf_dyn = df_of_filepaths_id,
df_of_filepaths_agg = df_of_filepaths_us,
df_of_filepaths_hosp_only = df_of_filepaths_ho,
df_of_filepaths_hosp_only = df_of_filepaths_ho
),
deployment = "main"
),
Expand All @@ -958,8 +993,8 @@ list(
submitting_model_name = "cfa-wwrenewal_all_ww",
submission_file_path = submission_file_path,
repo_file_path = repo_file_path, # we won't write to the repo
prod_run = FALSE, # This is not what we're submitting, even if it is part of a
# production run
prod_run = is_submitted_forecast, # This is not what we're submitting,
# even if it is part of a production run
is_for_public_repo = FALSE
)
),
Expand Down
4 changes: 3 additions & 1 deletion cfaforecastrenewalww/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ Suggests:
covidcast,
httr,
knitr,
withr
withr,
testthat
Additional_repositories: https://mc-stan.org/r-packages/
SystemRequirements: CmdStan (>=2.34.1)
RoxygenNote: 7.3.1
Encoding: UTF-8
LazyData: true
Config/testthat/edition: 3
Config/Needs/check: rcmdcheck, testthat
1 change: 1 addition & 0 deletions cfaforecastrenewalww/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(get_hosp_reporting_delay)
export(get_ind_m)
export(get_ind_m_cum_sum)
export(get_init_fun)
export(get_loc_model_map)
export(get_low_case_count_diagnostic)
export(get_metadata)
export(get_metadata_yaml)
Expand Down
Loading
Loading