-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode_generation_core_library.py
676 lines (515 loc) · 20.5 KB
/
mode_generation_core_library.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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 14 10:26:39 2020
Set of static functions to compute LG modes - HG mode are not included
@author: Marcos
"""
import numpy as np
from pylab import *
import numexpr as ne
import scipy
import scipy.special as sp
#simport numba_special
import time
#high speed packages that maybe the user does not have
try:
import cupy as cp
except ModuleNotFoundError:
print("Cupy module couldn't be imported")
try:
from numba import njit
except ModuleNotFoundError:
print("numba module couldn't be imported")
try:
from ipyparallel import Client
except ModuleNotFoundError:
print("Ipyparallel couldn't be imported")
############################## AUXILIAR FUNCTIONS #############################
############## ############## ############## ############## ##############
def cart2pol(x, y):
rho = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)
return(rho, phi)
def pol2cart(rho, phi):
x = rho * np.cos(phi)
y = rho * np.sin(phi)
return(x, y)
class times:
def tic():
global start_time
start_time = time.time()
return(start_time)
def toc():
elapsed_time = time.time() - start_time
print("Elapsed time = ",elapsed_time)
return(elapsed_time)
############################## AUXILIAR FUNCTIONS END #########################
############## ############## ############## ############## ###############
########################## MODES GENERATION FUNCTIONS #########################
############## ############## ############## ############## ##############
def graded_index_fiber_coefs(xx):
"""
Compute coef of the LG modes
"""
group = xx
if group%2 != 0:
pp = np.arange( group//2 +1 ) + 1
else:
pp = np.arange(group//2) + 1
c = 1
m = []
k = 0
n = []
for i in pp:
v = np.arange(i)
k = np.concatenate((v,v))
m = np.concatenate ((m,k))
if v.shape !=0:
s = np.array(n[-(v.shape[0]-1)::]) +1
l = np.concatenate ( ( s , np.array([0]) ) )
r = np.concatenate ((l,l+1))
n = np.concatenate ((n,r))
else:
n = np.concatenate ((0,1))
if group%2 != 0:
mn = np.array([m,n])
mn = mn[:,0:-v.shape[0]]
else:
mn = np.array([m,n])
return mn
def LGFarFieldGouyPhase(mode_index):
p = mode_index[0,:] # Controls Laguerre polynomial degree --> number of zeros -- radial
l = mode_index[1,:] # Modify phase -- azimutal
N = ( l + (2*p) ) * np.pi/2
PSI = np.exp(-1j*N) #Gouy phase positive or negative ???
return(PSI)
def applyphase(Ein, phase):
#Ein --> M,N,N ; phase --> M
return(Ein * phase[:,None,None])
@njit(parallel=True)
def LGmodes_CPU_parallel(w0,X,Y,mode_index,LG):
#Compute just one part of the piramid --> complex conjugate must be done later
RHO = np.sqrt(X**2 + Y**2)
PHI = np.arctan2(Y, X)
LGpols = LG
#Modes
p = mode_index[0] # Controls Laguerre polynomial degree --> number of zeros
l = mode_index[1] # Modify phase
Emn = np.zeros( (mode_index.shape[1],X.shape[0],X.shape[0]) , np.complex64)
for m in range(p.shape[0]):
LG = LGpols[m]
aa = (np.exp( (-l[m]*PHI)*1j) ) /w0
bb = np.power(RHO/w0,l[m])
cc = np.exp(-(RHO**2) / (w0**2))
E = aa * bb * cc * LG
Emn[m,...] = E / (np.sqrt(np.sum(np.abs(E)**2)))
return Emn
#LG poly is a numpy array
def LGmodes_GPU(w0, X, Y, mode_index, LG, modeType = 'numpy'):
"""
Computes LG modes on the GPU :
w0 -- radius of the field (Mode field diammeter /2)
X aand Y -- Cloud of points that represent the space (meshgrid in cartesian coordinates)
mode_index -- 2D array with the modes indexes, first row = p, second raw = l
p = polynomial degree
l = modified phase
LG -- pre-computed Laguerre polynomials -- can be an numpy array or cupy array
LGtype -- specify the output array type
"""
RHO,PHI = cart2pol(X,Y)
p = mode_index[0,:,None,None]
l = mode_index[1,:,None,None]
RHO = RHO[None,:,:]
PHI = PHI[None,:,:]
w0_gpu = cp.asarray(w0)
RHO_gpu = cp.asarray(RHO).astype(cp.complex64)
PHI_gpu = cp.asarray(PHI).astype(cp.complex64)
p_gpu = cp.asarray(p) # Controls Laguerre polynomial degree --> number of zeros
l_gpu = cp.asarray(l) # Modify phase
#Check what type of the input LG polynomials ---> Send them to GPU if there were not
if type(LG) == np.ndarray:
LG_gpu = cp.asarray(LG).astype(cp.complex64)
else:
LG_gpu = LG
# Emn_gpu = cp.zeros( (p.shape[0],X.shape[0],X.shape[0]) , cp.complex64)
# print(Emn_gpu.dtype)
# Emn_gpu = ( (cp.exp( (-l_gpu*PHI_gpu)*1j) )/w0_gpu) * \
# cp.power(RHO_gpu/w0_gpu,l_gpu) * \
# cp.exp(-(RHO_gpu**2) / (cp.power(w0_gpu,2))) * \
# LG_gpu
Emn_gpu = ( (cp.exp( (-l_gpu*PHI_gpu)*1j) ) /w0_gpu) * cp.power(RHO_gpu/w0_gpu,l_gpu) * cp.exp(-(RHO_gpu**2) / (cp.power(w0_gpu,2))) * LG_gpu
Emn_gpu = Emn_gpu / (cp.sqrt(cp.sum(cp.absolute(Emn_gpu)**2,(1,2))))[:,None,None]
if modeType == 'cupy':
return(Emn_gpu)
elif modeType == 'numpy':
return(cp.asnumpy(Emn_gpu))
def LGmodes_CPU(w0,X,Y,mode_index,LG):
#Compute just one part of the piramid --> complex conjugate must be done later
RHO,PHI = cart2pol(X,Y)
RHO = RHO[None,:,:]
PHI = PHI[None,:,:]
#Modes
p = mode_index[0,:,None,None] # Controls Laguerre polynomial degree --> number of zeros
l = mode_index[1,:,None,None] # Modify phase
Emn = np.zeros( (mode_index.shape[1],X.shape[0],X.shape[0]) , np.complex64)
# x = ((RHO**2) * (2 / w0**2)) #Argument of the genlaguerre function
# LG = sp.eval_genlaguerre(p,l,x)
LG = LG
aa = ( (np.exp( (-l*PHI)*1j) ) /w0)
bb = np.power(RHO/w0,l)
cc = np.exp(-(RHO**2) / (w0**2))
Emn[:mode_index.shape[1],:,:] = ne.evaluate("aa * bb * cc * LG")
Emn = Emn / (np.sqrt(np.sum(abs(Emn)**2,(1,2))))[:,None,None]
return(Emn)
@njit(parallel=True)
def ComputeAllLGmodes_list_parallel ( LGmodes, indexes):
"""
Computes the comlex conjugate of the LGmodes if it is needed.
- LGmodes matrix (Modes,X,Y).
- Index of the half piramid, from LGindexes(modeGroup)function.
- returns a list with all the modes
"""
WholeModesSet = []
LGmodesConjugate = np.conjugate(LGmodes)
#LGmn modes --> Unique modes n = 0
n = indexes[1,:]
for count,n_idx in enumerate(n):
if (n_idx == 0):
#Independent mode
WholeModesSet.append(LGmodes[count,...])
else:
#Pair of modes
WholeModesSet.append(LGmodes[count,...])
WholeModesSet.append(LGmodesConjugate[count,...])
#Done for Loop
return(WholeModesSet)
@njit(parallel=True)
def ComputeAllLGmodes_array_parallel ( LGmodes, indexes ):
"""
Computes the comlex conjugate of the LGmodes if it is needed.
- LGmodes matrix (Modes,X,Y).
- Index of the half piramid, from LGindexes(modeGroup)function.
- return an arry with all the modes
"""
LGmodesConjugate = np.conjugate(LGmodes) #conjugate all the input modes
#LGmn modes --> Unique modes n = 0
n = indexes[1,:]
l = len(n)
uniqueM = len(np.where(n==0)[0])
num_modes = (l - uniqueM)*2 + uniqueM
WholeModesSet = np.zeros((num_modes,LGmodes.shape[1],LGmodes.shape[2]),np.complex64)
count = 0;
for idx,n_idx in enumerate(n):
if (n_idx == 0):
#Independent mode
WholeModesSet[count,...] = (LGmodes[idx,...])
count += 1
else:
#Pair of modes
WholeModesSet[count,...] = (LGmodes[idx,...])
count += 1
WholeModesSet[count,...] = (LGmodesConjugate[idx,...])
count += 1
#Done for Loop
return(WholeModesSet)
def ComputeAllLGmodes_array ( LGmodes, indexes):
"""
Computes the comlex conjugate of the LGmodes if it is needed.
- LGmodes matrix (Modes,X,Y).
- Index of the half piramid, from LGindexes(modeGroup)function.
- return an arry with all the modes
"""
LGmodesConjugate = np.conjugate(LGmodes) #conjugate all the input modes
#LGmn modes --> Unique modes n = 0
n = indexes[1,:]
l = len(n)
uniqueM = len(np.where(n==0)[0])
num_modes = (l - uniqueM)*2 + uniqueM
WholeModesSet = np.zeros((num_modes,LGmodes.shape[1],LGmodes.shape[2]),np.complex64)
count = 0;
for idx,n_idx in enumerate(n):
if (n_idx == 0):
#Independent mode
WholeModesSet[count,...] = (LGmodes[idx,...])
count += 1
else:
#Pair of modes
WholeModesSet[count,...] = (LGmodes[idx,...])
count += 1
WholeModesSet[count,...] = (LGmodesConjugate[idx,...])
count += 1
#Done for Loop
return(WholeModesSet)
def ComputeAllLGmodes_list ( LGmodes, indexes):
"""
Computes the comlex conjugate of the LGmodes if it is needed.
- LGmodes matrix (Modes,X,Y).
- Index of the half piramid, from LGindexes(modeGroup)function.
"""
WholeModesSet = []
LGmodesConjugate = conjugate(LGmodes)
#LGmn modes --> Unique modes n = 0
n = indexes[1,:]
for count,n_idx in enumerate(n):
if (n_idx == 0):
#Independent mode
WholeModesSet.append(LGmodes[count,...])
else:
#Pair of modes
WholeModesSet.append(LGmodes[count,...])
WholeModesSet.append(LGmodesConjugate[count,...])
#Done for Loop
return((WholeModesSet))
@njit(parallel=True)
def ComputeAllLGmodesFarField_array_parallel ( LGmodes, indexes, Gouy ):
"""
Computes the comlex conjugate of the LGmodes if it is needed.
- LGmodes matrix (Modes,X,Y).
- Index of the half piramid, from LGindexes(modeGroup)function.
- return an arry with all the modes
"""
LGmodesConjugate = np.conjugate(LGmodes) #conjugate all the input modes
#LGmn modes --> Unique modes n = 0
n = indexes[1,:]
l = len(n)
uniqueM = len(np.where(n==0)[0])
num_modes = (l - uniqueM)*2 + uniqueM
WholeModesSet = np.zeros((num_modes,LGmodes.shape[1],LGmodes.shape[2]),np.complex64)
count = 0;
for idx,n_idx in enumerate(n):
if (n_idx == 0):
#Independent mode
WholeModesSet[count,...] = (LGmodes[idx,...]) * Gouy[idx]
count += 1
else:
#Pair of modes
WholeModesSet[count,...] = (LGmodes[idx,...]) * Gouy[idx]
count += 1
WholeModesSet[count,...] = (LGmodesConjugate[idx,...]) * Gouy[idx]
count += 1
#Done for Loop
return(WholeModesSet)
def ComputeAllLGmodesFarField_array ( LGmodes, indexes, Gouy):
"""
Computes the comlex conjugate of the LGmodes if it is needed.
- LGmodes matrix (Modes,X,Y).
- Index of the half piramid, from LGindexes(modeGroup)function.
- return an arry with all the modes
"""
LGmodesConjugate = np.conjugate(LGmodes) #conjugate all the input modes
#LGmn modes --> Unique modes n = 0
n = indexes[1,:]
l = len(n)
uniqueM = len(np.where(n==0)[0])
num_modes = (l - uniqueM)*2 + uniqueM
WholeModesSet = np.zeros((num_modes,LGmodes.shape[1],LGmodes.shape[2]),np.complex64)
count = 0;
for idx,n_idx in enumerate(n):
if (n_idx == 0):
#Independent mode
WholeModesSet[count,...] = (LGmodes[idx,...]) * Gouy[idx]
count += 1
else:
#Pair of modes
WholeModesSet[count,...] = (LGmodes[idx,...]) * Gouy[idx]
count += 1
WholeModesSet[count,...] = (LGmodesConjugate[idx,...]) * Gouy[idx]
count += 1
#Done for Loop
return(WholeModesSet)
######################## MODES GENERATION FUNCTIONS END #######################
############## ############## ############## ############## ##############
##################### LAGUERRE POLYNOMIALK GENERATION #########################
############## ############## ############## ############## ##############
#Function to be run with ipyparallel that give you the LG polynomials
def eval_genlaguerreCPU(p,l,x):
return sp.eval_genlaguerre(p,l,x)
def LGpol(p,l):
o = scipy.special.eval_genlaguerre(p,l,x)
return o
def eval_genlaguerreCPU_parallel(p,l,x):
"""
NOTE : IPCLUSTER MUST BE LUNCH!!!
Compute Laguerre polinomials using Ipyparallel:
p -- is de degree of the Laguerre polynomials
l -- is the coef that modulate the polynomial
x -- the points where the polynomial wants to be evaluated
returns an array in the GPU
"""
try:
rc = Client()
dview = rc[:] # get all the
except TimeoutError:
print('Try to laucnh the cluster : ipcluster start -n (num of cores)')
#Make modules visible insides the cluster
with dview.sync_imports():
import numpy
import scipy.special
import scipy
dview.push(dict(x = x))# make x parameter visible to all the cores
LGpoly = dview.map_sync(LGpol,p,l)
return(np.array(LGpoly)) #return a numpy array
def Okernel(p,l,k):
with np.errstate(divide='ignore'):
o = sp.factorial(p+l) / ( sp.factorial(k) * sp.factorial(p-k) * sp.factorial(l+k) )
return(o)
def eval_genlaguerreGPU(p,l,x) :
"""
Compute Laguerre polinomials in the GPU:
p -- is de degree of the Laguerre polynomials
l -- is the coef that modulate the polynomial
x -- the points where the polynomial wants to be evaluated
returns an array in the GPU
"""
maxK = int(p.max())
Xmatrix = cp.zeros( (maxK+1,x.shape[0],x.shape[1]), float )
k = np.arange(0,maxK+1,1, int)
k_gpu = cp.arange(0,maxK+1,1, int)
x_gpu = cp.asarray(x).astype(cp.float) #Argument of the LG function
Xmatrix = cp.power( x_gpu, k_gpu[:,None,None] ) * cp.power((-1),k_gpu[:,None,None])
Xmatrix.shape
N = int( p.shape[0])
O = np.zeros((k.shape[0],N))
O.shape
for i in k:
O[i,:] = Okernel(p,l,i)
O[O == np.inf] = 0
O_gpu = cp.asarray(O).astype(cp.float)
#Mem checking
meminfo = cp.cuda.Device(0).mem_info #Tuple (free,total)
temp_nbytes = x.shape[0]**2 * (maxK+1) * N * 64 / 8 # dim x dim x DIM x DiM (4 dim array) - float64 beeing use / bytes
LG_test_nbytes = x.shape[0]**2 * N * 64 / 8
memfree = meminfo[0]
memNeed = temp_nbytes + LG_test_nbytes
print('Mem. avaliable ', memfree/1024**3, ' mem. needed ', memNeed/1024**3, ' in Gb')
if(memfree > memNeed):
temp = O_gpu[:,:,None,None] * Xmatrix[:,None,...]
#print(temp.nbytes/1024**3)
LG_test = cp.sum(temp,axis = 0)
del temp
cp._default_memory_pool.free_all_blocks()
else:
print('Performing it in blocks ...')
#Do it in chuncks
LG_test = cp.zeros((N,x.shape[0],x.shape[1]),float)
# No smart : do it in # chuncks -->
chuncks = 4 # Hardcoded to 2 since I am not going to go that high in modegroups
ch = N//chuncks
rr = N%ch
for i in range(chuncks):
lowLim = i*ch
if chuncks == i+1: # We are in the last iteration
highLim = ch*(i+1) + rr
else:
highLim = ch*(i+1)
temp = O_gpu[: , lowLim : highLim , None , None] * Xmatrix[:,None,...]
LG_test[lowLim : highLim , ...] = cp.sum(temp, axis = 0)
#print('Indexing from ', lowLim, ' to ', highLim , ' out ', N)
del temp
cp._default_memory_pool.free_all_blocks()
print('Done')
#Xmatrix is a 3D array, dimenssion depends on p and resolution of the modes.
#O_gpu is 2D array with all possible coefs that multiply Xmatrix.
#here I should implement how to do it in chucks in case temp gets so big
# del temp
#cp._default_memory_pool.free_all_blocks()
#cp.cuda.Device(0).mem_info
#floats64 cupy array are 8 bytes -> probably change to float 32
#temSize = O_gpu.shape(1) * Xmatrix.shape * 8
#temp = O_gpu[:,:,None,None] * Xmatrix[:,None,...] #This take a lot of memory, but I can be compute in chuncks+
# print(temp.shape)
# print(O_gpu.shape, Xmatrix.shape)
# print(temp.nbytes)
# print(temp.dtype)
#LG_test = cp.sum(temp,axis = 0)
#del temp
#cp._default_memory_pool.free_all_blocks()
return LG_test
################### LAGUERRE POLYNOMIALK GENERATION END #######################
############## ############## ############## ############## ##############
############### LG POLY + MODE GEN FUNCTIONS COMPACTATION #####################
############## ############## ############## ############## ##############
#This functions are more ready to use. Give you an extra level of abstraction
#COMPACT ALL ABOVE GENERATION FUNCTION IN ONE DEPENDING OF SOME FLAGS
def LGmodes(w0,X,Y,mode_index, engine = 'GPU', multicore = True):
"""
Compute LGmodes of a given mode field diamter/2 and XY grid for some
mode_index coeficients. Computation can be done in the GPU or in
the CPU{serial or parallel}. Check the inbuilt functions for more info
"""
#Compute some commom variables : LG poly argument
#coefs are needed
p = mode_index[0]
l = mode_index[1]
#space is needed
RHO,PHI = cart2pol(X,Y)
lgArg = ((RHO**2) * (2 / w0**2))
#NOTE : There are thing can be simplied I know... I am repeting things...
# I am reusing some stuff
if engine == 'GPU':
print('Engine : GPU')
LGpolynomials = eval_genlaguerreGPU(p,l,lgArg)
mm = LGmodes_GPU(w0, X, Y, mode_index, LGpolynomials)
else: #then target
if multicore == True:
print('Engine : CPU multicore')
LGpolynomials = eval_genlaguerreCPU_parallel(p,l,lgArg)
mm = LGmodes_CPU_parallel(w0,X,Y,mode_index,LGpolynomials)
else:
print('Engine : CPU singlecore')
#Make arrays compatible for vectorization using single core
pp = p[:,None,None]
ll = l[:,None,None]
llgArg = lgArg[None,...]
LGpolynomials = eval_genlaguerreCPU(pp,ll,llgArg)
mm = LGmodes_CPU(w0,X,Y,mode_index,LGpolynomials)
return(mm)
def computeWholeSetofModes(modes_array,indexes, multicore = True):
if multicore == True:
return( ComputeAllLGmodes_array_parallel(modes_array,indexes) )
else:
return(ComputeAllLGmodes_array ( modes_array, indexes))
def computeWholeSetofModesFarField(modes_array,indexes, Gouy, multicore = True):
if multicore == True:
return( ComputeAllLGmodesFarField_array_parallel(modes_array, indexes, Gouy) )
else:
return(ComputeAllLGmodesFarField_array( modes_array, indexes, Gouy))
if __name__ == "__main__":
t = times
import mark_lib as mkl
samples = 1024
px_mmf = 0.3
w0 = 15.3/2
x = arange(-samples//2,samples//2,1) * px_mmf
X,Y = meshgrid(x,x)
#Modes: This just compute half of the piramid
mode_group_max = 21
index = graded_index_fiber_coefs(mode_group_max)
# t.tic()
# m,p = mkl.modes.LGnm_fiber(1565,w0,X,Y,index)
# t.toc()
t.tic()
mm = LGmodes(w0,X,Y,index, engine = 'GPU', multicore = True)
t.toc()
# t.tic()
# mmm,ppp = LGmodes(w0,X,Y,index, engine = 'CPU', multicore = True)
# t.toc()
#Test speed
#mempool = cp.get_default_memory_pool()
#pinned_mempool = cp.get_default_pinned_memory_pool()
# t.tic()
# LGmodesgpu = LGmodes(w0,X,Y,index,engine = 'GPU', multicore = True)
# t.toc()
# t.tic()
# LGmodesCPUparallel = LGmodes(w0,X,Y,index,engine = 'CPU', parallel = True)
# t.toc()
# t.tic()
# LGmodesCPUparallel = LGmodes(w0,X,Y,index,engine = 'CPU', parallel = False)
# t.toc()
# RHO,PHI = cart2pol(X,Y)
# x = ((RHO**2) * (2 / w0**2))
# #Pure GPU
# LGpolynomialsGPU = eval_genlaguerreGPU(index[0],index[1],x)
# LGmodes = LGmodes_GPU(w0,X,Y,index,LGpolynomialsGPU)
# #LGpolynomialsCPU = eval_genlaguerreCPU_parallel(index[0],index[1],x)
# LGWholeSet = ComputeAllLGmodes_array ( LGmodes, index)