-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_cuda.py
565 lines (479 loc) · 21.7 KB
/
test_cuda.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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
from madflow.config import (
int_me,
float_me,
DTYPE,
DTYPEINT,
run_eager,
complex_tf,
complex_me
)
from madflow.wavefunctions_flow import oxxxxx, ixxxxx, vxxxxx, sxxxxx, _vx_no_BRST_check
from madflow.parameters import Model
import os
import sys
import numpy as np
import tensorflow as tf
import tensorflow.math as tfmath
import collections
"""
ModelParamTupleConst = collections.namedtuple("constants", ["mdl_MT","mdl_WT"])
ModelParamTupleFunc = collections.namedtuple("functions", ["GC_10","GC_11"])
root_path = '/home/gabriele/Scaricati/MG5_aMC_v3_1_1'
sys.path.insert(0, root_path)
sys.path.insert(0, os.path.join(root_path, 'madgraph'))
sys.path.insert(0, os.path.join(root_path, 'aloha', 'template_files'))
import models.import_ufo as import_ufo
import models.check_param_card as param_card_reader
"""
# import the ALOHA routines
from aloha_1_gg_ttx import *
import time
def get_model_param(model, param_card_path):
param_card = param_card_reader.ParamCard(param_card_path)
# External (param_card) parameters
aEWM1 = param_card['SMINPUTS'].get(1).value
mdl_Gf = param_card['SMINPUTS'].get(2).value
aS = param_card['SMINPUTS'].get(3).value
mdl_ymb = param_card['YUKAWA'].get(5).value
mdl_ymt = param_card['YUKAWA'].get(6).value
mdl_ymtau = param_card['YUKAWA'].get(15).value
mdl_MZ = param_card['MASS'].get(23).value
mdl_MT = param_card['MASS'].get(6).value
mdl_MB = param_card['MASS'].get(5).value
mdl_MH = param_card['MASS'].get(25).value
mdl_MTA = param_card['MASS'].get(15).value
mdl_WZ = param_card['DECAY'].get(23).value
mdl_WW = param_card['DECAY'].get(24).value
mdl_WT = param_card['DECAY'].get(6).value
mdl_WH = param_card['DECAY'].get(25).value
#PS-independent parameters
mdl_conjg__CKM1x1 = 1.0
mdl_conjg__CKM3x3 = 1.0
mdl_CKM3x3 = 1.0
ZERO = 0.0
mdl_complexi = complex(0,1)
mdl_MZ__exp__2 = mdl_MZ**2
mdl_MZ__exp__4 = mdl_MZ**4
mdl_sqrt__2 = np.sqrt(2)
mdl_MH__exp__2 = mdl_MH**2
mdl_aEW = 1/aEWM1
mdl_MW = np.sqrt(mdl_MZ__exp__2/2. + np.sqrt(mdl_MZ__exp__4/4. - (mdl_aEW*np.pi*mdl_MZ__exp__2)/(mdl_Gf*mdl_sqrt__2)))
mdl_sqrt__aEW = np.sqrt(mdl_aEW)
mdl_ee = 2*mdl_sqrt__aEW*np.sqrt(np.pi)
mdl_MW__exp__2 = mdl_MW**2
mdl_sw2 = 1 - mdl_MW__exp__2/mdl_MZ__exp__2
mdl_cw = np.sqrt(1 - mdl_sw2)
mdl_sqrt__sw2 = np.sqrt(mdl_sw2)
mdl_sw = mdl_sqrt__sw2
mdl_g1 = mdl_ee/mdl_cw
mdl_gw = mdl_ee/mdl_sw
mdl_vev = (2*mdl_MW*mdl_sw)/mdl_ee
mdl_vev__exp__2 = mdl_vev**2
mdl_lam = mdl_MH__exp__2/(2.*mdl_vev__exp__2)
mdl_yb = (mdl_ymb*mdl_sqrt__2)/mdl_vev
mdl_yt = (mdl_ymt*mdl_sqrt__2)/mdl_vev
mdl_ytau = (mdl_ymtau*mdl_sqrt__2)/mdl_vev
mdl_muH = np.sqrt(mdl_lam*mdl_vev__exp__2)
mdl_I1x33 = mdl_yb*mdl_conjg__CKM3x3
mdl_I2x33 = mdl_yt*mdl_conjg__CKM3x3
mdl_I3x33 = mdl_CKM3x3*mdl_yt
mdl_I4x33 = mdl_CKM3x3*mdl_yb
mdl_ee__exp__2 = mdl_ee**2
mdl_sw__exp__2 = mdl_sw**2
mdl_cw__exp__2 = mdl_cw**2
#PS-dependent parameters
mdl_sqrt__aS = np.sqrt(aS)
mdl_G__exp__2 = lambda G: complex_me(G**2)
# PS-dependent couplings
GC_10 = lambda G: complex_me(-G)
GC_11 = lambda G: complex_me(mdl_complexi*G)
constants = ModelParamTupleConst(float_me(mdl_MT),float_me(mdl_WT))
functions = ModelParamTupleFunc(GC_10,GC_11)
return Model(constants, functions)
def areclose(t1, t2):
dist = tf.fill(tf.shape(t1), float_me(0.0001))
#dist = tf.fill(tf.shape(t1), float_me(0.002))
#dist = tf.fill(tf.shape(t1), float_me(0.0))
# Check if the real parts are close
result = tf.math.less_equal(tf.math.abs(tf.math.real(t1 - t2)), dist)
tf.debugging.assert_equal(result, True)
# Check if the imaginary parts are close
result = tf.math.less_equal(tf.math.abs(tf.math.imag(t1 - t2)), dist)
tf.debugging.assert_equal(result, True)
print("...ok")
def vxxxxxtest(all_ps, ZERO, hel, fl, num, MatrixOp):
print("Testing vxxxxx...")
pw0 = vxxxxx(all_ps[:,num], ZERO, hel[num], fl)
cw0 = MatrixOp.vxxxxx(all_ps, ZERO, hel[num], fl, num, pw0)
#print(pw0, cw0)
areclose(pw0, cw0)
def oxxxxxtest(all_ps, ZERO, hel, fl, MatrixOp):
print("Testing oxxxxx...")
pw0 = oxxxxx(all_ps[:,2], ZERO, hel[2], fl)
cw0 = MatrixOp.oxxxxx(all_ps, ZERO, hel[2], fl, pw0)
areclose(pw0, cw0)
def ixxxxxtest(all_ps, ZERO, hel, fl, MatrixOp):
print("Testing ixxxxx...")
pw0 = ixxxxx(all_ps[:,3], ZERO, hel[3], fl)
cw0 = MatrixOp.ixxxxx(all_ps, ZERO, hel[3], fl, pw0)
#print(pw0, cw0)
areclose(pw0, cw0)
def vxnobrstchecktest(all_ps, hel, MatrixOp):
print("Testing _vx_no_BRST_check...")
nhel = hel[0]
p = all_ps[:,0]
nsv = float_me(-1)
pt2 = p[:, 1] ** 2 + p[:, 2] ** 2
pp = tfmath.minimum(p[:, 0], tfmath.sqrt(pt2 + p[:, 3] ** 2))
pt = tfmath.minimum(pp, tfmath.sqrt(pt2))
hel0 = 1 - tfmath.abs(nhel)
nsvahl = nsv * tfmath.abs(nhel)
pw0 = _vx_no_BRST_check(p, ZERO, nhel, nsv, hel0, nsvahl, pp, pt)
cw0 = MatrixOp.vxnobrstcheck(all_ps, ZERO, nhel, nsv, hel0, nsvahl, pp, pt, pw0)
#print(pw0, cw0)
np.set_printoptions(precision=15)
#print(pw0.numpy())
#print(cw0.numpy())
areclose(pw0, cw0)
def vvv1p0_1test(all_ps, hel, mdl_MT, GC_10, MatrixOp):
print("Testing VVV1P0_1...")
ZERO = float_me(0.)
w0 = vxxxxx(all_ps[:,0],ZERO,hel[0],float_me(-1))
w1 = vxxxxx(all_ps[:,1],ZERO,hel[1],float_me(-1))
w2 = oxxxxx(all_ps[:,2],mdl_MT,hel[2],float_me(+1))
w3 = ixxxxx(all_ps[:,3],mdl_MT,hel[3],float_me(-1))
pw4= VVV1P0_1(w0, w1, GC_10, ZERO, ZERO)
cw4 = MatrixOp.vvv1p01(all_ps, hel, w0, w1, GC_10, ZERO, ZERO, mdl_MT, pw4)
areclose(pw4, cw4)
def ffv1_0test(all_ps, hel, mdl_MT, GC_10, GC_11, MatrixOp):
print("Testing FFV1_0...")
ZERO = float_me(0.)
w0 = vxxxxx(all_ps[:,0],ZERO,hel[0],float_me(-1))
w1 = vxxxxx(all_ps[:,1],ZERO,hel[1],float_me(-1))
w2 = oxxxxx(all_ps[:,2],mdl_MT,hel[2],float_me(+1))
w3 = ixxxxx(all_ps[:,3],mdl_MT,hel[3],float_me(-1))
w4= VVV1P0_1(w0, w1, GC_10, ZERO, ZERO)
pamp0 = FFV1_0(w3,w2,w4,GC_11)
camp0 = MatrixOp.ffv10(all_ps, hel, w3, w2, w4, GC_10, GC_11, mdl_MT, pamp0)
#print(pamp0, camp0)
areclose(pamp0, camp0)
def ffv1_1test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp):
print("Testing FFV1_1...")
ZERO = float_me(0.)
w0 = vxxxxx(all_ps[:,0],ZERO,hel[0],float_me(-1))
w1 = vxxxxx(all_ps[:,1],ZERO,hel[1],float_me(-1))
w2 = oxxxxx(all_ps[:,2],mdl_MT,hel[2],float_me(+1))
w3 = ixxxxx(all_ps[:,3],mdl_MT,hel[3],float_me(-1))
w4 = VVV1P0_1(w0, w1, GC_10, ZERO, ZERO)
amp0 = FFV1_0(w3,w2,w4,GC_11)
cw0 = MatrixOp.vxxxxx(all_ps,ZERO,hel[0],float_me(-1), 0, w0)
cw1 = MatrixOp.vxxxxx(all_ps,ZERO,hel[1],float_me(-1), 1, w1)
cw2 = MatrixOp.oxxxxx(all_ps,mdl_MT,hel[2],float_me(+1), w2)
cw3 = MatrixOp.ixxxxx(all_ps,mdl_MT,hel[3],float_me(-1), w3)
cw4 = MatrixOp.vvv1p01(all_ps, hel, cw0, cw1, GC_10, ZERO, ZERO, mdl_MT, w4)
camp0 = MatrixOp.ffv10(all_ps, hel, cw3, cw2, cw4, GC_10, GC_11, mdl_MT, amp0)
pw4 = FFV1_1(w2,w0,GC_11,mdl_MT,mdl_WT)
"""
cw4 = MatrixOp.ffv11(all_ps, hel, w2, w0, GC_10, GC_11, mdl_MT, mdl_WT, pw4)
"""
cw4 = MatrixOp.ffv11(all_ps, hel, cw2, cw0, GC_10, GC_11, mdl_MT, mdl_WT, pw4)
#print(pw4, cw4)
areclose(pw4, cw4)
def ffv1_2test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp):
print("Testing FFV1_2...")
ZERO = float_me(0.)
w0 = vxxxxx(all_ps[:,0],ZERO,hel[0],float_me(-1))
w1 = vxxxxx(all_ps[:,1],ZERO,hel[1],float_me(-1))
w2 = oxxxxx(all_ps[:,2],mdl_MT,hel[2],float_me(+1))
w3 = ixxxxx(all_ps[:,3],mdl_MT,hel[3],float_me(-1))
w4 = VVV1P0_1(w0, w1, GC_10, ZERO, ZERO)
amp0 = FFV1_0(w3,w2,w4,GC_11)
w4 = FFV1_1(w2,w0,GC_11,mdl_MT,mdl_WT)
amp1 = FFV1_0(w3,w4,w1,GC_11)
w4 = FFV1_2(w3,w0,GC_11,mdl_MT,mdl_WT)
cw0 = MatrixOp.vxxxxx(all_ps,ZERO,hel[0],float_me(-1), 0, w0)
cw1 = MatrixOp.vxxxxx(all_ps,ZERO,hel[1],float_me(-1), 1, w1)
cw2 = MatrixOp.oxxxxx(all_ps,mdl_MT,hel[2],float_me(+1), w2)
cw3 = MatrixOp.ixxxxx(all_ps,mdl_MT,hel[3],float_me(-1), w3)
cw4 = MatrixOp.vvv1p01(all_ps, hel, cw0, cw1, GC_10, ZERO, ZERO, mdl_MT, w4)
camp0 = MatrixOp.ffv10(all_ps, hel, cw3, cw2, cw4, GC_10, GC_11, mdl_MT, amp0)
cw4 = MatrixOp.ffv11(all_ps, hel, cw2, cw0, GC_10, GC_11, mdl_MT, mdl_WT, w4)
camp1 = MatrixOp.ffv10(all_ps, hel, cw3, cw4, cw1, GC_10, GC_11, mdl_MT, amp1)
"""
cw4 = MatrixOp.ffv12(all_ps, hel, w3, w0, GC_10, GC_11, mdl_MT, mdl_WT, w4)
"""
cw4 = MatrixOp.ffv12(all_ps, hel, cw3, cw0, GC_10, GC_11, mdl_MT, mdl_WT, w4)
#print(w4, cw4)
areclose(w4, cw4)
def jamptest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp):
print("Testing tf.stack...")
ZERO = float_me(0.)
w0 = vxxxxx(all_ps[:,0],ZERO,hel[0],float_me(-1))
w1 = vxxxxx(all_ps[:,1],ZERO,hel[1],float_me(-1))
w2 = oxxxxx(all_ps[:,2],mdl_MT,hel[2],float_me(+1))
w3 = ixxxxx(all_ps[:,3],mdl_MT,hel[3],float_me(-1))
w4 = VVV1P0_1(w0, w1, GC_10, ZERO, ZERO)
amp0 = FFV1_0(w3,w2,w4,GC_11)
w4 = FFV1_1(w2,w0,GC_11,mdl_MT,mdl_WT)
amp1 = FFV1_0(w3,w4,w1,GC_11)
w4 = FFV1_2(w3,w0,GC_11,mdl_MT,mdl_WT)
amp2= FFV1_0(w4,w2,w1,GC_11)
jamp = tf.stack([complex_tf(0,1)*amp0-amp1,-complex(0,1)*amp0-amp2], axis=0)
cw0 = MatrixOp.vxxxxx(all_ps,ZERO,hel[0],float_me(-1), 0, w0)
cw1 = MatrixOp.vxxxxx(all_ps,ZERO,hel[1],float_me(-1), 1, w1)
cw2 = MatrixOp.oxxxxx(all_ps,mdl_MT,hel[2],float_me(+1), w2)
cw3 = MatrixOp.ixxxxx(all_ps,mdl_MT,hel[3],float_me(-1), w3)
cw4 = MatrixOp.vvv1p01(all_ps, hel, cw0, cw1, GC_10, ZERO, ZERO, mdl_MT, w4)
camp0 = MatrixOp.ffv10(all_ps, hel, cw3, cw2, cw4, GC_10, GC_11, mdl_MT, amp0)
cw4 = MatrixOp.ffv11(all_ps, hel, cw2, cw0, GC_10, GC_11, mdl_MT, mdl_WT, w4)
camp1 = MatrixOp.ffv10(all_ps, hel, cw3, cw4, cw1, GC_10, GC_11, mdl_MT, amp1)
cw4 = MatrixOp.ffv12(all_ps, hel, cw3, cw0, GC_10, GC_11, mdl_MT, mdl_WT, w4)
camp1 = MatrixOp.ffv10(all_ps, hel, cw4, cw2, cw1, GC_10, GC_11, mdl_MT, amp2)
cjamp = MatrixOp.stacktest(amp0, amp1, amp2, jamp)
#print(jamp, cjamp)
areclose(jamp, cjamp)
def matrixtest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp):
print("Testing matrix element...")
#start = time.time()
ZERO = float_me(0.)
ncolor = 2
denom = tf.constant([3,3], dtype=DTYPECOMPLEX)
cf = tf.constant([[16,-2], [-2,16]], dtype=DTYPECOMPLEX)
w0 = vxxxxx(all_ps[:,0],ZERO,hel[0],float_me(-1))
w1 = vxxxxx(all_ps[:,1],ZERO,hel[1],float_me(-1))
w2 = oxxxxx(all_ps[:,2],mdl_MT,hel[2],float_me(+1))
w3 = ixxxxx(all_ps[:,3],mdl_MT,hel[3],float_me(-1))
w4 = VVV1P0_1(w0, w1, GC_10, ZERO, ZERO)
amp0 = FFV1_0(w3,w2,w4,GC_11)
w4 = FFV1_1(w2,w0,GC_11,mdl_MT,mdl_WT)
amp1 = FFV1_0(w3,w4,w1,GC_11)
w4 = FFV1_2(w3,w0,GC_11,mdl_MT,mdl_WT)
amp2= FFV1_0(w4,w2,w1,GC_11)
jamp = tf.stack([complex_tf(0,1)*amp0-amp1,-complex(0,1)*amp0-amp2], axis=0)
#print(jamp, cf, tf.math.conj(jamp)/tf.reshape(denom, (ncolor, 1)))
ret = tf.einsum("ie, ij, je -> e", jamp, cf, tf.math.conj(jamp)/tf.reshape(denom, (ncolor, 1)))
res = tf.math.real(ret)
#end = time.time()
#print(f"time (python) (s): {end-start}")
#start = time.time()
cres = MatrixOp.matrix(all_ps,hel,mdl_MT,mdl_WT,GC_10,GC_11)
#end = time.time()
#print(f"time (python) (s): {end-start}")
"""
cw0 = MatrixOp.vxxxxx(all_ps,ZERO,hel[0],float_me(-1), w0)
cw1 = MatrixOp.vxxxxx(all_ps,ZERO,hel[1],float_me(-1), w1)
cw2 = MatrixOp.oxxxxx(all_ps,mdl_MT,hel[2],float_me(+1), w2)
cw3 = MatrixOp.ixxxxx(all_ps,mdl_MT,hel[3],float_me(-1), w3)
cw4 = MatrixOp.vvv1p01(all_ps, hel, cw0, cw1, GC_10, ZERO, ZERO, mdl_MT, w4)
camp0 = MatrixOp.ffv10(all_ps, hel, cw3, cw2, cw4, GC_10, GC_11, mdl_MT, amp0)
cw4 = MatrixOp.ffv11(all_ps, hel, cw2, cw0, GC_10, GC_11, mdl_MT, mdl_WT, w4)
camp1 = MatrixOp.ffv10(all_ps, hel, cw3, cw4, cw1, GC_10, GC_11, mdl_MT, amp1)
cw4 = MatrixOp.ffv12(all_ps, hel, cw3, cw0, GC_10, GC_11, mdl_MT, mdl_WT, w4)
camp1 = MatrixOp.ffv10(all_ps, hel, cw4, cw2, cw1, GC_10, GC_11, mdl_MT, amp2)
cjamp = MatrixOp.stacktest(amp0, amp1, amp2, jamp)
cret = tf.einsum("ie, ij, je -> e", cjamp, cf, tf.math.conj(cjamp)/tf.reshape(denom, (ncolor, 1)))
cres = tf.math.real(cret)
"""
#print(res, cres)
areclose(res, cres)
def matrix(all_ps,hel,mdl_MT,mdl_WT,GC_10,GC_11):
ngraphs = 3
nwavefuncs = 5
ncolor = 2
ZERO = float_me(0.)
denom = tf.constant([3,3], dtype=DTYPECOMPLEX)
cf = tf.constant([[16,-2],
[-2,16]], dtype=DTYPECOMPLEX)
w0 = vxxxxx(all_ps[:,0],ZERO,hel[0],float_me(-1))
w1 = vxxxxx(all_ps[:,1],ZERO,hel[1],float_me(-1))
w2 = oxxxxx(all_ps[:,2],mdl_MT,hel[2],float_me(+1))
w3 = ixxxxx(all_ps[:,3],mdl_MT,hel[3],float_me(-1))
w4= VVV1P0_1(w0,w1,GC_10,ZERO,ZERO)
# Amplitude(s) for diagram number 1
amp0= FFV1_0(w3,w2,w4,GC_11)
w4= FFV1_1(w2,w0,GC_11,mdl_MT,mdl_WT)
# Amplitude(s) for diagram number 2
amp1= FFV1_0(w3,w4,w1,GC_11)
w4= FFV1_2(w3,w0,GC_11,mdl_MT,mdl_WT)
# Amplitude(s) for diagram number 3
amp2= FFV1_0(w4,w2,w1,GC_11)
jamp = tf.stack([complex_tf(0,1)*amp0-amp1, -complex(0,1)*amp0-amp2], axis=0)
ret = tf.einsum("ie, ij, je -> e", jamp, cf, tf.math.conj(jamp)/tf.reshape(denom, (ncolor, 1)))
return tf.math.real(ret)
def smatrixtest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp):
print("Testing smatrix...")
denominator = float_me(256)
nevts = tf.shape(all_ps, out_type=DTYPEINT)[0]
#matrixOp = tf.load_op_library('./matrix.so')
#matrixOp = tf.load_op_library('./matrix_cu.so')
ans = tf.zeros(nevts, dtype=DTYPE)
ans2 = tf.zeros(nevts, dtype=DTYPE)
for hel in helicities:
ans += matrix(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11)
ans2 += MatrixOp.matrix(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11)
res = ans/denominator
cres = ans2/denominator
#print(res, cres)
areclose(res, cres)
def test_custom_op(all_ps, helicities, mdl_MT, mdl_WT, GC_10, GC_11, op):
Op = tf.load_op_library(op)
for hel in helicities:
#print(hel)
if op == './matrix.so':
vxnobrstchecktest(all_ps, hel, Op)
vxxxxxtest(all_ps, ZERO, hel, float_me(-1), 0, Op)
vxxxxxtest(all_ps, ZERO, hel, float_me(-1), 1, Op)
oxxxxxtest(all_ps, mdl_MT, hel, float_me(+1), Op)
ixxxxxtest(all_ps, mdl_MT, hel, float_me(-1), Op)
vvv1p0_1test(all_ps, hel, mdl_MT, GC_10, Op)
ffv1_0test(all_ps, hel, mdl_MT, GC_10, GC_11, Op)
ffv1_1test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, Op)
ffv1_2test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, Op)
jamptest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, Op)
matrixtest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, Op)
smatrixtest(all_ps, helicities, mdl_MT, mdl_WT, GC_10, GC_11, Op)
if __name__ == "__main__":
import sys, pathlib
import numpy as np
"""
# Read up the model
model_sm = pathlib.Path(root_path) / "models/sm"
if not model_sm.exists():
print(f"No model sm found at {model_sm}, test cannot continue")
sys.exit(0)
model = import_ufo.import_model(model_sm.as_posix())
model_params = get_model_param(model, 'Cards/param_card.dat')
"""
# Define th phase space
# The structure asked by the matrix elements is
# (nevents, ndimensions, nparticles)
# the 4 dimensions of the 4-momentum is expected as
# (E, px, py, pz)
ndim = 4
npar = 4
nevents = 2
max_momentum = 7e3
par_ax = 1
dim_ax = 2
# Now generate random outgoing particles in a com frame (last_p carries whatever momentum is needed to sum 0 )
shape = [nevents, 0, 0]
shape[par_ax] = npar - 3
shape[dim_ax] = ndim - 1
partial_out_p = tf.random.uniform(shape, minval=-max_momentum, maxval=max_momentum, dtype=DTYPE)
last_p = -tf.reduce_sum(partial_out_p, keepdims=True, axis=par_ax)
out_p = tf.concat([partial_out_p, last_p], axis=par_ax)
"""
if "mdl_MT" in dir(model_params):
# TODO fill in the mass according to the particles
out_m = tf.reshape((npar - 2) * [model_params.mdl_MT], (1, -1, 1))
else:
out_m = 0.0
out_e = tf.sqrt(tf.reduce_sum(out_p ** 2, keepdims=True, axis=dim_ax) + out_m ** 2)
outgoing_4m = tf.concat([out_e, out_p], axis=dim_ax)
# Put all incoming momenta in the z axis (TODO: for now assume massless input)
ea = tf.reduce_sum(out_e, axis=par_ax, keepdims=True) / 2
zeros = tf.zeros_like(ea)
inc_p1 = tf.concat([ea, zeros, zeros, ea], axis=dim_ax)
inc_p2 = tf.concat([ea, zeros, zeros, -ea], axis=dim_ax)
all_ps = tf.concat([inc_p1, inc_p2, outgoing_4m], axis=par_ax)
"""
#hel = float_me([-1,-1,-1,1])
ZERO = float_me(0.)
# Test functions
helicities = float_me([ \
[-1,-1,-1,1],
[-1,-1,-1,-1],
[-1,-1,1,1],
[-1,-1,1,-1],
[-1,1,-1,1],
[-1,1,-1,-1],
[-1,1,1,1],
[-1,1,1,-1],
[1,-1,-1,1],
[1,-1,-1,-1],
[1,-1,1,1],
[1,-1,1,-1],
[1,1,-1,1],
[1,1,-1,-1],
[1,1,1,1],
[1,1,1,-1]])
#for hel in helicities:
#print(hel, hel[0])
# 1 , 2 , 3 , 4
# mdl_MT, mdl_WT, GC_10, GC_11
mdl_MT = float_me(173.0)
mdl_WT = float_me(1.4915000200271606)
#"""
all_ps = tf.constant([
[[ 6072.61964028, 0., 0., 6072.61964028],
[ 6072.61964028, 0., 0., -6072.61964028],
[ 6072.61964028,-2777.31637198, 1722.92077616, 5118.08236202],
[ 6072.61964028, 2777.31637198,-1722.92077616,-5118.08236202]],
[[ 3068.10329143, 0., 0., 3068.10329143],
[ 3068.10329143, 0., 0., -3068.10329143],
[ 3068.10329143,-1224.19479866, 2778.9848378, -438.00476374],
[ 3068.10329143, 1224.19479866,-2778.9848378, 438.00476374]],
[[ 207.05393783212523,0., 0., 207.05393783212523],
[ 196.25596330440683,0., 0., -196.25596330440683],
[ 204.2077863772509,26.549849378381349,-30.275756768746309,100.74871744673455],
[ 199.10211475928111,-26.549849378381314,30.275756768746284,-89.950742919016179]],
[[ 483.818431423889,0., 0., 483.818431423889],
[ 1958.0249399692245,0., 0., -1958.0249399692245],
[ 1676.7361874941203,-121.69728292164577,735.07104367991008,-1492.1044114019417],
[ 765.10718389899318,121.69728292164575,-735.07104367991008,17.897902856606152]],
[[ 8429.3766316 , 0., 0., 8429.3766316],
[ 8429.3766316 , 0., 0., -8429.3766316],
[ 8429.3766316 ,-5648.23696759, 5725.21450186,-2524.62442017],
[ 8429.3766316 , 5648.23696759,-5725.21450186, 2524.62442017]],
[[ 9204.28055424, 0., 0., 9204.28055424],
[ 9204.28055424, 0., 0., -9204.28055424],
[ 9204.28055424,-6050.88909762,-4094.10402439,-5598.55641098],
[ 9204.28055424, 6050.88909762, 4094.10402439, 5598.55641098]]], dtype=tf.float64)
#"""
#print(all_ps)
GC_10 = tf.ones_like(all_ps[:,0,0], dtype=DTYPECOMPLEX) * tf.constant([-1.21771579-0.j])
GC_11 = tf.ones_like(all_ps[:,0,0], dtype=DTYPECOMPLEX) * tf.constant([0.+1.21771579j])
#print(mdl_MT, mdl_WT, GC_10, GC_11)
"""
#vxnobrstchecktest(all_ps, hel, MatrixOp)
vxxxxxtest(all_ps, ZERO, hel, float_me(-1), MatrixOp)
oxxxxxtest(all_ps, mdl_MT, hel, float_me(+1), MatrixOp)
ixxxxxtest(all_ps, mdl_MT, hel, float_me(-1), MatrixOp)
vvv1p0_1test(all_ps, hel, mdl_MT, GC_10, MatrixOp)
ffv1_0test(all_ps, hel, mdl_MT, GC_10, GC_11, MatrixOp)
ffv1_1test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp)
ffv1_2test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp)
jamptest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp)
matrixtest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp)
#print(all_ps[:,0], all_ps[:,1])
"""
"""
model_params.freeze_alpha_s(0.118)
"""
#print(float_me(tfmath.sqrt(0.5)), np.sqrt(0.5))
"""
ops = ['./matrix.so', './matrix_cu.so']
for op in ops:
Op = tf.load_op_library(op)
test_custom_op(all_ps, helicities, mdl_MT, mdl_WT, GC_10, GC_11, Op, op)
"""
#MatrixOp = tf.load_op_library('./matrix.so')
#test_custom_op(all_ps, helicities, mdl_MT, mdl_WT, GC_10, GC_11, './matrix.so')
#test_custom_op(all_ps, helicities, mdl_MT, mdl_WT, GC_10, GC_11, MatrixcuOp)
MatrixcuOp = tf.load_op_library('./matrix_cu.so')
for hel in helicities:
#print(hel)
"""
vxnobrstchecktest(all_ps, hel, MatrixOp)
vxxxxxtest(all_ps, ZERO, hel, float_me(-1), 0, MatrixOp)
vxxxxxtest(all_ps, ZERO, hel, float_me(-1), 1, MatrixOp)
oxxxxxtest(all_ps, mdl_MT, hel, float_me(+1), MatrixOp)
ixxxxxtest(all_ps, mdl_MT, hel, float_me(-1), MatrixOp)
vvv1p0_1test(all_ps, hel, mdl_MT, GC_10, MatrixOp)
ffv1_0test(all_ps, hel, mdl_MT, GC_10, GC_11, MatrixOp)
ffv1_1test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp)
ffv1_2test(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp)
jamptest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixOp)
"""
matrixtest(all_ps, hel, mdl_MT, mdl_WT, GC_10, GC_11, MatrixcuOp)
smatrixtest(all_ps, helicities, mdl_MT, mdl_WT, GC_10, GC_11, MatrixcuOp)