Library

Filters

group filters

Quantum filters are used to select a subset of qubits of a LibKet::QExpression object to which a particular quantum gate is applied. The following code creates a quantum filter that selects the first three qubits:

auto filter = QFilterSelectRange<0,2>();

The same can be achieved using wrapper functions:

auto filter = filters::range<0,2>();

Quantum filters can be combined to a quantum filter chain. The following code creates a quantum filter that selects the first three even qubits and shifts them by +1 afterwards:

auto filter = filters::shift<1>(filters::sel<0,2,4>());

Quantum filter chains can also be created by creating individual LibKet::filters::QFilter objects and using their LibKet::filters::QFilter::operator()

auto filter = QFilterShift<1>() ( QFilterSelect<0,2,4>() );

LibKet provides the following quantum filters (with wrapper functions):

  • LibKet::filters::QFilterSelect (LibKet::filters::sel)

  • LibKet::filters::QFilterSelectAll (LibKet::filters::all)

  • LibKet::filters::QFilterShift (LibKet::filters::shift)

  • LibKet::filters::QFilterSelectRange (LibKet::filters::range)

  • LibKet::filters::QRegister (LibKet::filters::qureg)

  • LibKet::filters::QBit (LibKet::filters::qubit)

All quantum filters are implemented as expression templates so that, when multiple filters are combined to a filter chain, a single LibKet::filters::QFilter object is created at compile time.

template<typename _expr, bool = std::is_base_of<filters::QFilter, typename std::decay<_expr>::type>::value>
struct getFilter
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/QFilter.hpp>

Type trait extracts the filter from an expression.

template<typename _expr, bool = std::is_base_of<filters::QFilter, typename std::decay<_expr>::type>::value>
struct getPreviousFilter
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/QFilter.hpp>

Type trait extracts the previous filter from an expression.

class QFilter : public LibKet::QBase
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/QFilter.hpp>

Filter base class.

The Quantum filter base class is the base class of all Quantum filter classes. It is used to identify a generic type T as Quantum filter, e.g.

template <typename T
bool is_filter(T t) { return std::is_base_of<QFilter, typename
std::decay<T>::type>::value; }

Subclassed by LibKet::filters::QFilterSelectAll

Gates

Initialisation

group init

Functions

inline constexpr auto init() noexcept

Init gate creator.

This overload of the LibKet::gates::init() function can be used as the inner-most gate in a quantum expression

Be careful with using the initialization gate as terminal in quantum expressions that serve as sub-expressions. The following code creates two sub-expressions both using the initialization gate as terminal and creates them to another expression. The so-defined quantum expression is likely invalid since it re-initializes the quantum expr within the algorithm

auto expr1 = gates::hadamard( gates::init() );
auto expr2 = gates::hadamard( gates::init() );

auto expr3 = expr1( expr2 );

Warning

class QInit : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Init.hpp>

Init gate class.

The Init gate class implements the initialization gate for an arbitrary number of quantum bits

group prep_x

Functions

inline constexpr auto prep_x() noexcept

Prep_X gate creator.

This overload of the LibKet::gates::prep_x() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::prep_x();

class QPrep_X : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Prep_X.hpp>

Prep_X class.

The Prep_X class implements the initialization of an arbitrary number of quantum bits in the X-basis. Striktly speaking, Prep_X is not a quantum gate.

By using Prep_X, qubits will be initialized in the x-basis in the \(\left|+\right> = \frac{\left|0\right> + \left|1\right>}{\sqrt{2}}\) state

group prep_y

Functions

inline constexpr auto prep_y() noexcept

Prep_Y gate creator.

This overload of the LibKet::gates::prep_y() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::prep_y();

class QPrep_Y : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Prep_Y.hpp>

Prep_Y class.

The Prep_Y class implements the initialization of an arbitrary number of quantum bits in the Y-basis. Striktly speaking, Prep_Y is not a quantum gate.

By using Prep_Y, qubits will be initialized in the y-basis in the \(\left|+i\right> = \frac{\left|0\right> + i\left|1\right>}{\sqrt{2}}\) state

group prep_z

Functions

inline constexpr auto prep_z() noexcept

Prep_Z gate creator.

This overload of the LibKet::gates::prep_z() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::prep_z();

class QPrep_Z : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Prep_Z.hpp>

Prep_Z class.

The Prep_Z class implements the initialization of an arbitrary number of quantum bits in the Z-basis. Striktly speaking, Prep_Z is not a quantum gate.

By using Prep_Z, qubits will be initialized in the z-basis in the \(\left|0\right>\) .

group reset

Functions

inline constexpr auto reset() noexcept

Reset gate creator.

This overload of the LibKet::gates::reset() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::reset();

class QReset : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Reset.hpp>

Reset class.

The Reset class implements the initialization of an arbitrary number of quantum bits in the Z-basis. Striktly speaking, Reset is not a quantum gate.

Measurements

group measure

Functions

inline constexpr auto measure() noexcept

Measure gate creator.

This overload of the LibKet::gates::measure() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::measure();

class QMeasure : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Measure.hpp>

Measure class.

The Measure class implements the measurement of an arbitrary number of quantum bits in the Z-basis. Striktly speaking, measure is not a quantum gate.

group measure_x

Functions

inline constexpr auto measure_x() noexcept

Measure_X gate creator.

This overload of the LibKet::gates::measure_x() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::measure_x();

class QMeasure_X : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Measure_X.hpp>

Measure_X class.

The Measure_X class implements the measurement of an arbitrary number of quantum bits in the Z-basis. Striktly speaking, Measure_X is not a quantum gate.

group measure_y

Functions

inline constexpr auto measure_y() noexcept

Measure_Y gate creator.

This overload of the LibKet::gates::measure_y() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::measure_y();

class QMeasure_Y : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Measure_Y.hpp>

Measure_Y class.

The Measure_Y class implements the measurement of an arbitrary number of quantum bits in the Z-basis. Striktly speaking, Measure_y is not a quantum gate.

group measure_z

Functions

inline constexpr auto measure_z() noexcept

Measure_Z gate creator.

This overload of the LibKet::gates::measure_z() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::measure_z();

class QMeasure_Z : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Measure_Z.hpp>

Measure_Z class.

The Measure_Z class implements the measurement of an arbitrary number of quantum bits in the Z-basis. Striktly speaking, Measure_z is not a quantum gate.

Single Qubit Gates

group pauli_x

Functions

inline constexpr auto pauli_x() noexcept

Pauli_X gate creator.

This overload of the LibKet::gates::pauli_x() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::pauli_x();

class QPauli_X : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Pauli_X.hpp>

Pauli_X gate class.

The Pauli_X gate class implements the quantum Pauli_X gate for an arbitrary number of quantum bits.

The Pauli_X gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|1\right>\) and \(\left|1\right>\) to \(\left|0\right>\).

The Pauli_X gate is a single-qubit rotation through \(\pi\) radians around the x-axis.

The unitary matrix reads

\[\begin{split} X = \begin{pmatrix} 0 & 1\\ 1 & 0 \end{pmatrix} \end{split}\]

group pauli_y

Functions

inline constexpr auto pauli_y() noexcept

Pauli_Y gate creator.

This overload of the LibKet::gates::pauli_y() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::pauli_y();

class QPauli_Y : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Pauli_Y.hpp>

Pauli_Y gate class.

The Pauli_Y gate class implements the quantum Pauli_Y gate for an arbitrary number of quantum bits.

The Pauli_Y gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(-i\left|1\right>\) and \(\left|1\right>\) to \(i\left|0\right>\).

The Pauli-Y gate is a single-qubit rotation through \(\pi\) radians around the y-axis.

The unitary matrix reads

\[\begin{split} Y = \begin{pmatrix} 0 & -i\\ i & 0 \end{pmatrix} \end{split}\]

group pauli_z

Functions

inline constexpr auto pauli_z() noexcept

Pauli_Z gate creator.

This overload of the LibKet::gates::pauli_z() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::pauli_z();

class QPauli_Z : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Pauli_Z.hpp>

Pauli_Z gate class.

The Pauli_Z gate class implements the quantum Pauli_Z gate for an arbitrary number of quantum bits.

The Pauli_Z gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|0\right>\) and \(\left|1\right>\) to \(-\left|1\right>\).

The Pauli_Z gate is a single-qubit rotation through \(\pi\) radians around the z-axis.

The unitary matrix reads

\[\begin{split} Z = \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix} \end{split}\]

group identity

Functions

inline constexpr auto identity() noexcept

Identity gate creator.

This overload of the LibKet::gates::identity() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::identity( );

class QIdentity : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Identity.hpp>

Identity gate class.

The Identity gate class implements the quantum identity gate for an arbitrary number of quantum bits

The identity gate is a single-qubit operation that leaves the basis state \(\left|0\right>\) and \(\left|1\right>\) unchanged.

The unitary matrix reads

\[\begin{split} I = \begin{pmatrix} 1 & 0\\ \ 0 & 1 \end{pmatrix} \end{split}\]

group hadamard

Functions

inline constexpr auto hadamard() noexcept

Hadamard gate creator.

This overload of the LibKet::gates::hadamard() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::hadamard();

class QHadamard : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Hadamard.hpp>

Hadamard gate class.

The Hadamard gate class implements the quantum Hadamard gate for an arbitrary number of quantum bits.

The Hadamard gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\frac{\left|0\right>+\left|1\right>}{\sqrt{2}}\) and \(\left|1\right>\) to \(\frac{\left|0\right>-\left|1\right>}{\sqrt{2}}\), thus creating an equal superposition of the two basis states.

The unitary matrix reads

\[\begin{split} H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \end{split}\]

group s

Unnamed Group

UNARY_GATE_DEFAULT_IMPL(QS, s)

\(S\) gate default implementation

Functions

inline constexpr auto s() noexcept

\(S\) gate creator

This overload of the LibKet::gates::gate_s() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::s();

class QS : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_S.hpp>

\(S\) gate class

The \(S\) gate class implements the quantum \(S\) gate gate for an arbitrary number of quantum bits.

The \(S\) gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|0\right>\) and \(\left|1\right>\) to \(i\left|1\right>\).

The \(S\) gate is also known as the phase gate or the Z90 gate, because it represents a 90-degree rotation around the z-axis.

The \(S\) gate is related to the \(T\) gate by the relationship \(S=T^{2}\).

The unitary matrix reads

\[\begin{split} S = \begin{pmatrix} 1 & 0\\ 0 & i \end{pmatrix} \end{split}\]

group sdag

Functions

inline constexpr auto sdag() noexcept

\(S\)-dagger gate creator

This overload of the LibKet::gates::gate_sdag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::sdag();

class QSdag : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Sdag.hpp>

\(S\)-dagger gate class

The \(S\)-dagger gate class implements the quantum \(S\)-dagger gate for an arbitrary number of quantum bits.

The \(S\)-dagger gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|0\right>\) and \(\left|1\right>\) to \(-i\left|1\right>\).

The \(S^{\dagger}\) gate is also defined as the conjugate transpose of the \(S\) gate.

The unitary matrix reads

\[\begin{split} S^{\dagger} = \begin{pmatrix} 1 & 0\\ \ 0 & -i \end{pmatrix} \end{split}\]

group rotate_x90

Functions

inline constexpr auto rotate_x90() noexcept

Rotate_X90 gate creator.

This overload of the LibKet::gate:rotate_x90() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_x90();

class QRotate_X90 : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_X90.hpp>

Rotate_X90 gate class.

The Rotate_X90 gate class implements the quantum Rotate_X90 gate for an arbitrary number of quantum bits.

The Rotate_X90 gate is a single-qubit rotation through angle \(\frac{\pi}{2}\) (radians) around the x-axis.

The unitary matrix reads

\[\begin{split} R_{x}\left(\frac{\pi}{2}\right) = \begin{pmatrix} \frac{1}{\sqrt{2}} & -i\frac{1}{\sqrt{2}}\\ -i\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \end{pmatrix} \end{split}\]

group rotate_mx90

Functions

inline constexpr auto rotate_mx90() noexcept

Rotate_MX90 gate creator.

This overload of the LibKet::gate:rotate_mx90() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_mx90();

class QRotate_MX90 : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_MX90.hpp>

Rotate_MX90 gate class.

The Rotate_MX90 gate class implements the quantum Rotate_MX90 gate for an arbitrary number of quantum bits.

The Rotate_MX90 gate is a single-qubit rotation through angle \(-\frac{\pi}{2}\) (radians) around the x-axis.

The unitary matrix reads

\[\begin{split} R_{x}\left(-\frac{\pi}{2}\right) = \begin{pmatrix} \frac{1}{\sqrt{2}} & i\frac{1}{\sqrt{2}}\\ i\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \end{pmatrix} \end{split}\]

group rotate_y90

Functions

inline constexpr auto rotate_y90() noexcept

Rotate_Y90 gate creator.

This overload of the LibKet::gate:rotate_y90() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_y90();

class QRotate_Y90 : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_Y90.hpp>

Rotate_Y90 gate class.

The Rotate_Y90 gate class implements the quantum Rotate_Y90 gate for an arbitrary number of quantum bits.

The Rotate_Y90 gate is a single-qubit rotation through angle \(\frac{\pi}{2}\) (radians) around the y-axis.

The unitary matrix reads

\[\begin{split} R_{y}(\frac{\pi}{2}) = \begin{pmatrix} \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}}\\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \end{pmatrix} \end{split}\]

group rotate_my90

Functions

inline constexpr auto rotate_my90() noexcept

Rotate_MY90 gate creator.

This overload of the LibKet::gate:rotate_my90() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_my90();

class QRotate_MY90 : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_MY90.hpp>

Rotate_MY90 gate class.

The Rotate_MY90 gate class implements the quantum Rotate_MY90 gate for an arbitrary number of quantum bits.

The Rotate_MY90 gate is a single-qubit rotation through angle \(-\frac{\pi}{2}\) (radians) around the y-axis.

The unitary matrix reads

\[\begin{split} R_{y}\left(-\frac{\pi}{2}\right) = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}}\\ -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \end{pmatrix} \end{split}\]

group sqrtnot

Functions

template<typename _tol = QConst_M_ZERO_t>
inline constexpr auto sqrt_not() noexcept

Square-root-of-NOT gate creator.

This overload of the LibKet::gates::sqrt_not() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto qcirc = gates::sqrt_not();

template<typename _tol = QConst_M_ZERO_t>
class QSqrt_Not : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Sqrt_Not.hpp>

Square-root-of-NOT gate class.

The Quantum square root of NOT gate class implements the square root of NOT gate for an arbitrary number of qubits.

The square root of NOT gate (or square root of Pauli_X, \(\sqrt{X}\)) acts on a single qubit. It maps the basis state \(\left|0\right>\) to \(\frac{(1+i)\left|0\right> + (1-i)\left|1\right>}{2}\) and \(\left|1\right>\) to \(\frac{(1-i)\left|0\right> + (1+i)\left|1\right>}{2}\).

The unitary matrix reads

\[\begin{split} \sqrt{X} = \frac{1}{2} \begin{pmatrix} 1+i & 1-i\\ \ 1-i & 1+i \end{pmatrix} \end{split}\]

group t

Functions

inline constexpr auto t() noexcept

\(T\) gate creator

This overload of the LibKet::gate:gate_t() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::t();

class QT : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_T.hpp>

\(T\) gate class

The \(T\) gate class implements the quantum \(T\) gate gate for an arbitrary number of quantum bits.

The \(T\) gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|0\right>\) and \(\left|1\right>\) to \(\exp(i\frac{\pi}{4})\left|1\right>\).

The \(T\) gate is related to the \(S\) gate by the relationship \(S=T^{2}\).

The unitary matrix reads

\[\begin{split} T = \begin{pmatrix} 1 & 0\\ 0 & \exp(i\frac{\pi}{4}) \end{pmatrix} \end{split}\]

group tdag

Functions

inline constexpr auto tdag() noexcept

\(T\)-dagger gate creator

This overload of the LibKet::gate:gate_tdag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::tdag();

class QTdag : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Tdag.hpp>

\(T\)-dagger gate class

The \(T\)-dagger gate class implements the quantum \(T\)-dagger gate for an arbitrary number of quantum bits.

The \(T\)-dagger is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|0\right>\) and \(\left|1\right>\) to \(\exp(-i\frac{\pi}{4})\left|1\right>\).

The \(T^{\dagger}\) gate is also defined as the conjugate transpose of the \(T\) gate

The unitary matrix reads

\[\begin{split} T^{\dagger} = \begin{pmatrix} 1 & 0 \\ 0 & \exp(-i\frac{\pi}{4}) \end{pmatrix} \end{split}\]

group barrier

Functions

inline constexpr auto barrier() noexcept

Barrier gate creator.

This overload of the LibKet::gates::barrier() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr1 = gates::hadamard( gates::barrier() );

If the so-defined expression is used as sub-expression then the synchronization gate ensures that no optimization takes place. In the following example, the double application of the Hadamard gate would be eliminated without the barrier inbetween the two gates

auto expr2 = expr1( gates::hadamard() );

Returns

UnaryQGate object

class QBarrier : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Barrier.hpp>

Barrier gate class.

The quantum synchronization gate ensures that quantum expression optimization does not proceed beyond the synchronization barrier.

The following code creates a quantum expression consisting of three Hadamard gates applied consecutively, which by the built-in optimization of quantum expressions yields a single Hadamard gate

auto expr = gates::hadamard( gates::hadamard( gates::hadamard() ) ); // same as
auto expr = gates::hadamard();

To prevent the built-in optimization from taking place, the quantum synchronization gate can be inserted between the gates

auto expr = gates::hadamard( gates::barrier ( gates::hadamard( gates::barrier ( gates::hadamard() ) ) ) );

group u2
template<typename _functor, typename _tol = QConst_M_ZERO_t>
class QUnitary2 : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Unitary2.hpp>

\(2\times 2\) unitary gate class

The \(2\times2\) unitary gate accepts an arbitrary \(2\times 2\) unitary matrix \(U\) as input and performs the ZYZ decomposition of \(U\)

\[ U = \exp(i\Phi) R_z(\alpha)R_y(\beta)R_z(\gamma) \]

with \(\Phi,\alpha,\beta,\gamma\) are rotation angles.

group u2dag
template<typename _functor, typename _tol = QConst_M_ZERO_t>
class QUnitary2dag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Unitary2.hpp>

\(2\times 2\) unitary gate (conjugate transpose) class

The \(2\times2\) unitary gate (conjugate transpose) accepts an arbitrary \(2\times 2\) unitary matrix \(U\) as input and performs the ZYZ decomposition of the conjugate transpose of \(U\)

\[ U^\dagger = \exp(i\Phi) R_z(-\gamma)R_y(-\beta)R_z(-\alpha) \]

with \(\Phi,\alpha,\beta,\gamma\) are rotation angles.

Parameterized Single Qubit Gates

group rotate_x

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto rotate_x(_angle) noexcept

Rotate_X gate creator.

This overload of the LibKet::gates::rotate_x() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_x();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QRotate_X : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_X.hpp>

Rotate_X gate class.

The Rotate_X gate class implements the quantum Rotate_X gate for an arbitrary number of quantum bits.

The Rotate_X gate is a single-qubit rotation through angle \(\theta\) (radians) around the x-axis.

The unitary matrix reads

\[\begin{split} R_{x}(\theta) = \begin{pmatrix} \cos(\frac{\theta}{2}) & -i\sin(\frac{\theta}{2})\\ -i\sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \end{pmatrix} \end{split}\]

group rotate_xdag

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto rotate_xdag(_angle) noexcept

Rotate_Xdag gate creator.

This overload of the LibKet::gates::rotate_xdag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_xdag();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QRotate_Xdag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_X.hpp>

Rotate_Xdag gate class.

The Rotate_Xdag gate class implements the inverse quantum Rotate_X gate for an arbitrary number of quantum bits.

The \(R_{x}^{\dagger}(\theta)\) gate is defined as the conjugate transpose of the Rotate_X gate.

The unitary matrix reads

\[\begin{split} R_{x}^{\dagger}(\theta) = \begin{pmatrix} \cos(\frac{\theta}{2}) & i\sin(\frac{\theta}{2})\\ i\sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \end{pmatrix} \end{split}\]

group rotate_y

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto rotate_y(_angle) noexcept

Rotate_Y gate creator.

This overload of the LibKet::gates::rotate_y() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_y();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QRotate_Y : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_Y.hpp>

Rotate_Y gate class.

The Rotate_Y gate class implements the quantum Rotate_Y gate for an arbitrary number of quantum bits.

The Rotate_Y gate is a single-qubit rotation through angle \(\theta\) (radians) around the y-axis.

The unitary matrix reads

\[\begin{split} R_{y}(\theta) = \begin{pmatrix} \cos(\frac{\theta}{2}) & -\sin(\frac{\theta}{2})\\ \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \end{pmatrix} \end{split}\]

group rotate_ydag

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto rotate_ydag(_angle) noexcept

Rotate_Ydag gate creator.

This overload of the LibKet::gates::rotate_ydag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_ydag();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QRotate_Ydag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_Y.hpp>

Rotate_Ydag gate class.

The Rotate_Ydag gate class implements the inverse quantum Rotate_Y gate for an arbitrary number of quantum bits.

The \(R_{y}^{\dagger}(\theta)\) gate is defined as the conjugate transpose of the Rotate_Y gate.

The unitary matrix reads

\[\begin{split} R_{y}^{\dagger}(\theta) = \begin{pmatrix} \cos(\frac{\theta}{2}) & \sin(\frac{\theta}{2})\\ -\sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \end{pmatrix} \end{split}\]

group rotate_z

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto rotate_z(_angle) noexcept

Rotate_Z gate creator.

This overload of the LibKet::gates::rotate_z() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_z();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QRotate_Z : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_Z.hpp>

Rotate_Z gate class.

The Rotate_Z gate class implements the quantum Rotate_Z gate for an arbitrary number of quantum bits.

The Rotate_Z gate is a single-qubit rotation through angle \(\theta\) (radians) around the z-axis.

The unitary matrix reads

\[\begin{split} R_{z}(\theta) = \begin{pmatrix} \exp(-i\frac{\theta}{2}) & 0\\ 0 & \exp(i\frac{\theta}{2}) \end{pmatrix} \end{split}\]

group rotate_zdag

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto rotate_zdag(_angle) noexcept

Rotate_Zdag gate creator.

This overload of the LibKet::gates::rotate_zdag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::rotate_zdag();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QRotate_Zdag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Rotate_Z.hpp>

Rotate_Zdag gate class.

The Rotate_Zdag gate class implements the inverse quantum Rotate_Z gate for an arbitrary number of quantum bits.

The \(R_{z}^{\dagger}(\theta) \) gate is defined as the conjugate transpose of the Rotate_Z gate.

The unitary matrix reads

\[\begin{split} R_{z}^{\dagger}(\theta)= \begin{pmatrix} \exp(i\frac{\theta}{2}) & 0\\ 0 & \exp(-i\frac{\theta}{2}) \end{pmatrix} \end{split}\]

group phase

Unnamed Group

UNARY_GATE_DEFAULT_IMPL_AT(QPhase, phase)

Phase gate default implementation.

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto phase(_angle) noexcept

Phase gate creator.

This overload of the LibKet::gates::phase() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::phase();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QPhase : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Phase.hpp>

PHASE gate class.

The PHASE gate class implements the quantum phase gate for an arbitrary number of quantum bits.

The PHASE gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|0\right>\) and \(\left|1\right>\) to \(\exp(i\theta)\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{PHASE} = \begin{pmatrix} 1 & 0\\ 0 & \exp(i\theta) \end{pmatrix} \end{split}\]

group phasedag

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto phasedag(_angle) noexcept

Phasedag gate creator.

This overload of the LibKet::gates::phasedag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::phasedag();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QPhasedag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Phase.hpp>

PHASEdag gate class.

The PHASEdag gate class implements the inverse quantum phase gate for an arbitrary number of quantum bits.

The PHASEdag gate is a single-qubit operation that maps the basis state \(\left|0\right>\) to \(\left|0\right>\) and \(\left|1\right>\) to \(\exp(-i\theta)\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{PHASE}^{\dagger} = \begin{pmatrix} 1 & 0\\ 0 & \exp(-i\theta) \end{pmatrix} \end{split}\]

Two Qubit Gates

group cnot

Functions

inline constexpr auto cnot() noexcept

CNOT (controlled-X) gate creator.

This overload of the LibKet::gates::CNOT() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::cnot();

class QCNOT : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CNOT.hpp>

CNOT (controlled-X) gate class.

The CNOT (controlled-X) gate class implements the quantum CNOT gate for an arbitrary number of quantum bits.

The CNOT (controlled-X) gate is a two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. It maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|01\right>\), \(\left|10\right>\) to \(\left|11\right>\) and \(\left|11\right>\) to \(\left|10\right>\).

The CNOT (controlled-X) gates leaves the control qubit unchanged and performs a Pauli-X gate on the target qubit only when the control qubit is in state \(\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{pmatrix} \end{split}\]

group cy

Functions

inline constexpr auto cy() noexcept

CY (controlled-Y) gate creator.

This overload of the LibKet::gates::cy() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::cy();

class QCY : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CY.hpp>

CY (controlled-Y) gate class.

The CY (controlled-Y) gate class implements the quantum controlled-Y gate for an arbitrary number of quantum bits

The CY (controlled-Y) gate is a two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. It maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|01\right>\), \(\left|10\right>\) to \(i\left|11\right>\) and \(\left|11\right>\) to \(-i\left|10\right>\).

The CY (controlled-Y) gates leaves the control qubit unchanged and performs a Pauli-Y gate on the target qubit only when the control qubit is in state \(\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{CY} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & -i\\ 0 & 0 & i & 0 \end{pmatrix} \end{split}\]

group cz

Functions

inline constexpr auto cz() noexcept

CZ (controlled-Z) gate creator.

This overload of the LibKet::gates::cz() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::cz();

class QCZ : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CZ.hpp>

CZ (controlled-Z) gate class.

The CZ (controlled-Z) gate class implements the quantum controlled-Z gate for an arbitrary number of quantum bits

The CZ (controlled-Z) gate is a two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. It maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|01\right>\), \(\left|10\right>\) to \(\left|10\right>\) and \(\left|11\right>\) to \(-\left|11\right>\).

The CZ (controlled-Z) gates leaves the control qubit unchanged and performs a Pauli-Z gate on the target qubit only when the control qubit is in state \(\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{CZ} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1 \end{pmatrix} \end{split}\]

group swap

Functions

inline constexpr auto swap() noexcept

Swap gate creator.

This overload of the LibKet::gate:swap() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::swap();

class QSwap : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Swap.hpp>

Swap gate class.

The LibKet SWAP gate class implements the quantum swap gate for an arbitrary number of quantum bits.

The SWAP gate is a two-qubit operation that maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|10\right>\), \(\left|10\right>\) to \(\left|01\right>\) and \(\left|11\right>\) to \(\left|11\right>\).

The SWAP gate swaps the state of the two qubits involved in the operation.

The unitary matrix reads

\[\begin{split} \text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0\\ \ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{pmatrix} \end{split}\]

group sqrtswap

Functions

inline constexpr auto sqrt_swap() noexcept

Square-root-of-swap gate creator.

This overload of the LibKet::gate:sqrt_swap() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::sqrt_swap();

class QSqrt_Swap : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_Sqrt_Swap.hpp>

Swap gate class.

The Square root of SWAP gate class implements the quantum square root of SWAP gate for an arbitrary number of quantum bits.

The square root of SWAP gate (or square root of SWAP, \(\sqrt{\text{SWAP}}\)) is two qubit operation which implements the square root of SWAP gate.

The unitary matrix reads

\[\begin{split} \sqrt{\text{SWAP}} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1+i}{2} & \frac{1-i}{2} & 0 \\ 0 & \frac{1-i}{2} & \frac{1+i}{2} & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \end{split}\]

group cu2

Unnamed Group

BINARY_GATE_DEFAULT_IMPL_FTOR(QCUnitary2, cunitary2)

\(2\times 2\) controlled unitary gate default implementation

Functions

template<typename _functor, typename _tol = QConst_M_ZERO_t>
inline constexpr auto cunitary2() noexcept

\(2\times 2\) controlled unitary gate creator

This overload of the LibKet::gates::cunitary2() function can be used as terminal, i.e. the inner-most gate in a quantum expression

struct CU2_ftor {
  inline auto operator()() const noexcept
  {
    return arma::vec{ 1.0/sqrt(2.0), -1.0/sqrt(2.0),                               
                      1.0/sqrt(2.0),  1.0/sqrt(2.0)};
  }
};

auto expr = gates::cunitary2<CU2_ftor>();

template<typename _functor, typename _tol = QConst_M_ZERO_t>
class QCUnitary2 : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CUnitary2.hpp>

\(2\times 2\) controlled unitary gate class

The \(2\times2\) controlled unitary gate accepts an arbitrary \(2\times 2\) unitary matrix \(U\) as input and performs the controlled ZYZ decomposition of \(U\)

\[ U = \exp(i\Phi) R_z(\alpha)R_y(\beta)R_z(\gamma) \]

with \(\Phi,\alpha,\beta,\gamma\) are rotation angles.

group cu2dag

Functions

template<typename _functor, typename _tol = QConst_M_ZERO_t>
inline constexpr auto cunitary2dag() noexcept

\(2\times 2\) controlled unitary gate (conjugate transpose) creator

This overload of the LibKet::gates::cunitary2dag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

struct CU2_ftor {
inline auto operator()() const noexcept
 return arma::vec{ 1.0/sqrt(2.0), -1.0/sqrt(2.0),                               
                   1.0/sqrt(2.0),  1.0/sqrt(2.0)};
};

auto expr = gates::cunitary2dag<CU2_ftor>();

template<typename _functor, typename _tol = QConst_M_ZERO_t>
class QCUnitary2dag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CUnitary2.hpp>

\(2\times 2\) controlled unitary gate (conjugate transpose) class

The \(2\times2\) controlled unitary gate (conjugate transpose) accepts an arbitrary \(2\times 2\) unitary matrix \(U\) as input and performs the ZYZ decomposition of the conjugate transpose of \(U\)

\[ U^\dagger = \exp(i\Phi) R_z(-\gamma)R_y(-\beta)R_z(-\alpha) \]

with \(\Phi,\alpha,\beta,\gamma\) are rotation angles.

Parameterized Two Qubit Gates

group cphase

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto cphase(_angle) noexcept

CPHASE (controlled phase shift) gate creator.

This overload of the LibKet::gates::cphase() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::cphase();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QCPhase : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CPhase.hpp>

CPHASE (controlled phase shift) gate class.

The CPHASE (controlled phase shift) gate class implements the quantum controlled phase shift gate for an arbitrary number of quantum bits

The CPHASE (controlled phase shift) gate is a two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. It maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|01\right>\), \(\left|10\right>\) to \(\left|10\right>\) and \(\left|11\right>\) to \(\exp(i\theta)\left|11\right>\).

The CPHASE (controlled phase shift) gates leaves the control qubit unchanged and performs a Phase gate on the target qubit only when the control qubit is in state \(\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{CPHASE} = \begin{pmatrix} 1 & 0 & 0 & 0\\ \ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & \exp(i\theta) \end{pmatrix} \end{split}\]

group cphasedag

Functions

template<typename _tol = QConst_M_ZERO_t, typename _angle>
inline constexpr auto cphasedag(_angle) noexcept

CPHASEDAG (inverse controlled phase shift) gate creator.

This overload of the LibKet::gates::cphasedag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::cphasedag();

template<typename _angle, typename _tol = QConst_M_ZERO_t>
class QCPhasedag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CPhase.hpp>

CPHASEDAG (inverse controlled phase shift) gate class.

The CPHASEDAG (inverse controlled phase shift) gate class implements the quantum controlled phase shift gate for an arbitrary number of quantum bits

The CPHASEDAG (inverse controlled phase shift) gate is a two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. It maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|01\right>\), \(\left|10\right>\) to \(\left|10\right>\) and \(\left|11\right>\) to \(\exp(-i\theta)\left|11\right>\).

The \(\text{CPHASE}^{\dagger}\) (inverse controlled phase shift) gate is also defined as the conjugate transpose of the CPHASE gate.

The unitary matrix reads

\[\begin{split} \text{CPHASE}^{\dagger} = \begin{pmatrix} 1 & 0 & 0 & 0\\ \ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & \exp(-i\theta) \end{pmatrix} \end{split}\]

group cphasek

Functions

template<std::size_t k, typename _tol = QConst_M_ZERO_t>
inline constexpr auto cphasek() noexcept

CPHASEK (controlled phase shift with \(\pi/2^k\) angle) gate creator.

This overload of the LibKet::gates::cphasek() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::cphasek();

template<std::size_t k, typename _tol = QConst_M_ZERO_t>
class QCPhaseK : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CPhaseK.hpp>

CPHASEK (controlled phase shift with \(\pi/2^k\) angle) gate class.

The CPHASEK (controlled phase shift with \(\pi/2^k\) angle) gate class implements the quantum controlled phase shift with \(\pi/2^k\) angle gate for an arbitrary number of quantum bits

The CPHASEK (controlled phase shift with \(\pi/2^k\) angle) gate is a two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. It maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|01\right>\), \(\left|10\right>\) to \(\left|10\right>\) and \(\left|11\right>\) to \(\exp(\frac{2 \pi i}{2^{k}})\left|11\right>\).

The CPHASEK (controlled phase shift with \(\pi/2^k\) angle) gates leaves the control qubit unchanged and performs a Phase gate on the target qubit only when the control qubit is in state \(\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{CPHASEK} = \begin{pmatrix} 1 & 0 & 0 & 0\\ \ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & \exp(\frac{2 \pi i}{2^{k}}) \end{pmatrix} \end{split}\]

group cphasekdag

Functions

template<std::size_t k, typename _tol = QConst_M_ZERO_t>
inline constexpr auto cphasekdag() noexcept

CPHASEKDAG (inverse controlled phase shift with \(\pi/2^k\) angle) gate creator.

This overload of the LibKet::gates::cphasekdag() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::cphasekdag();

template<std::size_t k, typename _tol = QConst_M_ZERO_t>
class QCPhaseKdag
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CPhaseK.hpp>

CPHASEKDAG (inverse controlled phase shift with \(\pi/2^k\) angle) gate class.

The CPHASEKDAG (inverse controlled phase shift with \(\pi/2^k\) angle) gate class implements the quantum controlled phase shift with \(\pi/2^k\) angle gate for an arbitrary number of quantum bits

The CPHASEKDAG (inverse controlled phase shift with \(\pi/2^k\) angle) gate is a two-qubit operation, where the first qubit is usually referred to as the control qubit and the second qubit as the target qubit. It maps the basis state \(\left|00\right>\) to \(\left|00\right>\), \(\left|01\right>\) to \(\left|01\right>\), \(\left|10\right>\) to \(\left|10\right>\) and \(\left|11\right>\) to \(\exp(-\frac{2 \pi i}{2^{k}})\left|11\right>\).

The CPHASEKDAG (inverse controlled phase shift with \(\pi/2^k\) angle) gates leaves the control qubit unchanged and performs a Phase gate on the target qubit only when the control qubit is in state \(\left|1\right>\).

The \(\text{CPHASEK}^{\dagger}\) (inverse controlled phase shift with \(\pi/2^k\) angle) is also defined as the conjugate transpose of the CPHASEK gate.

The unitary matrix reads

\[\begin{split} \text{CPHASEK}^{\dagger} = \begin{pmatrix} 1 & 0 & 0 & 0\\ \ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & \exp(-\frac{2 \pi i}{2^{k}}) \end{pmatrix} \end{split}\]

Three Qubit Gates

group ccnot

Functions

inline constexpr auto ccnot() noexcept

CCNOT (Toffoli) gate creator.

This overload of the LibKet::gates::ccnot() function can be used as terminal, i.e. the inner-most gate in a quantum expression

auto expr = gates::ccnot();

class QCCNOT : public LibKet::gates::QGate
#include </home/docs/checkouts/readthedocs.org/user_builds/libket/checkouts/latest/libket/gates/QGate_CCNOT.hpp>

CCNOT (Toffoli) gate class.

The CCNOT (Toffoli) gate class implements the quantum CCNOT (Toffoli) gate for an arbitrary number of quantum bits

The CCNOT (Toffoli) gate is a three-qubit operation, where the first qubit and the second qubit are usually referred to as the control qubits and the third qubit as the target qubit. It maps the basis state \(\left|000\right>\) to \(\left|000\right>\), \(\left|001\right>\) to \(\left|001\right>\), \(\left|010\right>\) to \(\left|010\right>\), \(\left|011\right>\) to \(\left|011\right>\), \(\left|100\right>\) to \(\left|100\right>\), \(\left|101\right>\) to \(\left|101\right>\), \(\left|110\right>\) to \(\left|111\right>\) and \(\left|110\right>\) to \(\left|110\right>\)

The CCNOT (Toffoli) gates leaves the control qubit unchanged and performs a Pauli-X gate on the target qubit only when both the control qubits are in state \(\left|1\right>\).

The unitary matrix reads

\[\begin{split} \text{CCNOT} = \begin{pmatrix} 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{pmatrix} \end{split}\]

Circuits

Quantum Fourier Transform

The code below can be used to apply the Quantum Fourier Transform on qubits 0 to n.

auto expr = qft(range<0,n>(init()));

This generates the following circuit for \(n = 5\):

Figure made with TikZ

This image shows the circuit created with the above line of code

Inverse QFT is called using function qftdag().

AllSwap

The LibKet AllSwap circuit swaps all qubits in a given selection. The LibKet AllSwap circuit can be applied to the first n qubits of your register as follows:

auto expr = allswap(range<0,n>(init()));

This creates the following circuit for n = 5:

Figure made with TikZ

This image shows the circuit created with the above line of code

Arbitrary Control

The Arbitrary control circuit allows controlled unitary qubit gates (e.g. cx, cy, cz, cphase, etc) to be controlled by multiple qubits. For every \(N\) control qubits, \(N-1\) ancilla qubits are needed. The following code snippet constructs a cnot gate controlled by qubits 0 to 3.

auto expr = arb_ctrl<>(cx(),              //Control gate
                       sel<0,1,2,3>(),    //Control qubits
                       sel<7>(),          //Target qubits
                       sel<4,5,6>(init()) //Ancilla qubits
                      );

This generates the following circuit:

Figure made with TikZ

Arbitrary Control circuit for cnot gate

Quantum Phase Estimation

Oracle

Devices

Atos QLM

This class executes quantum circuits on the Atos Quantum Learning Machine (QLM) simulator. It adopts Atos’ AQASM quantum assembly language: Atos Website

Available QDevices in LibKet:

atos_qlm_feynman_simulator  /**< Atos QLM Feynman integral path simulator          */
atos_qlm_linalg_simulator   /**< Atos QLM Linear algebra-based  simulator          */
atos_qlm_stabs_simulator    /**< Atos QLM Stabilizer-based simulator               */
atos_qlm_mps_simulator      /**< Atos QLM Matrix product state-based simulator     */

Cirq

This class executes quantum circuits locally on the Cirq simulator, a Python software library for writing, manipulating, and optimizing quantum circuits, and then running them on quantum computers and quantum simulators. It adopts the Cirq quantum assembly language. Cirq provides useful features such as dealing with today’s noisy intermediate-scale quantum computers: Cirq Website

Available QDevices in LibKet:

cirq_simulator             /**< Cirq simulator                                    */
cirq_simulator_simulator   /**< Cirq simulator (name demangling)                  */
cirq_bristlecone_simulator /**< Cirq Bristlecone simulator                        */
cirq_foxtail_simulator     /**< Cirq Foxtail simulator                            */
cirq_sycamore_simulator    /**< Cirq Sycamore simulator                           */
cirq_sycamore23_simulator  /**< Cirq Sycamore23 simulator                         */

Qiskit

Qiskit is another python basesd open-source SDK for working with quantum computers and simulators at the level of pulses, circuits and application modules: Qiskit Website

Available QDevices in LibKet:

qiskit_almaden_simulator      /**< Qiskit  20-qubit local simulator                  */
qiskit_armonk_simulator       /**< Qiskit   1-qubit local simulator                  */
qiskit_athens_simulator       /**< Qiskit   5-qubit local simulator                  */
qiskit_belem_simulator        /**< Qiskit   5-qubit local simulator                  */
qiskit_boeblingen_simulator   /**< Qiskit  20-qubit local simulator                  */
qiskit_bogota_simulator       /**< Qiskit   5-qubit local simulator                  */
qiskit_brooklyn_simulator     /**< Qiskit  65-qubit local simulator                  */
qiskit_burlington_simulator   /**< Qiskit   5-qubit local simulator                  */
qiskit_cairo_simulator        /**< Qiskit  27-qubit local simulator                  */
qiskit_cambridge_simulator    /**< Qiskit  28-qubit local simulator                  */
qiskit_casablanca_simulator   /**< Qiskit   7-qubit local simulator                  */
qiskit_dublin_simulator       /**< Qiskit  27-qubit local simulator                  */
qiskit_essex_simulator        /**< Qiskit   5-qubit local simulator                  */
qiskit_guadalupe_simulator    /**< Qiskit  16-qubit local simulator                  */
qiskit_hanoi_simulator        /**< Qiskit  27-qubit local simulator                  */
qiskit_jakarta_simulator      /**< Qiskit   7-qubit local simulator                  */
qiskit_johannesburg_simulator /**< Qiskit  20-qubit local simulator                  */
qiskit_kolkata_simulator      /**< Qiskit  27-qubit local simulator                  */
qiskit_lagos_simulator        /**< Qiskit   7-qubit local simulator                  */
qiskit_lima_simulator         /**< Qiskit   5-qubit local simulator                  */
qiskit_london_simulator       /**< Qiskit   5-qubit local simulator                  */
qiskit_manhattan_simulator    /**< Qiskit  65-qubit local simulator                  */
qiskit_manila_simulator       /**< Qiskit   5-qubit local simulator                  */
qiskit_melbourne_simulator    /**< Qiskit  15-qubit local simulator                  */
qiskit_montreal_simulator     /**< Qiskit  27-qubit local simulator                  */
qiskit_mumbai_simulator       /**< Qiskit  27-qubit local simulator                  */
qiskit_nairobi_simulator      /**< Qiskit   7-qubit local simulator                  */
qiskit_ourense_simulator      /**< Qiskit   5-qubit local simulator                  */
qiskit_paris_simulator        /**< Qiskit  27-qubit local simulator                  */
qiskit_peekskill_simulator    /**< Qiskit  27-qubit local simulator                  */
qiskit_poughkeepsie_simulator /**< Qiskit  20-qubit local simulator                  */
qiskit_quito_simulator        /**< Qiskit   5-qubit local simulator                  */
qiskit_rochester_simulator    /**< Qiskit  53-qubit local simulator                  */
qiskit_rome_simulator         /**< Qiskit   5-qubit local simulator                  */
qiskit_rueschlikon_simulator  /**< Qiskit  16-qubit local simulator                  */
qiskit_santiago_simulator     /**< Qiskit   5-qubit local simulator                  */
qiskit_singapore_simulator    /**< Qiskit  20-qubit local simulator                  */
qiskit_sydney_simulator       /**< Qiskit  27-qubit local simulator                  */
qiskit_tenerife_simulator     /**< Qiskit   5-qubit local simulator                  */
qiskit_tokyo_simulator        /**< Qiskit  20-qubit local simulator                  */
qiskit_toronto_simulator      /**< Qiskit  27-qubit local simulator                  */
qiskit_valencia_simulator     /**< Qiskit   5-qubit local simulator                  */
qiskit_vigo_simulator         /**< Qiskit   5-qubit local simulator                  */
qiskit_yorktown_simulator     /**< Qiskit   5-qubit local simulator                  */
qiskit_washington_simulator   /**< Qiskit 127-qubit local simulator                  */
qiskit_perth_simulator        /**< Qiskit   7-qubit local simulator                  */

qiskit_pulse_simulator       /**< Qiskit pulse local simulator                      */
qiskit_qasm_simulator        /**< Qiskit universal local simulator                  */
qiskit_statevector_simulator /**< Qiskit statevector local simulator                */
qiskit_unitary_simulator     /**< Qiskit density matrix local simulator             */

qiskit_aer_density_matrix_simulator       /**< Qiskit Aer density matrix local simulator         */
qiskit_aer_extended_stabilizer_simulator  /**< Qiskit Aer extended stabilizer local simulator    */
qiskit_aer_matrix_product_state_simulator /**< Qiskit Aer matrix product state local simulator   */
qiskit_aer_simulator                      /**< Qiskit Aer local simulator                        */
qiskit_aer_stabilizer_simulator           /**< Qiskit Aer stabilizer local simulator             */
qiskit_aer_statevector_simulator          /**< Qiskit Aer statevector local simulator            */
qiskit_aer_superop_simulator              /**< Qiskit Aer superop local simulator                */
qiskit_aer_unitary_simulator              /**< Qiskit Aer unitary local simulator                */

IBMQ

This class executes quantum circuits remotely on physical quantum devices made accessible through IBM’s Quantum Experience cloud services. It adopts the OpenQASM v2.0 quantum assembly language: IBMQ Website

Available QDevices in LibKet:

// IBM-Q Experience
ibmq_almaden_simulator      /**< IBM-Q  20-qubit remote simulator                  */
ibmq_armonk_simulator       /**< IBM-Q   1-qubit remote simulator                  */
ibmq_athens_simulator       /**< IBM-Q   5-qubit remote simulator                  */
ibmq_belem_simulator        /**< IBM-Q   5-qubit remote simulator                  */
ibmq_boeblingen_simulator   /**< IBM-Q  20-qubit remote simulator                  */
ibmq_bogota_simulator       /**< IBM-Q   5-qubit remote simulator                  */
ibmq_brooklyn_simulator     /**< IBM-Q  65-qubit remote simulator                  */
ibmq_burlington_simulator   /**< IBM-Q   5-qubit remote simulator                  */
ibmq_cairo_simulator        /**< IBM-Q  27-qubit remote simulator                  */
ibmq_cambridge_simulator    /**< IBM-Q  28-qubit remote simulator                  */
ibmq_casablanca_simulator   /**< IBM-Q   7-qubit remote simulator                  */
ibmq_dublin_simulator       /**< IBM-Q  27-qubit remote simulator                  */
ibmq_essex_simulator        /**< IBM-Q   5-qubit remote simulator                  */
ibmq_guadalupe_simulator    /**< IBM-Q  16-qubit remote simulator                  */
ibmq_hanoi_simulator        /**< IBM-Q  27-qubit remote simulator                  */
ibmq_jakarta_simulator      /**< IBM-Q   7-qubit remote simulator                  */
ibmq_johannesburg_simulator /**< IBM-Q  20-qubit remote simulator                  */
ibmq_kolkata_simulator      /**< IBM-Q  27-qubit remote simulator                  */
ibmq_lagos_simulator        /**< IBM-Q   7-qubit remote simulator                  */
ibmq_lima_simulator         /**< IBM-Q   5-qubit remote simulator                  */
ibmq_london_simulator       /**< IBM-Q   5-qubit remote simulator                  */
ibmq_manhattan_simulator    /**< IBM-Q  65-qubit remote simulator                  */
ibmq_manila_simulator       /**< IBM-Q   5-qubit remote simulator                  */
ibmq_melbourne_simulator    /**< IBM-Q  15-qubit remote simulator                  */
ibmq_montreal_simulator     /**< IBM-Q  27-qubit remote simulator                  */
ibmq_mumbai_simulator       /**< IBM-Q  27-qubit remote simulator                  */
ibmq_nairobi_simulator      /**< IBM-Q   7-qubit remote simulator                  */
ibmq_ourense_simulator      /**< IBM-Q   5-qubit remote simulator                  */
ibmq_paris_simulator        /**< IBM-Q  27-qubit remote simulator                  */
ibmq_peekskill_simulator    /**< IBM-Q  27-qubit remote simulator                  */
ibmq_poughkeepsie_simulator /**< IBM-Q  20-qubit remote simulator                  */
ibmq_quito_simulator        /**< IBM-Q   5-qubit remote simulator                  */
ibmq_rochester_simulator    /**< IBM-Q  53-qubit remote simulator                  */
ibmq_rome_simulator         /**< IBM-Q   5-qubit remote simulator                  */
ibmq_rueschlikon_simulator  /**< IBM-Q  16-qubit remote simulator                  */
ibmq_santiago_simulator     /**< IBM-Q   5-qubit remote simulator                  */
ibmq_singapore_simulator    /**< IBM-Q  20-qubit remote simulator                  */
ibmq_sydney_simulator       /**< IBM-Q  27-qubit remote simulator                  */
ibmq_tenerife_simulator     /**< IBM-Q   5-qubit remote simulator                  */
ibmq_tokyo_simulator        /**< IBM-Q  20-qubit remote simulator                  */
ibmq_toronto_simulator      /**< IBM-Q  27-qubit remote simulator                  */
ibmq_valencia_simulator     /**< IBM-Q   5-qubit remote simulator                  */
ibmq_vigo_simulator         /**< IBM-Q   5-qubit remote simulator                  */
ibmq_yorktown_simulator     /**< IBM-Q   5-qubit remote simulator                  */
ibmq_washington_simulator   /**< IBM-Q 127-qubit remote simulator                  */
ibmq_perth_simulator        /**< IBM-Q   7-qubit remote simulator                  */

ibmq_qasm_simulator         /**< IBM-Q universal remote simulator                  */

ibmq_almaden                /**< IBM-Q  20-qubit processor                         */
ibmq_armonk                 /**< IBM-Q   1-qubit processor                         */
ibmq_athens                 /**< IBM-Q   5-qubit processor                         */
ibmq_belem                  /**< IBM-Q   5-qubit processor                         */
ibmq_boeblingen             /**< IBM-Q  20-qubit processor                         */
ibmq_bogota                 /**< IBM-Q   5-qubit processor                         */
ibmq_brooklyn               /**< IBM-Q  65-qubit processor                         */
ibmq_cairo                  /**< IBM-Q  27-qubit processor                         */
ibmq_burlington             /**< IBM-Q   5-qubit processor                         */
ibmq_cambridge              /**< IBM-Q  28-qubit processor                         */
ibmq_casablanca             /**< IBM-Q   7-qubit processor                         */
ibmq_dublin                 /**< IBM-Q  27-qubit processor                         */
ibmq_essex                  /**< IBM-Q   5-qubit processor                         */
ibmq_guadalupe              /**< IBM-Q  16-qubit processor                         */
ibmq_hanoi                  /**< IBM-Q  27-qubit processor                         */
ibmq_jakarta                /**< IBM-Q   7-qubit processor                         */
ibmq_johannesburg           /**< IBM-Q  20-qubit processor                         */
ibmq_kolkata                /**< IBM-Q  27-qubit processor                         */
ibmq_lagos                  /**< IBM-Q   7-qubit processor                         */
ibmq_lima                   /**< IBM-Q   5-qubit processor                         */
ibmq_london                 /**< IBM-Q   5-qubit processor                         */
ibmq_manhattan              /**< IBM-Q  65-qubit processor                         */
ibmq_manila                 /**< IBM-Q   5-qubit processor                         */
ibmq_melbourne              /**< IBM-Q  15-qubit processor                         */
ibmq_montreal               /**< IBM-Q  27-qubit processor                         */
ibmq_mumbai                 /**< IBM-Q  27-qubit processor                         */
ibmq_nairobi                /**< IBM-Q   7-qubit processor                         */
ibmq_ourense                /**< IBM-Q   5-qubit processor                         */
ibmq_paris                  /**< IBM-Q  27-qubit processor                         */
ibmq_peekskill              /**< IBM-Q  27-qubit processor                         */
ibmq_poughkeepsie           /**< IBM-Q  20-qubit processor                         */
ibmq_quito                  /**< IBM-Q   5-qubit processor                         */
ibmq_rochester              /**< IBM-Q  53-qubit processor                         */
ibmq_rome                   /**< IBM-Q   5-qubit processor                         */
ibmq_rueschlikon            /**< IBM-Q  16-qubit processor                         */
ibmq_santiago               /**< IBM-Q   5-qubit processor                         */
ibmq_singapore              /**< IBM-Q  20-qubit processor                         */
ibmq_sydney                 /**< IBM-Q  27-qubit processor                         */
ibmq_tenerife               /**< IBM-Q   5-qubit processor                         */
ibmq_tokyo                  /**< IBM-Q  20-qubit processor                         */
ibmq_toronto                /**< IBM-Q  27-qubit processor                         */
ibmq_valencia               /**< IBM-Q   5-qubit processor                         */
ibmq_vigo                   /**< IBM-Q   5-qubit processor                         */
ibmq_yorktown               /**< IBM-Q   5-qubit processor                         */
ibmq_washington             /**< IBM-Q 127-qubit processor                         */
ibmq_perth                  /**< IBM-Q   7-qubit processor                         */

Quantum Inspire

This class executes quantum circuits remotely on the Quantum-Inspire simulator made accessible through QuTech’s Quantum-Inspire cloud services. It adopts the commonQASM v1.0 quantum assembly language. The goal of Quantum Inspire is to provide users access to various technologies to perform quantum computations and insights in principles of quantum computing and access to the community: Quantum Inpsire Website

Available QDevices in LibKet:

qi_26_simulator  /**< Quantum Inspire 26-qubit simulator                */
qi_34_simulator  /**< Quantum Inspire 34-qubit simulator                */
qi_spin2         /**< Quantum Inspire spin-2 processor (2 qubits)       */
qi_starmon5      /**< Quantum Inspire starmon-5 processor (5 qubits)    */

Rigetti

This class executes quantum circuits remotely on physical quantum devices made accessible through Rigetti’s Quantum Cloud Service (QCS). It adopts Rigetti’s Quantum Instruction Language. Rigetti builds quantum computers and the superconducting quantum processors that power them: Rigetti Website

Available QDevices in LibKet:

rigetti_aspen_8_simulator   /**< Rigetti Aspen-8 simulator                         */
rigetti_aspen_9_simulator   /**< Rigetti Aspen-9 simulator                         */
rigetti_aspen_10_simulator  /**< Rigetti Aspen-10 simulator                        */
rigetti_9q_square_simulator /**< Rigetti 9Q-square simulator                       */
rigetti_aspen_8             /**< Rigetti Aspen-8 processor                         */
rigetti_aspen_9             /**< Rigetti Aspen-9 processor                         */
rigetti_aspen_10            /**< Rigetti Aspen-10 processor                        */

QuEST

The Quantum Exact Simulation Toolkit is a high performance simulator of quantum circuits, state-vectors and density matrices. QuEST implements multiple useful feathuers such as multithreading, GPU acceleration and distribution: QuEST Website

Available QDevices in LibKet:

quest   /**< QuEST simulator                                   */

QX

The QX Simulator is a universal quantum computer simulator developped at QuTech by Nader Khammassi. The QX allows quantum algorithm designers to simulate the execution of their quantum circuits on a quantum computer. It adopts a low-level quantum assembly language Quantum Code: QX Website

Available QDevices in LibKet:

qx    /**< QX simulator                                      */

OpenQL

This class compiles the quantum circuit using the OpenQL backend. It adopts the OpenQL quantum assembly language. OpenQL is a framework for high-level quantum programming in C++/Python. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language and the compiled micro-code for various target platforms: OpenQL website

Available QDevices in LibKet:

openql_cc_light_compiler     /**< OpenQL compiler for CC-Light                      */
openql_cc_light17_compiler   /**< OpenQL compiler for CC-Light17                    */
openql_qx_compiler           /**< OpenQL compiler for QX simulator                  */