qkd_key_rate.base package

Init base objects

class qkd_key_rate.base.AsymptoticKeyRateEstimate(detector, **kwargs)[source]

Bases: KeyRate

Asymptotic key rate base class

abstract compute_rate(*, mu, attenuation)[source]

Computes the key-rate given intensity-settings and an attenuation

Parameters:
  • mu (ArrayLike) – Used intensities

  • attenuation (float) – Attenuation of the channel

Return type:

float

Returns:

key-rate

Raises:

ValueError – When mu is given with invalid dimensions

class qkd_key_rate.base.Corrector(alice, bob)[source]

Bases: object

Error corrector base class.

__init__(alice, bob)[source]

Base class for error correcting

Parameters:
  • Alice – The sending party

  • Bob – The receiving party

static calculate_error_rate(message1, message2)[source]

Calculate the error rate between two messages.

If messages differ in length, the number of errors is calculated using the number of bits of the shortest message.

Parameters:
  • message1 (Message) – First message

  • message2 (Message) – Second message

Returns:

Ratio of errors over the message length.

Return type:

error_rate

calculate_key_reconciliation_rate(exposed_bits=False)[source]

Calculate the key reconciliation rate.

Parameters:
  • exposed_bits (bool) – If true, uses the number of exposed bits to compute the

  • Otherwise (key-reconciliation rate.) –

  • and (uses the ratio between the in-) –

  • length. (output message) –

Returns:

The reconciliation rate

Return type:

key_rate

static calculate_number_of_errors(message1, message2)[source]

Calculate the error rate between two messages If messages differ in length, the number of errors is calculated using the number of bits of the shortest message.

Parameters:
  • message1 (Message) – First message

  • message2 (Message) – Second message

Returns:

Number of errors.

Return type:

number_of_errors

correct_errors(detail_transcript=False)[source]

Receiver Bob corrects the errors based on Alice her message.

Parameters:

detail_transcript (Optional[bool]) – Whether to print a detailed transcript

Return type:

CorrectorOutputBase

static create_message_tag_pair(message, shared_key)[source]

Prepares a message-tag hashed pair.

The message can be communicated publicly. The tag is the hash of the message, given a key.

Parameters:
  • message (Message) – To be communicated message

  • key – Shared secret key

Returns:

To be communicated message tag: Hash of the message, given the key, with length of the key

Return type:

message

abstract summary()[source]
Calculate a summary object for the error correction containing
  • original message

  • corrected message

  • error rate (before and after correction)

  • number_of_exposed_bits

  • key_reconciliation_rate

  • protocol specific parameters

Return type:

CorrectorOutputBase

class qkd_key_rate.base.CorrectorOutputBase(input_alice, output_alice, input_bob, output_bob, input_error, output_error, output_length, number_of_exposed_bits, key_reconciliation_rate, number_of_communication_rounds)[source]

Bases: object

Base class corrector summary object

Parameters:
  • input_alice (Message) – Input message Alice

  • output_alice (Message) – Corrected message Alice

  • input_bob (Message) – Input message Bob

  • output_bob (Message) – Corrected message Bob

  • input_error (float) – Input error rate

  • output_error (float) – Output error rate

  • output_length (int) – Output message length

  • number_of_exposed_bits (int) – Number of bits exposed in protocol

  • key_reconciliation_rate (float) – Key reconciliation efficiency

  • number_of_communication_rounds (int) – Number of communication rounds

input_alice: Message
input_bob: Message
input_error: float
key_reconciliation_rate: float
number_of_communication_rounds: int
number_of_exposed_bits: int
output_alice: Message
output_bob: Message
output_error: float
output_length: int
class qkd_key_rate.base.Detector(name, jitter_source, jitter_detector, dead_time, detection_window, efficiency_system, polarization_drift=0.122782758757646, error_detector=0, dark_count_frequency=None, dark_count_rate=None, detection_frequency=None, interval=None, efficiency_detector=None, efficiency_party=None)[source]

Bases: ABC

Class for the detectors to be used in the key-rate estimates.

__init__(name, jitter_source, jitter_detector, dead_time, detection_window, efficiency_system, polarization_drift=0.122782758757646, error_detector=0, dark_count_frequency=None, dark_count_rate=None, detection_frequency=None, interval=None, efficiency_detector=None, efficiency_party=None)[source]

Initialise a Detector instance.

Parameters:
  • name (str) – Label of the detector party

  • jitter_source (float) – Time-delay introduced at the source

  • jitter_detector (float) – Time-delay introduced at the detector

  • dead_time (float) – The recovery time before a new event can be recorded

  • detection_window (float) – Time window used for event detection

  • efficiency_system (float) – Efficiency of the detecting side without the detector

  • polarization_drift (float) – Shift/drift in the encoding of the photons

  • error_detector (float) – Error-rate of detector

  • dark_count_frequency (Optional[float]) – Number of dark-counts per second

  • dark_count_rate (Optional[float]) – Number of dark-counts per detection window

  • detection_frequency (Optional[float]) – Number of detection windows per second

  • interval (Optional[float]) – Length of a single detection window in seconds

  • efficiency_detector (Optional[float]) – Efficiency of the detector on the detecting side

  • efficiency_party (Optional[float]) – Total efficiency of the detecting side

If related optional arguments are both given they must satisfy

  • \(\text{interval} = \frac{1}{\text{detection_frequency}}\)

  • \(\text{dark_count_frequency} = \text{dark_count_rate} \cdot \text{detection_frequency}\)

  • \(\text{efficiency_party} = \text{efficiency_system} \cdot \text{efficiency_detector}\)

If they are not given, they are calculated using the same formulas.

Returns:

Detector instance with specified parameters.

Raises:
  • ValueError – If a required field is missing.

  • ValueError – If a needed optional field is missing.

  • AssertionError – If inconsistent related optional fields are provided.

customise(name=None, jitter_source=None, jitter_detector=None, dead_time=None, detection_window=None, efficiency_system=None, polarization_drift=None, error_detector=None, dark_count_frequency=None, dark_count_rate=None, detection_frequency=None, interval=None, efficiency_detector=None, efficiency_party=None)[source]

Create a detector with customised parameter from current detector

See __init__() for parameter description.

Return type:

Detector

classmethod from_file(path)[source]

Construct Detectors from csv file.

Parameters:

path (str) – Path to csv file.

Return type:

List[Detector]

get_parameters()[source]

Get all parameters of the Detector

Return type:

dict[str, Any]

required_fields = ['name', 'jitter_source', 'jitter_detector', 'dead_time', 'detection_window', 'efficiency_system']
class qkd_key_rate.base.FiniteKeyRateEstimate(detector, **kwargs)[source]

Bases: KeyRate

Finite key rate base class

abstract compute_rate(*, mu, attenuation, probability_basis_X, probability_basis_Z, n_X=None)[source]

Computes the key-rate given intensity-settings and an attenuation

Parameters:
  • mu (ArrayLike) – Used intensities

  • attenuation (float) – Attenuation of the channel

  • probability_basis_X (ArrayLike) – Probabilities for each intensity in the X-basis

  • probability_basis_Z (ArrayLike) – Probabilities for each intensity in the Z-basis

  • n_X (Optional[int]) – Number of pulses in the X-basis. If not provided, will be estimated from gain, probability_basis_X and total number of pules.

Return type:

float

Returns:

key-rate

Raises:

ValueError – When mu is given with invalid dimensions

class qkd_key_rate.base.Message(message)[source]

Bases: object

Message object

apply_permutation(permutation)[source]

Apply a permutation to the message

Parameters:

permutation (List[int]) – The permutation that is applied

property length: int

Length of message

Return type:

int

message: Union[List[int], List[str], str]
pop(index=-1)[source]

Remove bit at a specific index from message

Return type:

int

classmethod random_message(message_length)[source]

Generate a random message

Parameters:

message_length (int) – Length of random message

Return type:

Message

Returns:

random message

class qkd_key_rate.base.ParityStrategy(error_rate, sampling_fraction=0.5, number_of_passes=10, switch_after_pass=None)[source]

Bases: object

Parity strategy to be used in the Cascade protocol.

In the Cascade protocol, for efficiency reasons, we may change the strategy of our blocks after some passes. This class deals with the parity strategy

__init__(error_rate, sampling_fraction=0.5, number_of_passes=10, switch_after_pass=None)[source]
Parameters:
  • error_rate (float) – An estimate of the error rate in the message

  • sampling_fraction (float) – Fraction of the string that is sampled after switching strategies

  • number_of_passes (int) – Total number of Cascade iterations

  • switch_after_pass (Optional[int]) – After which pass we switch the strategy

calculate_message_parity_strategy(message_size)[source]

Sets the parity strategy

Initial strategy is to double the block size in each subsequent pass. After some number of passes, we may change the strategy by randomly sampling bits from the message in new blocks.

Parameters:

message_size (int) – Size of the message for which to calculate the parity strategy

Returns:

The block size and number of blocks for each pass

Return type:

size_blocks_parities

get_start_block_size()[source]

Determine starting block size.

Return type:

int

Returns:

The largest block size that is compatible with given error-rate

class qkd_key_rate.base.Permutations(permutations)[source]

Bases: object

Permutations object

__add__(other)[source]

Combine two permutations

Return type:

Permutations

__len__()[source]

Return number of passes

Return type:

int

static calculate_inverted_permutations(permutations)[source]

Invert every permutation in a list of permutations

Return type:

List[List[int]]

classmethod random_permutation(number_of_passes, message_size)[source]

Generate a random Permutations object

Parameters:
  • number_of_passes (int) – Total number of iterations

  • message_size (int) – Size of the message for which to calculate the parity strategy

Return type:

Permutations

shorten_pass(pass_idx, max_length)[source]

In some protocols, the message length decreases, this function adjusts the permutations accordingly, by discarding large indices.

Parameters:
  • pass_idx (int) – Index of the permutation to shorten

  • max_length (int) – New message length, and maximum of the entries in

  • permutation (the) –

Return type:

None

class qkd_key_rate.base.ReceiverBase(message, permutations, name=None)[source]

Bases: SenderBase

This class encodes all functions only available to the receiver.

The receiver is assumed to have a string with errors and is thus assumed to correct the errors.

__init__(message, permutations, name=None)[source]
Parameters:
  • message (Message) – Input message of the sender party

  • permutations (Permutations) – List containing permutations for each pass

  • name (Optional[str]) – Name of the sender party

abstract correct_errors(alice)[source]

The main routine, find and correct errors.

Return type:

None

correct_individual_error(error_index)[source]

Corrects a single error by flipping bit at location ‘error_index’.

Return type:

None

class qkd_key_rate.base.Schedule(schedule)[source]

Bases: object

Schedule object for Winnow protocol

next_pass()[source]

Find iteration index for the next pass and update processed schedule. This iteration index describes the Hamming-distance used in that specific interaction in the protocol.

Return type:

int

property remaining_passes: int

Number of remaining passes in schedule

Return type:

int

classmethod schedule_from_error_rate(error_rate=0.15)[source]

Get schedule based on error rate

Return type:

Schedule

class qkd_key_rate.base.SenderBase(message, permutations, name=None)[source]

Bases: object

This class encodes all functions available to both sender and receiver.

__init__(message, permutations, name=None)[source]
Parameters:
  • message (Message) – Input message of the sender party

  • permutations (Permutations) – List containing permutations for each pass

  • name (Optional[str]) – Name of the sender party

property message: Message

Returns the (partially corrected) message.

Return type:

Message

property original_message: Message

Returns original uncorrected message.

Return type:

Message