Public Member Functions

QuCoSi::Gate Class Reference

Single- and multi-qubit gate of varying complexity. More...

List of all members.

Public Member Functions

 Gate ()
 Constructs the 2 × 2 zero matrix.
 Gate (const int rows, const int cols)
 Constructs the rows × cols zero matrix.
Gateoperator= (const MatrixXc &m)
Gate tensorDot (const Gate &m) const
 Computes the tensor product of this gate with m.
GatetensorDotSet (const Gate &m)
 Sets the tensor product of this gate and m as this gate.
Gate tensorPow (const int n) const
 Computes the nth tensor power of this gate.
GatetensorPowSet (const int n)
 Sets the nth tensor power of this gate as this gate.
Gate applyTo (const int j, const int n) const
 Extends this gate to a n-qubits gate.
GateapplyToSet (const int j, const int n)
 Sets the to n-qubits extended gate as this gate.
GateX ()
 X gate ( $\sigma_1$ Pauli matrix, NOT gate)
GateY ()
 Y gate ( $\sigma_2$ Pauli matrix)
GateZ ()
 Z gate ( $\sigma_3$ Pauli matrix)
GateH ()
 H gate (Hadamard gate)
GateP ()
 P gate (phase shift gate)
GateT ()
 T gate ( $\pi/4$ phase shift gate)
GateR (const fptype k)
 R(k) gate (general phase shift gate)
GateI ()
 I gate (identity gate)
GateRx (const fptype theta)
 Rx(theta) gate
GateRy (const fptype theta)
 Ry(theta) gate
GateRz (const fptype theta)
 Rz(theta) gate
GateCNOT ()
 CNOT gate (controlled NOT gate)
GateCCNOT ()
 CCNOT gate (Toffoli gate, controlled CNOT gate)
GateCSWAP ()
 CSWAP gate (Fredkin gate, controlled SWAP gate)
GateC (const int t, const int c, const int n, const Gate &U)
 Ctcn(U) gate (controlled U gate)
GateSWAP ()
 SWAP gate
GateS (const int p, const int q, const int n)
 Spqn gate
GateS (const std::vector< int > &sigma)
 S(sigma) gate
GateU (const std::vector< int > &f)
 Uf gate for one output qubit
GateU (const std::vector< int > &f, const int m)
 Uf gate for multiple output qubits
GateF (const int n)
 Fn gate (quantum Fourier transform (QFT) gate)

Detailed Description

Single- and multi-qubit gate of varying complexity.

The Gate class is the base for all quantum circuits in QuCoSi. It provides common quantum gates for one to three qubits, more complex gates for an arbitrary number of qubits, and methods to combine or extend them. Since gates are represented by unitary matrices, this class is derived of Eigen's dynamic size matrix class that uses complex numbers. Therefore composition of multiple gates is easily accomplished by simple matrix multiplication of single gates.

Definition at line 42 of file Gate.


Constructor & Destructor Documentation

QuCoSi::Gate::Gate (  )  [inline]

Constructs the 2 × 2 zero matrix.

Definition at line 47 of file Gate.

QuCoSi::Gate::Gate ( const int  rows,
const int  cols 
) [inline]

Constructs the rows × cols zero matrix.

Parameters:
rows the number of rows of this gate
cols the number of columns of this gate

Definition at line 54 of file Gate.


Member Function Documentation

Gate& QuCoSi::Gate::operator= ( const MatrixXc m  )  [inline]

Definition at line 56 of file Gate.

Gate QuCoSi::Gate::tensorDot ( const Gate m  )  const [inline]

Computes the tensor product of this gate with m.

The tensor product $\mathbf{A} \otimes \mathbf{B}$ of two gates $\mathbf{A} \in K^{m \times n}$ and $\mathbf{B} \in K^{p \times q}$ is defined as:

\[ \mathbf{A}\, \otimes\, \mathbf{B} = \left(\begin{array}{ccc} a_{11} \mathbf{B} & \cdots & a_{1n} \mathbf{B} \\ \vdots & \ddots & \vdots \\ a_{m1} \mathbf{B} & \cdots & a_{mn} \mathbf{B} \end{array}\right) = \left(\begin{array}{cccccccccc} a_{11} b_{11} & \cdots & a_{11} b_{1q} & \cdots & \cdots & a_{1n} b_{11} & \cdots & a_{1n} b_{1q} \\ \vdots & \ddots & \vdots & & & \vdots & \ddots & \vdots \\ a_{11} b_{p1} & \cdots & a_{11} b_{pq} & \cdots & \cdots & a_{1n} b_{p1} & \cdots & a_{1n} b_{pq} \\ \vdots & & \vdots & \ddots & & \vdots & & \vdots \\ \vdots & & \vdots & & \ddots & \vdots & & \vdots \\ a_{m1} b_{11} & \cdots & a_{m1} b_{1q} & \cdots & \cdots & a_{mn} b_{11} & \cdots & a_{mn} b_{1q} \\ \vdots & \ddots & \vdots & & & \vdots & \ddots & \vdots \\ a_{m1} b_{p1} & \cdots & a_{m1} b_{pq} & \cdots & \cdots & a_{mn} b_{p1} & \cdots & a_{mn} b_{pq} \end{array}\right) \in K^{mp \times nq} \ . \]

Parameters:
m the right hand side operand of the tensor product
Returns:
the tensor product of this gate with Gate m
See also:
http://en.wikipedia.org/wiki/Kronecker_product

Definition at line 95 of file Gate.

Here is the caller graph for this function:

Gate& QuCoSi::Gate::tensorDotSet ( const Gate m  )  [inline]

Sets the tensor product of this gate and m as this gate.

Parameters:
m the right hand side operand of the tensor product
Returns:
a reference to *this
See also:
tensorDot()

Definition at line 117 of file Gate.

Here is the call graph for this function:

Here is the caller graph for this function:

Gate QuCoSi::Gate::tensorPow ( const int  n  )  const [inline]

Computes the nth tensor power of this gate.

The nth tensor power of a gate $\mathbf{A}$ is the n-fold tensor product of $\mathbf{A}$ with itself:

\[ \mathbf{A}^{\otimes n} = \underbrace{\mathbf{A} \otimes \ldots \otimes \mathbf{A}}_n \ . \]

Parameters:
n the exponent of the tensor power
Returns:
this gate raised to the nth power
See also:
tensorDot()

Definition at line 136 of file Gate.

Here is the call graph for this function:

Here is the caller graph for this function:

Gate& QuCoSi::Gate::tensorPowSet ( const int  n  )  [inline]

Sets the nth tensor power of this gate as this gate.

Parameters:
n the exponent of the tensor power
Returns:
a reference to *this
See also:
tensorPow()

Definition at line 151 of file Gate.

Here is the call graph for this function:

Gate QuCoSi::Gate::applyTo ( const int  j,
const int  n 
) const [inline]

Extends this gate to a n-qubits gate.

This method constructs a gate that acts on n qubits so that the original gate acts on the qubit(s) at position j and all other qubits are left unchanged. This is accomplished by tensor multiplication of an appropriate number of identity gates from the left and the right to the original gate.

Parameters:
j the position of the qubit(s) the original gate acts on
n the number of qubits the returned gate acts on
Returns:
the for n qubits extended gate
See also:
tensorDot()

Definition at line 170 of file Gate.

Here is the call graph for this function:

Here is the caller graph for this function:

Gate& QuCoSi::Gate::applyToSet ( const int  j,
const int  n 
) [inline]

Sets the to n-qubits extended gate as this gate.

Parameters:
j the position of the qubit(s) the original gate acts on
n the number of qubits the extended gate acts on
Returns:
a reference to *this
See also:
applyTo()

Definition at line 195 of file Gate.

Here is the call graph for this function:

Gate& QuCoSi::Gate::X (  )  [inline]

X gate ( $\sigma_1$ Pauli matrix, NOT gate)

\[\mathbf{X} = \left(\begin{array}{cc} 0 & 1\\ 1 & 0 \end{array}\right) \]

Returns:
a reference to *this

Definition at line 212 of file Gate.

Gate& QuCoSi::Gate::Y (  )  [inline]

Y gate ( $\sigma_2$ Pauli matrix)

\[\mathbf{Y} = \left(\begin{array}{cc} 0 & -i\\ i & 0 \end{array}\right) \]

Returns:
a reference to *this

Definition at line 231 of file Gate.

Gate& QuCoSi::Gate::Z (  )  [inline]

Z gate ( $\sigma_3$ Pauli matrix)

\[\mathbf{Z} = \left(\begin{array}{cc} 1 & 0\\ 0 & -1 \end{array}\right) = \mathbf{R}(2) \]

Returns:
a reference to *this
See also:
R()

Definition at line 252 of file Gate.

Gate& QuCoSi::Gate::H (  )  [inline]

H gate (Hadamard gate)

\[\mathbf{H} = \frac{1}{\sqrt{2}} \left(\begin{array}{cc} 1 & 1\\ 1 & -1 \end{array}\right) = \frac{1}{\sqrt{2}} (\mathbf{X} + \mathbf{Z}) \]

Returns:
a reference to *this

Definition at line 272 of file Gate.

Gate& QuCoSi::Gate::P (  )  [inline]

P gate (phase shift gate)

\[\mathbf{P} = \left(\begin{array}{cc} 1 & 0\\ 0 & i \end{array}\right) = \mathbf{R}(4) \]

Returns:
a reference to *this
See also:
R()

Definition at line 293 of file Gate.

Gate& QuCoSi::Gate::T (  )  [inline]

T gate ( $\pi/4$ phase shift gate)

\[\mathbf{T} = \left(\begin{array}{cc} 1 & 0\\ 0 & e^{\pi i/4} \end{array}\right) = \mathbf{R}(8) \]

Returns:
a reference to *this
See also:
R()

Definition at line 314 of file Gate.

Gate& QuCoSi::Gate::R ( const fptype  k  )  [inline]

R(k) gate (general phase shift gate)

\[\mathbf{R}(k) = \left(\begin{array}{cc} 1 & 0\\ 0 & e^{2 \pi i/k} \end{array}\right) \]

Parameters:
k the phase shift of this gate
Returns:
a reference to *this

Definition at line 334 of file Gate.

Gate& QuCoSi::Gate::I (  )  [inline]

I gate (identity gate)

\[\mathbf{I} = \left(\begin{array}{cc} 1 & 0\\ 0 & 1 \end{array}\right) = \mathbf{R}(1) \]

Returns:
a reference to *this

Definition at line 354 of file Gate.

Gate& QuCoSi::Gate::Rx ( const fptype  theta  )  [inline]

Rx(theta) gate

Rotates a qubit about the x-axis on the Bloch sphere by the angle theta.

\[\mathbf{R_x}(\theta) = \exp \left( -i \frac{\theta}{2} \mathbf{X} \right) = \cos \frac{\theta}{2} \mathbf{I} - i \sin \frac{\theta}{2} \mathbf{X} = \left(\begin{array}{cc} \cos \frac{\theta}{2} & -i \sin \frac{\theta}{2} \\ -i \sin \frac{\theta}{2} & \cos \frac{\theta}{2} \end{array}\right) \]

Parameters:
theta the angle of rotation about the x-axis
Returns:
a reference to *this

Definition at line 379 of file Gate.

Gate& QuCoSi::Gate::Ry ( const fptype  theta  )  [inline]

Ry(theta) gate

Rotates a qubit about the y-axis on the Bloch sphere by the angle theta.

\[\mathbf{R_y}(\theta) = \exp \left( -i \frac{\theta}{2} \mathbf{Y} \right) = \cos \frac{\theta}{2} \mathbf{I} - i \sin \frac{\theta}{2} \mathbf{Y} = \left(\begin{array}{cc} \cos \frac{\theta}{2} & -\sin \frac{\theta}{2} \\ \sin \frac{\theta}{2} & \cos \frac{\theta}{2} \end{array}\right) \]

Parameters:
theta the angle of rotation about the y-axis
Returns:
a reference to *this

Definition at line 405 of file Gate.

Gate& QuCoSi::Gate::Rz ( const fptype  theta  )  [inline]

Rz(theta) gate

Rotates a qubit about the z-axis on the Bloch sphere by the angle theta.

\[\mathbf{R_z}(\theta) = \exp \left( -i \frac{\theta}{2} \mathbf{Z} \right) = \cos \frac{\theta}{2} \mathbf{I} - i \sin \frac{\theta}{2} \mathbf{Z} = \left(\begin{array}{cc} \exp \left(-i \frac{\theta}{2} \right) & 0 \\ 0 & \exp \left(i \frac{\theta}{2} \right) \end{array}\right) \]

Parameters:
theta the angle of rotation about the z-axis
Returns:
a reference to *this

Definition at line 431 of file Gate.

Gate& QuCoSi::Gate::CNOT (  )  [inline]

CNOT gate (controlled NOT gate)

\[\mathbf{CNOT} = \left(\begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{array}\right) = \mathbf{C}_{102}(\mathbf{X}) \]

Returns:
a reference to *this
See also:
C(), X()

Definition at line 454 of file Gate.

Gate& QuCoSi::Gate::CCNOT (  )  [inline]

CCNOT gate (Toffoli gate, controlled CNOT gate)

\[\mathbf{CCNOT} = \left(\begin{array}{cccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{array}\right) = \mathbf{C}_{103}(\mathbf{CNOT}) \]

Returns:
a reference to *this
See also:
C(), CNOT()

Definition at line 483 of file Gate.

Gate& QuCoSi::Gate::CSWAP (  )  [inline]

CSWAP gate (Fredkin gate, controlled SWAP gate)

\[\mathbf{CSWAP} = \left(\begin{array}{cccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{array}\right) = \mathbf{C}_{103}(\mathbf{SWAP}) \]

Returns:
a reference to *this
See also:
C(), SWAP()

Definition at line 513 of file Gate.

Gate& QuCoSi::Gate::C ( const int  t,
const int  c,
const int  n,
const Gate U 
) [inline]

Ctcn(U) gate (controlled U gate)

This method constructs a gate that acts on n qubits so that the gate U is applied to the qubit(s) at position t (the target qubit(s)) if the qubit at position c (the control qubit) is 1.

Parameters:
t the position of the target qubit(s)
c the position of the control qubit
n the number of qubits this gate acts on
U the gate that acts on the target qubit and that is controlled by the control qubit
Returns:
a reference to *this

Definition at line 537 of file Gate.

Here is the call graph for this function:

Gate& QuCoSi::Gate::SWAP (  )  [inline]

SWAP gate

\[\mathbf{SWAP} = \left(\begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{array}\right) = \mathbf{S}_{102} = \mathbf{S}_{012} \]

Returns:
a reference to *this
See also:
S()

Definition at line 588 of file Gate.

Gate& QuCoSi::Gate::S ( const int  p,
const int  q,
const int  n 
) [inline]

Spqn gate

This method constructs a $2^n \times 2^n$ tensor permutation matrix that permutes the pth and qth qubits in a tensor product of n qubits.

Parameters:
p the new position of the qth qubit
q the new position of the pth qubit
n the number of qubits this gate acts on
Returns:
a reference to *this

Definition at line 609 of file Gate.

Here is the caller graph for this function:

Gate& QuCoSi::Gate::S ( const std::vector< int > &  sigma  )  [inline]

S(sigma) gate

This method constructs a tensor permutation matrix that permutes qubits according to the permutation sigma. For example, this matrix acts on the tensor product of the qubits $ q_0,\ q_1,\ \ldots,\ q_k$ as follows:

\[ \mathbf{S}(\sigma) \left(q_0 \otimes q_1 \otimes \ldots \otimes q_k\right) = q_{\sigma(0)} \otimes q_{\sigma(1)} \otimes \ldots \otimes q_{\sigma(k)} \ . \]

Note:
The implementation of this method is based on proposition 6.2 in the paper arXiv:math/0508053v2 by Rakotonirina Christian. It takes advantage of the fact that the dimension of single qubits is 2 so that the multiple row and column indices $i_1 \ldots i_k$ and $j_1 \ldots j_k$ can be obtained from the row and column indices of the permutation matrix with std::bitsets.
Parameters:
sigma the permutation that will be applied to qubits
Returns:
a reference to *this
See also:
http://arxiv.org/abs/math/0508053

Definition at line 644 of file Gate.

Gate& QuCoSi::Gate::U ( const std::vector< int > &  f  )  [inline]

Uf gate for one output qubit

This method constructs a gate that can be associated with the function $f:\,\{0,1,2,\ldots,2^n-1\} \rightarrow \{0,1\}$. It is defined so that it acts on a tensor product of n + 1 qubits as

\[ \mathbf{U}_f |x\rangle_n |y\rangle_1 = |x\rangle_n |y \oplus f(x)\rangle_1 \ , \]

where $\oplus$ denotes binary addition.

Parameters:
f the function associated with this gate
Returns:
a reference to *this

Definition at line 696 of file Gate.

Gate& QuCoSi::Gate::U ( const std::vector< int > &  f,
const int  m 
) [inline]

Uf gate for multiple output qubits

This method constructs a gate that can be associated with the function $f:\,\{0,1,2,\ldots,2^n-1\} \rightarrow \{0,1,2,\ldots,2^m-1\}$. It is defined so that it acts on a tensor product of n + m qubits as

\[ \mathbf{U}_f |x\rangle_n |y\rangle_m = |x\rangle_n |y \oplus f(x)\rangle_m \ , \]

where $\oplus$ denotes bitwise binary addition.

Parameters:
f the function associated with this gate
m the number of output qubits
Returns:
a reference to *this

Definition at line 729 of file Gate.

Gate& QuCoSi::Gate::F ( const int  n  )  [inline]

Fn gate (quantum Fourier transform (QFT) gate)

This method constructs the quantum Fourier transform gate that acts on n qubits. It is defined as:

\[\mathbf{F}_n = 2^{-n/2} \left(\begin{array}{cccccc} 1 & 1 & 1 & 1 & \cdots & 1 \\ 1 & \omega^1 & \omega^2 & \omega^3 & \cdots & \omega^{2^n-1}\\ 1 & \omega^2 & \omega^4 & \omega^6 & \cdots & \omega^{2(2^n-1)}\\ 1 & \omega^3 & \omega^6 & \omega^9 & \cdots & \omega^{3(2^n-1)}\\ \vdots & \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & \omega^{2^n-1} & \omega^{2(2^n-1)} & \omega^{3(2^n-1)} & \cdots & \omega^{(2^n-1)^2} \end{array}\right), \quad \omega = \exp\left(2 \pi i/2^n\right) \ . \]

Parameters:
n the number of qubits this gate acts on
Returns:
a reference to *this

Definition at line 765 of file Gate.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs