Skip to content

191 spawner recruit rebased #364

191 spawner recruit rebased

191 spawner recruit rebased #364

# Check that r4ss functions SS_output() and SS_plots() run with changes in ss3
# using the test models.
# Only runs on a pull request and a push to main if tpl files have changed.
name: test-r4ss-with-ss3
on:
workflow_dispatch:
push:
paths:
- '**.tpl'
branches:
- main
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize', 'ready_for_review']
paths:
- '**.tpl'
branches:
- main
# Run models without estimation, then run r4ss SS_plots() and SS_output()
jobs:
test-r4ss-with-ss3:
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 and other necessary linux packages
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install --only-upgrade libstdc++6
sudo apt-get install -y libcurl4-openssl-dev
- name: Setup R
uses: r-lib/actions/setup-r@v2
- name: Install R packages to run in parallel
run: Rscript -e 'install.packages(c("remotes","parallely", "furrr", "future"))'
- name: Install r4ss
run: Rscript -e 'remotes::install_github("r4ss/r4ss")'
# - name: Get admb and put in path, linux
# run: |
# wget https://github.com/admb-project/admb/releases/download/admb-13.2/admb-13.2-linux.zip
# sudo unzip admb-13.2-linux.zip -d /usr/local/bin
# sudo chmod 755 /usr/local/bin/admb-13.2/bin/admb
# echo "/usr/local/bin/admb-13.2/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 and R scripts to needed locations
run: |
mv test-models-repo/models test-models-repo/model_runs
mv SS330/ss3 test-models-repo/model_runs/ss3
mv test-models-repo/.github/r_scripts/run_from_par.R test-models-repo/run_from_par.R
mv test-models-repo/.github/r_scripts/run_compare_noest.R test-models-repo/run_compare_noest.R
- name: Change permissions on ss3 exes
run: sudo chmod a+x test-models-repo/model_runs/ss3
- name: Run models without estimation using the run_from_par.R script in the test models repo
run: |
cd test-models-repo && Rscript run_from_par.R
- name: Run SS_output() and SS_plots() on test models
run: |
# Setup parallel
ncores <- parallelly::availableCores(omit = 1)
future::plan(future::multisession, workers = ncores)
# Get model names
mod_names <- list.dirs("test-models-repo/model_runs", full.names = FALSE, recursive = FALSE)
print(mod_names)
if(length(mod_names) == 0) {
stop("Did not r4ss on any models; perhaps path to models is not correct?")
}
# Run SS_output() on test models in parallel and return errors
out <- furrr::future_map(mod_names, function(i) {
tryCatch(r4ss::SS_output(file.path("test-models-repo", "model_runs", i),
verbose = FALSE, hidewarn = TRUE, printstats = FALSE),
error = function(e) {
print(e)
}
)
})
# Run SS_plots() on test models in parallel and return errors
plots <- furrr::future_map(out, function(x) {
tryCatch(r4ss::SS_plots(x, verbose = FALSE, openfile = FALSE),
error = function(e) {
print(e)
})
})
# Determine if job fails and return model names with errors from either function if there are any
out_issues <- mod_names[unlist(lapply(out, function(x) "error" %in% class(x)))]
plotting_issues<- mod_names[unlist(lapply(plots, function(x) "error" %in% class(x)))]
if(length(out_issues) == 0 & length(plotting_issues) == 0) {
message("All r4ss functions completed successfully!")
} else {
message("There were some errors. SS_output() failed to run for model_runs ",
paste0(out_issues, collapse = ", "), "; SS_plots() failed to run for ",
"models ", paste0(plotting_issues, collapse = " ,"), ". More info ",
"below.")
message("Problems with SS_output():")
for(i in out_issues) {
message(i)
tmp_loc <- which(mod_names == i)
print(out[[tmp_loc]])
}
message("Problems with SS_plot()")
for(p in plotting_issues) {
message(p)
tmp_loc <- which(mod_names == p)
print(plots[[tmp_loc]])
}
q(status = 1)
}
shell: Rscript {0}
# could archive files, but the archive will be large, so may not be worth it.