##// END OF EJS Templates
ENH: initial .mailmap to unify major contributors appearance in shortlog...
ENH: initial .mailmap to unify major contributors appearance in shortlog Now instead of 785 Fernando Perez 632 Brian Granger 572 MinRK 572 vivainio 307 Thomas Kluyver 253 fperez 250 epatters 205 Ville M. Vainio 187 Brian E. Granger 110 Gael Varoquaux 106 walter.doerwald 69 gvaroquaux 52 Barry Wark 45 Brian E Granger 41 ldufrechou 40 Robert Kern 25 Jorgen Stenarson 20 vivainio2 16 Paul Ivanov 15 bgranger ... it would look like 1052 Fernando Perez 879 Brian E. Granger 802 Ville M. Vainio 588 Benjamin Ragan-Kelley 307 Thomas Kluyver 262 Evan Patterson 180 Gael Varoquaux 108 Walter Doerwald 70 Laurent Dufréchou 52 Barry Wark 42 Robert Kern ... There are more contributors which haven't yet been added to the mailmap file

File last commit:

r4637:d919e2ec
r4798:eb389453
Show More
qft.ipynb
163 lines | 35.6 KiB | text/plain | TextLexer

Quantum Fourier Transform

In [1]:
%load_ext sympyprinting
In [2]:
from sympy import sqrt, symbols, Rational
from sympy import expand, Eq, Symbol, simplify, exp, sin
from sympy.physics.quantum import *
from sympy.physics.quantum.qubit import *
from sympy.physics.quantum.gate import *
from sympy.physics.quantum.grover import *
from sympy.physics.quantum.qft import QFT, IQFT, Fourier
from sympy.physics.quantum.circuitplot import circuit_plot

QFT is useful for a quantum algorithm for factoring numbers which is exponentially faster than what is thought to be possible on a classical machine.
The transform does a DFT on the state of a quantum system
There is a simple decomposition of the QFT in terms of a few elementary gates.

QFT Gate and Circuit

Build a 3 qubit QFT and decompose it into primitive gates.

In [3]:
fourier = QFT(0,3).decompose(); fourier
Out[3]:
$$SWAP_{0,2} H_{0} C_{0}{\left(S_{1}\right)} H_{1} C_{0}{\left(T_{2}\right)} C_{1}{\left(S_{2}\right)} H_{2}$$
In [4]:
circuit_plot(fourier, nqubits=3)
Out[4]:
<sympy.physics.quantum.circuitplot.CircuitPlot object at 0x4992910>
No description has been provided for this image

The QFT circuit can be represented in various symbolic forms.

In [5]:
m = represent(fourier, nqubits=3)
In [6]:
m
Out[6]:
$$\left(\begin{smallmatrix}\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2}\\\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi}\\\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath}\\\frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath}\\\frac{1}{4} \sqrt{2} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} \mathbf{\imath} & - \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi} & - \frac{1}{4} \sqrt{2} & \frac{1}{4} \sqrt{2} \mathbf{\imath} e^{\frac{1}{4} \mathbf{\imath} \pi} & \frac{1}{4} \sqrt{2} \mathbf{\imath} & \frac{1}{4} \sqrt{2} e^{\frac{1}{4} \mathbf{\imath} \pi}\end{smallmatrix}\right)$$
In [7]:
represent(Fourier(0,3), nqubits=3)*4/sqrt(2)
Out[7]:
$$\left(\begin{smallmatrix}1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\1 & \omega & \omega^{2} & \omega^{3} & \omega^{4} & \omega^{5} & \omega^{6} & \omega^{7}\\1 & \omega^{2} & \omega^{4} & \omega^{6} & 1 & \omega^{2} & \omega^{4} & \omega^{6}\\1 & \omega^{3} & \omega^{6} & \omega & \omega^{4} & \omega^{7} & \omega^{2} & \omega^{5}\\1 & \omega^{4} & 1 & \omega^{4} & 1 & \omega^{4} & 1 & \omega^{4}\\1 & \omega^{5} & \omega^{2} & \omega^{7} & \omega^{4} & \omega & \omega^{6} & \omega^{3}\\1 & \omega^{6} & \omega^{4} & \omega^{2} & 1 & \omega^{6} & \omega^{4} & \omega^{2}\\1 & \omega^{7} & \omega^{6} & \omega^{5} & \omega^{4} & \omega^{3} & \omega^{2} & \omega\end{smallmatrix}\right)$$

QFT in Action

Build a 3 qubit state to take the QFT of.

In [8]:
state = (Qubit('000') + Qubit('010') + Qubit('100') + Qubit('110'))/sqrt(4); state
Out[8]:
$$\frac{1}{2} \left({\left|000\right\rangle } + {\left|010\right\rangle } + {\left|100\right\rangle } + {\left|110\right\rangle }\right)$$

Perform the QFT.

In [9]:
qapply(fourier*state)
Out[9]:
$$\frac{1}{2} \sqrt{2} {\left|000\right\rangle } + \frac{1}{2} \sqrt{2} {\left|100\right\rangle }$$