-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXGC-DiffusionOptimizer.py
More file actions
executable file
·290 lines (235 loc) · 8.06 KB
/
XGC-DiffusionOptimizer.py
File metadata and controls
executable file
·290 lines (235 loc) · 8.06 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
#!/usr/bin/env python3
import argparse
import shutil
import os
import f90nml
#import xml.etree.ElementTree as ET
import lxml.etree as ET
from effis.composition import Workflow, EffisLogger, Input
from effis.composition.runner import slurm, perlmutter, frontier
class suchyta:
perlmutter = {
'src' : "/global/homes/e/esuchyta/software/src/XGC-Devel",
'build' : "/global/homes/e/esuchyta/software/build/perlmutter/XGC-Devel",
'examples': "/global/homes/e/esuchyta/software/src/XGC-Examples",
'analysis': "/global/homes/e/esuchyta/software/src/XGC-Analysis",
'adios': '/global/homes/e/esuchyta/software/install/perlmutter/adios2-gcc/lib/python3.11/site-packages',
'gpus' : 4,
'per': 32, # 64 cores, but with 128 threads, which Slurm counts
}
frontier = {
'src' : "/ccs/home/esuchyta/software/src/XGC-Devel",
'build' : "/ccs/home/esuchyta/software/build/frontier/XGC-Devel",
'examples': "/ccs/home/esuchyta/software/src/XGC-Examples",
'analysis': "/ccs/home/esuchyta/software/src/XGC-Analysis",
'adios': '/ccs/home/esuchyta/software/install/frontier/adios2-gcc12.2.0/lib/python3.11/site-packages',
'gpus' : 8,
'per': 14, # Default gives one core to system stuff
}
def SetupArgs():
runner = Workflow.DetectRunnerInfo()
if (runner is not None) and (not isinstance(runner, slurm)):
EffisLogger.RaiseError(ValueError, "Current example batch setup is for Slurm")
slurmparser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Run Configuration
##############################################
slurmparser.add_argument(
"-o", "--outdir",
type=str,
help="Path to run directory",
required=True,
)
slurmparser.add_argument(
"-x", "--xgc",
type=str,
help="Flavor of XGC",
required=True,
choices=(
'xgca-cpp',
'xgca-cpp-gpu',
'xgc-es-cpp',
'xgc-es-cpp-gpu',
'xgc-eem-cpp',
'xgc-eem-cpp-gpu',
)
)
if isinstance(runner, (perlmutter, frontier)):
slurmparser.add_argument(
"-e", "--example",
type=str,
help="Which example to run",
required=False,
default=os.path.join(getattr(suchyta, runner.__class__.__name__)['examples'], "ecbc_low_beta_n6"),
)
slurmparser.add_argument(
"-s", "--suchyta",
action="store_true",
help="Use Eric Suchyta's software",
)
else:
slurmparser.add_argument(
"-e", "--example",
type=str,
help="Which example to run",
required=True,
)
##############################################
# Scheduler Properties
##############################################
slurmparser.add_argument(
"-c", "--charge",
type=str,
help="Account to charge",
required=True,
dest="Charge",
)
slurmparser.add_argument(
"-n", "--nodes",
type=int,
help="Number of nodes to use",
required=False,
default=1,
dest="Nodes",
)
slurmparser.add_argument(
"-w", "--walltime",
type=str,
help="Wall time to request",
required=False,
default="00:15:00",
dest="Walltime",
)
if isinstance(runner, perlmutter):
slurmparser.add_argument(
"-q", "--qos",
type=str,
help="QOS",
required=False,
default="regular",
dest="QOS"
)
elif isinstance(runner, frontier):
slurmparser.add_argument(
"-q", "--qos",
type=str,
help="QOS",
required=False,
dest="QOS"
)
##############################################
args = slurmparser.parse_args()
if isinstance(runner, perlmutter) and args.suchyta:
args.Constraint = 'gpu'
return args, runner
def WriteXML(outdir):
filename = os.path.join(outdir, "adios2cfg.xml")
tree = ET.parse(filename, parser=ET.XMLParser(remove_blank_text=True))
adios_config = tree.getroot()
#kind = "BP5"
ios = adios_config.findall('io')
for io in ios:
engines = io.findall('engine')
for engine in engines:
#engine.set('type', kind)
engine.text = None
kind = "BP5"
dname = 'diagnosis.diffusion_profiles'
ios = adios_config.findall(f"./io[@name='{dname}']")
if len(ios) == 0:
ios = [ET.SubElement(adios_config, "io")]
for io in ios:
io.set("name", dname)
engines = io.findall('engine')
if len(engines) == 0:
engines = [ET.SubElement(io, "engine")]
for engine in engines:
engine.set("type", kind)
dname = "input.diffusion_coefficients"
ET.indent(tree)
tree.write(filename)
def EditNML(Directory):
n = f90nml.Namelist()
n["sml_param"] = {}
n["sml_param"]["sml_mstep"] = 6
n["diag_param"] = {}
n["diag_param"]['diag_1d_on'] = True
n["diag_param"]['diag_1d_period'] = 1
n["diag_param"]['diag_3d_on'] = True
n["diag_param"]['diag_3d_period'] = 1
n["diag_param"]['diag_diff_profiles_on'] = True
n["diag_param"]['diag_diff_profiles_period'] = 1
n["diff_param"] = {}
n["diff_param"]['diff_update_period'] = 2
n["diff_param"]["diff_update_on"] = True
filename = os.path.join(Directory, "input")
tmp = "{0}.tmp".format(filename)
shutil.copy(filename, tmp)
os.remove(filename)
f90nml.patch(tmp, n, out_path=filename)
os.remove(tmp)
if __name__ == "__main__":
args, runner = SetupArgs()
if ('suchyta' in dir(args)) and args.suchyta:
setup = getattr(suchyta, runner.__class__.__name__)
else:
EffisLogger.RaiseError(RuntimeError, "Edit the example for your setup")
extra = {}
for key in ('Nodes', 'Walltime', 'Charge', 'QOS', 'Constraint'):
if key in dir(args):
extra[key] = getattr(args, key)
if isinstance(runner, frontier):
extra['SchedulerDirectives'] = ["--threads-per-core", "2"]
MyWorkflow = Workflow(
Runner=runner,
Directory=args.outdir,
Subdirs=False,
**extra,
)
# ITG_core_deltaf - xgc-es-cpp-gpu
# ecbc_low_beta_n6 - xgc-eem-cpp-gpu
# neoclassical_core - xgca-cpp-gpu
AppInfo = {
'cmd': os.path.join(setup['build'], 'bin', args.xgc),
'Nodes': args.Nodes,
'Ranks': args.Nodes * setup['gpus'],
'RanksPerNode': setup['gpus'],
'GPUsPerRank': 1,
'CoresPerRank': setup['per'],
'MPIRunnerArguments': ['--gpu-bind', 'closest'],
'SetupFile': os.path.join(setup['build'], "setup.sh"),
}
if isinstance(runner, frontier):
AppInfo['MPIRunnerArguments'] += ["--threads-per-core", "2"]
Simulation = MyWorkflow.Application(
Name="XGC",
LogFile="XGC.log",
**AppInfo,
)
Simulation.Input += os.path.join(setup['src'], "quickstart", "inputs", "petsc.rc")
Simulation.Input += os.path.join(setup['src'], "quickstart", "inputs", "adios2cfg.xml")
usedir = args.example
if os.path.isfile(args.example):
usedir = os.path.dirname(args.example)
Simulation.Input += Input(args.example, rename="input")
for filename in os.listdir(usedir):
Simulation.Input += os.path.join(usedir, filename)
env = {}
pythonpath = [
setup['analysis'],
setup['adios']
]
if 'PYTHONPATH' in os.environ:
pythonpath += [os.environ['PYTHONPATH']]
env['PYTHONPATH'] = ':'.join(pythonpath)
Analysis = MyWorkflow.Application(
Runner=None,
Environment=env,
Name="DiffusionOptmizer",
LogFile="DiffusionOptimizer.log",
cmd="python3",
CommandLineArguments=os.path.join(setup['analysis'], "Diffusion_Optimizer", "diffusion_optimizer.py"),
)
MyWorkflow.Create()
WriteXML(Simulation.Directory)
EditNML(Simulation.Directory)
MyWorkflow.Submit()