-
Notifications
You must be signed in to change notification settings - Fork 14
/
Run.py
executable file
·108 lines (84 loc) · 3.27 KB
/
Run.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
#!/usr/bin/env python3
'''
(C) Copyright 2023 UCAR
This software is licensed under the terms of the Apache Licence Version 2.0
which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
'''
####################################################################################################
# This script generates a suite.rc file from a pre-configured set MPAS-Workflow scenarios, and then
# submits those suites via Cylc
####################################################################################################
## Usage:
# source env/cheyenne.${YourShell}
# ./Run.py {{runConfig}}
# external modules
import argparse
from collections.abc import Iterable
import glob
import os
from pathlib import Path
import subprocess
# local modules
from initialize.config.Config import Config
from initialize.config.Logger import Logger
from initialize.config.Scenario import Scenario
from initialize.suites.SuiteBase import SuiteLookup
def main():
'''
main program
'''
hname = os.getenv('NCAR_HOST')
cylc = os.getenv('CYLC_ENV')
if hname == "derecho" and cylc is None:
print('CYLC_ENV environment variable is not set, setting it to /glade/work/jwittig/conda-envs/my-cylc8.2')
os.environ['CYLC_ENV'] = '/glade/work/jwittig/conda-envs/my-cylc8.2'
run = Run()
run.execute()
class Run(Logger):
def __init__(self):
super().__init__()
# Parse command line
ap = argparse.ArgumentParser()
ap.add_argument('config', type=str,
help='configuration file; e.g., runs/test.yaml, scenarios/{{scenarioName}}.yaml')
ap.add_argument('-b', '--bundle_dir', help='mpas bundle directory')
ap.add_argument('-x', '--suffix', help='experiment name suffix')
args = ap.parse_args()
assert Path(args.config).is_file(), (self.logPrefix+'config ('+args.config+') does not exist')
self.__configFile = args.config
self.__config = Config(args.config, args.bundle_dir, args.suffix)
def execute(self):
'''
execute the scenarios
'''
if self.__config.has('scenarios'):
# scenario location(s)
scenarios = self.__config.getOrDie('scenarios')
assert isinstance(scenarios, Iterable), 'scenarios must be a list of scenario files'
else:
scenarios = [self.__configFile]
for scenarioFile in scenarios:
assert Path(scenarioFile).is_file(), (self.logPrefix+'scenario ('+scenarioFile+') does not exist')
print("#########################################################################")
print("Running the scenario: "+scenarioFile)
print("#########################################################################")
self.clean(self)
scenario = Scenario(scenarioFile, self.__config._bundle_dir, self.__config._suffix)
scenario.initialize()
# suite name (defaults to Cycle)
suiteName = scenario.getConfig().getOrDefault('suite', 'Cycle')
suite = SuiteLookup(suiteName, scenario.getConfig())
suite.submit()
self.clean(self)
@staticmethod
def clean(self):
self.log('cleaning up auto-generated files...', level=self.MSG_DEBUG)
for g in [
"config/auto/*.csh",
"suite.rc",
]:
files = glob.glob(g)
for file in files:
sub = subprocess.run(['rm', file])
## execute main program
if __name__ == '__main__': main()