This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dodo.py
175 lines (146 loc) · 5.23 KB
/
dodo.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
174
175
from pathlib import Path
from operator import itemgetter
from scripts import (
info,
info_file,
results_dir,
lattices_generated_dir,
simulation_elegant_dir,
)
base_dir = Path(__file__).parent
# TODO:
# * what does "clean" do???
all_lattices = info["lattices"]
lattices = {}
for lattice in all_lattices:
for simulation_program in lattice["simulations"]:
try:
lattices[simulation_program].append(lattice)
except KeyError:
lattices[simulation_program] = [lattice]
def task_index_json():
def save_data(path, data):
path.write_text(data)
return None
import json
target = results_dir / "index.json"
yield {
"name": "index.json",
"actions": [(save_data, (target, json.dumps(info)))],
"targets": [target],
"file_dep": [info_file],
}
def task_index_json_per_lattice():
"simalar to task_index_json, but info file per lattice"
def save_data(path, data):
path.write_text(data)
return None
import json
for lattice in info["lattices"]:
namespace, name = itemgetter("namespace", "name")(lattice)
target = results_dir / namespace / name / "index.json"
target.parent.mkdir(parents=True, exist_ok=True)
yield {
"name": f"{namespace}/{name}",
"actions": [(save_data, (target, json.dumps(lattice)))],
"targets": [target],
"file_dep": [info_file],
"clean": True,
}
def task_lattice_info():
from scripts.data_lattice_info import results, __file__ as python_file
for lattice in all_lattices:
namespace, name = itemgetter("namespace", "name")(lattice)
output_dir = results_dir / namespace / name
targets = [
output_dir / path
for path in [
"lattice_info.json",
]
]
lattice_file = (lattices_generated_dir / namespace / name).with_suffix(".json")
yield {
"name": f"{namespace}/{name}",
"actions": [(results, (lattice, output_dir))],
"targets": targets,
"file_dep": [python_file, lattice_file],
"clean": True,
}
def task_apace_summary():
from scripts.data_apace import results, __file__ as python_file
for lattice in lattices["apace"]:
namespace, name = itemgetter("namespace", "name")(lattice)
output_dir = results_dir / namespace / name / "apace"
targets = [
output_dir / path
for path in [
"twiss_tables.json",
"twiss.svg",
"floor_plan_cell.svg",
]
]
lattice_file = (lattices_generated_dir / namespace / name).with_suffix(".json")
yield {
"name": f"{namespace}/{name}",
"actions": [(results, (lattice, output_dir))],
"targets": targets,
"file_dep": [python_file, lattice_file],
"clean": True,
}
def task_elegant_twiss_simulation():
for lattice in lattices["elegant"]:
namespace, name, energy = itemgetter("namespace", "name", "energy")(lattice)
run_file = base_dir / "elegant" / "twiss.ele"
lattice_file = (lattices_generated_dir / namespace / name).with_suffix(".lte")
target = (simulation_elegant_dir / namespace / name).with_suffix(".twi")
target.parent.mkdir(parents=True, exist_ok=True)
yield {
"name": f"{namespace}/{name}",
"actions": [
f"elegant {run_file} -macro=energy={energy},lattice={lattice_file},filename={target} > /dev/null"
],
"targets": [target],
"file_dep": [run_file, lattice_file],
"clean": True,
}
def task_elegant_summary():
from scripts.data_elegant import results, __file__ as python_file
for lattice in lattices["elegant"]:
namespace, name = itemgetter("namespace", "name")(lattice)
output_dir = results_dir / namespace / name / "elegant"
targets = [
output_dir / path
for path in [
"twiss_tables.json",
"twiss.svg",
"chroma.svg",
]
]
twi_file = (simulation_elegant_dir / namespace / name).with_suffix(".twi")
yield {
"name": f"{namespace}/{name}",
"actions": [(results, (lattice, output_dir))],
"targets": targets,
"file_dep": [python_file, twi_file],
"clean": True,
}
def task_madx_summary():
from scripts.data_madx import results, __file__ as python_file
for lattice in lattices["madx"]:
namespace, name = itemgetter("namespace", "name")(lattice)
output_dir = results_dir / namespace / name / "madx"
targets = [
output_dir / path
for path in [
"twiss_tables.json",
"twiss.svg",
]
]
lattice_file = (lattices_generated_dir / namespace / name).with_suffix(".madx")
yield {
"name": f"{namespace}/{name}",
"actions": [(results, (lattice, output_dir))],
"targets": targets,
"file_dep": [python_file, lattice_file],
"clean": True,
}