appendix C Outcome pairing strategies

 

C.1 Additional strategies for pair selection in Python

In chapter 4, we explain one way of selecting outcome pairs. Following are two additional methods, which may perform better depending on the context.

C.1.1 Recognizing pairs by checking the digit for the target qubit

Given a target qubit position t, we can traverse through all outcomes and select pairs by finding the “0 side” of a pair and adding 2t to find the “1 side.” Given n qubits, we know the decimal forms of the outcomes are 0 to 2n – 1. For each possible outcome, we check whether the target qubit in the binary form is 0 using the is_bit_set function. If the target qubit is 0 in the binary form, we find the second item in the pair by adding 2t.

Listing C.1 Traverse-and-check method for selecting pairs
def is_bit_set(m, k):
    return m & (1 << k) != 0

def pair_generator_check_digit(n, t):
    distance = int(2 ** t)                 #1

    for k0 in range(2**n):                   #2
        if not is_bit_set(k0, t):            #3
            k1 = k0 + distance      #4
            yield k0, k1

Let’s take the example of three qubits (n = 3) and target qubit 0 (t = 0) and generate the pairs using this method:

for (k0, k1) in pair_generator_check_digit(3, 0):
    print(k0, k1)

0 1
2 3
4 5
6 7

The pairs match the highlighted rows discussed previously and shown in figure C.1.

C.1.2 Generating pairs by concatenating the prefix, target, and suffix