Table Of Contents

Previous topic

Control sequences (qit.seq)

Next topic


This Page

Demos and examples (qit.examples)

This module contains various examples which demonstrate the features of QIT. The tour function is a “guided tour” to the toolkit which runs all the demos in succession.


adiabatic_qc_3sat([n, n_clauses, clauses, ...]) Adiabatic quantum computing demo.
bb84([n]) Bennett-Brassard 1984 quantum key distribution protocol demo.
bernstein_vazirani([n, linear]) Bernstein-Vazirani algorithm demo.
grover_search([n]) Grover search algorithm demo.
markov_decoherence(T1, T2[, B]) Markovian decoherence demo.
nmr_sequences([seqs, titles]) NMR control sequences demo.
phase_estimation_precision(t, U[, u]) Quantum phase estimation demo.
qft_circuit([dim]) Quantum Fourier transform circuit demo.
quantum_channels([p]) Visualization of simple one-qubit channels.
quantum_walk([steps, n, p, n_coin]) Quantum random walk demo.
qubit_and_resonator([d_r]) Qubit coupled to a microwave resonator demo.
shor_factorization([N, cheat]) Shor’s factorization algorithm demo.
superdense_coding([d]) Superdense coding demo.
teleportation([d]) Quantum teleportation demo.
tour() Guided tour to the quantum information toolkit.

General-purpose quantum algorithms

adiabatic_qc(H0, H1, s0[, tmax]) Adiabatic quantum computing.
phase_estimation(t, U, s[, implicit]) Quantum phase estimation algorithm.
find_order(a, N[, epsilon]) Quantum order-finding subroutine.
qit.examples.adiabatic_qc_3sat(n=6, n_clauses=None, clauses=None, problem=u'3sat')

Adiabatic quantum computing demo.

This example solves random 3-SAT problems by simulating the adiabatic quantum algorithm of [7].

Note that this is incredibly inefficient because we first essentially solve the NP-complete problem classically using an exhaustive search when computing the problem Hamiltonian H1, and then simulate an adiabatic quantum computer solving the same problem using the quantum algorithm.

qit.examples.adiabatic_qc(H0, H1, s0, tmax=50)

Adiabatic quantum computing.

This is a helper function for simulating the adiabatic quantum algorithm of [7] and plotting the results.


Bennett-Brassard 1984 quantum key distribution protocol demo.

Simulate the protocol with n qubits transferred.

qit.examples.bernstein_vazirani(n=6, linear=True)

Bernstein-Vazirani algorithm demo.

Simulates the Bernstein-Vazirani algorithm [1], which, given a black box oracle implementing a linear Boolean function f_a(x) := a \cdot x, returns the bit vector a (and thus identifies the function) with just a single oracle call. If the oracle function is not linear, the algorithm will fail.

Grover search algorithm demo.

Simulate the Grover search algorithm [8] formulated using amplitude amplification in a system of n qubits.

qit.examples.markov_decoherence(T1, T2, B=None)

Markovian decoherence demo.

Given decoherence times T1 and T2, creates a markovian bath B and a coupling operator D which reproduce them on a single-qubit system.

qit.examples.nmr_sequences(seqs=None, titles=None)

NMR control sequences demo.

Compares the performance of different single-qubit NMR control sequences in the presence of systematic errors. Plots the fidelity of each control sequence as a function of both off-resonance error f and fractional pulse length error g.

Reproduces fidelity plots in [6].

qit.examples.phase_estimation(t, U, s, implicit=False)

Quantum phase estimation algorithm.

Estimate an eigenvalue of the unitary lmap U using t qubits, starting from the state s.

Returns the state of the index register after the phase estimation circuit, but before final measurement.

To get a result accurate to n bits with probability \ge 1 -\epsilon, choose

t \ge n + \left\lceil \log_2\left(2 +\frac{1}{2 \epsilon}\right) \right \rceil.

See [5], [17] chapter 5.2.

qit.examples.phase_estimation_precision(t, U, u=None)

Quantum phase estimation demo.

Estimate an eigenvalue of unitary operator U using t bits, starting from the state u. Plots and returns the probability distribution of the resulting t-bit approximations. If u is not given, use a random eigenvector of U.

Uses phase_estimation.

qit.examples.qft_circuit(dim=(2, 3, 3, 2))

Quantum Fourier transform circuit demo.

Simulate the quadratic QFT circuit construction. dim is the dimension vector of the subsystems.

NOTE: If dim is not palindromic the resulting circuit also reverses the order of the dimensions in the SWAP cascade.

U |x_1, x_2, \ldots, x_n\rangle
= \frac{1}{\sqrt{d}} \sum_{k_i} |k_n,\ldots, k_2, k_1\rangle \exp\left(i 2 \pi \left(\sum_{r=1}^n k_r 0.x_r x_{r+1}\ldots x_n\right)\right)
= \frac{1}{\sqrt{d}} \sum_{k_i} |k_n,\ldots, k_2, k_1\rangle \exp\left(i 2 \pi 0.x_1 x_2 \ldots x_n \left(\sum_{r=1}^n d_1 d_2 \cdots d_{r-1} k_r \right)\right).


Visualization of simple one-qubit channels.

Visualizes the effect of different quantum channels on a qubit using the Bloch sphere representation.

qit.examples.quantum_walk(steps=7, n=11, p=0.05, n_coin=2)

Quantum random walk demo.

Simulates a 1D quantum walker controlled by a unitary quantum coin. On each step the coin is flipped and the walker moves either to the left or to the right depending on the result.

After each step, the position of the walker is measured with probability p. p == 1 results in a fully classical random walk, whereas p == 0 corresponds to the “fully quantum” case.


Qubit coupled to a microwave resonator demo.

Simulates a qubit coupled to a microwave resonator. Reproduces plots from the experiment in [9].

qit.examples.shor_factorization(N=9, cheat=False)

Shor’s factorization algorithm demo.

Simulates Shor’s factorization algorithm, tries to factorize the integer N. If cheat is False, simulates the full algorithm. Otherwise avoids the quantum part.

NOTE: This is a very computationally intensive quantum algorithm to simulate classically, and probably will not run for any nontrivial value of N (unless you choose to cheat, in which case instead of simulating the quantum part (implemented in find_order) we use a more efficient classical algorithm for the order-finding).

See [20], [17] chapter 5.3.

qit.examples.find_order(a, N, epsilon=0.25)

Quantum order-finding subroutine.

Finds the period of the function f(x) = a^x mod N. epsilon is the maximum allowed failure probability for the subroutine.

Returns r, s where r/s approximates period/T.

Uses phase_estimation.

See [20], [17] chapter 5.3.


Superdense coding demo.

Simulate Alice sending two d-its of information to Bob using a shared EPR qudit pair.


Quantum teleportation demo.

Simulate the teleportation of a d-dimensional qudit from Alice to Bob.


Guided tour to the quantum information toolkit.