add offset option for ENV Q #97
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
# Build SS3 and run models with estimation and hessian | |
name: run-ss3-bootstrap-files | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- '**.tpl' | |
branches: | |
- main | |
pull_request: | |
types: ['opened', 'edited', 'reopened', 'synchronize', 'ready_for_review'] | |
paths: | |
- '**.tpl' | |
branches: | |
- main | |
# run fast running SS3 models with estimation | |
jobs: | |
run-ss3-bootstrap-files: | |
if: github.event.pull_request.draft == false | |
runs-on: ubuntu-latest | |
env: | |
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
R_KEEP_PKG_SOURCE: yes | |
steps: | |
- name: Checkout ss3 repo | |
uses: actions/checkout@v4 | |
- name: Checkout models repo | |
uses: actions/checkout@v4 | |
with: | |
repository: 'nmfs-ost/ss3-test-models' | |
path: test-models-repo | |
- name: install libcurl | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libcurl4-openssl-dev | |
- name: setup R | |
uses: r-lib/actions/setup-r@v2 | |
# - name: Get admb and put in path, linux | |
# run: | | |
# wget https://github.com/admb-project/admb/releases/download/admb-13.1/admb-13.1-linux.zip | |
# sudo unzip admb-13.1-linux.zip -d /usr/local/bin | |
# sudo chmod 755 /usr/local/bin/admb-13.1/bin/admb | |
# echo "/usr/local/bin/admb-13.1/bin" >> $GITHUB_PATH | |
# - name: Build stock synthesis | |
# run: | | |
# rm -rf SS330 | |
# mkdir SS330 | |
# /bin/bash ./Make_SS_330_new.sh -b SS330 | |
- name: Build stock synthesis with admb docker image | |
run: | | |
rm -rf SS330 | |
rm -rf ss3_osx.tar | |
mkdir SS330 | |
chmod 777 SS330 | |
/bin/bash ./Make_SS_330_new.sh --admb docker -b SS330 | |
- name: move exes, scripts to needed locations | |
run: | | |
mv test-models-repo/models test-models-repo/model_runs | |
mv SS330/ss3 test-models-repo/model_runs/Simple_with_DM_sizefreq/ss3 | |
- name: change permissions on ss3 exes | |
run: sudo chmod a+x test-models-repo/model_runs/Simple_with_DM_sizefreq/ss3 | |
- name: download R packages | |
run: Rscript -e 'install.packages(c("remotes", "purrr", "arsenal", "utils"))' | |
- name: install r4ss | |
run: Rscript -e 'remotes::install_github("r4ss/r4ss")' | |
- name: does ss3 produce bootstrap files | |
run: | | |
# Use Simple_with_DM_sizefreq model to test bootstrap files | |
boot_mod_dir <- grep("Simple_with_DM_sizefreq", list.dirs(file.path("test-models-repo", "model_runs"), full.names = TRUE, recursive = FALSE), value = TRUE) | |
# Change to have model output 8 bootstrap files | |
boot_files <- r4ss::SS_read(dir = boot_mod_dir) | |
boot_files$start$N_bootstraps <- 10 | |
r4ss::SS_write(boot_files, dir = boot_mod_dir, overwrite = TRUE) | |
r4ss::run(dir = boot_mod_dir, exe = file.path(getwd(), "test-models-repo", "model_runs", "Simple_with_DM_sizefreq", "ss3")) | |
bootstrap_length <- length(list.files(boot_mod_dir, pattern = "data_boot")) | |
if(bootstrap_length != (boot_files$start$N_bootstraps - 2)){ | |
stop("Did not produce the amount of bootstrap files specified.") | |
} else { | |
message("All bootstrap files produced.") | |
} | |
# Make sure values in echo and bootstrap files are different | |
dat <- r4ss::SS_readdat(file = file.path(boot_mod_dir,"data_echo.ss_new")) | |
boot1 <- r4ss::SS_readdat(file = file.path(boot_mod_dir,"data_boot_001.ss")) | |
boot2 <- r4ss::SS_readdat(file = file.path(boot_mod_dir,"data_boot_002.ss")) | |
# unlist sizefreq data | |
dat_sizefreq <- purrr::map_df(dat$sizefreq_data_list, ~.x) | |
boot1_sizefreq <- purrr::map_df(boot1$sizefreq_data_list, ~.x) | |
boot2_sizefreq <- purrr::map_df(boot2$sizefreq_data_list, ~.x) | |
df <- data.frame( | |
var = c("lencomp", "lencomp","catch","catch","CPUE","CPUE", "agecomp","agecomp","sizefreq","sizefreq"), | |
data_compare = rep(c("dat_boot1", "boot1_boot2"), 5), | |
n_diff = c( | |
sum(summary(arsenal::comparedf(dat$lencomp, boot1$lencomp))$diffs.byvar.table$n), | |
sum(summary(arsenal::comparedf(boot1$lencomp, boot2$lencomp))$diffs.byvar.table$n), | |
length(summary(arsenal::comparedf(dat$catch, boot1$catch, int.as.num = TRUE))$diffs.table$row.x), | |
length(summary(arsenal::comparedf(dat$catch, boot1$catch, int.as.num = TRUE))$diffs.table$row.x), | |
length(summary(arsenal::comparedf(dat$CPUE, boot1$CPUE, int.as.num = TRUE))$diffs.table$row.x), | |
length(summary(arsenal::comparedf(boot1$CPUE, boot2$CPUE, int.as.num = TRUE))$diffs.table$row.x), | |
sum(summary(arsenal::comparedf(dat$agecomp, boot1$agecomp))$diffs.byvar.table$n), | |
sum(summary(arsenal::comparedf(boot1$agecomp, boot2$agecomp))$diffs.byvar.table$n), | |
sum(summary(arsenal::comparedf(dat_sizefreq, boot1_sizefreq))$diffs.byvar.table$n), | |
sum(summary(arsenal::comparedf(boot1_sizefreq, boot2_sizefreq))$diffs.byvar.table$n) | |
) | |
) | |
df_error <- df |> | |
dplyr::filter(dplyr::if_any(dplyr::where(is.numeric), ~ .x < 20)) | |
print_and_capture <- function(x){ | |
paste(utils::capture.output(print(x)), collapse = "\n") | |
} | |
if(length(df_error > 0)){ | |
stop("Bootstrap data produced less than 20 changes in a data type, see printed table below.\n", print_and_capture(df_error)) | |
} else { | |
message("Bootstrap data types all have > 20 changes") | |
} | |
# Check that the model produced all .ss_new files and that they have content in them | |
ss_new_files <- list.files(boot_mod_dir, pattern = ".ss_new") | |
ss_new_validate <- c("control.ss_new", "data_echo.ss_new", "forecast.ss_new", "starter.ss_new", "wtatage.ss_new") | |
new_dif <- setdiff(ss_new_files, ss_new_validate) | |
if(length(new_dif) > 0){ | |
stop("Not all .ss_new files were produced") | |
} else { | |
message("All .ss_new files produced") | |
} | |
ss_new_length <- purrr::map(ss_new_files, ~length(readLines(file.path(boot_mod_dir, .x)))) | |
ss_new_too_short <- any(ss_new_length |> purrr::map_lgl(~.x < 10)) | |
if(ss_new_too_short == TRUE){ | |
stop("Error producing all lines in one or more .ss_new files") | |
} else { | |
message("All .ss_new files seem to be appropriate length") | |
} | |
shell: Rscript {0} |