-
Notifications
You must be signed in to change notification settings - Fork 1
/
AssignIBPReduction.wl
315 lines (255 loc) · 8.69 KB
/
AssignIBPReduction.wl
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
(* ::Package:: *)
commandLineMode=True
If[commandLineMode,
(*workingPath=$CommandLine[[-1]];(*we can specify working path in command line*)
If[workingPath==="-script",workingPath=Directory[]<>"/"];
If[!DirectoryQ[workingPath],
Print["Warning: the argument working path ",workingPath," does not exist."];
workingPath=Directory[]<>"/";
Print["\t\t redefining working path as current working folder: ",workingPath,"."];
];*)
packagePath=DirectoryName[$InputFileName];
AbsMissionInput=$CommandLine[[-1]];
workingPath=DirectoryName[AbsMissionInput];(*is this really used?*)
missionInput=FileNameSplit[AbsMissionInput][[-1]];
MathematicaCommand=Import[packagePath<>"/preload/MathematicaCommand.txt"];
ShellProcessor=Import[packagePath<>"/preload/ShellProcessor.txt"];
EnvVarSetter=Import[packagePath<>"/preload/EnvVarSetter.txt"];
,
Print["WARNING: program is not running in command line mode!"];
workingPath=NotebookDirectory[];
packagePath="/home/zihao/projects/SyzygyRed/Parallelization/github/NeatIBP/";
outputPath="";
]
(*AppendTo[$Path,workingPath];*)
If[Get[packagePath<>"default_settings.txt"]===$Failed,Exit[0]]
If[Get[workingPath<>missionInput]===$Failed,Print["Unable to open config file "<>workingPath<>missionInput<>". Exiting.";Exit[]]]
If[outputPath===Automatic,
outputPath=workingPath<>"outputs/"<>ReductionOutputName<>"/";
]
If[Intersection[StringSplit[outputPath,""],{" ","\t","\n","?","@","#","$","*","&","(",")","\"","\'","|"}]=!={},
Print["echo \"Path "<>outputPath<>" is illegal. Exiting.\""];
Exit[0];
]
If[StringSplit[outputPath,""][[-1]]=!="/",outputPath=outputPath<>"/"]
SetDirectory[workingPath]
TimeString[]:=Module[{at},at=FromAbsoluteTime[AbsoluteTime[]];StringRiffle[#,"_"]&[(ToString[Floor[#]]&/@at[[1,1;;6]])]<>"_"<>ToString[Floor[1000*(#-Floor[#])&[ at[[1,6]]]]]]
finishedTagFile="results/NeatIBP_finished.tag"
If[!FileExistsQ[outputPath<>"results/summary.txt"],
If[PerformIBPReduction===True,Print["Summary failed, cannot perform IBP reduction."]];
Exit[0];
]
If[PerformIBPReduction=!=True,
Export[outputPath<>finishedTagFile,"","Text"];
Exit[];
]
If[CutIndices==="spanning cuts",
If[
DirectoryQ[outputPath<>"results/results_spanning_cuts/"]&&
FileExistsQ[outputPath<>"tmp/spanning_cuts_mode.txt"]
,
mode="spanning cuts";
,
Print[outputPath," does not look like a spanning cuts folder. Failed."];
Exit[];
]
,
mode="normal";
]
shortenFinishQScript="
if [ ! -e "<>outputPath<>"tmp/spanning_cuts_IBP_shorten_finished.txt ]
then
echo \"*** Err: Spanning cuts shorten not finised in \"\""<>outputPath<>"\"
echo \"Cannot run kira reduction on them.\"
echo \"Exiting.\"
exit 1
fi
"
Switch[mode,
"normal",
Switch[IBPReductionMethod,
"None",
script="echo \"IBPReductionMethod=None, will not perform IBP reduction.\"\n";
,
"Kira",
(*if we want to modify this part of code, do not forget to modify that in spanning cuts mode too!*)
KiraCommandRefined=StringRiffle[
DeleteCases[
StringSplit[KiraCommand," "]
,""]
," "];
If[!FileExistsQ[FermatPath],
Print["***File at ",FermatPath," does not exist. Exiting."];
Exit[];
];
If[FileNameSplit[FermatPath][[-1]]=!="fer64",
Print["***FermatPath ",FermatPath," should be specified to \"fer64\". Exiting."];
Exit[];
];
If[Count[
FileExistsQ/@Select[
StringSplit[KiraCommandRefined," "],
FileNameSplit[#][[-1]]==="kira"&
]
,True]<1,
Print["***KiraCommand \"",KiraCommand,"\" is not an correct kira command. Please check. Exiting."];
Exit[];
];(*kira command may include some settings*)
Switch[EnvVarSetter,
"export",
script="export FERMATPATH=\""<>FermatPath<>"\"";
(*script=script<>"\n"<>"export KiraCommand=\""<>KiraCommand<>"\"";*)
,
"setenv",
script="setenv FERMATPATH \""<>FermatPath<>"\"";
(*script=script<>"\n"<>"setenv KiraCommand \""<>KiraCommand<>"\"";*)
,
_,
Print[" ***EnvVarSetter \"",EnvVarSetter,"\" is not supported yet."];
Print["Valid values:"];
Print["\t1. export"];
Print["\t2. setenv"];
Print["Please check the spelling or contact the developers of NeatIBP."];
Print["Exiting."];
Exit[];
];
If[ForceRemoveExistingKiraResults===True,
kiraScriptSetting=""
,
kiraScriptSetting="-f "
];
script=script<>"\n"<>ShellProcessor<>" "<>packagePath<>
"interfaces/Kira/interface/run_kira_reduction.sh"<>" "<>
kiraScriptSetting<>"\""<>KiraCommandRefined<>"\" "<>outputPath<>"\n";
,
"FFNumerical",
script=MathematicaCommand<>" "<>packagePath<>"FFSolveIBP.wl "<>outputPath<>"\n";
,
_,
(*this should have been excluded by initialization, but... better double checked*)
Print["***Err: Unkown IBPReductionMethod ",IBPReductionMethod];(*we'd better use PrintAndLog*)
Exit[];
];
,
"spanning cuts",
Switch[IBPReductionMethod,
"None",
script="echo \"IBPReductionMethod=None, will not perform IBP reduction.\"\n";
,
"Kira",
(*if we want to modify this part of code, do not forget to modify that in normal mode too!*)
KiraCommandRefined=StringRiffle[
DeleteCases[
StringSplit[KiraCommand," "]
,""]
," "];
If[!FileExistsQ[FermatPath],
Print["***File at ",FermatPath," does not exist. Exiting."];
Exit[];
];
If[FileNameSplit[FermatPath][[-1]]=!="fer64",
Print["***FermatPath ",FermatPath," should be specified to \"fer64\". Exiting."];
Exit[];
];
If[Count[
FileExistsQ/@Select[
StringSplit[KiraCommandRefined," "],
FileNameSplit[#][[-1]]==="kira"&
]
,True]<1,
Print["***KiraCommand \"",KiraCommand,"\" is not an correct kira command. Please check. Exiting."];
Exit[];
];(*kira command may include some settings*)
Switch[EnvVarSetter,
"export",
script="export FERMATPATH=\""<>FermatPath<>"\"";
(*script=script<>"\n"<>"export KiraCommand=\""<>KiraCommand<>"\"";*)
,
"setenv",
script="setenv FERMATPATH \""<>FermatPath<>"\"";
(*script=script<>"\n"<>"setenv KiraCommand \""<>KiraCommand<>"\"";*)
,
_,
Print[" ***EnvVarSetter \"",EnvVarSetter,"\" is not supported yet."];
Print["Valid values:"];
Print["\t1. export"];
Print["\t2. setenv"];
Print["Please check the spelling or contact the developers of NeatIBP."];
Print["Exiting."];
Exit[];
];
If[ForceRemoveExistingKiraResults===True,
kiraScriptSetting=""
,
kiraScriptSetting="-f "
];
If[UseShortenedIBPForKira===True,
kiraScriptSetting=kiraScriptSetting<>"-s ";
script=script<>"\n"<>MathematicaCommand<>" -script "<>packagePath<>
"FFSpanningCutsConsistencyCheck.wl "<>outputPath<>"\n";
script=script<>MathematicaCommand<>" -script "<>packagePath<>
"FFSpanningCutsIBPShorten.wl "<>outputPath<>"\n";
script=script<>shortenFinishQScript<>"\n\n";
];
spanningCuts=Get[outputPath<>"tmp/spanningCuts.txt"];
Switch[ParallelKiraReductionForSpanningCuts,
True,
For[i=1,i<=Length[spanningCuts],i++,
cut=spanningCuts[[i]];
cutString="cut_"<>StringRiffle[ToString/@cut,"_"];
cutPath=outputPath<>"results/results_spanning_cuts/"<>cutString<>"/";
script=script<>ShellProcessor<>" "<>packagePath<>
"interfaces/Kira/interface/run_kira_reduction.sh"<>" "<>
kiraScriptSetting<>"\""<>KiraCommandRefined<>"\" "<>cutPath<>" &\n";
If[ParallelKiraJobNumber=!=Infinity,
If[Mod[i,ParallelKiraJobNumber]===0,
script=script<>"wait\n";
];
];
];
If[ParallelKiraJobNumber===Infinity,
script=script<>"wait\n";
,
If[Mod[i,ParallelKiraJobNumber]=!=0,
script=script<>"wait\n";
]
];
,
False,
For[i=1,i<=Length[spanningCuts],i++,
cut=spanningCuts[[i]];
cutString="cut_"<>StringRiffle[ToString/@cut,"_"];
cutPath=outputPath<>"results/results_spanning_cuts/"<>cutString<>"/";
script=script<>ShellProcessor<>" "<>packagePath<>
"interfaces/Kira/interface/run_kira_reduction.sh"<>" "<>
kiraScriptSetting<>"\""<>KiraCommandRefined<>"\" "<>cutPath<>"\n";
];
,
_,
Print["**** Err: ParallelKiraReductionForSpanningCuts must be True or False. Exiting."];
Exit[1];
];
If[UseShortenedIBPForKira===True,
IBPMergeSetting="-s "
,
IBPMergeSetting=""
];
script=script<>"\n"<>MathematicaCommand<>" -script "<>packagePath<>
"ReducedSpanningCutsMerge.wl "<>IBPMergeSetting<>"-Kira "<>outputPath<>"\n";
,
"FFNumerical",
script="echo \"Sorry, FFNumerical reduction in spanning cuts mode is in to-do list, not online yet.\"\n";
,
_,
(*this should have been excluded by initialization, but... better double checked*)
Print["***Err: Unkown IBPReductionMethod ",IBPReductionMethod];(*we'd better use PrintAndLog*)
Exit[];
];
,
_,
Print["AssignIBPReduction.wl: unkown mode ", mode, ". Failed"];
Exit[];
]
script=script<>" >> "<>outputPath<>finishedTagFile;
Print[outputPath<>"tmp/assigned_reduction_script.sh"]
Export[outputPath<>"tmp/assigned_reduction_script.sh",script,"Text"]