-
Notifications
You must be signed in to change notification settings - Fork 20
169 lines (143 loc) · 7.26 KB
/
run-ss3-bootstrap.yml
File metadata and controls
169 lines (143 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Build SS3 and run Simple_with_DM_sizefreq model from test models
# repo to make sure that ss3 makes bootstrap files and that all
# .ss_new files were produced.
# Only runs on a pull request and a push to main if the tpl files have changed.
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
concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true
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@v6
- name: Checkout test models repo
uses: actions/checkout@v6
with:
repository: 'nmfs-ost/ss3-test-models'
path: test-models-repo
- name: Install libcurl & other necessary 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
sudo apt-get install -y libfontconfig1-dev
sudo apt-get install -y libharfbuzz-dev libfribidi-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: Ensure that ss3 produces 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 and run model
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)
# Compare data and bootstrap files
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")
}
# Error if not enough changes made in bootstrap files
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 correct 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}