def connect_to_zlock_server(): # setup connection with the zprocess.locking server, depending on labconfig settings: config = LabConfig(required_params={ 'ports': ['zlock'], 'servers': ['zlock'] }) host = config.get('servers', 'zlock') port = config.get('ports', 'zlock') if socket.gethostbyname(host) == socket.gethostbyname('localhost'): try: # short connection timeout if localhost, don't want to # waste time: zprocess.locking.connect(host, port, timeout=0.05) except zmq.ZMQError: # No zprocess.locking server running on localhost. Start one. It will run # forever, even after this program exits. This is important for # other programs which might be using it. I don't really consider # this bad practice since the server is typically supposed to # be running all the time: devnull = open(os.devnull, 'w') subprocess.Popen([sys.executable, '-m', 'zprocess.locking'], stdout=devnull, stderr=devnull) # Try again. Longer timeout this time, give it time to start up: zprocess.locking.connect(host, port, timeout=15) else: zprocess.locking.connect(host, port) # The user can call these functions to change the timeouts later if they # are not to their liking: set_default_timeout(DEFAULT_TIMEOUT)
def connect_to_zlock_server(): # setup connection with the zprocess.locking server, depending on labconfig settings: config = LabConfig(required_params={ 'ports': ['zlock'], 'servers': ['zlock'] }) host = config.get('servers', 'zlock') port = config.get('ports', 'zlock') if socket.gethostbyname(host) == socket.gethostbyname('localhost'): try: # short connection timeout if localhost, don't want to # waste time: zprocess.locking.connect(host, port, timeout=0.05) except zmq.ZMQError: # No zprocess.locking server running on localhost. Start one. It will run # forever, even after this program exits. This is important for # other programs which might be using it. I don't really consider # this bad practice since the server is typically supposed to # be running all the time: start_daemon([sys.executable, '-m', 'zprocess.locking']) # Try again. Longer timeout this time, give it time to start up: zprocess.locking.connect(host, port, timeout=15) else: zprocess.locking.connect(host, port) # Check if the zlock server supports read-write locks: global _server_supports_readwrite if hasattr(zprocess.locking, 'get_protocol_version'): version = zprocess.locking.get_protocol_version() if LooseVersion(version) >= LooseVersion('1.1.0'): _server_supports_readwrite = True # The user can call these functions to change the timeouts later if they # are not to their liking: set_default_timeout(DEFAULT_TIMEOUT)
def create_folder(self): sequence_index = 0 exp_config = LabConfig() shot_storage = exp_config.get('paths', 'experiment_shot_storage') folder = rm.generate_output_folder(self.experiment_name, shot_storage, date.today().strftime('%Y\%m\%d'), sequence_index) folder = os.path.join(os.path.dirname(folder), '%04d_test' % sequence_index) # Make sure shots go to a unique directory while True: try: os.makedirs(folder) break except: sequence_index += 1 folder = rm.generate_output_folder( self.experiment_name, shot_storage, date.today().strftime('%Y\%m\%d'), sequence_index) folder = os.path.join(os.path.dirname(folder), '%04d_test' % sequence_index) print('Created {} folder.'.format(folder)) return folder, sequence_index
def _get_device_dirs(): """Return the directory of labscript_devices, and the folders containing submodules of any packages listed in the user_devices labconfig setting""" try: user_devices = LabConfig().get('DEFAULT', 'user_devices') except (LabConfig.NoOptionError, LabConfig.NoSectionError): user_devices = 'user_devices' # Split on commas, remove whitespace: user_devices = [s.strip() for s in user_devices.split(',')] return _get_import_paths(['labscript_devices'] + user_devices)
def __init__(self, host=None, port=None): ZMQClient.__init__(self) if host is None: host = LabConfig().get('servers', 'runmanager', fallback='localhost') if port is None: port = LabConfig().getint('ports', 'runmanager', fallback=DEFAULT_PORT) self.host = host self.port = port
def submit_to_blacs(shot_file, host='localhost', timeout=5): """Submit a shot file to BLACS running on the given hostname. Uses port number as saved in labconfig. Returns BLACS's reponse or raises an exception if shot was not added successfully.""" from labscript_utils.labconfig import LabConfig import zprocess from labscript_utils.shared_drive import path_to_agnostic config = LabConfig() port = int(config.get('ports', 'blacs')) data = path_to_agnostic(shot_file) response = zprocess.zmq_get(port, host, data, timeout=timeout) if 'added successfully' not in response: raise Exception(response) return response
def get_config(): """Get relevant options from LabConfig, substituting defaults where appropriate and return as a dict""" global _cached_config # Cache the config so it is not loaded multiple times per process: if _cached_config is not None: return _cached_config labconfig = LabConfig() config = {} try: config['zlock_host'] = labconfig.get('servers', 'zlock') except (labconfig.NoOptionError, labconfig.NoSectionError): msg = "No zlock server specified in labconfig" raise RuntimeError(msg) try: config['zlock_port'] = labconfig.get('ports', 'zlock') except (labconfig.NoOptionError, labconfig.NoSectionError): config['zlock_port'] = zprocess.zlock.DEFAULT_PORT # We hard-code the zlog host and port, since zlog always runs on the computer with # the top-level process config['zlog_host'] = 'localhost' config['zlog_port'] = zprocess.zlog.DEFAULT_PORT try: config['zprocess_remote_port'] = labconfig.get('ports', 'zprocess_remote') except (labconfig.NoOptionError, labconfig.NoSectionError): config['zprocess_remote_port'] = zprocess.remote.DEFAULT_PORT try: shared_secret_file = labconfig.get('security', 'shared_secret') except (labconfig.NoOptionError, labconfig.NoSectionError): config['shared_secret'] = None config['shared_secret_file'] = None else: config['shared_secret'] = open(shared_secret_file).read().strip() config['shared_secret_file'] = shared_secret_file try: config['allow_insecure'] = labconfig.getboolean( 'security', 'allow_insecure') except (labconfig.NoOptionError, labconfig.NoSectionError): config['allow_insecure'] = False if config['shared_secret'] is None and not config['allow_insecure']: raise ValueError(_ERR_NO_SHARED_SECRET.replace('/', os.sep)) try: config['logging_maxBytes'] = labconfig.getint('logging', 'maxBytes') except (labconfig.NoOptionError, labconfig.NoSectionError): config['logging_maxBytes'] = 1024 * 1024 * 50 try: config['logging_backupCount'] = labconfig.getint( 'logging', 'backupCount') except (labconfig.NoOptionError, labconfig.NoSectionError): config['logging_backupCount'] = 1 _cached_config = config return config
def connect_to_zlock_server(): # setup connection with the zprocess.locking server, depending on labconfig settings: config = LabConfig(required_params={ 'ports': ['zlock'], 'servers': ['zlock'] }) host = config.get('servers', 'zlock') port = config.get('ports', 'zlock') if socket.gethostbyname(host) == socket.gethostbyname('localhost'): try: # short connection timeout if localhost, don't want to # waste time: zprocess.locking.connect(host, port, timeout=0.05) except zmq.ZMQError: # No zprocess.locking server running on localhost. Start one. It will run # forever, even after this program exits. This is important for # other programs which might be using it. I don't really consider # this bad practice since the server is typically supposed to # be running all the time: if os.name == 'nt': creationflags = 0x00000008 # DETACHED_PROCESS from the win32 API # Note that we must not remain in same working directory, or we will hold a lock # on it that prevents it from being deleted. subprocess.Popen([sys.executable, '-m', 'zprocess.locking'], creationflags=creationflags, stdout=None, stderr=None, close_fds=True, cwd=os.getenv('temp')) else: devnull = open(os.devnull, 'w') if not os.fork(): os.setsid() subprocess.Popen( [sys.executable, '-m', 'zprocess.locking'], stdin=devnull, stdout=devnull, stderr=devnull, close_fds=True) os._exit(0) # Try again. Longer timeout this time, give it time to start up: zprocess.locking.connect(host, port, timeout=15) else: zprocess.locking.connect(host, port) # The user can call these functions to change the timeouts later if they # are not to their liking: set_default_timeout(DEFAULT_TIMEOUT)
def run(self, connection_name, hardware_name, device_name): self._connection_name = connection_name self._hardware_name = hardware_name self._device_name = device_name self.data = np.array([], dtype=np.float64) if self._connection_name != '-': title = "{} ({})".format(self._hardware_name, self._connection_name) else: title = "{}".format(self._hardware_name) self.plot_win = pg.plot([], title=title) broker_pub_port = int(LabConfig().get('ports', 'BLACS_Broker_Pub')) context = zmq.Context() self.socket = context.socket(zmq.SUB) self.socket.connect("tcp://127.0.0.1:%d" % broker_pub_port) self.socket.setsockopt(zmq.SUBSCRIBE, "{} {}\0".format(self._device_name, self._hardware_name).encode('utf-8')) self.analog_in_thread = threading.Thread(target=self._analog_read_loop) self.analog_in_thread.daemon = True self.analog_in_thread.start() self.cmd_thread = threading.Thread(target=self._cmd_loop) self.cmd_thread.daemon = True self.cmd_thread.start() QtGui.QApplication.instance().exec_() self.to_parent.put("closed")
def __init__(self, host=None, port=None, timeout=None): ZMQClient.__init__(self) if host is None: host = LabConfig().get('servers', 'runmanager', fallback='localhost') if port is None: port = LabConfig().getint('ports', 'runmanager', fallback=DEFAULT_PORT) if timeout is None: timeout = LabConfig().getfloat('timeouts', 'communication_timeout', fallback=60) self.host = host self.port = port self.timeout = timeout
def run_new_batch_of_shots(param_df,globals_filepath_list,experiment_name): param_name_list = param_df.columns.tolist() param_array = param_df.to_numpy() groups = rm.get_all_groups(globals_filepath_list) seq_globals = rm.get_globals(groups) seq_globals, evaled_globals, expansions = check_for_iterables_and_evaluate(seq_globals) shots=[] for ind_shot in np.arange(param_array.shape[0]): shot = rm.expand_globals(seq_globals, evaled_globals)[0] # dict for ind_param,param_name in enumerate(param_name_list): shot[param_name] = param_array[ind_shot,ind_param] shots.append(shot) print('Shots fired:') print(shots) folder, sequence_index = create_folder(experiment_name) seq_id = rm.generate_sequence_id(experiment_name, '%Y_%m_%d') filenames = rm.make_run_files(folder, seq_globals, shots, seq_id, sequence_index, '', shuffle=True) print('Submitting {} shots.'.format(len(shots))) exp_config = LabConfig() script_storage = exp_config.get('paths', 'labscriptlib') script_name = script_storage +'\\' + experiment_name + '.py' for fid in filenames: return_code, stdout, stderr = rm.compile_labscript(script_name, fid) print(return_code, stdout, stderr) response = rm.submit_to_blacs(fid) print(response) return
def connect_to_zlock_server(): # setup connection with the zprocess.locking server, depending on labconfig settings: config = LabConfig(required_params={'ports':['zlock'],'servers':['zlock']}) host = config.get('servers','zlock') port = config.get('ports','zlock') if socket.gethostbyname(host) == socket.gethostbyname('localhost'): try: # short connection timeout if localhost, don't want to # waste time: zprocess.locking.connect(host,port,timeout=0.05) except zmq.ZMQError: # No zprocess.locking server running on localhost. Start one. It will run # forever, even after this program exits. This is important for # other programs which might be using it. I don't really consider # this bad practice since the server is typically supposed to # be running all the time: if os.name == 'nt': creationflags=0x00000008 # DETACHED_PROCESS from the win32 API # Note that we must not remain in same working directory, or we will hold a lock # on it that prevents it from being deleted. subprocess.Popen([sys.executable,'-m','zprocess.locking'], creationflags=creationflags, stdout=None, stderr=None, close_fds=True, cwd=os.getenv('temp')) else: devnull = open(os.devnull,'w') if not os.fork(): os.setsid() subprocess.Popen([sys.executable,'-m','zprocess.locking'], stdin=devnull, stdout=devnull, stderr=devnull, close_fds=True) os._exit(0) # Try again. Longer timeout this time, give it time to start up: zprocess.locking.connect(host,port,timeout=15) else: zprocess.locking.connect(host, port) # The user can call these functions to change the timeouts later if they # are not to their liking: set_default_timeout(DEFAULT_TIMEOUT)
def create_analog_input_widgets(self, channel_properties): exp_config = LabConfig() broker_pub_port = int(exp_config.get('ports', 'BLACS_Broker_Pub')) # close old socket if there is one if self.socket is not None: self.socket.close() self.socket = None if self.context is not None: self.context.term() self.context = None # create a new subscribe socket to receive analoge values self.context = zmq.Context() self.socket = self.context.socket(zmq.SUB) self.socket.connect("tcp://127.0.0.1:%d" % broker_pub_port) widgets = {} for hardware_name, properties in channel_properties.items(): properties.setdefault('display_name', None) properties.setdefault('horizontal_alignment', False) properties.setdefault('parent', None) if hardware_name in self._AI: widgets[hardware_name] = self._AI[hardware_name].create_widget( properties['display_name'], properties['horizontal_alignment'], properties['parent']) self.socket.setsockopt( zmq.SUBSCRIBE, "{} {}\0".format(self.device_name, hardware_name).encode('utf-8')) self.analog_in_thread = threading.Thread(target=self._analog_read_loop, args=(widgets, )) self.analog_in_thread.daemon = True self.analog_in_thread.start() return widgets
def new_sequence_details(script_path, config=None, increment_sequence_index=True): """Generate the details for a new sequence: the toplevel attrs sequence_date, sequence_index, sequence_id; and the the output directory and filename prefix for the shot files, according to labconfig settings. If increment_sequence_index=True, then we are claiming the resulting sequence index for use such that it cannot be used by anyone else. This should be done if the sequence details are immediately about to be used to compile a sequence. Otherwise, set increment_sequence_index to False, but in that case the results are indicative only and one should call this function again with increment_sequence_index=True before compiling the sequence, as otherwise the sequence_index may be used by other code in the meantime.""" if config is None: config = LabConfig() script_basename = os.path.splitext(os.path.basename(script_path))[0] shot_storage = config.get('DEFAULT', 'experiment_shot_storage') shot_basedir = os.path.join(shot_storage, script_basename) now = datetime.datetime.now() sequence_timestamp = now.strftime('%Y%m%dT%H%M%S') # Toplevel attributes to be saved to the shot files: sequence_date = now.strftime('%Y-%m-%d') sequence_id = sequence_timestamp + '_' + script_basename sequence_index = next_sequence_index(shot_basedir, now, increment_sequence_index) sequence_attrs = { 'script_basename': script_basename, 'sequence_date': sequence_date, 'sequence_index': sequence_index, 'sequence_id': sequence_id, } # Compute the output directory based on labconfig settings: try: subdir_format = config.get('runmanager', 'output_folder_format') except (LabConfig.NoOptionError, LabConfig.NoSectionError): subdir_format = os.path.join('%Y', '%m', '%d', '{sequence_index:05d}') # Format the output directory according to the current timestamp, sequence index and # sequence_timestamp, if present in the format string: subdir = now.strftime(subdir_format).format( sequence_index=sequence_index, sequence_timestamp=sequence_timestamp) shot_output_dir = os.path.join(shot_basedir, subdir) # Compute the shot filename prefix according to labconfig settings: try: filename_prefix_format = config.get('runmanager', 'filename_prefix_format') except (LabConfig.NoOptionError, LabConfig.NoSectionError): # Default, for backward compatibility: filename_prefix_format = '{sequence_timestamp}_{script_basename}' # Format the filename prefix according to the current timestamp, sequence index, # sequence_timestamp, and script_basename, if present in the format string: filename_prefix = now.strftime(filename_prefix_format).format( sequence_index=sequence_index, sequence_timestamp=sequence_timestamp, script_basename=script_basename, ) return sequence_attrs, shot_output_dir, filename_prefix
self.camera.stop_acquisition() self.camera._abort_acquisition = False if __name__ == '__main__': import sys try: camera_name = sys.argv[1] except IndexError: print('Call me with the name of a camera as defined in BLACS.') sys.exit(0) from labscript_utils.labconfig import LabConfig print('Reading labconfig') lc = LabConfig() h5_filepath = lc.get('paths', 'connection_table_h5') print( f'Getting properties of {camera_name} from connection table: {h5_filepath}' ) with h5py.File(h5_filepath, 'r') as h5_file: device_properties = labscript_utils.properties.get( h5_file, camera_name, 'device_properties') port = labscript_utils.properties.get( h5_file, camera_name, 'connection_table_properties')['BIAS_port'] print('Getting imaqdx_properties from device_properties:') imaqdx_properties = device_properties['added_properties'] # print(imaqdx_properties)
# Convert path to local slashes and shared drive prefix: h5_filepath = labscript_utils.shared_drive.path_to_local(h5_filepath) logger.info('local filepath: %s' % h5_filepath) # we add the shot to a queue so that we don't have to wait for the app to come up before # responding to runmanager shots_to_process_queue.put(h5_filepath) return 'ok' if __name__ == "__main__": qapplication = QApplication(sys.argv) shots_to_process_queue = Queue() config_path = os.path.join(config_prefix, '%s.ini' % socket.gethostname()) exp_config = LabConfig(config_path, {'ports': ['runviewer']}) port = int(exp_config.get('ports', 'runviewer')) myappid = 'monashbec.runviewer' # arbitrary string try: ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) except: logger.info('Not on a windows machine') # Start experiment server experiment_server = RunviewerServer(port) app = RunViewer() def execute_program(): qapplication.exec_()
########## config_path = os.path.join(config_prefix,'%s.ini'%socket.gethostname()) settings_path = os.path.join(config_prefix,'%s_BLACS.h5'%socket.gethostname()) required_config_params = {"DEFAULT":["experiment_name"], "programs":["text_editor", "text_editor_arguments", ], "paths":["shared_drive", "connection_table_h5", "connection_table_py", ], "ports":["BLACS", "lyse"], } exp_config = LabConfig(config_path,required_config_params) port = int(exp_config.get('ports','BLACS')) # Start experiment server experiment_server = ExperimentServer(port) # Create Connection Table object logger.info('About to load connection table: %s'%exp_config.get('paths','connection_table_h5')) connection_table_h5_file = exp_config.get('paths','connection_table_h5') try: connection_table = ConnectionTable(connection_table_h5_file) except: # dialog = gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_ERROR,gtk.BUTTONS_NONE,"The connection table in '%s' is not valid. Please check the compilation of the connection table for errors\n\n"%self.connection_table_h5file) # dialog.run()
for plugin in BLACS.plugins.values(): try: plugin_callbacks = plugin.get_callbacks() if plugin_callbacks is not None: if name in plugin_callbacks: callbacks.append(plugin_callbacks[name]) except Exception: logger.exception('Error getting callbacks from %s.' % str(plugin)) # Sort all callbacks by priority: callbacks.sort( key=lambda callback: getattr(callback, 'priority', DEFAULT_PRIORITY)) return callbacks exp_config = LabConfig() if not exp_config.has_section('BLACS/plugins'): exp_config.add_section('BLACS/plugins') modules = {} for module_name in os.listdir(PLUGINS_DIR): if os.path.isdir(os.path.join( PLUGINS_DIR, module_name)) and module_name != '__pycache__': # is it a new plugin? # If so lets add it to the config if not module_name in [ name for name, val in exp_config.items('BLACS/plugins') ]: exp_config.set('BLACS/plugins', module_name, str(module_name in default_plugins))
plotgreen = (0, 0.8, 0.4) ### redefine ROIs to be tighter: plotROIs = deepcopy(ROIs) for roiname, roidict in plotROIs.iteritems(): roidict['y1'] += 11 roidict['x1'] += 12 roidict['y2'] -= 9 roidict['x2'] -= 9 ## Therefore have to redefine wx, wy, plot_condensate_centre too: plotwx = plotROIs['roi0']['x2'] - plotROIs['roi0']['x1'] plotwy = plotROIs['roi0']['y2'] - plotROIs['roi0']['y1'] plot_condensate_centre = array([0.5 * plotwx, 0.5 * plotwy]) exp_config = LabConfig() shot_storage_directory = exp_config.get('paths', 'experiment_shot_storage') results_path = exp_config.get('paths', 'analysis_output_folder') ## A list of files to pull the images from: files = [ r'20171004T093812_flat_trap_rb_quad_lev_240.h5', r'20171004T121555_flat_trap_rb_quad_lev_052.h5', r'20171004T144649_flat_trap_rb_quad_lev_109.h5' ] full_paths = [os.path.join(shot_storage_directory, file) for file in files] ## Set up the figure environment fig = figure('Example images', figsize=(4.75, 3.575)) gs = GridSpec(3, 4) ## Define the labels to use for each column of the figure:
# Convert path to local slashes and shared drive prefix: h5_filepath = labscript_utils.shared_drive.path_to_local(h5_filepath) logger.info('local filepath: %s'%h5_filepath) # we add the shot to a queue so that we don't have to wait for the app to come up before # responding to runmanager shots_to_process_queue.put(h5_filepath) return 'ok' if __name__ == "__main__": qapplication = QApplication(sys.argv) shots_to_process_queue = Queue() config_path = os.path.join(config_prefix,'%s.ini'%socket.gethostname()) exp_config = LabConfig(config_path,{'ports':['runviewer']}) port = int(exp_config.get('ports','runviewer')) myappid = 'monashbec.runviewer' # arbitrary string try: ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) except: logger.info('Not on a windows machine') # Start experiment server experiment_server = RunviewerServer(port) app = RunViewer() def execute_program(): qapplication.exec_()
# data to be sent back to the lyse GUI if running within lyse _updated_data = {} # dictionary of plot id's to classes to use for Plot object _plot_classes = {} # A fake Plot object to subclass if we are not running in the GUI Plot = object # An empty dictionary of plots (overwritten by the analysis worker if running within lyse) plots = {} # A threading.Event to delay the delay_event = threading.Event() # a flag to determine whether we should wait for the delay event _delay_flag = False # get port that lyse is using for communication try: _labconfig = LabConfig(required_params={"ports": ["lyse"]}) _lyse_port = int(_labconfig.get('ports', 'lyse')) except Exception: _lyse_port = 42519 if len(sys.argv) > 1: path = sys.argv[1] else: path = None class _RoutineStorage(object): """An empty object that analysis routines can store data in. It will persist from one run of an analysis routine to the next when the routine is being run from within lyse. No attempt is made to store data to disk, so if the routine is run multiple times from the command line instead of
from __future__ import division import os import numpy as np import labscript_utils.h5_lock import h5py import matplotlib.pyplot as plt from lyse import * import pandas as pd import runmanager.remote from labscript_utils.labconfig import LabConfig labconfig = LabConfig() from optimization_classes import * <<<<<<< HEAD save_file_path = os.path.join(labconfig.get('DEFAULT', 'experiment_shot_storage'), 'Optimization_testRoutine_4.h5') params = ['param1', 'param2'] param_ranges = [[-1.0,2.0],[-1.0,2.0]] optimizer = DownhillSimplex(save_file_path, params, param_ranges, side = 1.5) ======= save_file_path = os.path.join(labconfig.get('DEFAULT', 'experiment_shot_storage'), 'Optimization_testRoutine_8.h5') params = ['rfEvapStart_amp', 'rfEvapStart_freq', 'rfEvapMid_amp', 'rfEvapEnd_amp', 'rfEvapEnd_freq'] param_ranges = [[0.0,1.0],[10.0,40.0], [0.0, 1.0], [0.0, 1.0], [1.0, 20.0]] optimizer = DownhillSimplex(save_file_path, params, param_ranges, initial_point = [0.5623, 22, .78, .45, 4] ) >>>>>>> e635434002d746ebd0fcaf5776a459bd20c57355 df = data() try: singleshot_filename = 'single_shot_optimization'
# # # shared_drive.py # # # # Copyright 2013, Monash University # # # # This file is part of the labscript suite (see # # http://labscriptsuite.org) and is licensed under the Simplified # # BSD License. See the license.txt file in the root of the project # # for the full license. # # # ##################################################################### import os from labscript_utils.labconfig import LabConfig _config = LabConfig(required_params={'paths':['shared_drive']}) prefix = _config.get('paths','shared_drive') # ensure prefix ends with a slash: if not prefix.endswith(os.path.sep): prefix += os.path.sep def path_to_agnostic(path): path = os.path.abspath(path) if path.startswith(prefix): path = path.split(prefix, 1)[1] path = 'Z:\\' + path path = path.replace(os.path.sep, '\\') return path def path_to_local(path):
def make_labconfig_file(install_folder): from labscript_utils.labconfig import LabConfig, default_config_path source_path = os.path.join(install_folder, 'labconfig', 'example.ini') target_path = default_config_path if os.path.exists(target_path): # Don't modify it, leave their config as it is: return print('making default labconfig file') with open(source_path) as infile, open(target_path, 'w') as outfile: data = infile.read() data = data.replace('\\', os.path.sep) outfile.write(data) # Now change some things about it: config = LabConfig() config.set('DEFAULT', 'labscript_suite', install_folder) if sys.platform == 'linux2': config.set('programs', 'text_editor', 'gedit') elif sys.platform == 'darwin': config.set('programs', 'text_editor', 'open') config.set('programs', 'text_editor_arguments', '-a TextEdit {file}') if sys.platform != 'win32': config.set('programs', 'hdf5_viewer', 'hdfview') config.set('DEFAULT', 'shared_drive', os.path.join(os.getenv('HOME'), 'labscript_shared'))
from __future__ import division import os import numpy as np import labscript_utils.h5_lock import h5py import matplotlib.pyplot as plt from lyse import * import pandas as pd from labscript_utils.labconfig import LabConfig labconfig = LabConfig() from optimization_classes_v2 import * experiment_name = 'test_experiment' globals_filepath_list = [ os.path.join(labconfig.get('DEFAULT', 'experiment_shot_storage'), 'globals.h5') ] param_name_list = ['x', 'y', 'z'] param_min_max_list = [(-5.0, 5.0), (-5.0, 5.0), (-5.0, 5.0)] storage = routine_storage if not hasattr(storage, 'optimization_protocol'): storage.optimization_protocol = DifferentialEvolution( experiment_name, globals_filepath_list, param_name_list, param_min_max_list, loops=10, popsize=20)
# Simplified BSD License. See the license.txt file in the root of # # the project for the full license. # # # ##################################################################### from __future__ import division import os from numbers import Number from zprocess import zmq_get from labscript_utils.labconfig import LabConfig, config_prefix import socket __version__ = '1.0.0' _exp_config = LabConfig( os.path.join(config_prefix, '%s.ini' % socket.gethostname())) class MiseParameter(object): def __init__(self, min, max, mutation_rate=None, log=False, initial=None): # Check for valid min and max if not isinstance(min, Number) or not isinstance( max, Number) or not max > min: raise ValueError( 'MiseParameter must have unequal numerical min and max values, with min < max.' ) # Set default mutation rate if unset: if mutation_rate is None: mutation_rate = (max - min) / 10
def run_new_batch_of_shots(self, param_array): param_array = np.array(param_array) groups = rm.get_all_groups(self.globals_filepath_list) # Check to see if a "my class name" such as Differential Evolution exists. Create if not # within group populate default variables if they don't exist. Otherwise keep and use the values # in h5 file for optimization parameters, ... including terminate. So make a default loops = -1 for "dont stop ever" # and a "StopNow" boolean # for k, v in groups.iteritems(): # print(k, v) seq_globals = rm.get_globals(groups) # for k, v in seq_globals['Calibrations'].iteritems(): # print(k, v) seq_globals, evaled_globals, expansions = self.check_for_iterables_and_evaluate( seq_globals) # TODO keep those as the true globals and make copies to pass to the different outer products. # sg1 = seq_globals.copy() # eg1 = evaled_globals.copy() # exp1 = expansions.copy() # --------------------- set values # only set the booleans assuming the other values are sensible shots = [] for ind_shot in np.arange(param_array.shape[0]): shot = rm.expand_globals(seq_globals, evaled_globals)[0] # dict for ind_param, param_name in enumerate(self.param_name_list): shot[param_name] = param_array[ind_shot, ind_param] # # and add them to outer products # if param_values.size>1: # print('adding inner products' # expansions[param_name] = u'inner' # seq_globals['main'][param_name] = \ # seq_globals['main'][param_name][:-1] + (u'inner',) shots.append(shot) print('Shots fired:') print(shots) folder, sequence_index = self.create_folder() self.current_folder = folder try: self.sequence_index_list.append(sequence_index) except (AttributeError): self.sequence_index_list = [] self.sequence_index_list.append(sequence_index) seq_id = rm.generate_sequence_id(self.experiment_name, '%Y_%m_%d') # print(seq_id) filenames = rm.make_run_files(folder, seq_globals, shots, seq_id, sequence_index, '', shuffle=True) # print(filenames.next()) print('Submitting {} shots.'.format(len(shots))) exp_config = LabConfig() script_storage = exp_config.get('paths', 'labscriptlib') script_name = script_storage + '\\' + self.experiment_name + '.py' for fid in filenames: return_code, stdout, stderr = rm.compile_labscript( script_name, fid) print(return_code, stdout, stderr) response = rm.submit_to_blacs(fid) print(response) return
config_path = r'C:\labconfig\\' + socket.gethostname() + r'.ini' settings_path = r'C:\labconfig\\' + socket.gethostname() + r'_BLACS.h5' required_config_params = { "DEFAULT": ["experiment_name"], "programs": [ "text_editor", "text_editor_arguments", ], "paths": [ "shared_drive", "connection_table_h5", "connection_table_py", ], "ports": ["BLACS"], } exp_config = LabConfig(config_path, required_config_params) # # Load Connection Table # # Get file paths (used for file watching later) connection_table_h5file = exp_config.get('paths', 'connection_table_h5') connection_table_labscript = exp_config.get('paths', 'connection_table_py') # Create Connection Table object try: connection_table = ConnectionTable(connection_table_h5file) except Exception as e: print(e) dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_NONE,
# # # shared_drive.py # # # # Copyright 2013, Monash University # # # # This file is part of the labscript suite (see # # http://labscriptsuite.org) and is licensed under the Simplified # # BSD License. See the license.txt file in the root of the project # # for the full license. # # # ##################################################################### import os from labscript_utils.labconfig import LabConfig _config = LabConfig(required_params={'paths': ['shared_drive']}) prefix = _config.get('paths', 'shared_drive') # ensure prefix ends with a slash: if not prefix.endswith(os.path.sep): prefix += os.path.sep def path_to_agnostic(path): path = os.path.abspath(path) if path.startswith(prefix): path = path.split(prefix, 1)[1] path = 'Z:\\' + path path = path.replace(os.path.sep, '\\') return path
'settings', 'front_panel_settings', 'labscript_utils.h5_lock', 'labscript_utils.shared_drive', 'labscript_utils.labconfig', 'zprocess', ], sub=True) splash.update_text('loading labconfig') required_config_params = { "DEFAULT": ["apparatus_name", "app_saved_configs"], "programs": ["text_editor", "text_editor_arguments",], "paths": ["shared_drive", "connection_table_h5", "connection_table_py",], "ports": ["BLACS", "lyse"], } exp_config = LabConfig(required_params=required_config_params) settings_dir = Path(exp_config.get('DEFAULT', 'app_saved_configs'), 'blacs') if not settings_dir.exists(): os.makedirs(settings_dir, exist_ok=True) settings_path = str(settings_dir / f'{hostname()}_BLACS.h5') port = int(exp_config.get('ports','BLACS')) # Start experiment server splash.update_text('starting experiment server') experiment_server = ExperimentServer(port) # Create Connection Table object splash.update_text('loading connection table') logger.info('About to load connection table: %s'%exp_config.get('paths','connection_table_h5')) connection_table_h5_file = exp_config.get('paths','connection_table_h5')
from scipy.stats import sem from labscript_utils.labconfig import LabConfig import os import StringIO import PIL import xlsxwriter import matplotlib.gridspec as gridspec from matplotlib.ticker import FormatStrFormatter import matplotlib.lines as mlines from matplotlib.legend_handler import HandlerLine2D from analysislib.johnstone_vortices_2018.parameters import * from vortex_thermometer import thermometer_cdN, beta ## Check where to save output: exp_config = LabConfig() results_path = exp_config.get('paths', 'analysis_output_folder') ## Set up output to xlsx spreadsheet: workbook = xlsxwriter.Workbook(os.path.join(results_path, 'grid_data.xlsx')) worksheet_early = workbook.add_worksheet('Early time grid data') worksheet_late = workbook.add_worksheet('Late time grid data') worksheet_spectra = workbook.add_worksheet('Early time energy spectra') bold = workbook.add_format({'bold': True}) bold_center = workbook.add_format({'bold': True, 'align': 'center'}) boldshaded = workbook.add_format({'bold': True, 'bg_color': '#CCCCCC'}) shaded = workbook.add_format({ 'bg_color': '#CCCCCC', 'align': 'center', 'left': 1, 'right': 1
], sub=True) ########## settings_path = os.path.join(config_prefix,'%s_BLACS.h5'%hostname) required_config_params = {"DEFAULT":["experiment_name"], "programs":["text_editor", "text_editor_arguments", ], "paths":["shared_drive", "connection_table_h5", "connection_table_py", ], "ports":["BLACS", "lyse"], } exp_config = LabConfig(required_params = required_config_params) port = int(exp_config.get('ports','BLACS')) # Start experiment server experiment_server = ExperimentServer(port) # Create Connection Table object logger.info('About to load connection table: %s'%exp_config.get('paths','connection_table_h5')) connection_table_h5_file = exp_config.get('paths','connection_table_h5') connection_table = ConnectionTable(connection_table_h5_file, logging_prefix='BLACS', exceptions_in_thread=True) logger.info('connection table loaded') qapplication = QApplication(sys.argv) qapplication.setAttribute(Qt.AA_DontShowIconsInMenus, False)
splash.update_text('loading labconfig') required_config_params = { "DEFAULT": ["apparatus_name", "app_saved_configs"], "programs": [ "text_editor", "text_editor_arguments", ], "paths": [ "shared_drive", "connection_table_h5", "connection_table_py", ], "ports": ["BLACS", "lyse"], } exp_config = LabConfig(required_params=required_config_params) settings_dir = Path(exp_config.get('DEFAULT', 'app_saved_configs'), 'blacs') if not settings_dir.exists(): os.makedirs(settings_dir, exist_ok=True) settings_path = str(settings_dir / f'{hostname()}_BLACS.h5') port = int(exp_config.get('ports', 'BLACS')) # Start experiment server splash.update_text('starting experiment server') experiment_server = ExperimentServer(port) # Create Connection Table object splash.update_text('loading connection table') logger.info('About to load connection table: %s' %
settings_path = os.path.join(config_prefix, '%s_BLACS.h5' % socket.gethostname()) required_config_params = { "DEFAULT": ["experiment_name"], "programs": [ "text_editor", "text_editor_arguments", ], "paths": [ "shared_drive", "connection_table_h5", "connection_table_py", ], "ports": ["BLACS", "lyse"], } exp_config = LabConfig(config_path, required_config_params) port = int(exp_config.get('ports', 'BLACS')) # Start experiment server experiment_server = ExperimentServer(port) # Create Connection Table object logger.info('About to load connection table: %s' % exp_config.get('paths', 'connection_table_h5')) connection_table_h5_file = exp_config.get('paths', 'connection_table_h5') try: connection_table = ConnectionTable(connection_table_h5_file) except: # dialog = gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_ERROR,gtk.BUTTONS_NONE,"The connection table in '%s' is not valid. Please check the compilation of the connection table for errors\n\n"%self.connection_table_h5file)
def make_labconfig_file(install_folder): from labscript_utils.labconfig import LabConfig, default_config_path source_path = os.path.join(install_folder, 'labconfig', 'example.ini') target_path = default_config_path if os.path.exists(target_path): # Don't modify it, leave their config as it is: return print('making default labconfig file') with open(source_path) as infile, open(target_path, 'w') as outfile: data = infile.read() data = data.replace('\\', os.path.sep) outfile.write(data) # Now change some things about it: config = LabConfig() config.set('DEFAULT', 'labscript_suite', install_folder) if sys.platform == 'linux2': config.set('programs', 'text_editor', 'gedit') elif sys.platform == 'darwin': config.set('programs', 'text_editor', 'open') config.set('programs', 'text_editor_arguments', '-a TextEdit {file}') if sys.platform != 'win32': config.set('programs', 'hdf5_viewer', 'hdfview')