helper_functions module¶
- helper_functions.calculate_parity(bit_string)¶
Calculates the parity of a bit string
- Parameters
bit_string (str) – bit string on which parity is to be calculated
- Returns
parity – 0 if even parity 1 if odd parity
- Return type
int
- helper_functions.calculate_parity_matrix_totals()¶
Calculates the number of items in each row of the parity matrix
- Returns
parity_matrix_totals – List holding parity matrix totals for each row in the parity matrix.
- Return type
list
- helper_functions.calculate_simple_parity_bits()¶
Returns a list of qubits with exactly two non zero rows in the parity matrix
- Returns
simple_parity_bits – A list of all qubits with exactly two non zero rows in the parity matrix
- Return type
list
- helper_functions.calculate_standard_error(list_in)¶
Calculates the standard error of a list of numbers
- Parameters
list_in (list) – data for analysis
- Returns
standard_deviation (float) – standard deviation estimated from sample
standard_error (float) – standard error estimated from sample result of calculation
- helper_functions.compute_string_validity(value, codewords, reversed_data_string, post_selection=False, simple=False, single=False, single_bit=0)¶
Categorises a string as valid, invalid or outside the codeword and based on this assigns the number of counts of that string to the values returned. Various algorithms for determining validaty are supported, including post selection, where a bit is only valid if it is the codewords, simple decoding based on the parity of three bits and looking at a single bit only.
- Parameters
value (int) – number of strings for this data string
codewords (list) – holds allowed codewords
reversed_data_string (str) – string holding element to be processed
post_selection (bool) – if true then only strings in logical zero are invalid. Strings outside the codespace are counted separately.
simple (bool) – looks only at the parity of bits with exactly two non-zero columns in the parity matrix
single (bool) – look at single bit only
single_bit (int) – single bit to validate against
- Returns
valid (int) – value if the bit string is valid
invalid (int) – value if the bit string is invalid
outside_codeword (int) – value if the bit string is outside the codespace
Notes
This code was originally designed to handle the codewords in a list of lists, but will also work fine with a list of strings.
- helper_functions.convert_codewords(codewords)¶
Changes the codewords list of lists to a list of strings
- Parameters
codewords (list) – allowed codewords for logical zero
- Returns
list_of_strings – a list of strings
- Return type
list
Notes
No longer needed at present as codeword is a list of strings but retained in case needed in future.
- helper_functions.correct_qubit(data_in, ancilla, data_qubits)¶
Returns the corrected data bit string calculated from the ancilla settings.
- Parameters
data_in (str) – input data bit string
ancilla (str) – three bit ancilla logical Z code
data_qubits (int) – length of bit string
- Returns
data_out – corrected data bit string
- Return type
str
Notes
The ancilla number calculation needs to take into account that the ancilla bit string is reversed compared to numbering of the databits shown on the Qiskit diagrams. This code corrects bit string errors only, not phase errors
- helper_functions.count_valid_output_strings(counts, codewords, data_location=0, post_selection=False, simple=False, single=False, single_bit=0)¶
Finds the number of valid and invalid output bit strings in a given location in a dictionary representing the counts for each output bit string. Various algorithms for determining validaty are supported, including post selection, where a bit is only valid if it is the codewords, simple decoding based on the parity of three bits and looking at a single bit only.
- Parameters
counts (dictionary) – holds the observed populations for each combination of qubit
codewords (list) – holds allowed codewords
data_location (int) – location of the data string
post_selection (bool) – if true then only strings in logical zero are invalid. Strings outside the codespace are counted separately.
simple (bool) – looks only at the parity of bits with exactly two non-zero columns in the parity matrix
single (bool) – look at single bit only
single_bit (int) – single bit to validate against
- Returns
count_valid (int) – Number of valid bit strings
count_invalid (int) – Number of invalid bit strings
count_outside_codeword (int) – Number of strings outside codespace.
Notes
This code was originally designed to handle the codewords in a list of lists, but will also work fine with a list of strings.
- helper_functions.find_ancilla_values(counts, ancilla_qubits, ancilla_location=0)¶
Returns a dictionary with a count of each possible ancilla bit string.
- Parameters
counts (dictionary) – counts for each possible output bit string
ancilla_qubits (int) – number of ancilla qubits
ancilla_location (int) – designates which bit string is relevant
- Returns
ancilla_values – dictionary containing the count of each possible ancilla bit string
- Return type
dict
- helper_functions.find_individual_ancilla_values(ancilla_values, data_qubits, ancilla_qubits, label_string='')¶
Returns the count of individual ancilla bit strings as a dictionary.
- Parameters
ancilla_values (dict) – holds the counts for each combination of ancilla bit strings.
data_qubits (int) – number of data qubits used as an offset to calculate the ancilla number
ancilla_qubits (int) – number of ancilla qubits
label_string (str) – first part of label
- Returns
individual_ancilla_values – dictionary containing the count of individual ancilla bit string
- Return type
dict
- helper_functions.find_parity(counts)¶
Finds the parity of the output bit string held in the counts dictionary.
- Parameters
counts (dictionary) – Holds the observed output bit strings
- Returns
parity_count – A dictionary holding the parity count for each observed output bit string.
- Return type
dict
- helper_functions.flip_code_words(codewords_in)¶
Returns a list of codewords for the logical one from the list of codewords for the logical zero by flipped each bit of the input codewords.
- Parameters
codewords_in (list) – logical codewords in seven bit Steane code data qubit for the logical zero
- Returns
Codewords_out – bit flipped input codeword
- Return type
list
- helper_functions.get_codewords()¶
Stores the codewords for the logical zero in one place
- Returns
codewords – A list of valid codewords for the logical zero
- Return type
list
- helper_functions.get_noise(p_meas, single_qubit_error, two_qubit_error, single_qubit_gate_set, two_qubit_gate_set, all=True, noisy_qubit_list=[], decohere=False, dummy_gate_set=[], dummy_gate_error=0)¶
Returns a noise model
- Parameters
p_meas (float) – probability of X error on measurement
single_qubit_error (float) – probability of a depolarizing error on a single qubit gate
two_qubit_error (float) – probability of a depolarizing error on a two qubit gate
single_qubit_gate_set (list) – list of all single qubit gate types relevant for noise
two_qubit_gate_set (list) – list of all two qubit gate types relevant for noise
all (bool) – apply two gate noise to all qubits
noisy_qubit_list (list of list) – list of list of noisy qubits on which errors are applied
decohere (bool) – Add extra noise to represent de-coherence
dummy_gate_set (list) – Set of dummy gates on which the de-coherence error is applied. Normally [‘id’].
dummy_gate_error (float) – error to apply to dummy gate which is set up to model de-coherence at certain stages in the circuit.
- Returns
noise_model – noise model to be used
- Return type
dict
Notes
Can apply noise selectively to qubits in noisy_qubit_list. This is a list of lists.
- helper_functions.get_parity_check_matrix()¶
Stores the parity matrix in one place
- helper_functions.look_up_data(input_string, logical_zero, logical_one)¶
Looks up the input data to determine if the string is a logical one, logical zero, or outside the code base.
- Parameters
input_string (str) – data for analysis
logical_zero (list) – list of strings representing a logical zero
logical_one (str) – list of strings representing a logical one
- Returns
output_string – result of look-up
- Return type
str
- helper_functions.mean_of_list(list_in)¶
Returns the mean of a list
- Parameters
list_in (list) – data for analysis
- Returns
mean – result of calculation
- Return type
float
- helper_functions.print_time()¶
Prints current time
- helper_functions.process_FT_results(counts, codewords, data_meas_strings=['0'], anc_zero='0', anc_one='1', verbose=False, data_qubits=7, ancilla_start=0, data_meas_start=0, data_start=0, ancilla_types=2, ancilla_qubits=0, ancilla_meas_repeats=1, data_meas_qubits=0, data_meas_repeats=0, post_selection=False, simple=False)¶
Process results from fault tolerant processing.
- Parameters
counts (dictionary) – results for analysis
codewords (list) – list of valid data codewords
data_meas_strings (string) – allowed strings for the data measurement bits
anc_zero (string) – allowed strings for the ancilla zero
anc_one (string) – allowed strings for the ancilla one
verbose (bool) – if true enables printing
data_qubits (int) – Length of data bit string. Usually seven
ancilla_start (int) – starting place for ancilla (if any)
data_meas_start (int) – starting place for data measurement qubits (if any)
data_start (int) – starting place for data string
ancilla_types (int) – number of different ancilla types. Normally 2 (X and Z) or 0
ancilla_qubits (int) – number of strings for each ancilla qubits. Normally 0, 1 or 3
ancilla_meas_repeats (int) – number of times ancilla measurements are repeated. Normally 3 or 1
data_meas_qubits (int) – number of distinct data measurement qubits. Normally 7, 1 or 0
data_meas_repeats (int) – number of times data measurements are repeated. Normally 3 or 1.
post_select (bool) – if true then only strings in logical zero are invalid
simple (bool) – if true then simple decoding based on three bits shall be used.
- Returns
error_rate (float) – error rate calculated
rejected (int) – strings rejected for validation
accepted (int) – strings accepted for validation
valid (int) – strings validated and found to be in the code space
invalid (int) – strings validated and found to not be in the code space
Notes
This function takes the output string, splits it, and determines if it passes data and ancilla checks. If so the data keyword is validated.
- helper_functions.string_ancilla_mask(location, length)¶
Returns a bit string with a 1 in a certain bit and the 0 elsewhere.
- Parameters
location (int) – location of the bit which should be set to ‘1’ in the mask
length (int) – length of string in the mask
- Returns
string – ancilla bit mask string in required format
- Return type
str
- helper_functions.string_reverse(input_string)¶
Reverses a string.
- Parameters
input_string (str) – Holds the string to be reversed
- Returns
reversed_string – The reversed string
- Return type
str
- helper_functions.strings_AND_bitwise(string1, string2)¶
Returns the bitwise AND of two equal length bit strings.
- Parameters
string1 (str) – First string
string2 (str) – Second string
- Returns
string_out – bitwise AND of the two input strings
- Return type
str
- helper_functions.summarise_logical_counts(counts, logical_zero_strings, logical_one_strings, data1_location, data2_location, simple=False)¶
Simplifies bit strings for logical operations to show each qubit as 0, 1, or 2 instead of the full bit string.
means qubit is the logical zero
means qubit is the logical one
means qubit is outside code space
- Parameters
counts (dict) – results of computation
logical_zero_strings (list) – list of strings in logical zero
logical_one_strings (list) – list of strings in logical zero
data1_location (int) – where in the counts bit string data1 is held
data2_location (int) – where in the counts bit string data2 is held
simple (bool) – use simple decoding based on bit parity
- Returns
new_counts – simplified results
- Return type
dict
- helper_functions.validate_integer(number)¶
Checks if a number is an integer.
- Parameters
number (int) – number to be validated