S15qkd/error_correction.py
def _do_error_correction():
    '''
    Executes error correction based on the files in the ec_queue.
    The queue consists of raw key file names generated by costream or splicer.
    This function usually runs as a thread waiting for pipe input.

    This function checks each file for the number of bits and once enough bits are available
    it notifies the error correction process by writing into the eccmdpipe.
    '''
    global ec_queue, minimal_block_size, first_epoch_info, undigested_epochs_info, init_QBER_info
    undigested_raw_bits = 0
    first_epoch = ''
    undigested_epochs = 0
    while proc_error_correction is not None and proc_error_correction.poll() is None:
        # Attempt get from queue (FIFO). If no item is available, sleep a while
        # and try again.
        try:
            file_name = ec_queue.get_nowait()
        except queue.Empty:
            time.sleep(qkd_globals.EPOCH_DURATION)
            continue
        # Use diagbb84 to check for raw key bits
        args = f'{FoldersQKD.RAWKEYS}/{file_name}'
        proc_diagbb84 = subprocess.Popen([program_diagbb84, *args.split()],
                                         stderr=subprocess.PIPE,
                                         stdout=subprocess.PIPE)
        proc_diagbb84.wait()
        diagbb84_result = (proc_diagbb84.stdout.read()).decode().split()
        diagbb84_error = (proc_diagbb84.stderr.read()).decode()
        logger.debug(f'diagbb84_result: {file_name} {diagbb84_result}')
        if diagbb84_error != '':
            logger.error(f'diagbb84_error: {diagbb84_error}')

        if int(diagbb84_result[0]) == 0 or int(diagbb84_result[1]) != 1:
            logger.error(f'Either epoch file is not a BB84 file or more than 1 bit per entry.')
            continue

        if undigested_epochs == 0:
            first_epoch = file_name
        undigested_epochs += 1
        undigested_raw_bits += int(diagbb84_result[2])
        # Execute error correction when enough raw bits are accumulated.
        # Could be also based on number of epochs.
        if undigested_raw_bits > minimal_block_size:
            # notify the error correction process about the first epoch, number of epochs, and the servoed QBER
            qkd_globals.writer(
                PipesQKD.ECCMD, f'0x{first_epoch} {undigested_epochs} {float("{0:.4f}".format(servoed_QBER))}')
            logger.info(
                f'Started error correction for {undigested_epochs} epochs starting with epoch {first_epoch}.')
            first_epoch_info = first_epoch
            undigested_epochs_info = undigested_epochs
            init_QBER_info = servoed_QBER
            undigested_raw_bits = 0
            undigested_epochs = 0
        else:
            logger.debug(
                f'Undigested raw bits:{undigested_raw_bits}. Undigested epochs: {undigested_epochs}.')
        ec_queue.task_done()
    logger.info(f'Thread finished.')

    Executes error correction based on the files in the ec_queue.
    The queue consists of raw key file names generated by costream or splicer.
    This function usually runs as a thread waiting for pipe input.

    This function checks each file for the number of bits and once enough bits are available
    it notifies the error correction process by writing into the eccmdpipe.
    
Executes error correction based on the files in the ec_queue.
The queue consists of raw key file names generated by costream or splicer.
This function usually runs as a thread waiting for pipe input.

This function checks each file for the number of bits and once enough bits are available
it notifies the error correction process by writing into the eccmdpipe.
Executes error correction based on the files in the ec_queue . The queue consists of raw key file names generated by costream or splicer . This function usually runs as a thread waiting for pipe input . This function checks each file for the number of bits and once enough bits are available it notifies the error correction process by writing into the eccmdpipe .
def _do_error_correction():
    global ec_queue, minimal_block_size, first_epoch_info, undigested_epochs_info, init_QBER_info
    undigested_raw_bits = 0
    first_epoch = ''
    undigested_epochs = 0
    while proc_error_correction is not None and proc_error_correction.poll() is None:
        try:
            file_name = ec_queue.get_nowait()
        except queue.Empty:
            time.sleep(qkd_globals.EPOCH_DURATION)
            continue
        args = f'{FoldersQKD.RAWKEYS}/{file_name}'
        proc_diagbb84 = subprocess.Popen([program_diagbb84, *args.split()],
                                         stderr=subprocess.PIPE,
                                         stdout=subprocess.PIPE)
        proc_diagbb84.wait()
        diagbb84_result = (proc_diagbb84.stdout.read()).decode().split()
        diagbb84_error = (proc_diagbb84.stderr.read()).decode()
        logger.debug(f'diagbb84_result: {file_name} {diagbb84_result}')
        if diagbb84_error != '':
            logger.error(f'diagbb84_error: {diagbb84_error}')
        if int(diagbb84_result[0]) == 0 or int(diagbb84_result[1]) != 1:
            logger.error(f'Either epoch file is not a BB84 file or more than 1 bit per entry.')
            continue
        if undigested_epochs == 0:
            first_epoch = file_name
        undigested_epochs += 1
        undigested_raw_bits += int(diagbb84_result[2])
        if undigested_raw_bits > minimal_block_size:
            qkd_globals.writer(
                PipesQKD.ECCMD, f'0x{first_epoch} {undigested_epochs} {float("{0:.4f}".format(servoed_QBER))}')
            logger.info(
                f'Started error correction for {undigested_epochs} epochs starting with epoch {first_epoch}.')
            first_epoch_info = first_epoch
            undigested_epochs_info = undigested_epochs
            init_QBER_info = servoed_QBER
            undigested_raw_bits = 0
            undigested_epochs = 0
        else:
            logger.debug(
                f'Undigested raw bits:{undigested_raw_bits}. Undigested epochs: {undigested_epochs}.')
        ec_queue.task_done()
    logger.info(f'Thread finished.')
def _do_error_correction ( ) : global ec_queue , minimal_block_size , first_epoch_info , undigested_epochs_info , init_QBER_info undigested_raw_bits = 0 first_epoch = '' undigested_epochs = 0 while proc_error_correction is not None and proc_error_correction . poll ( ) is None : try : file_name = ec_queue . get_nowait ( ) except queue . Empty : time . sleep ( qkd_globals . EPOCH_DURATION ) continue args = f'{FoldersQKD.RAWKEYS}/{file_name}' proc_diagbb84 = subprocess . Popen ( [ program_diagbb84 , * args . split ( ) ] , stderr = subprocess . PIPE , stdout = subprocess . PIPE ) proc_diagbb84 . wait ( ) diagbb84_result = ( proc_diagbb84 . stdout . read ( ) ) . decode ( ) . split ( ) diagbb84_error = ( proc_diagbb84 . stderr . read ( ) ) . decode ( ) logger . debug ( f'diagbb84_result: {file_name} {diagbb84_result}' ) if diagbb84_error != '' : logger . error ( f'diagbb84_error: {diagbb84_error}' ) if int ( diagbb84_result [ 0 ] ) == 0 or int ( diagbb84_result [ 1 ] ) != 1 : logger . error ( f'Either epoch file is not a BB84 file or more than 1 bit per entry.' ) continue if undigested_epochs == 0 : first_epoch = file_name undigested_epochs += 1 undigested_raw_bits += int ( diagbb84_result [ 2 ] ) if undigested_raw_bits > minimal_block_size : qkd_globals . writer ( PipesQKD . ECCMD , f'0x{first_epoch} {undigested_epochs} {float("{0:.4f}".format(servoed_QBER))}' ) logger . info ( f'Started error correction for {undigested_epochs} epochs starting with epoch {first_epoch}.' ) first_epoch_info = first_epoch undigested_epochs_info = undigested_epochs init_QBER_info = servoed_QBER undigested_raw_bits = 0 undigested_epochs = 0 else : logger . debug ( f'Undigested raw bits:{undigested_raw_bits}. Undigested epochs: {undigested_epochs}.' ) ec_queue . task_done ( ) logger . info ( f'Thread finished.' )
Executes error correction based on the files in the ec_queue.
Executes error correction based on the files in the ec_queue .
'''
    Executes error correction based on the files in the ec_queue.
    The queue consists of raw key file names generated by costream or splicer.
    This function usually runs as a thread waiting for pipe input.

    This function checks each file for the number of bits and once enough bits are available
    it notifies the error correction process by writing into the eccmdpipe.
    ''' # Attempt get from queue (FIFO). If no item is available, sleep a while # and try again. # Use diagbb84 to check for raw key bits # Execute error correction when enough raw bits are accumulated. # Could be also based on number of epochs. # notify the error correction process about the first epoch, number of epochs, and the servoed QBER