Circuit module

The Circuit Module calls the Circuit class to build any pre-defined circuit available by providing a name (e.g. “Grover”, “Teleportation”), and then calls the run_circuit() function on the created Circuit objects to run them.

class Circuit.Bell

Bases: Circuit.Circuit

Creates Bell States by applying the necessary Gates.

run_circuit()

Runs the circuit with the given Bell States

Returns

Bell States

class Circuit.Circuit(name)

Bases: Interface.Interface

Defines the circuit of the algorithm. Checks that the prompts are of the correct formats.

AorM_prompt()

A function to prompt for an animation/measurement.

qubit_prompt()

A function to prompt for a qubit. Only accepts 0 or 1.

run_circuit()

A function to run the circuit according to the specified name.

show_results()

A function to show the results obtained according to the circuit being run/tested.

size_prompt()

A function to prompt for the system size, catching any possible errors on the way.

class Circuit.Grover

Bases: Circuit.Circuit

Implementation of Grover’s algorithm. Runs the circuit with the specified gates and visualizes the result of the algorithm.

plot_probs(state, ax)

A function to plot the probability of each state as a bar chart.

prep_circuit()

Preparation of circuit

Returns

qbits of the circuit, desired state to look for and the prompt for animation/measurements

run_circuit(*args)

Run of the circuit with the Grover’s algorithm

Returns

number of iterations needed to terminate and the success of finding the desired state in Grover’s algorithm (1 for success, 0 for failure)

show_results(qubits, iters)

A function to run Grover’s algorithm with various numbers of qubits and plot the resulting iterations, comparing it to the predicted O(sqrtN) and the classical O(N)

class Circuit.Teleportation

Bases: Circuit.Circuit

Begins by initializing Alice’s and Bob’s qubits to the user’s selection. The program then stores the state of the quantum channel, and proceeds to entangle Alice’s qubit with the unknown one. Next, a Bell measurement takes place which collapses this entangled state to one of four possible Bell states. According to the result, a correction gate is applied to Bob’s qubit, which is then measured on the computational basis to give either 0 or 1.

prep_circuit()

Preparation of circuit

Returns

Alice’s qubit and Bob’s qubit

run_circuit(*args)

Run of the circuit for Teleportation.

Returns

collapsed state as measured by Bob.

show_results(errors_a, errors_b, alphas, betas, alpha, beta)

A function to show results of teleportation

Circuit.main()

Runs both Grover and Teleportation Implementations