def _advance(self, suppress_errors=False): print time.time() # prevent multiple advances from happening at the same time if self.is_advancing: raise AlreadyAdvancing() try: # start timer ti = time.time() # signal that we are advancing self.is_advancing = True # check status of current experiment # if it is comple if self.experiment: remaining_points = get_remaining_points(self.parameters) if remaining_points: if self.experiment.get('shot_number') is not None: self.experiment['shot_number'] += 1 else: if self.experiment.get('name'): print "experiment ({}): completed".format( self.experiment['name']) self._advance_experiment() else: self._advance_experiment() remaining_points = get_remaining_points(self.parameters) if remaining_points: if self.experiment.get('repeat_shot'): self.experiment['repeat_shot'] = False remaining_points += 1 else: self._advance_parameter_values( suppress_errors=suppress_errors) #print "experiment ({}): remaining points: {}".format(self.experiment['name'], remaining_points) name = self.experiment.get('name') shot_number = self.experiment.get('shot_number') if self.experiment.get('loop'): print "experiment ({}): shot {}".format( name, shot_number + 1) elif (shot_number is not None): print "experiment ({}): shot {} of {}".format( name, shot_number + 1, remaining_points + shot_number) else: self._advance_parameter_values(suppress_errors=suppress_errors) self._update_parameters(suppress_errors=suppress_errors) tf = time.time() if self.verbose: print 'advanced in {} s'.format(tf - ti) except: if not suppress_errors: raise finally: self.is_advancing = False
def _advance(self): # prevent multiple advances from happening at the same time if self.is_advancing: raise AlreadyAdvancing() try: # signal that we are advancing self.is_advancing = True # check status of current experiment # if it is comple if self.experiment: remaining_points = get_remaining_points(self.parameters) if remaining_points: self.experiment['shot_number'] += 1 else: if self.experiment.get('name'): print "experiment ({}): completed".format( self.experiment['name']) self._advance_experiment() else: self._advance_experiment() remaining_points = get_remaining_points(self.parameters) if remaining_points: if self.experiment.get('repeat_shot'): self.experiment['repeat_shot'] = False remaining_points += 1 else: self._advance_parameter_values() #print "experiment ({}): remaining points: {}".format(self.experiment['name'], remaining_points) name = self.experiment.get('name') shot_number = self.experiment.get('shot_number') if self.experiment.get('loop'): print "experiment ({}): shot {}".format(name, shot_number) elif shot_number: print "experiment ({}): shot {} of {}".format( name, shot_number, remaining_points + shot_number) else: self._advance_parameter_values() self._update_parameters() except: raise AdvanceError() finally: self.is_advancing = False
def _advance(self, suppress_errors=False): # prevent multiple advances from happening at the same time if self.is_advancing: raise AlreadyAdvancingError() try: # start timer ti = time.time() # signal that we are advancing self.is_advancing = True # check if pause experiment if self.is_paused: print('[conductor] Experiment paused') while (self.is_paused is True): if (self.is_paused is False): break elif (self.is_stop is True): self._experiment_pause_toggle() break time.sleep(0.1) print('[conductor] Experiment resumed') # check if the experiment stops, if True, this will trigger is_end and ends all experiments elif self.is_stop: print('[conductor] Stopping experiments') self.previous_experiment = self.experiment.copy() # save the previous shot for later self.is_end = True # check if this is the first_shot elif self.is_first: # for the first shot of experiment, you want to write sequence and run self._advance_experiment() self._advance_parameter_values(suppress_errors=suppress_errors) name = self.experiment.get('name') shot_number = self.experiment.get('shot_number') print("[conductor] Experiment ({}): shot {}".format(name, shot_number)) # Basically should be shot#0 else: # check if you have to repeat shot. if self.experiment.get('repeat_shot'): # if so, this will simply re-do the current shot again. self.previous_experiment = self.experiment.copy() self.experiment['repeat_shot'] = False name = self.experiment.get('name') shot_number = self.experiment.get('shot_number') print("[conductor] Experiment ({}): shot {} repeated".format(name, shot_number)) # if no repeat shot, will check if there is remaining_points else: remaining_points = get_remaining_points(self.parameters) # if remaining points, it is not the end of current experiment, then advance parameter values # looped experiments will always have remaining points if remaining_points: self.previous_experiment = self.experiment.copy() self._advance_parameter_values(suppress_errors=suppress_errors) name = self.experiment.get('name') self.experiment['shot_number'] += 1 shot_number = self.experiment.get('shot_number') print("[conductor] Experiment ({}): shot {}".format(name, shot_number)) # if there is no remaining_points left, probably means that it is an 'unlooped' experiment. else: self._advance_experiment() # if no experiment left in queue, it is the end of experiments. if not self.experiment: self.is_end = True else: # if popped up experiment exists, this is in transition to the first shot of the queued experiment. self._advance_parameter_values(suppress_errors=suppress_errors) name = self.experiment.get('name') shot_number = self.experiment.get('shot_number') print("[conductor] Experiment ({}): shot {}".format(name, shot_number)) self.is_first = True self._update_parameters(suppress_errors=suppress_errors) tf = time.time() if self.verbose: print('advanced in {} s'.format(tf - ti)) except: if not suppress_errors: raise finally: shot_number = self.experiment.get('shot_number') remaining_points = get_remaining_points(self.parameters) self._send_update({'shots': {'current_shot': shot_number, 'remaining_shots': remaining_points}}) self.is_advancing = False