# Classical Logic¶

This module allows us to use a “simple” reversible binary adder to benchmark a quantum computer. The code is contained in the module classical_logic.

The benchmark is simplistic and not very rigorous as it does not test any specific feature of the hardware. Further the whole circuit is classical in the sense that we start and end in computational basis states and all gates simply perform classical not, controlled not (CNOT), or doubly controlled not (CCNOT aka a Toffoli gate). Finally, even for the modest task of adding two one bit numbers, the CZ gate (our fundamental two qubit gate) count is very high for the circuit. This in turn implies a low probability of the entire circuit working.

- Ripple Carry Adder
- Draw the noiseless qc topology
- One bit addtion: 1+1 = 10 i.e. 2
- Two bit addition
- Draw the noisy qc topology
- Now try 1+1=2 on a noisy qc
- Get results for all summations of pairs of 2-bit strings
- Get the distribution of the hamming weight of errors
- Plot distribution of 00+00 and 11+11 and compare to random
- Plot average distribution over all summations; compare to random
- Now do the same, but with addition in the X basis
- Error probability to random guess probability as a function of number of added bits

## Circuit Primitives¶

`CNOT_X_basis` (control, target) |
The CNOT in the X basis, i.e. |

`CCNOT_X_basis` (control1, control2, target) |
The CCNOT (Toffoli) in the X basis, i.e. |

`majority_gate` (a, b, c, in_x_basis) |
The majority gate. |

`unmajority_add_gate` (a, b, c, in_x_basis) |
The UnMajority and Add gate, or UMA for short. |

`unmajority_add_parallel_gate` (a, b, c, in_x_basis) |
An alternative form of the UnMajority and Add gate, or UMA for short. |

## Ripple Carry adder¶

`assign_registers_to_line_or_cycle` (start, …) |
From the start node assign registers as they are laid out in the ideal circuit diagram in [CDKM96]. |

`get_qubit_registers_for_adder` (qc, …) |
Searches for a layout among the given qubits for the two n-bit registers and two additional ancilla that matches the simple layout given in figure 4 of [CDKM96]. |

`adder` (num_a, num_b, register_a, register_b, …) |
Produces a program implementing reversible adding on a quantum computer to compute a + b. |

`get_n_bit_adder_results` (qc, n_bits, …) |
Convenient wrapper for collecting the results of addition for every possible pair of n_bits long summands. |

`get_success_probabilities_from_results` (results) |
Get the probability of a successful addition for each possible pair of two n_bit summands from the results output by get_n_bit_adder_results |

`get_error_hamming_distributions_from_results` (results) |
Get the distribution of the hamming weight of the error vector (number of bits flipped between output and expected answer) for each possible pair of two n_bit summands using results output by get_n_bit_adder_results |