-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreakpoint_tasks.py
More file actions
387 lines (287 loc) · 11.7 KB
/
breakpoint_tasks.py
File metadata and controls
387 lines (287 loc) · 11.7 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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
"""Entrypoint tasks which complete either a segement of work or the full pipeline.
Entrypoint tasks which complete either a segement of work or the full pipeline in which
ExecuteSupplementalTasksWithCluster executes the entire cluster with outputs for tools. Many of
these tasks will both start a cluster in Coiled before spinning it down after finishing work.
License: BSD
"""
import luigi
import cluster_tasks
import const
import export_tasks
import normalize_tasks
import preprocess_climate_tasks
import preprocess_combine_tasks
import preprocess_yield_tasks
import sim_tasks
import stats_tasks
import training_tasks
import usda_tasks
class SampleClimatePreprocessTask(cluster_tasks.EndClusterTask):
"""Task which completes through gneerating a subset of climate summaries.
Task which completes through gneerating a small sample of climate summaries as preprocessed
geotiffs that go through geohashing as a testing step. This will end the cluster on completion.
"""
def get_prereq(self):
"""Get the tasks that need to be completed.
Returns:
Single task (PreprocessClimateGeotiffsTask) that is required to reach this breakpoint.
"""
return preprocess_climate_tasks.PreprocessClimateGeotiffsTask(
dataset_name='sample',
conditions=['observations'],
years=const.YEARS[0:2]
)
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_sample_climate_preprocess'
class FullClimatePreprocessTask(cluster_tasks.EndClusterTask):
"""Task which completes through gneerating a subset of climate summaries.
Task which completes through gneerating a small sample of climate summaries as preprocessed
geotiffs that go through geohashing as a testing step. This will end the cluster on completion.
"""
def get_prereq(self):
"""Get the tasks that need to be completed.
Returns:
Single task (PreprocessClimateGeotiffsTask) that is required to reach this breakpoint.
"""
return preprocess_climate_tasks.PreprocessClimateGeotiffsTask(
dataset_name='historic',
conditions=['observations'],
years=const.YEARS
)
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_full_climate_preprocess'
class YieldSampleTask(cluster_tasks.EndClusterTask):
"""Task which completes through getting yield samples."""
def get_prereq(self):
"""Get the tasks that need to be completed.
Returns:
Single task to be completed.
"""
return preprocess_yield_tasks.PreprocessYieldGeotiffsDistTask()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_yield_sample'
class RunThroughPreprocessTask(cluster_tasks.EndClusterTask):
"""Run all preprocessing tasks on historic data.
Breakpoint which runs up until training (preprocessing tasks). This will end the cluster on
completion. Note that this only includes historic acutals not future values predicted by third
party models.
"""
def get_prereq(self):
"""Get the tasks that need to be completed.
Returns:
Single task (CombineHistoricPreprocessTask) that is required to reach this breakpoint.
"""
return preprocess_combine_tasks.CombineHistoricPreprocessTask()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_preprocess'
class RunThroughPreprocessFutureTask(cluster_tasks.EndClusterTask):
"""Run all preprocessing tasks on future data.
Breakpoint which runs up until training (preprocessing tasks). This will end the cluster on
completion. Note that this only includes future values predicted by third party models and not
historic acutals.
"""
def get_prereq(self):
"""Get the tasks that need to be completed.
Returns:
Tasks for 2030_SSP245 and 2050_SSP245.
"""
return {
'history': normalize_tasks.GetHistoricAsDeltaTask(),
'2030_SSP245': normalize_tasks.GetFutureAsDeltaTask(
condition='2030_SSP245'
),
'2050_SSP245': normalize_tasks.GetFutureAsDeltaTask(
condition='2050_SSP245'
)
}
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_preprocess_future'
class RunThroughSweepTask(cluster_tasks.EndClusterTask):
"""Run through a model sweep with all dependent tasks.
Run through a model sweep with all dependent tasks, closing the cluster afterwards upon
completion.
"""
def get_prereq(self):
"""Get the tasks that need to be completed.
Returns:
Single task (SweepTask).
"""
return training_tasks.SweepTask()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_sweep'
class RunThroughExtendedSweepTask(cluster_tasks.EndClusterTask):
"""Execute extended sweep.
Execute extended sweep for the set of meta-parameter combinations less likely to be successful
before terminating the cluster.
"""
def get_prereq(self):
"""Get the dependent task.
Returns:
Single dependent task (SweepExtendedTask).
"""
return training_tasks.SweepExtendedTask()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_sweep_ext'
class RunThroughHistoricProject(cluster_tasks.EndClusterTask):
"""Task which executes through backwards projection.
Breakpoint which preprocesses, trains models, and makes projections backwards into historic
data. This is largely useful for testing prior to making future predictions. Will terminate
cluster.
"""
def get_prereq(self):
"""Get the dependent task.
Returns:
Single dependent task (ProjectHistoricTask).
"""
return sim_tasks.ProjectHistoricTask()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_project_historic'
class RunThroughSimTask(cluster_tasks.EndClusterTask):
"""Task which runs through simulation of future outcomes.
Breakpoint task which completes the data pipeline through Monte Carlo (includes preprocessing,
model training, etc). This is largely useful for running the pipeline for raw predictions prior
to generation of outputs for tools and visualizations. Will terminate cluster.
"""
def get_prereq(self):
"""Get the dependent task.
Returns:
Single dependent task (CombineSimulationsTask).
"""
return sim_tasks.CombineSimulationsTask()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_sim'
class RunThroughHistTask(cluster_tasks.EndClusterTask):
"""Run the pipeline to the point of generating future prediction system-wide histograms.
Run the pipeline through model training and simulation before summarizing results as system-wide
histograms which can be used in tooling. Will terminate cluster. Unlike
ExecuteSupplementalTasks, this covers only one tool.
"""
def get_prereq(self):
"""Get the dependent task.
Returns:
Single dependent task (HistExportTask).
"""
return export_tasks.HistExportTask()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_hist'
class ExecuteSupplementalTasks(luigi.Task):
"""Execute the pipeline through supplemental tasks.
Execute the pipeline and report on supplemental data outputs which can be used in the paper and'
tools. Will not terminate the cluster and this task is largely useful for debugging the pipeline
in its entirety.
"""
def requires(self):
return {
'stats': stats_tasks.CombineStatsTask(),
'climate': export_tasks.ClimateExportTask(),
'sweep': export_tasks.SweepExportTask(),
'hist': export_tasks.HistExportTask(),
'summary': export_tasks.SummaryExportTask(),
'combined': export_tasks.CombinedTasksRecordTask(),
'rates': export_tasks.ExportClaimsRatesTask(),
'ratesHold': export_tasks.ExportClaimsRatesHoldYearTask()
}
def output(self):
"""Indicate where a status report file should be written.
Returns:
Local target for the status file.
"""
return luigi.LocalTarget(const.get_file_location('break_supplemental.txt'))
def run(self):
"""Execute the pipeline through the supplemental tasks."""
with self.output().open('w') as f:
f.write('done')
class ExecuteSignificantLongTask(luigi.Task):
"""Execute the pipeline to determine the frequency of significant results with long geohashes.
Execute the pipeline to determine the frequency of significant results with long geohashes
(5 character). This is largely useful for debugging or answering follow up questions from the
pipeline. Does not terminate cluster.
"""
def requires(self):
"""Get the task that needs to be completed for this breakpoint to be reached.
Returns:
Single dependency (DeterminePercentSignificantLongTask).
"""
return stats_tasks.DeterminePercentSignificantLongTask()
def output(self):
"""Indicate where a status report file should be written.
Returns:
Local target for the status file.
"""
return luigi.LocalTarget(const.get_file_location('long_sig.txt'))
def run(self):
"""Execute the pipeline through the significant long geohash task."""
with self.output().open('w') as f:
f.write('done')
class ExecuteSupplementalTasksWithCluster(cluster_tasks.EndClusterTask):
"""Execute the entire data pipeline before terminating the cluster."""
def get_prereq(self):
"""Get the task that needs to be completed for this breakpoint to be reached.
Returns:
Single dependency (ExecuteSupplementalTasks).
"""
return ExecuteSupplementalTasks()
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_supplemental'
class ExecuteAllWithCluster(cluster_tasks.EndClusterTask):
"""Execute the entire data pipeline with extended sweep before terminating the cluster."""
def get_prereq(self):
"""Get the task that needs to be completed for this breakpoint to be reached.
Returns:
Multiple dependency.
"""
return [
ExecuteSupplementalTasks(),
training_tasks.SweepExtendedTask(),
usda_tasks.SummarizeYearlyActualClaims()
]
def get_task_name(self):
"""Get a machine friendly name for this task.
Returns:
Machine-friendly name.
"""
return 'end_supplemental_all'