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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
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 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
Exemplo n.º 8
0
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 
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
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
Exemplo n.º 12
0

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)

    # Get server settings
    server_kwargs = {}
Exemplo n.º 13
0
        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_()

    sys.exit(execute_program())
Exemplo n.º 14
0
    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()
        # dialog.destroy()
        logger.exception('connection table failed to load')
# 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_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)
    logger.info('QApplication instantiated')
    app = BLACS(qapplication)
Exemplo n.º 17
0
                                      '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')
    connection_table = ConnectionTable(connection_table_h5_file, logging_prefix='BLACS', exceptions_in_thread=True)
Exemplo n.º 18
0
    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'))
            "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,
            "The connection table in '%s' is not valid. Please check the compilation of the connection table for errors\n\n"
            % connection_table_h5file)

        dialog.run()
        dialog.destroy()
        sys.exit("Invalid Connection Table")
Exemplo n.º 20
0
_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 lyse, or the lyse analysis subprocess is restarted, data will not be
Exemplo n.º 21
0
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)
Exemplo n.º 22
0
        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_()
    
    sys.exit(execute_program())
Exemplo n.º 23
0
### 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:
labels0 = ['A', 'B', 'C']
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'
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
})
    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()
        # dialog.destroy()
Exemplo n.º 27
0
# 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):
    if path.startswith('Z:\\'):