Quantum++  v1.1
A modern C++11 quantum computing library
qpp::Gates Class Referencefinal

const Singleton class that implements most commonly used gates More...

#include <classes/gates.h>

Inheritance diagram for qpp::Gates:
Collaboration diagram for qpp::Gates:

Public Member Functions

cmat Rn (double theta, const std::vector< double > &n) const
 Qubit rotation of theta about the 3-dimensional real (unit) vector n. More...
 
cmat RX (double theta) const
 Qubit rotation of theta about the X axis. More...
 
cmat RY (double theta) const
 Qubit rotation of theta about the Y axis. More...
 
cmat RZ (double theta) const
 Qubit rotation of theta about the Z axis. More...
 
cmat Zd (idx D=2) const
 Generalized Z gate for qudits. More...
 
cmat SWAPd (idx D=2) const
 SWAP gate for qudits. More...
 
cmat Fd (idx D=2) const
 Quantum Fourier transform gate for qudits. More...
 
cmat Xd (idx D=2) const
 Generalized X gate for qudits. More...
 
template<typename Derived = Eigen::MatrixXcd>
Derived Id (idx D=2) const
 Identity gate. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > CTRL (const Eigen::MatrixBase< Derived > &A, const std::vector< idx > &ctrl, const std::vector< idx > &subsys, idx n, idx d=2) const
 Generates the multi-partite multiple-controlled-A gate in matrix form. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > expandout (const Eigen::MatrixBase< Derived > &A, idx pos, const std::vector< idx > &dims) const
 Expands out. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > expandout (const Eigen::MatrixBase< Derived > &A, idx pos, const std::initializer_list< idx > &dims) const
 Expands out. More...
 
template<typename Derived >
dyn_mat< typename Derived::Scalar > expandout (const Eigen::MatrixBase< Derived > &A, idx pos, idx n, idx d=2) const
 Expands out. More...
 

Public Attributes

cmat Id2 {cmat::Identity(2, 2)}
 Identity gate. More...
 
cmat H {cmat::Zero(2, 2)}
 Hadamard gate. More...
 
cmat X {cmat::Zero(2, 2)}
 Pauli Sigma-X gate. More...
 
cmat Y {cmat::Zero(2, 2)}
 Pauli Sigma-Y gate. More...
 
cmat Z {cmat::Zero(2, 2)}
 Pauli Sigma-Z gate. More...
 
cmat S {cmat::Zero(2, 2)}
 S gate. More...
 
cmat T {cmat::Zero(2, 2)}
 T gate. More...
 
cmat CNOT {cmat::Identity(4, 4)}
 Controlled-NOT control target gate. More...
 
cmat CZ {cmat::Identity(4, 4)}
 Controlled-Phase gate. More...
 
cmat CNOTba {cmat::Zero(4, 4)}
 Controlled-NOT target control gate. More...
 
cmat SWAP {cmat::Identity(4, 4)}
 SWAP gate. More...
 
cmat TOF {cmat::Identity(8, 8)}
 Toffoli gate. More...
 
cmat FRED {cmat::Identity(8, 8)}
 Fredkin gate. More...
 

Private Member Functions

 Gates ()
 Initializes the gates. More...
 
 ~Gates ()=default
 Default destructor. More...
 

Friends

class internal::Singleton< const Gates >
 

Additional Inherited Members

- Static Public Member Functions inherited from qpp::internal::Singleton< const Gates >
static const Gatesget_instance () noexcept(std::is_nothrow_constructible< const Gates >::value)
 
static const Gatesget_thread_local_instance () noexcept(std::is_nothrow_constructible< const Gates >::value)
 
- Protected Member Functions inherited from qpp::internal::Singleton< const Gates >
 Singleton () noexcept=default
 
 Singleton (const Singleton &)=delete
 
Singletonoperator= (const Singleton &)=delete
 
virtual ~Singleton ()=default
 

Detailed Description

const Singleton class that implements most commonly used gates

Constructor & Destructor Documentation

◆ Gates()

qpp::Gates::Gates ( )
inlineprivate

Initializes the gates.

◆ ~Gates()

qpp::Gates::~Gates ( )
privatedefault

Default destructor.

Member Function Documentation

◆ CTRL()

template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::Gates::CTRL ( const Eigen::MatrixBase< Derived > &  A,
const std::vector< idx > &  ctrl,
const std::vector< idx > &  subsys,
idx  n,
idx  d = 2 
) const
inline

Generates the multi-partite multiple-controlled-A gate in matrix form.

See also
qpp::applyCTRL()
Note
The dimension of the gate A must match the dimension of subsys
Parameters
AEigen expression
ctrlControl subsystem indexes
subsysSubsystem indexes where the gate A is applied
nTotal number of subsystems
dSubsystem dimensions
Returns
CTRL-A gate, as a matrix over the same scalar field as A

◆ expandout() [1/3]

template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::Gates::expandout ( const Eigen::MatrixBase< Derived > &  A,
idx  pos,
const std::vector< idx > &  dims 
) const
inline

Expands out.

See also
qpp::kron()

Expands out A as a matrix in a multi-partite system. Faster than using qpp::kron(I, I, ..., I, A, I, ..., I).

Parameters
AEigen expression
posPosition
dimsDimensions of the multi-partite system
Returns
Tensor product $ I\otimes\cdots\otimes I\otimes A \otimes I \otimes\cdots\otimes I$, with A on position pos, as a dynamic matrix over the same scalar field as A

◆ expandout() [2/3]

template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::Gates::expandout ( const Eigen::MatrixBase< Derived > &  A,
idx  pos,
const std::initializer_list< idx > &  dims 
) const
inline

Expands out.

See also
qpp::kron()

Expands out A as a matrix in a multi-partite system. Faster than using qpp::kron(I, I, ..., I, A, I, ..., I).

Note
The std::initializer_list overload exists because otherwise, in the degenerate case when dims has only one element, the one element list is implicitly converted to the element's underlying type, i.e. qpp::idx, which has the net effect of picking the wrong (non-vector) qpp::expandout() overload
Parameters
AEigen expression
posPosition
dimsDimensions of the multi-partite system
Returns
Tensor product $ I\otimes\cdots\otimes I\otimes A \otimes I \otimes\cdots\otimes I$, with A on position pos, as a dynamic matrix over the same scalar field as A

◆ expandout() [3/3]

template<typename Derived >
dyn_mat<typename Derived::Scalar> qpp::Gates::expandout ( const Eigen::MatrixBase< Derived > &  A,
idx  pos,
idx  n,
idx  d = 2 
) const
inline

Expands out.

See also
qpp::kron()

Expands out A as a matrix in a multi-partite system. Faster than using qpp::kron(I, I, ..., I, A, I, ..., I).

Parameters
AEigen expression
posPosition
nNumber of subsystems
dSubsystem dimension
Returns
Tensor product $ I\otimes\cdots\otimes I\otimes A \otimes I \otimes\cdots\otimes I$, with A on position pos, as a dynamic matrix over the same scalar field as A

◆ Fd()

cmat qpp::Gates::Fd ( idx  D = 2) const
inline

Quantum Fourier transform gate for qudits.

Note
Defined as $ F = \sum_{j,k=0}^{D-1} \exp(2\pi \mathrm{i} jk/D) |j\rangle\langle k| $
Parameters
DDimension of the Hilbert space
Returns
Fourier transform gate for qudits

◆ Id()

template<typename Derived = Eigen::MatrixXcd>
Derived qpp::Gates::Id ( idx  D = 2) const
inline

Identity gate.

Note
Can change the return type from complex matrix (default) by explicitly specifying the template parameter
Parameters
DDimension of the Hilbert space
Returns
Identity gate on a Hilbert space of dimension D

◆ Rn()

cmat qpp::Gates::Rn ( double  theta,
const std::vector< double > &  n 
) const
inline

Qubit rotation of theta about the 3-dimensional real (unit) vector n.

Parameters
thetaRotation angle
n3-dimensional real (unit) vector
Returns
Rotation gate

◆ RX()

cmat qpp::Gates::RX ( double  theta) const
inline

Qubit rotation of theta about the X axis.

Parameters
thetaRotation angle
Returns
Rotation gate

◆ RY()

cmat qpp::Gates::RY ( double  theta) const
inline

Qubit rotation of theta about the Y axis.

Parameters
thetaRotation angle
Returns
Rotation gate

◆ RZ()

cmat qpp::Gates::RZ ( double  theta) const
inline

Qubit rotation of theta about the Z axis.

Parameters
thetaRotation angle
Returns
Rotation gate

◆ SWAPd()

cmat qpp::Gates::SWAPd ( idx  D = 2) const
inline

SWAP gate for qudits.

Parameters
DDimension of the Hilbert space
Returns
SWAP gate for qudits

◆ Xd()

cmat qpp::Gates::Xd ( idx  D = 2) const
inline

Generalized X gate for qudits.

Note
Defined as $ X = \sum_{j=0}^{D-1} |j\oplus 1\rangle\langle j| $, i.e. raising operator $ X|j\rangle = |j\oplus 1\rangle$
Parameters
DDimension of the Hilbert space
Returns
Generalized X gate for qudits

◆ Zd()

cmat qpp::Gates::Zd ( idx  D = 2) const
inline

Generalized Z gate for qudits.

Note
Defined as $ Z = \sum_{j=0}^{D-1} \exp(2\pi \mathrm{i} j/D) |j\rangle\langle j| $
Parameters
DDimension of the Hilbert space
Returns
Generalized Z gate for qudits

Friends And Related Function Documentation

◆ internal::Singleton< const Gates >

friend class internal::Singleton< const Gates >
friend

Member Data Documentation

◆ CNOT

cmat qpp::Gates::CNOT {cmat::Identity(4, 4)}

Controlled-NOT control target gate.

◆ CNOTba

cmat qpp::Gates::CNOTba {cmat::Zero(4, 4)}

Controlled-NOT target control gate.

◆ CZ

cmat qpp::Gates::CZ {cmat::Identity(4, 4)}

Controlled-Phase gate.

◆ FRED

cmat qpp::Gates::FRED {cmat::Identity(8, 8)}

Fredkin gate.

◆ H

cmat qpp::Gates::H {cmat::Zero(2, 2)}

Hadamard gate.

◆ Id2

cmat qpp::Gates::Id2 {cmat::Identity(2, 2)}

Identity gate.

◆ S

cmat qpp::Gates::S {cmat::Zero(2, 2)}

S gate.

◆ SWAP

cmat qpp::Gates::SWAP {cmat::Identity(4, 4)}

SWAP gate.

◆ T

cmat qpp::Gates::T {cmat::Zero(2, 2)}

T gate.

◆ TOF

cmat qpp::Gates::TOF {cmat::Identity(8, 8)}

Toffoli gate.

◆ X

cmat qpp::Gates::X {cmat::Zero(2, 2)}

Pauli Sigma-X gate.

◆ Y

cmat qpp::Gates::Y {cmat::Zero(2, 2)}

Pauli Sigma-Y gate.

◆ Z

cmat qpp::Gates::Z {cmat::Zero(2, 2)}

Pauli Sigma-Z gate.


The documentation for this class was generated from the following file: