-
Notifications
You must be signed in to change notification settings - Fork 0
/
chap-edd.py
executable file
·179 lines (148 loc) · 7.18 KB
/
chap-edd.py
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
#!/usr/bin/env python3
##!/usr/bin/python3
'''
Sample Pegasus workflow for running an EDD workflow as part of the
CHESS Analysis Pipelines (CHAP)
https://github.com/keara-soloway/CHAPBookWorkflows
'''
import argparse
import logging
import os
import shutil
import sys
from Pegasus.api import *
logging.basicConfig(level=logging.DEBUG)
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
# need to know where Pegasus is installed for notifications
PEGASUS_HOME = shutil.which('pegasus-version')
PEGASUS_HOME = os.path.dirname(os.path.dirname(PEGASUS_HOME))
def generate_wf():
'''
Main function that parses arguments and generates the pegasus
workflow
'''
parser = argparse.ArgumentParser(description="generate a CHAP edd workflow")
parser.add_argument('--execution_site', dest='execution_site', default="condorpool", required=False,
help='the site on which you want to run your workflows (condorpool|sge). defaults to condorpool')
args = parser.parse_args(sys.argv[1:])
wf = Workflow('chap-edd')
tc = TransformationCatalog()
rc = ReplicaCatalog()
# --- Properties ----------------------------------------------------------
# set the concurrency limit for the download jobs, and send some extra usage
# data to the Pegasus developers
props = Properties()
props['pegasus.catalog.workflow.amqp.url'] = 'amqp://friend:[email protected]:5672/prod/workflows'
#props['pegasus.data.configuration'] = 'nonsharedfs'
props.write()
# --- Event Hooks ---------------------------------------------------------
# get emails on all events at the workflow level
wf.add_shell_hook(EventType.ALL, '{}/share/pegasus/notification/email'.format(PEGASUS_HOME))
# --- Transformations -----------------------------------------------------
container = Container(
'chap',
Container.SINGULARITY,
'http://data.isi.edu/chess/images/chap.sif',
mounts=["{}:/{}/:rw".format(BASE_DIR, BASE_DIR)],
image_site="nonlocal"
)
tc.add_containers(container)
chap_wrapper = Transformation(
'chap_wrapper',
site='local',
container=container,
pfn=BASE_DIR + '/executables/chap_wrapper.sh',
is_stageable=True
)
tc.add_transformations(chap_wrapper)
# --- Site Catalog -------------------------------------------------
sc = SiteCatalog()
# add a local site with an optional job env file to use for compute jobs
shared_scratch_dir = "{}/local/scratch".format(BASE_DIR)
local_storage_dir = "{}/local/storage".format(BASE_DIR)
local = Site("local") \
.add_directories(
Directory(Directory.SHARED_SCRATCH, shared_scratch_dir)
.add_file_servers(FileServer("file://" + shared_scratch_dir, Operation.ALL)),
Directory(Directory.LOCAL_STORAGE, local_storage_dir)
.add_file_servers(FileServer("file://" + local_storage_dir, Operation.ALL)))
sc.add_sites(local)
# add a sge site for CHESS SGE Cluster
cluster_name = "sge"
shared_scratch_dir = "{}/sge/scratch".format(BASE_DIR)
local_storage_dir = "{}/sge/storage".format(BASE_DIR)
sge = Site(cluster_name) \
.add_directories(
Directory(Directory.SHARED_SCRATCH, shared_scratch_dir)
.add_file_servers(
FileServer("file://" + shared_scratch_dir, Operation.ALL))) \
.add_condor_profile(grid_resource="batch sge") \
.add_pegasus_profile(
style="glite",
queue="all.q",
data_configuration="nonsharedfs",
auxillary_local="true",
nodes=1,
ppn=1,
runtime=1800,
clusters_num=2
)
sc.add_sites(sge)
# --- Workflow -----------------------------------------------------
# track the yaml files for the chess wrapper that are required for each job
executables_dir = os.path.join(BASE_DIR, "executables")
input_dir = os.path.join(BASE_DIR, "input")
calibrate_detector_yaml = File("calibrate_detector.yaml")
rc.add_replica('local', calibrate_detector_yaml, os.path.join(executables_dir, calibrate_detector_yaml.lfn))
diffraction_volume_yaml = File("diffraction_volume.yaml")
rc.add_replica('local', diffraction_volume_yaml, os.path.join(executables_dir, diffraction_volume_yaml.lfn))
microstrain_maps_yaml = File("microstrain_maps.yaml")
rc.add_replica('local', microstrain_maps_yaml, os.path.join(executables_dir, microstrain_maps_yaml.lfn))
# other files from the input directory
ceria_calibration_yaml = File("ceria_calibration.yaml")
rc.add_replica('local', ceria_calibration_yaml, os.path.join(input_dir, ceria_calibration_yaml.lfn))
dvl_yaml = File("dvl.yaml")
rc.add_replica('local', dvl_yaml, os.path.join(input_dir, dvl_yaml.lfn))
strain_analysis_yaml = File("strain_analysis.yaml")
rc.add_replica('local', strain_analysis_yaml, os.path.join(input_dir, strain_analysis_yaml.lfn))
# common input data.tar file
data_tar = File("data.tar")
rc.add_replica('local', data_tar, os.path.join(input_dir, data_tar.lfn))
# calibrate detector job
ceria_calibrated = File("ceria_calibrated.yaml")
calibrate_detector_job = Job('chap_wrapper', node_label="calibrate_detector")
calibrate_detector_job.add_args(calibrate_detector_yaml)
calibrate_detector_job.add_inputs(data_tar, calibrate_detector_yaml, ceria_calibration_yaml)
calibrate_detector_job.add_outputs(ceria_calibrated)
for output in ['mca1_calibration_fit_mask_hkls.png', 'mca1_calibration_tth_initial_guess.png']:
calibrate_detector_job.add_outputs(File(output), stage_out=True)
wf.add_jobs(calibrate_detector_job)
# diffraction volume job
dvl_measured = File("dvl_measured.yaml")
diffraction_volume_job = Job('chap_wrapper', node_label="diffraction_volume")
diffraction_volume_job.add_args(diffraction_volume_yaml)
diffraction_volume_job.add_inputs(data_tar, diffraction_volume_yaml, dvl_yaml)
diffraction_volume_job.add_outputs(dvl_measured)
for output in ['mca1_dvl.png', 'mca1_dvl_mask.png']:
diffraction_volume_job.add_outputs(File(output), stage_out=True)
wf.add_jobs(diffraction_volume_job)
# the microstrain_maps job
microstrain_maps_job = Job('chap_wrapper', node_label="microstrain_maps")
microstrain_maps_job.add_args(microstrain_maps_yaml)
microstrain_maps_job.add_inputs(data_tar, microstrain_maps_yaml, strain_analysis_yaml, ceria_calibrated)
for output in ['strain.nxs', 'mca1_strainanalysis_unconstrained_fits.mp4', 'mca1_strainanalysis_fit_mask_hkls.png',
'mca1_strainanalysis_material_config.png']:
microstrain_maps_job.add_outputs(File(output), stage_out=True)
wf.add_jobs(microstrain_maps_job)
# add dependencies explicitly
wf.add_dependency(microstrain_maps_job, parents=[calibrate_detector_job])
try:
wf.add_transformation_catalog(tc)
wf.add_site_catalog(sc)
wf.add_replica_catalog(rc)
wf.write()
wf.plan( sites=[args.execution_site], verbose=3, submit=True)
except PegasusClientError as e:
print(e.output)
if __name__ == '__main__':
generate_wf()