-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-singularity-work-dir.py
More file actions
82 lines (67 loc) · 2.57 KB
/
Copy pathsetup-singularity-work-dir.py
File metadata and controls
82 lines (67 loc) · 2.57 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
# 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:
print("#!/bin/bash", file=f)
print("#==============================================", file=f)
print("# this file has a specific format since it is", file=f)
print("# also read by python. only FOO=bar and", file=f)
print("# the use of $BAZ can be substituted. comments", file=f)
print("# start in column 0", file=f)
print("#==============================================", file=f)
print(file=f)
print("PIPELINE_LOCAL_DEV=False", file=f)
print(f"LOCAL_REPOSITORY_PATH={work_path}", file=f)
print(f"LOCAL_DATABASE_PATH={work_path}/db", file=f)
print(
"KIM_PROPERTY_PATH=$LOCAL_REPOSITORY_PATH/test-drivers/*/local-props/**/:"
"$LOCAL_REPOSITORY_PATH/test-drivers/*/local_props/**/",
file=f,
)
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")