-
Notifications
You must be signed in to change notification settings - Fork 0
346 lines (290 loc) · 11.7 KB
/
main.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# Model workflow code
name: Model CI # ==============================================================
on: # controls when the workflow will run
push: # trigger workflow on push events, but only for the main branch
branches: [ main ]
paths:
- "model-api/**"
- ".github/actions/build-model/**"
- ".github/workflows/main.yml"
- "st-kit/**"
- "!README.md" # don't rebuild on documentation changes
pull_request: # triggers workflow on pull request events (main branch only)
branches: [ main ] # ensures changes are "mergeable"
workflow_dispatch: # permits manual triggers from the Actions tab
# inputs:
# debug_enabled:
# description: 'Run the build with tmate debugging enabled'
# required: false
# default: false
# workflow_run:
# workflows: [ "Docker" ]
# branches: [ main ]
# types: [ completed ]
jobs: # =======================================================================
# ---------------------------------------------------------------------------
count-vars: # creates template models for count data
# ---------------------------------------------------------------------------
strategy:
matrix:
likelihood: [ poisson,
negative-binomial-simple, negative-binomial,
gen-pois,
zero-inflated-poisson, zero-inflated-negative-binomial ]
link: [ linear, exponential ]
gle: [ b0, b0-b1 ]
include:
# Includes a new variable demo with a value of true for the matrix leg
# matching the following likelihood, link, and gle.
- likelihood: poisson
link: exponential
gle: b0-b1
demo: true
exclude:
# excludes parameterizations
- likelihood: gen-pois
link: linear
runs-on: ubuntu-latest
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v2
- name: Pull model API from GitLab
run: |
git submodule update --init --remote model-api
# Build the JAGS model and save it in tmp
- name: Build model
uses: ./.github/actions/build-model # composite action to create model
with:
data-type: ${{ github.job }}
likelihood: ${{ matrix.likelihood }}
link: ${{ matrix.link }}
gle: ${{ matrix.gle }}
demo: ${{ matrix.demo }}
# Each artifact behaves as a file share. Uploading to the same artifact
# multiple times in the same workflow can overwrite and append to already
# uploaded files.
- name: Upload tmp directory as an artifact
uses: actions/upload-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
retention-days: 1
# ---------------------------------------------------------------------------
binomial-vars: # creates template models for successes / trials data
# ---------------------------------------------------------------------------
strategy:
matrix:
likelihood: [ binomial, beta-binomial ] # zero-inflated-binomial, zero-inflated-beta-binomial
link: [ inverse-logit ]
gle: [ b0, b0-b1 ]
include:
- likelihood: binomial
link: inverse-logit
gle: b0
demo: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Pull model API from GitLab
run: |
git submodule update --init --remote model-api
- name: Build model
uses: ./.github/actions/build-model # composite action to create model
with:
data-type: ${{ github.job }}
likelihood: ${{ matrix.likelihood }}
link: ${{ matrix.link }}
gle: ${{ matrix.gle }}
demo: ${{ matrix.demo }}
- name: Upload tmp directory as an artifact
uses: actions/upload-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
retention-days: 1
# ---------------------------------------------------------------------------
nonnegative-continuous-vars: # template models for non-zero continuous data
# ---------------------------------------------------------------------------
strategy:
matrix:
likelihood: [ lognormal, gamma ] #, beta-binomial
link: [ linear ] # TODO: is exponential here even an option?
gle: [ b0, b0-b1 ]
include:
- likelihood: gamma
link: linear
gle: b0-b1
demo: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# with:
# submodules: true # fetch model and data API submodules
# fetch-depth: 0 # fetch all history for .GitInfo and .Lastmod
- name: Pull model API from GitLab
run: |
git submodule update --init --remote model-api
- name: Build model
uses: ./.github/actions/build-model # composite action to create model
with:
data-type: ${{ github.job }}
likelihood: ${{ matrix.likelihood }}
link: ${{ matrix.link }}
gle: ${{ matrix.gle }}
demo: ${{ matrix.demo }}
- name: Upload tmp directory as an artifact
uses: actions/upload-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
retention-days: 1
# ---------------------------------------------------------------------------
define-jags-model-matrix:
# ---------------------------------------------------------------------------
needs: [ count-vars, binomial-vars, nonnegative-continuous-vars ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download file share
uses: actions/download-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
- name: Create JAGS model file list as a JSON array
id: set-matrix # we need an "id" so we can use it in "outputs" below
run: |
echo "::set-output name=matrix::$(find tmp -name "model.jags" | \
perl -e 'use JSON; @in=grep(s/\n$//, <>); print encode_json(\@in)."\n";')"
- name: Copy model files into model zoo in assets
run: |
find tmp -type f -name '*.jags'
find tmp -type f -name '*.jags' \
-exec bash -c '
ZOO=$(sed "s/tmp/assets\/model-zoo/g" <<< $(dirname $0))
mkdir -p $(dirname $ZOO) && cp $0 $ZOO-model.jags' {} \;
# Push changes made to the repo during a workflow run
- name: Commit changes
uses: EndBug/add-and-commit@v7
with:
default_author: github_actions
branch: main
add: "assets/**/*-model.jags" # --force
message: Automatic update of model files in model zoo
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
# ---------------------------------------------------------------------------
use-jags-models-to-sim-data: # create dynamic matrix from json, simulate data
# ---------------------------------------------------------------------------
needs: [ define-jags-model-matrix ]
runs-on: ubuntu-latest
strategy:
matrix:
jags-model: ${{ fromJson(needs.define-jags-model-matrix.outputs.matrix) }}
options: [ --seed=123 ]
steps:
- uses: actions/checkout@v2
- name: Pull model API from GitLab
run: |
git submodule update --init --remote model-api
- name: Download file share
uses: actions/download-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
- name: Use cached results (simulate data and fit model)
id: verify
uses: ./.github/actions/call-r
with:
rfile: model-api/demo/sim.R
args: ${{ matrix.jags-model }}
opts: ${{ matrix.options }}
- name: Check status of model verification
run: echo "The exit status was ${{ steps.verify.outputs.code }}"
- name: Upload tmp directory as an artifact
uses: actions/upload-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
retention-days: 1
# ---------------------------------------------------------------------------
cleanup: # summarize sim fits, and write demo data to assets/_data
# ---------------------------------------------------------------------------
needs: [ use-jags-models-to-sim-data ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Pull model API from GitLab
run: |
git submodule update --init --remote model-api
- name: Download file share
uses: actions/download-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
- name: Move datasets flagged for demo to assets/_data
run: |
mkdir -p assets/_data
HINT_FILE=assets/_data/.generating-models.csv
rm -f $HINT_FILE && touch $HINT_FILE
echo file, generating_model >> $HINT_FILE
find tmp -type f -name 'demo' \
-exec bash -c '
DD_DIR=$(dirname $0)
DD_LAB=$(echo $0 | grep -oP "(?<=tmp/).*(?=-vars)")
DD_CSV=assets/_data/$DD_LAB-data.csv
echo $DD_CSV, $(basename $DD_DIR) >> assets/_data/.generating-models.csv
cp $DD_DIR/samples.csv $DD_CSV
cp $DD_DIR/sample-*.csv assets/_data' {} \;
ls assets/_data
# Push changes made to the repo during a workflow run
- name: Commit changes
uses: EndBug/add-and-commit@v7
with:
default_author: github_actions
branch: main
add: "assets/_data/**"
message: Automatic update of demo data
- name: Create model config file list as a JSON array
id: config-file-list # we need an "id" so we can use it in "outputs" below
run: |
echo "::set-output name=matrix::$(find assets -name "[a-z]*.yml" | \
perl -e 'use JSON; @in=grep(s/\n$//, <>); print encode_json(\@in)."\n";')"
outputs:
configs: ${{ steps.config-file-list.outputs.matrix }}
# ---------------------------------------------------------------------------
test: # use simulated data in the analysis pipeline
# ---------------------------------------------------------------------------
needs: [ cleanup ]
runs-on: ubuntu-latest
strategy:
matrix:
config-file: ${{ fromJson(needs.cleanup.outputs.configs) }}
# options: [ --n-adapt=1000 --n-update=5000 --n-iter=2500 --n-cores=1 --rm-dqs ]
steps:
- uses: actions/checkout@v2
- name: Pull model API from GitLab
run: |
git submodule update --init --remote model-api
- name: Download file share
uses: actions/download-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
- name: Test model API using data simulated in prior job
uses: ./.github/actions/call-r
with:
rfile: model-api/analysis-pipeline.R
args: ${{ matrix.config-file }}
opts: '--n-adapt=2000 --n-update=6000 --n-iter=3000 --n-cores=1 --rm-dqs' # ${{ matrix.options }}
# # Enable tmate debugging of manually-triggered workflows if the input
# # option was provided (i.e., debug_enabled=true)
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# # if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
- run: sudo mv assets/_output tmp/test-fits
- name: Upload tmp directory as an artifact
uses: actions/upload-artifact@v2
with:
name: artifact-${{ github.sha }}
path: tmp
retention-days: 1