def test_option7_algorithm():
    algorithm = get_algorithm_by_name('option7')
    assert algorithm.name == "option7"
    assert algorithm.cascade_iterations == 14
    assert algorithm.block_size_function(0.0, 10000, 1) == 131072
    assert algorithm.block_size_function(0.1, 10000, 1) == 16
    assert algorithm.block_size_function(0.01, 10000, 1) == 128
    assert algorithm.block_size_function(0.01, 10000, 2) == 512
    assert algorithm.block_size_function(0.01, 10000, 3) == 5000
    assert algorithm.block_size_function(0.001, 10000, 1) == 1024
    assert algorithm.biconf_iterations == 0
    assert not algorithm.biconf_error_free_streak
    assert not algorithm.biconf_correct_complement
    assert not algorithm.biconf_cascade
    assert algorithm.sub_block_reuse
    assert not algorithm.block_parity_inference
def test_biconf_algorithm():
    algorithm = get_algorithm_by_name('biconf')
    assert algorithm.name == "biconf"
    assert algorithm.cascade_iterations == 2
    assert algorithm.block_size_function(0.0, 10000, 1) == 92000
    assert algorithm.block_size_function(0.1, 10000, 1) == 10
    assert algorithm.block_size_function(0.01, 10000, 1) == 92
    assert algorithm.block_size_function(0.01, 10000, 2) == 276
    assert algorithm.block_size_function(0.01, 10000, 3) == 828
    assert algorithm.block_size_function(0.001, 10000, 1) == 920
    assert algorithm.biconf_iterations == 10
    assert algorithm.biconf_error_free_streak
    assert not algorithm.biconf_correct_complement
    assert not algorithm.biconf_cascade
    assert not algorithm.sub_block_reuse
    assert not algorithm.block_parity_inference
def test_yanetal_algorithm():
    algorithm = get_algorithm_by_name('yanetal')
    assert algorithm.name == "yanetal"
    assert algorithm.cascade_iterations == 10
    assert algorithm.block_size_function(0.0, 10000, 1) == 80000
    assert algorithm.block_size_function(0.1, 10000, 1) == 8
    assert algorithm.block_size_function(0.01, 10000, 1) == 80
    assert algorithm.block_size_function(0.01, 10000, 2) == 400
    assert algorithm.block_size_function(0.01, 10000, 3) == 5000
    assert algorithm.block_size_function(0.001, 10000, 1) == 800
    assert algorithm.biconf_iterations == 0
    assert not algorithm.biconf_error_free_streak
    assert not algorithm.biconf_correct_complement
    assert not algorithm.biconf_cascade
    assert not algorithm.sub_block_reuse
    assert not algorithm.block_parity_inference
    def __init__(self, algorithm_name, classical_channel, noisy_key,
                 estimated_bit_error_rate):
        """
        Create a Cascade reconciliation.

        Args:
            algorithm_name (str): The name of the Cascade algorithm.
            classical_channel (subclass of ClassicalChannel): The classical channel over which
                Bob communicates with Alice.
            noisy_key (Key): The noisy key as Bob received it from Alice that needs to be
                reconciliated.
            estimated_bit_error_rate (float): The estimated bit error rate in the noisy key.
        """

        # Store the arguments.
        self._classical_channel = classical_channel
        self._algorithm = get_algorithm_by_name(algorithm_name)
        assert self._algorithm is not None
        self._estimated_bit_error_rate = estimated_bit_error_rate
        self._noisy_key = noisy_key
        self._reconciled_key = None

        # Map key indexes to blocks.
        self._key_index_to_blocks = {}

        # Keep track of statistics.
        self.stats = Stats()

        # A set of blocks that are suspected to contain an error, pending to be corrected later.
        # These are stored as a priority queue with items (block.size, block) so that we can correct
        # the pending blocks in order of shortest block first.
        self._pending_try_correct = []

        # A set of blocks for which we have to ask Alice for the correct parity. To minimize the
        # number of message that Bob sends to Alice (i.e. the number of channel uses), we queue up
        # these pending parity questions until we can make no more progress correcting errors. Then
        # we send a single message to Alice to ask all queued parity questions, and proceed once we
        # get the answers.
        self._pending_ask_correct_parity = []