S15qkd/costream.py
def _genlog_digest(qkd_protocol, config_file_name: str = qkd_globals.config_file):
    '''
    Digests the genlog pipe written by costream.
    '''
    global latest_coincidences, latest_accidentals, latest_deltat, latest_sentevents
    global latest_compress, latest_rawevents, latest_outepoch
    fd = os.open(PipesQKD.GENLOG, os.O_RDONLY | os.O_NONBLOCK)
    f = os.fdopen(fd, 'rb', 0)  # non-blocking
    logger.info('Thread started.')
    with open(config_file_name, 'r') as f_config:
        config = json.load(f_config, object_hook=lambda d: SimpleNamespace(**d))
    if config.do_polarization_compensation is True and qkd_protocol == QKDProtocol.SERVICE:
        polarization_compensator = PolarizationDriftCompensation(
            config.LCR_polarization_compensator_path)
    pairs_over_accidentals_avg = 10
    while is_running():
        time.sleep(0.1)
        try:
            message = (f.readline().decode().rstrip('\n')).lstrip('\x00')
            if len(message) != 0:
                logger.debug(message)
                costream_info = message.split()
                latest_coincidences = costream_info[6]
                latest_accidentals = costream_info[5]
                latest_deltat = costream_info[4]
                latest_compress = costream_info[3]
                latest_sentevents = costream_info[2]
                latest_rawevents = costream_info[1]
                latest_outepoch = costream_info[0]
                # restart time difference finder if pairs to accidentals is too low
                pairs_over_accidentals = int(
                    latest_coincidences) / int(latest_accidentals)
                pairs_over_accidentals_avg = (pairs_over_accidentals_avg * 19 + pairs_over_accidentals) / 20
                if pairs_over_accidentals_avg < 2.5:
                    logger.error(
                        f'Pairs to accidental ratio bad: avg(p/a) = {pairs_over_accidentals_avg:.2f}')
                    controller.stop_key_gen()
                    if qkd_protocol == QKDProtocol.SERVICE:
                        controller.start_service_mode()
                    elif qkd_protocol == QKDProtocol.BBM92:
                        controller.start_key_generation()
                    continue
                if qkd_protocol == QKDProtocol.SERVICE:
                    controller.qkd_engine_state = QKDEngineState.SERVICE_MODE
                    logger.debug(message)
                    diagnosis = RawKeyDiagnosis(
                        FoldersQKD.RAWKEYS + '/' + message)
                    logger.debug(
                        f'Service mode, QBER: {diagnosis.quantum_bit_error}, Epoch: {costream_info[0]}')
                    if config.do_polarization_compensation is True:
                        polarization_compensator.update_QBER(
                            diagnosis.quantum_bit_error)
        except OSError:
            pass
        except Exception as a:
            logger.error(a)
    logger.info('Thread finished.')

    Digests the genlog pipe written by costream.
    
Digests the genlog pipe written by costream.
Digests the genlog pipe written by costream .
def _genlog_digest(qkd_protocol, config_file_name: str = qkd_globals.config_file):
    global latest_coincidences, latest_accidentals, latest_deltat, latest_sentevents
    global latest_compress, latest_rawevents, latest_outepoch
    fd = os.open(PipesQKD.GENLOG, os.O_RDONLY | os.O_NONBLOCK)
    f = os.fdopen(fd, 'rb', 0)  
    logger.info('Thread started.')
    with open(config_file_name, 'r') as f_config:
        config = json.load(f_config, object_hook=lambda d: SimpleNamespace(**d))
    if config.do_polarization_compensation is True and qkd_protocol == QKDProtocol.SERVICE:
        polarization_compensator = PolarizationDriftCompensation(
            config.LCR_polarization_compensator_path)
    pairs_over_accidentals_avg = 10
    while is_running():
        time.sleep(0.1)
        try:
            message = (f.readline().decode().rstrip('\n')).lstrip('\x00')
            if len(message) != 0:
                logger.debug(message)
                costream_info = message.split()
                latest_coincidences = costream_info[6]
                latest_accidentals = costream_info[5]
                latest_deltat = costream_info[4]
                latest_compress = costream_info[3]
                latest_sentevents = costream_info[2]
                latest_rawevents = costream_info[1]
                latest_outepoch = costream_info[0]
                pairs_over_accidentals = int(
                    latest_coincidences) / int(latest_accidentals)
                pairs_over_accidentals_avg = (pairs_over_accidentals_avg * 19 + pairs_over_accidentals) / 20
                if pairs_over_accidentals_avg < 2.5:
                    logger.error(
                        f'Pairs to accidental ratio bad: avg(p/a) = {pairs_over_accidentals_avg:.2f}')
                    controller.stop_key_gen()
                    if qkd_protocol == QKDProtocol.SERVICE:
                        controller.start_service_mode()
                    elif qkd_protocol == QKDProtocol.BBM92:
                        controller.start_key_generation()
                    continue
                if qkd_protocol == QKDProtocol.SERVICE:
                    controller.qkd_engine_state = QKDEngineState.SERVICE_MODE
                    logger.debug(message)
                    diagnosis = RawKeyDiagnosis(
                        FoldersQKD.RAWKEYS + '/' + message)
                    logger.debug(
                        f'Service mode, QBER: {diagnosis.quantum_bit_error}, Epoch: {costream_info[0]}')
                    if config.do_polarization_compensation is True:
                        polarization_compensator.update_QBER(
                            diagnosis.quantum_bit_error)
        except OSError:
            pass
        except Exception as a:
            logger.error(a)
    logger.info('Thread finished.')
def _genlog_digest ( qkd_protocol , config_file_name : str = qkd_globals . config_file ) : global latest_coincidences , latest_accidentals , latest_deltat , latest_sentevents global latest_compress , latest_rawevents , latest_outepoch fd = os . open ( PipesQKD . GENLOG , os . O_RDONLY | os . O_NONBLOCK ) f = os . fdopen ( fd , 'rb' , 0 ) logger . info ( 'Thread started.' ) with open ( config_file_name , 'r' ) as f_config : config = json . load ( f_config , object_hook = lambda d : SimpleNamespace ( ** d ) ) if config . do_polarization_compensation is True and qkd_protocol == QKDProtocol . SERVICE : polarization_compensator = PolarizationDriftCompensation ( config . LCR_polarization_compensator_path ) pairs_over_accidentals_avg = 10 while is_running ( ) : time . sleep ( 0.1 ) try : message = ( f . readline ( ) . decode ( ) . rstrip ( '\n' ) ) . lstrip ( '\x00' ) if len ( message ) != 0 : logger . debug ( message ) costream_info = message . split ( ) latest_coincidences = costream_info [ 6 ] latest_accidentals = costream_info [ 5 ] latest_deltat = costream_info [ 4 ] latest_compress = costream_info [ 3 ] latest_sentevents = costream_info [ 2 ] latest_rawevents = costream_info [ 1 ] latest_outepoch = costream_info [ 0 ] pairs_over_accidentals = int ( latest_coincidences ) / int ( latest_accidentals ) pairs_over_accidentals_avg = ( pairs_over_accidentals_avg * 19 + pairs_over_accidentals ) / 20 if pairs_over_accidentals_avg < 2.5 : logger . error ( f'Pairs to accidental ratio bad: avg(p/a) = {pairs_over_accidentals_avg:.2f}' ) controller . stop_key_gen ( ) if qkd_protocol == QKDProtocol . SERVICE : controller . start_service_mode ( ) elif qkd_protocol == QKDProtocol . BBM92 : controller . start_key_generation ( ) continue if qkd_protocol == QKDProtocol . SERVICE : controller . qkd_engine_state = QKDEngineState . SERVICE_MODE logger . debug ( message ) diagnosis = RawKeyDiagnosis ( FoldersQKD . RAWKEYS + '/' + message ) logger . debug ( f'Service mode, QBER: {diagnosis.quantum_bit_error}, Epoch: {costream_info[0]}' ) if config . do_polarization_compensation is True : polarization_compensator . update_QBER ( diagnosis . quantum_bit_error ) except OSError : pass except Exception as a : logger . error ( a ) logger . info ( 'Thread finished.' )
Digests the genlog pipe written by costream.
Digests the genlog pipe written by costream .
'''
    Digests the genlog pipe written by costream.
    ''' # non-blocking # restart time difference finder if pairs to accidentals is too low
qkd_protocol
config_file_name
str