-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup-singularity-work-dir.py
More file actions
69 lines (54 loc) · 2.31 KB
/
setup-singularity-work-dir.py
File metadata and controls
69 lines (54 loc) · 2.31 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
# Adapted from LLNL Orchestrator "KIMRun" module
# Set up a direcory structure so that the KDP utilities
# such as "kimitems" and "pipeline-run-pair" can be
# used with singularity
import os
CODE_TO_DIR = {
'MO': 'models',
'MD': 'model-drivers',
'TE': 'tests',
'TD': 'test-drivers',
'SM': 'simulator-models',
'VC': 'verification-checks',
}
def env_file_path(work_path):
return os.path.join(work_path, 'kimrun-env')
work_path = os.path.abspath(input("Directory you would like to work in?\n"))
os.mkdir(work_path)
kdp_env_file_path = os.path.join(work_path, 'kimrun-kdp-env')
kim_api_config_path = os.path.join(work_path, '.kim-api/config')
with open(env_file_path(work_path), 'w') as f:
f.write(f"PIPELINE_ENVIRONMENT_FILE={kdp_env_file_path}\n"
+ f"KIM_API_CONFIGURATION_FILE={kim_api_config_path}")
with open(kdp_env_file_path, 'w') as f:
f.write("#!/bin/bash\n"
+ "#==============================================\n"
+ "# this file has a specific format since it is\n"
+ "# also read by python. only FOO=bar and\n"
+ "# the use of $BAZ can be substituted. comments\n"
+ "# start in column 0\n"
+ "#==============================================\n\n"
+ "PIPELINE_LOCAL_DEV=True\n"
+ f"LOCAL_REPOSITORY_PATH={work_path}\n"
+ f"LOCAL_DATABASE_PATH={work_path}/db")
kdp_directories = list(CODE_TO_DIR.values()) + \
['errors', '.kim-api', 'test-results', 'verification-results']
# create KDP subdirectories
for dirname in kdp_directories:
dirpath = os.path.join(work_path, dirname)
os.mkdir(dirpath)
with open(kim_api_config_path, 'w') as f:
f.write(f"model-drivers-dir = {work_path}/md\n"
+ f"portable-models-dir = {work_path}/pm\n"
+ f"simulator-models-dir = {work_path}/sm\n")
with open(kim_api_config_path) as f:
for line in f:
if len(line) > 255:
raise RuntimeError(
'Path to the work directory is too long.\n'
'KIM API config file max line length = 255,\n'
'your path must be less than approx. 225 chars.')
print(
"Work directory created. Run Singularity with (at least) the following options:"
)
print(f"--env-file {env_file_path(work_path)} -B {work_path} --writable-tmpfs")