-
Notifications
You must be signed in to change notification settings - Fork 16
149 lines (128 loc) · 5.44 KB
/
test-r4ss-with-ss3.yml
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
# 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.