-
Notifications
You must be signed in to change notification settings - Fork 4
/
rocoto_utilities.py
173 lines (151 loc) · 7.34 KB
/
rocoto_utilities.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
##################################################################################
# Description
##################################################################################
# This module is designed to centralize the path definitions and assignment of
# different possible control flows for the rocoto workflow manager. One
# should define the appropriate paths for their system in the GLOBAL PARAMETERS
# below, and specify the appropriate control flows for the tasks to be run and
# monitored. Methods in this module can be used in other scripts for automating
# rocoto actions, used stand alone by calling actions in the bottom script
# section, or directly as functions in a Python session by importing the module.
#
##################################################################################
# License Statement:
##################################################################################
# This software is Copyright © 2024 The Regents of the University of California.
# All Rights Reserved. Permission to copy, modify, and distribute this software
# and its documentation for educational, research and non-profit purposes,
# without fee, and without a written agreement is hereby granted, provided that
# the above copyright notice, this paragraph and the following three paragraphs
# appear in all copies. Permission to make commercial use of this software may
# be obtained by contacting:
#
# Office of Innovation and Commercialization
# 9500 Gilman Drive, Mail Code 0910
# University of California
# La Jolla, CA 92093-0910
#
# This software program and documentation are copyrighted by The Regents of the
# University of California. The software program and documentation are supplied
# "as is", without any accompanying services from The Regents. The Regents does
# not warrant that the operation of the program will be uninterrupted or
# error-free. The end-user understands that the program was developed for
# research purposes and is advised not to rely exclusively on the program for
# any reason.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
# LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
# EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED
# HEREUNDER IS ON AN “AS IS” BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO
# OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# MODIFICATIONS.
#
#
##################################################################################
# Imports
##################################################################################
import os
import time
from datetime import datetime as dt
##################################################################################
# SET GLOBAL PARAMETERS
##################################################################################
# directory path for root of git clone of GSI-WRF-Cycling-Template
USR_HME = '/expanse/lustre/projects/ddp181/cgrudzien/JEDI-MPAS-Common-Case/GSI-WRF-Cycling-Template'
# directory for rocoto install
RCT_HME = '/expanse/lustre/projects/ddp181/cgrudzien/SOFT_ROOT/rocoto'
# Case study sub directories
CSES = [
'DeepDive',
]
# name of .xml workflows to execute and monitor WITHOUT the extension of file
CTR_FLWS = [
'2022122800_valid_date_ensemble',
]
END = dt(2024, 1, 1, 0)
##################################################################################
# Derived paths
##################################################################################
# path to .xml control flows
settings_dir = USR_HME + '/simulation_settings'
# path to database
dbs_dir = USR_HME + '/workflow_status'
##################################################################################
# Rocoto utility commands
##################################################################################
# The following commands are wrappers for the native rocoto functions described
# in its documentation:
#
# http://christopherwharrop.github.io/rocoto/
#
# The rocoto run and stat commands require no arguments and are defined by the
# global parameters in the above sections. For the boot and rewind commands, one
# should supply a list of strings corresponding to the control flow, cycle date
# time and the corresponding task names to boot or rewind. One can, e.g., loop
# through ensemble indexed tasks this way with an iterator of the form:
#
# run_rocotoboot(
# ['3denvar_test_run'],
# ['201902081800'],
# ['ungrib_ens_' + str(i).zfill(2) for i in range(21)]
# )
#
# to boot all tasks in a range for a specified date and control flow.
#
##################################################################################
def run_rocotorun():
for cse in CSES:
for ctr_flw in CTR_FLWS:
cmd = RCT_HME + '/bin/rocotorun -w ' +\
settings_dir + '/' + cse + '/' + ctr_flw + '/ctr_flw.xml' +\
' -d ' + dbs_dir + '/' + cse + '-' + ctr_flw + '.store -v 10'
os.system(cmd)
# update workflow statuses after loops
run_rocotostat()
def run_rocotostat():
for cse in CSES:
for ctr_flw in CTR_FLWS:
cmd = RCT_HME + '/bin/rocotostat -w ' +\
settings_dir + '/' + cse + '/' + ctr_flw + '/ctr_flw.xml' +\
' -d ' + dbs_dir + '/' + cse + '-' + ctr_flw + '.store -c all'+\
' > ' + dbs_dir + '/' + cse + '-' + ctr_flw + '_workflow_status.txt'
os.system(cmd)
def run_rocotoboot(cses, flows, cycles, tasks):
for cse in cses:
for ctr_flw in flows:
for cycle in cycles:
for task in tasks:
cmd = RCT_HME + '/bin/rocotoboot -w ' +\
settings_dir + '/' + cse + '/' + ctr_flw + '/ctr_flw.xml' +\
' -d ' + dbs_dir + '/' + cse + '-' + ctr_flw + '.store' +\
' -c ' + cycle + ' -t ' + task
os.system(cmd)
# update workflow statuses after loops
run_rocotostat()
def run_rocotorewind(cses, flows, cycles, tasks):
for cse in cses:
for ctr_flw in flows:
for cycle in cycles:
for task in tasks:
cmd = RCT_HME + '/bin/rocotorewind -w ' +\
settings_dir + '/' + cse + '/' + ctr_flw + '/ctr_flw.xml' +\
' -d ' + dbs_dir + '/' + cse + '-' + ctr_flw + '.store' +\
' -c ' + cycle + ' -t ' + task
os.system(cmd)
# update workflow statuses after loops
run_rocotostat()
##################################################################################
# Execute the following lines as script
##################################################################################
if __name__ == '__main__':
# monitor and advance the jobs
while (dt.now() < END):
run_rocotorun()
time.sleep(60)
##################################################################################
# end