@@ -280,7 +280,7 @@ def update(self):
280
280
self .uT = uT_org .copy ()
281
281
282
282
283
- def simulate (self , * , pcof0 = [], pt0 = [], qt0 = [], maxcores = - 1 , datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" , batchargs = []):
283
+ def simulate (self , * , pcof0 = [], pt0 = [], qt0 = [], maxcores = - 1 , datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" , mpirun = "mpirun -np " , batchargs = []):
284
284
"""
285
285
Simulate the quantm dynamics using the current settings.
286
286
@@ -308,10 +308,10 @@ def simulate(self, *, pcof0=[], pt0=[], qt0=[], maxcores=-1, datadir="./run_dir"
308
308
if len (pt0 ) > 0 and len (qt0 ) > 0 :
309
309
pcof0 = self .downsample_pulses (pt0 = pt0 , qt0 = qt0 )
310
310
311
- return self .__run (pcof0 = pcof0 , runtype = "simulation" , overwrite_popt = False , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash , batchargs = batchargs )
311
+ return self .__run (pcof0 = pcof0 , runtype = "simulation" , overwrite_popt = False , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash ,mpirun = mpirun , batchargs = batchargs )
312
312
313
313
314
- def optimize (self , * , pcof0 = [], pt0 = [], qt0 = [], maxcores = - 1 , datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" , batchargs = []):
314
+ def optimize (self , * , pcof0 = [], pt0 = [], qt0 = [], maxcores = - 1 , datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" , mpirun = "mpirun -np " , batchargs = []):
315
315
"""
316
316
Optimize the quantm dynamics using the current settings.
317
317
@@ -337,10 +337,10 @@ def optimize(self, *, pcof0=[], pt0=[], qt0=[], maxcores=-1, datadir="./run_dir"
337
337
if len (pt0 ) > 0 and len (qt0 ) > 0 :
338
338
pcof0 = self .downsample_pulses (pt0 = pt0 , qt0 = qt0 )
339
339
340
- return self .__run (pcof0 = pcof0 , runtype = "optimization" , overwrite_popt = True , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash , batchargs = batchargs )
340
+ return self .__run (pcof0 = pcof0 , runtype = "optimization" , overwrite_popt = True , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash , mpirun = mpirun , batchargs = batchargs )
341
341
342
342
343
- def evalControls (self , * , pcof0 = [], points_per_ns = 1 ,datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" ):
343
+ def evalControls (self , * , pcof0 = [], points_per_ns = 1 ,datadir = "./run_dir" , quandary_exec = "" , mpirun = "mpirun -np " , cygwinbash = "" ):
344
344
"""
345
345
Evaluate control pulses on a specific sample rate.
346
346
@@ -367,7 +367,7 @@ def evalControls(self, *, pcof0=[], points_per_ns=1,datadir="./run_dir", quandar
367
367
os .makedirs (datadir_controls , exist_ok = True )
368
368
runtype = 'evalcontrols'
369
369
configfile_eval = self .__dump (pcof0 = pcof0 , runtype = runtype , datadir = datadir_controls )
370
- err = execute (runtype = runtype , ncores = 1 , config_filename = configfile_eval , datadir = datadir_controls , quandary_exec = quandary_exec , verbose = False , cygwinbash = cygwinbash )
370
+ err = execute (runtype = runtype , ncores = 1 , config_filename = configfile_eval , datadir = datadir_controls , quandary_exec = quandary_exec , verbose = False , mpirun = mpirun , cygwinbash = cygwinbash )
371
371
time , pt , qt , _ , _ , _ , pcof , _ , _ = self .get_results (datadir = datadir_controls , ignore_failure = True )
372
372
373
373
# Save pcof to config.popt
@@ -428,7 +428,7 @@ def downsample_pulses(self, *, pt0=[], qt0=[]):
428
428
return pcof0
429
429
430
430
431
- def __run (self , * , pcof0 = [], runtype = "optimization" , overwrite_popt = False , maxcores = - 1 , datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" , batchargs = []):
431
+ def __run (self , * , pcof0 = [], runtype = "optimization" , overwrite_popt = False , maxcores = - 1 , datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" , mpirun = "mpirun -np " , batchargs = []):
432
432
"""
433
433
Internal helper function to launch processes to execute the C++ Quandary code:
434
434
1. Writes quandary config files to file system
@@ -442,17 +442,22 @@ def __run(self, *, pcof0=[], runtype="optimization", overwrite_popt=False, maxco
442
442
config_filename = self .__dump (pcof0 = pcof0 , runtype = runtype , datadir = datadir )
443
443
444
444
# Set default number of cores to the number of initial conditions, unless otherwise specified. Make sure ncores is an integer divisible of ninit.
445
- ncores = self ._ninit
445
+ ncores_init = self ._ninit
446
446
if maxcores > - 1 :
447
- ncores = min (self ._ninit , maxcores )
447
+ ncores_init = min (self ._ninit , maxcores )
448
448
for i in range (self ._ninit , 0 , - 1 ):
449
449
if self ._ninit % i == 0 : # i is a factor of ninit
450
- if i <= ncores :
451
- ncores = i
450
+ if i <= ncores_init :
451
+ ncores_init = i
452
452
break
453
+ # Set remaining number of cores for petsc
454
+ ncores_petsc = 1
455
+ if maxcores > ncores_init and maxcores % ncores_init == 0 :
456
+ ncores_petsc = int (maxcores / ncores_init )
457
+ ncores = ncores_init * ncores_petsc
453
458
454
459
# Execute subprocess to run Quandary
455
- err = execute (runtype = runtype , ncores = ncores , config_filename = config_filename , datadir = datadir , quandary_exec = quandary_exec , verbose = self .verbose , cygwinbash = cygwinbash , batchargs = batchargs )
460
+ err = execute (runtype = runtype , ncores = ncores , config_filename = config_filename , datadir = datadir , quandary_exec = quandary_exec , verbose = self .verbose , cygwinbash = cygwinbash , mpirun = mpirun , batchargs = batchargs )
456
461
if self .verbose :
457
462
print ("Quandary data dir: " , datadir , "\n " )
458
463
@@ -1332,7 +1337,7 @@ def timestep_richardson_est(quandary, tol=1e-8, order=2, quandary_exec=""):
1332
1337
return errs_J , errs_u , dts
1333
1338
1334
1339
1335
- def execute (* , runtype = "simulation" , ncores = 1 , config_filename = "config.cfg" , datadir = "." , quandary_exec = "" , verbose = False , cygwinbash = "" , batchargs = []):
1340
+ def execute (* , runtype = "simulation" , ncores = 1 , config_filename = "config.cfg" , datadir = "." , quandary_exec = "" , verbose = False , cygwinbash = "" , mpirun = "mpirun -np " , batchargs = []):
1336
1341
"""
1337
1342
Helper function to evoke a subprocess that executes Quandary.
1338
1343
@@ -1367,8 +1372,8 @@ def execute(*, runtype="simulation", ncores=1, config_filename="config.cfg", dat
1367
1372
if len (batchargs )> 0 :
1368
1373
myrun = batch_run # currently set to "srun -n"
1369
1374
else :
1370
- myrun = " mpirun -np "
1371
- runcommand = f"{ myrun } { ncores } " + runcommand
1375
+ myrun = mpirun
1376
+ runcommand = f"{ myrun } { ncores } " + runcommand
1372
1377
if verbose :
1373
1378
print ("Running Quandary ... " )
1374
1379
0 commit comments