@@ -322,9 +322,26 @@ def simulate(self, *, pcof0=[], pt0=[], qt0=[], maxcores=-1, datadir="./run_dir"
322322
323323
324324 if len (pt0 ) > 0 and len (qt0 ) > 0 :
325+ nsplines_org = self .nsplines
326+ spline_knot_spacing_org = self .spline_knot_spacing
327+ cw_org = self .carrier_frequency .copy ()
328+ self .carrier_frequency = [[0.0 ] for _ in range (len (self .Ne ))]
329+ spline_order_org = self .spline_order
330+ self .spline_order = 0
331+ self .spline_knot_spacing = self .dT
332+ self .nsplines = np .max ([2 ,int (np .ceil (self .nsteps * self .dT / self .spline_knot_spacing + 1 ))])
333+
325334 pcof0 = self .downsample_pulses (pt0 = pt0 , qt0 = qt0 )
326335
327- return self .__run (pcof0 = pcof0 , runtype = "simulation" , overwrite_popt = False , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash ,mpi_exec = mpi_exec , batchargs = batchargs )
336+ result = self .__run (pcof0 = pcof0 , runtype = "simulation" , overwrite_popt = False , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash ,mpi_exec = mpi_exec , batchargs = batchargs )
337+
338+ if len (pt0 ) > 0 and len (qt0 ) > 0 :
339+ self .nsplines = nsplines_org
340+ self .spline_knot_spacing = spline_knot_spacing_org
341+ self .spline_order = spline_order_org
342+ self .carrier_frequency = cw_org .copy ()
343+
344+ return result
328345
329346
330347 def optimize (self , * , pcof0 = [], pt0 = [], qt0 = [], maxcores = - 1 , datadir = "./run_dir" , quandary_exec = "" , cygwinbash = "" , mpi_exec = "mpirun -np " , batchargs = []):
@@ -351,11 +368,27 @@ def optimize(self, *, pcof0=[], pt0=[], qt0=[], maxcores=-1, datadir="./run_dir"
351368 expectedEnergy : Evolution of the expected energy of each oscillator and each initial condition. Acces: expectedEnergy[oscillator][initialcondition]
352369 population : Evolution of the population of each oscillator, of each initial condition. (expectedEnergy[oscillator][initialcondition])
353370 """
354-
371+
355372 if len (pt0 ) > 0 and len (qt0 ) > 0 :
373+ nsplines_org = self .nsplines
374+ spline_knot_spacing_org = self .spline_knot_spacing
375+ spline_order_org = self .spline_order
376+ cw_org = self .carrier_frequency .copy ()
377+ self .carrier_frequency = [[0.0 ] for _ in range (len (self .Ne ))]
378+ self .spline_order = 0
379+ self .spline_knot_spacing = self .dT
380+ self .nsplines = np .max ([2 ,int (np .ceil (self .nsteps * self .dT / self .spline_knot_spacing + 1 ))])
356381 pcof0 = self .downsample_pulses (pt0 = pt0 , qt0 = qt0 )
357382
358- return self .__run (pcof0 = pcof0 , runtype = "optimization" , overwrite_popt = True , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash , mpi_exec = mpi_exec , batchargs = batchargs )
383+ result = self .__run (pcof0 = pcof0 , runtype = "optimization" , overwrite_popt = True , maxcores = maxcores , datadir = datadir , quandary_exec = quandary_exec , cygwinbash = cygwinbash , mpi_exec = mpi_exec , batchargs = batchargs )
384+
385+ if len (pt0 ) > 0 and len (qt0 ) > 0 :
386+ self .nsplines = nsplines_org
387+ self .spline_knot_spacing = spline_knot_spacing_org
388+ self .spline_order = spline_order_org
389+ self .carrier_frequency = cw_org .copy ()
390+
391+ return result
359392
360393
361394 def evalControls (self , * , pcof0 = [], points_per_ns = 1 ,datadir = "./run_dir" , quandary_exec = "" , mpi_exec = "mpirun -np " , cygwinbash = "" ):
@@ -407,8 +440,6 @@ def evalControls(self, *, pcof0=[], points_per_ns=1,datadir="./run_dir", quandar
407440 def downsample_pulses (self , * , pt0 = [], qt0 = []):
408441 if self .spline_order == 0 : #specifying (pt, qt) only makes sense for piecewise constant B-splines
409442 Nsys = len (self .Ne )
410- self .nsplines = np .max ([2 ,int (np .ceil (self .nsteps * self .dT / self .spline_knot_spacing + 1 ))])
411- self .spline_knot_spacing = self .nsteps * self .dT / (self .nsplines - 1 )
412443 if len (pt0 ) == Nsys and len (qt0 ) == Nsys :
413444 sizes_ok = True
414445 for iosc in range (Nsys ):
@@ -1224,6 +1255,7 @@ def plot_expectedEnergy(Ne, time, expectedEnergy):
12241255 plt .subplots_adjust (hspace = 0.5 )
12251256 plt .subplots_adjust (wspace = 0.5 )
12261257 plt .draw ()
1258+ plt .pause (0.01 )
12271259 print ("\n Plotting expected energy dynamics" )
12281260 print ("-> Press <enter> to proceed." )
12291261 plt .waitforbuttonpress (1 );
@@ -1263,6 +1295,7 @@ def plot_population(Ne, time, population):
12631295 plt .subplots_adjust (hspace = 0.5 )
12641296 plt .subplots_adjust (wspace = 0.5 )
12651297 plt .draw ()
1298+ plt .pause (0.01 )
12661299 print ("\n Plotting population dynamics" )
12671300 print ("-> Press <enter> to proceed." )
12681301 plt .waitforbuttonpress (1 );
@@ -1335,6 +1368,7 @@ def plot_results_1osc(myconfig, p, q, expectedEnergy, population):
13351368 ax [row , col ].grid ()
13361369
13371370 plt .draw ()
1371+ plt .pause (0.01 )
13381372 print ("\n Plotting results..." )
13391373 print ("-> Press <enter> to proceed." )
13401374 plt .waitforbuttonpress (1 );
0 commit comments