-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub action for
cmdstanr
(#201)
* Copy check-cmdstan.yaml from epinowcast * Try making epidist specific * Remove epinowcast related code * Use epidist:: and cmdstanr:: * Corrections for this to run --------- Co-authored-by: Sam Abbott <[email protected]>
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: check-cmdstan | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.stan' | ||
branches: | ||
- main | ||
- develop | ||
schedule: | ||
- cron: '5 4 * * 1' | ||
pull_request: | ||
paths: | ||
- '**.stan' | ||
branches: | ||
- main | ||
- develop | ||
merge_group: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
check-cmdstan: | ||
if: "! contains(github.event.head_commit.message, '[ci skip]')" | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- name: cmdstan env vars | ||
run: | | ||
echo "CMDSTAN_PATH=${HOME}/.cmdstan" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Install cmdstan Linux system dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libcurl4-openssl-dev || true | ||
sudo apt-get install -y openmpi-bin openmpi-common libopenmpi-dev || true | ||
sudo apt-get install -y libpng-dev || true | ||
- uses: r-lib/actions/setup-r@v2 | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: local::. | ||
|
||
- name: Install cmdstan | ||
uses: epinowcast/actions/install-cmdstan@v1 | ||
with: | ||
cmdstan-version: 'latest' | ||
num-cores: 2 | ||
|
||
- name: Compile model and check syntax | ||
run: | | ||
dummy_obs <- data.table::data.table(case = 1L, ptime = 1, stime = 2, | ||
delay_daily = 1, delay_lwr = 1, delay_upr = 2, ptime_lwr = 1, | ||
ptime_upr = 2, stime_lwr = 1, stime_upr = 2, obs_at = 100, | ||
censored = "interval", censored_obs_time = 10, ptime_daily = 1, | ||
stime_daily = 1 | ||
) | ||
dummy_obs <- epidist::as_latent_individual(dummy_obs) | ||
stancode <- epidist::epidist( | ||
data = dummy_obs, fn = brms::make_stancode | ||
) | ||
mod <- cmdstanr::cmdstan_model( | ||
stan_file = cmdstanr::write_stan_file(stancode), compile = FALSE | ||
) | ||
message <- capture.output( | ||
mod$check_syntax(pedantic = FALSE), | ||
type = "message" | ||
) | ||
# We can't use TRUE here as pendatic check return lots of false | ||
# positives related to our use of functions. | ||
stopifnot( | ||
length(message) != 0 && | ||
all(message == "Stan program is syntactically correct") | ||
) | ||
shell: Rscript {0} |