-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrepareForSpanningCuts.wl
193 lines (137 loc) · 6 KB
/
PrepareForSpanningCuts.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
(* ::Package:: *)
commandLineMode=True
If[commandLineMode,
packagePath=DirectoryName[$InputFileName];
AbsMissionInput=$CommandLine[[-1]];
workingPath=DirectoryName[AbsMissionInput];
missionInput=FileNameSplit[AbsMissionInput][[-1]];
(*workingPath=Directory[]<>"/";
missionInput=$CommandLine[[-1]];*)
MathematicaCommand=Import[packagePath<>"/preload/MathematicaCommand.txt"];
ShellProcessor=Import[packagePath<>"/preload/ShellProcessor.txt"];
,
Print["WARNING: program is not running in command line mode!"];
workingPath=NotebookDirectory[];
missionInput="example.txt"
(*LoopMomenta={l1,l2};
ExternalMomenta={k1,k2,k4};
Propagators={l1^2,(l1-k1)^2,(l1-k1-k2)^2,(l2+k1+k2)^2,(l2-k4)^2,l2^2,(l1+l2)^2,(l1+k4)^2,(l2+k1)^2};
Kinematics={k1^2->0,k2^2->0,k4^2->0,k1 k2->s/2,k1 k4->t/2,k2 k4->(-s/2-t/2)};
GenericPoint={s->-1,t->-3};
TargetIntegrals={G[1,1,1,1,1,1,1,-5,0],G[1,1,1,1,1,1,1,-4,-1],G[1,1,1,1,1,1,1,-1,-4]}*)
]
(*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[Get[kinematicsFile]===$Failed,Print["Unable to open kinematics file "<>kinematicsFile<>". Exiting.";Exit[]]]
TargetIntegrals=Get[targetIntegralsFile]
If[TargetIntegrals===$Failed,Print["Unable to open target intergals file "<>targetIntegralsFile<>". Exiting.";Exit[]]]
If[outputPath===Automatic,
outputPath=workingPath<>"outputs/"<>ReductionOutputName<>"/";
Print["Output path has been set as "<>outputPath]
]
If[Intersection[StringSplit[outputPath,""],{" ","\t","\n","?","@","#","$","*","&","(",")","\"","\'","|"}]=!={},
Print["Path "<>outputPath<>" is illegal. Exiting."];
Exit[0];
]
If[StringSplit[outputPath,""][[-1]]=!="/",outputPath=outputPath<>"/"]
tmpPath=outputPath<>"tmp/"
If[FileExistsQ[tmpPath<>"once_initialized.txt"],
Export[outputPath<>"tmp/"<>"initialized.txt",""];
]
If[!FileExistsQ[tmpPath<>"initialized.txt"],
Print["Cannot perform this operation without finishing initialization... Please run this compuation from the beginning."];
Exit[0];
]
LogPath=outputPath<>"tmp/log_files/"
LogFile=LogPath<>"prepare_for_spanning_cuts"<>".txt";
PrintAndLog["Spanning cuts mode is on.\nPreparering for spanning cuts missions."]
timer=AbsoluteTime[]
SectorNumberToSectorIndex//ClearAll
SectorNumberToSectorIndex[num_]:=IntegerDigits[num,2,Length[Propagators]]//Reverse
TemporaryDirectory = outputPath<>"tmp/"
(*If[!DirectoryQ[#],Run["mkdir "<>#]]&[TemporaryDirectory]*)
TemporaryDirectorySingular = TemporaryDirectory<>"singular_temp/"
If[!DirectoryQ[#],Run["mkdir "<>#]]&[TemporaryDirectorySingular]
Get[packagePath<>"SyzygyRed.wl"]
(*runningScriptFolder=outputPath<>"tmp/running_scripts/"*)
Prepare[];
spanningCuts=Get[TemporaryDirectory<>"spanningCuts.txt"]
PrintAndLog["\tRead ",Length[spanningCuts]," spanning cuts."]
targetIndexLists=TargetIntegrals/.G->List;
uncuttableIndices=Select[Range[SDim],
MemberQ[Sign/@(targetIndexLists[[All,#]]-1),1]&
]
If[Length[uncuttableIndices]>0,
PrintAndLog["\tThe following indices are larger than 1 in certain targets:"];
PrintAndLog["\t",uncuttableIndices];
PrintAndLog["\tIn current version of NeatIBP, these indices are not cuttable."];
PrintAndLog["\tRedefining spanning cuts..."];
spanningCuts=Sort[Complement[#,uncuttableIndices]]&/@spanningCuts;
spanningCuts=spanningCuts//DeleteDuplicates;
newSpanningCuts=spanningCuts;
For[i=1,i<=Length[spanningCuts],i++,
For[j=1,j<=Length[spanningCuts],j++,
If[i==j,Continue[]];
If[SubsetQ[spanningCuts[[i]],spanningCuts[[j]]],
newSpanningCuts=DeleteCases[newSpanningCuts,spanningCuts[[i]]]
]
]
];
spanningCuts=newSpanningCuts;
Export[TemporaryDirectory<>"spanningCuts.txt",spanningCuts//InputForm//ToString];
PrintAndLog["\tDone."];
]
ModifiedConfig[file_,cut_]:=Module[{string},
string=Import[file];
string=StringReplace[string,{"CutIndices="~~Shortest[x__]~~"\n"->"\n"}];
string=string<>"\n\n(*-----actual cuts-----*)\nCutIndices="<>ToString[InputForm[cut]]<>";\n";
string=string<>"\n\n(*-----turn off IBP reduction in individual cuts-----*)\nPerformIBPReduction=False;\n";
(*string//Print;*)
string
]
(*Export[
TemporaryDirectory<>"run_cut.sh",
"cd $1
"<>packagePath<>"run.sh
cd -",
"Text"
]*)
Export[
TemporaryDirectory<>"run_cut.sh",
""<>packagePath<>"run.sh $1"<>missionInput,
"Text"
]
Run["chmod +x "<>TemporaryDirectory<>"run_cut.sh"]
(*we may need to recreate spanningCutsMissionMainPath by default, considering what if this is a 2nd time running? *)
Module[{i,cut,stringTail,cutMissionPath,runAllCutsScript},
PrintAndLog["Creating spanning cuts missions..."];
spanningCutsMissionMainPath=TemporaryDirectory<>"spanning_cuts_missions/";
runAllCutsScript="";
If[!DirectoryQ[#],CreateDirectory[#]]&[spanningCutsMissionMainPath];
For[i=1,i<=Length[spanningCuts],i++,
cut=spanningCuts[[i]];
stringTail=StringRiffle[ToString/@cut,"_"];
cutMissionPath=spanningCutsMissionMainPath<>"cut_"<>stringTail<>"/";
If[!DirectoryQ[#],CreateDirectory[#]]&[cutMissionPath];
(*Run["cp "<>workingPath<>missionInput<>" "inputBackupPath<>missionInput];*)
Export[cutMissionPath<>missionInput,ModifiedConfig[workingPath<>missionInput,cut]];
Run["cp "<>kinematicsFile<>" "cutMissionPath];
Run["cp "<>targetIntegralsFile<>" "cutMissionPath];
Switch[SpanningCutsEvaluationMode,
"Sequential",
runAllCutsScript=runAllCutsScript<>TemporaryDirectory<>"run_cut.sh "<>cutMissionPath<>"\n";
,
"Parallel",
runAllCutsScript=runAllCutsScript<>TemporaryDirectory<>"run_cut.sh "<>cutMissionPath<>" &\n";
,
_,
PrintAndLog["Unkown evaluation mode, using sequential. "];
runAllCutsScript=runAllCutsScript<>TemporaryDirectory<>"/run_cut.sh "<>cutMissionPath<>"\n";
];
];
If[SpanningCutsEvaluationMode==="Parallel",runAllCutsScript=runAllCutsScript<>"wait\n"];
Export[TemporaryDirectory<>"run_all_cuts.sh",runAllCutsScript,"Text"];
Run["chmod +x "<>TemporaryDirectory<>"run_all_cuts.sh"]
]
PrintAndLog["Finished. Time used: ",Round[AbsoluteTime[]-timer]," second(s)."]