S15qkd/timestampsimulator/timestamp_simulator.py
def simulate_pair_source_timestamps_write_into_two_files(file_name_ph1, file_name_ph2,
                                                         rate_photon_1, rate_photon_2,
                                                         rate_pairs, tot_time, pattern_photon_1=int(
                                                             '0001', 2),
                                                         pattern_photon_2=int('0001', 2), pair_delay=1e-6):
    '''Generates two timestamp streams which contain photon pairs and coherent light statistics.

    The streams are written into two files.
    '''
    # create photon waiting times from an exponential distribution
    # simulates exponential distribution for waiting times
    times_photon_1 = np.random.exponential(
        1 / rate_photon_1, int(rate_photon_1 * tot_time)).cumsum()
    times_photon_2 = np.random.exponential(1 / (rate_photon_2 - rate_pairs),
                                           int((rate_photon_2 - rate_pairs) * tot_time)).cumsum()  # simulates exponential distribution for waiting times

    # select random events in the channel 1 and add a partner photon in channel 2
    heralding_efficiency = rate_pairs / rate_photon_1
    mask = np.random.binomial(1, heralding_efficiency, len(times_photon_1)).astype(
        bool)  # selects randomly events to create pairs
    pair_times = times_photon_1[mask] + \
        pair_delay  # add photon pair time delay
    c = np.concatenate((times_photon_2, pair_times))

    # stack all the events and sort them with respect to time
    time_and_pattern_photon1 = np.vstack(
        [times_photon_1, np.repeat(pattern_photon_1, len(times_photon_1))]).T
    time_and_pattern_photon2 = np.vstack(
        [c, np.repeat(pattern_photon_2, len(c))]).T
    # sorting times
    time_and_pattern_photon1 = time_and_pattern_photon1[time_and_pattern_photon1[:, 0].argsort(
    )]
    time_and_pattern_photon2 = time_and_pattern_photon2[time_and_pattern_photon2[:, 0].argsort(
    )]

    # write to file
    with open(file_name_ph1, "wb") as f:
        for row in time_and_pattern_photon1:
            f.write(time_pattern_to_byte_timestamp(row[0] * 1e12, int(row[1])))

    with open(file_name_ph2, "wb") as f:
        for row in time_and_pattern_photon2:
            f.write(time_pattern_to_byte_timestamp(row[0] * 1e12, int(row[1])))
Generates two timestamp streams which contain photon pairs and coherent light statistics.

    The streams are written into two files.
    
Generates two timestamp streams which contain photon pairs and coherent light statistics.
The streams are written into two files.
Generates two timestamp streams which contain photon pairs and coherent light statistics . The streams are written into two files .
def simulate_pair_source_timestamps_write_into_two_files(file_name_ph1, file_name_ph2,
                                                         rate_photon_1, rate_photon_2,
                                                         rate_pairs, tot_time, pattern_photon_1=int(
                                                             '0001', 2),
                                                         pattern_photon_2=int('0001', 2), pair_delay=1e-6):
    times_photon_1 = np.random.exponential(
        1 / rate_photon_1, int(rate_photon_1 * tot_time)).cumsum()
    times_photon_2 = np.random.exponential(1 / (rate_photon_2 - rate_pairs),
                                           int((rate_photon_2 - rate_pairs) * tot_time)).cumsum()  
    heralding_efficiency = rate_pairs / rate_photon_1
    mask = np.random.binomial(1, heralding_efficiency, len(times_photon_1)).astype(
        bool)  
    pair_times = times_photon_1[mask] + \
        pair_delay  
    c = np.concatenate((times_photon_2, pair_times))
    time_and_pattern_photon1 = np.vstack(
        [times_photon_1, np.repeat(pattern_photon_1, len(times_photon_1))]).T
    time_and_pattern_photon2 = np.vstack(
        [c, np.repeat(pattern_photon_2, len(c))]).T
    time_and_pattern_photon1 = time_and_pattern_photon1[time_and_pattern_photon1[:, 0].argsort(
    )]
    time_and_pattern_photon2 = time_and_pattern_photon2[time_and_pattern_photon2[:, 0].argsort(
    )]
    with open(file_name_ph1, "wb") as f:
        for row in time_and_pattern_photon1:
            f.write(time_pattern_to_byte_timestamp(row[0] * 1e12, int(row[1])))
    with open(file_name_ph2, "wb") as f:
        for row in time_and_pattern_photon2:
            f.write(time_pattern_to_byte_timestamp(row[0] * 1e12, int(row[1])))
def simulate_pair_source_timestamps_write_into_two_files ( file_name_ph1 , file_name_ph2 , rate_photon_1 , rate_photon_2 , rate_pairs , tot_time , pattern_photon_1 = int ( '0001' , 2 ) , pattern_photon_2 = int ( '0001' , 2 ) , pair_delay = 1e-6 ) : times_photon_1 = np . random . exponential ( 1 / rate_photon_1 , int ( rate_photon_1 * tot_time ) ) . cumsum ( ) times_photon_2 = np . random . exponential ( 1 / ( rate_photon_2 - rate_pairs ) , int ( ( rate_photon_2 - rate_pairs ) * tot_time ) ) . cumsum ( ) heralding_efficiency = rate_pairs / rate_photon_1 mask = np . random . binomial ( 1 , heralding_efficiency , len ( times_photon_1 ) ) . astype ( bool ) pair_times = times_photon_1 [ mask ] + pair_delay c = np . concatenate ( ( times_photon_2 , pair_times ) ) time_and_pattern_photon1 = np . vstack ( [ times_photon_1 , np . repeat ( pattern_photon_1 , len ( times_photon_1 ) ) ] ) . T time_and_pattern_photon2 = np . vstack ( [ c , np . repeat ( pattern_photon_2 , len ( c ) ) ] ) . T time_and_pattern_photon1 = time_and_pattern_photon1 [ time_and_pattern_photon1 [ : , 0 ] . argsort ( ) ] time_and_pattern_photon2 = time_and_pattern_photon2 [ time_and_pattern_photon2 [ : , 0 ] . argsort ( ) ] with open ( file_name_ph1 , "wb" ) as f : for row in time_and_pattern_photon1 : f . write ( time_pattern_to_byte_timestamp ( row [ 0 ] * 1e12 , int ( row [ 1 ] ) ) ) with open ( file_name_ph2 , "wb" ) as f : for row in time_and_pattern_photon2 : f . write ( time_pattern_to_byte_timestamp ( row [ 0 ] * 1e12 , int ( row [ 1 ] ) ) )
Generates two timestamp streams which contain photon pairs and coherent light statistics.
Generates two timestamp streams which contain photon pairs and coherent light statistics .
'''Generates two timestamp streams which contain photon pairs and coherent light statistics.

    The streams are written into two files.
    ''' # create photon waiting times from an exponential distribution # simulates exponential distribution for waiting times # simulates exponential distribution for waiting times # select random events in the channel 1 and add a partner photon in channel 2 # selects randomly events to create pairs # add photon pair time delay # stack all the events and sort them with respect to time # sorting times # write to file
file_name_ph1
file_name_ph2
rate_photon_1
rate_photon_2
rate_pairs
tot_time
pattern_photon_1
pattern_photon_2
pair_delay