Skip to content

Standard Gates

View on GitHub

The Classiq platform provides many standard gates. Some key standard gates are shown here in detail.
All gates are covered in the reference manual.

# Generic imports
from classiq import QArray, QBit, allocate, create_model, qfunc, synthesize, write_qmod

Single Qubit Gates

An example is given for \(X\) gate. The gates \(I\), \(X\), \(Y\), \(Z\), \(H\), \(T\) are used in the same way.

For example: X

Function: X

Arguments:

  • target: QBit
from classiq import X


@qfunc
def main():
    q = QBit("q")
    allocate(1, q)

    X(q)


qmod = create_model(main)
write_qmod(qmod, "X")
qprog = synthesize(qmod)

Single Qubit Rotation Gates

An example is given for \(RZ\) gate. The gates \(RX\), \(RY\), \(RZ\) are used in the same way except for parameter name.

Parameter names for different rotation gates

  • RX: theta

  • RY: theta

  • RZ: phi

For example: RZ

\[ \begin{split}RZ(\theta) = \begin{pmatrix} {e^{-i\frac{\theta}{2}}} & 0 \\ 0 & {e^{i\frac{\theta}{2}}} \\ \end{pmatrix}\end{split} \]

Function: RZ

Arguments:

  • theta: CReal

  • target: QBit

from classiq import RZ


@qfunc
def main():
    q = QBit("q")
    allocate(1, q)

    theta = 1.9
    RZ(theta, q)


qmod = create_model(main)
write_qmod(qmod, "RZ")
qprog = synthesize(qmod)

R Gate

Rotation by \(\theta\) around the \(cos(\phi)X + sin(\phi)Y\) axis.

$$ \begin{split}R(\theta, \phi) = \begin{pmatrix} cos(\frac{\theta}{2}) & -ie^{-i\phi}sin(\frac{\theta}{2}) \

-ie^{i\phi}sin(\frac{\theta}{2}) & cos(\frac{\theta}{2}) \ \end{pmatrix}\end{split} $$

Parameters:

  • theta: CReal

  • phi: CReal

  • target: QBit

from classiq import R


@qfunc
def main():
    q = QBit("q")
    allocate(1, q)

    theta = 1
    phi = 2
    R(theta, phi, q)


qmod = create_model(main)
write_qmod(qmod, "R")
qprog = synthesize(qmod)

Phase Gate

Rotation about the Z axis by \(\lambda\) with global phase of \(\frac{\lambda}{2}\).

\[\begin{split}X = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\lambda} \end{pmatrix}\end{split}\]

Parameters:

  • theta: CReal

  • target: QBit

from classiq import PHASE


@qfunc
def main():
    q = QBit("q")
    allocate(1, q)

    theta = 1
    PHASE(theta, q)


qmod = create_model(main)
write_qmod(qmod, "PHASE")
qprog = synthesize(qmod)

Double Qubits Rotation Gates

An example is given for \(RZZ\) gate. The gates \(RXX\), \(RYY\), \(RZZ\) are used in the same way.

RZZ Gate

Rotation about ZZ.

\[ \begin{split}RZZ(\theta) = \begin{pmatrix} {e^{-i\frac{\theta}{2}}} & 0 & 0 & 0 \\ 0 & {e^{i\frac{\theta}{2}}} & 0 & 0 \\ 0 & 0 & {e^{i\frac{\theta}{2}}} & 0 \\ 0 & 0 & 0 & {e^{-i\frac{\theta}{2}}} \\ \end{pmatrix}\end{split} \]

Parameters:

  • theta: CReal

  • target: QArray[QBit]

from classiq import RZZ


@qfunc
def main():
    q = QArray("q")
    allocate(2, q)

    theta = 1
    RZZ(theta, q)


qmod = create_model(main)
write_qmod(qmod, "RZZ")
qprog = synthesize(qmod)

Controlled Gates

An example is given for \(CX\) gate. The gates \(CX\), \(CY\), \(CZ\), \(CH\), \(CSX\), \(CCX\) are used in a similar way.

In \(CCX\) Gate the ctrl_state parameter receives a value suitable for 2 control qubits. for example: "01".

CX Gate

The Controlled \(X\) gate.

Applies \(X\) Gate on the target qubit, based on the state of the control qubit (by default if the controlled state is \(|1\rangle\)).

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

Parameters:

  • control: QBit

  • target: QBit

from classiq import CX


@qfunc
def main():
    q_target = QBit("q_t")
    allocate(1, q_target)

    q_control = QBit("q_c")
    allocate(1, q_control)

    CX(q_control, q_target)


qmod = create_model(main)
write_qmod(qmod, "CX")
qprog = synthesize(qmod)

Controlled Rotations

An example is given for \(CRX\) gate. The gates \(CRX\), \(CRY\), \(CRZ\), CPhase are used in the same way.

CRX Gate

Controlled rotation around the X axis.

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

Parameters:

  • theta: CReal

  • control: QBit

  • target: QBit

from classiq import CRX


@qfunc
def main():
    q_target = QBit("q_t")
    allocate(1, q_target)

    q_control = QBit("q_c")
    allocate(1, q_control)

    theta = 1
    CRX(theta, q_control, q_target)


qmod = create_model(main)
write_qmod(qmod, "CRX")
qprog = synthesize(qmod)

Swap Gate

Swaps between two qubit states.

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

Parameters:

  • qbit0: QBit

  • qbit1: QBit

from classiq import SWAP


@qfunc
def main():
    q1 = QBit("q1")
    allocate(1, q1)

    q2 = QBit("q2")
    allocate(1, q2)

    SWAP(q1, q2)


qmod = create_model(main)
write_qmod(qmod, "SWAP")
qprog = synthesize(qmod)

U Gate

The single-qubit gate applies phase and rotation with three Euler angles.

Matrix representation:

\[ U(\gamma,\phi,\theta,\lambda) = e^{i\gamma}\begin{pmatrix} \cos(\frac{\theta}{2}) & -e^{i\lambda}\sin(\frac{\theta}{2}) \\ e^{i\phi}\sin(\frac{\theta}{2}) & e^{i(\phi+\lambda)}\cos(\frac{\theta}{2}) \\ \end{pmatrix} \]

Parameters:

  • theta: CReal

  • phi: CReal

  • lam: CReal

  • gam: CReal

  • target: QBit

from classiq import U


@qfunc
def main():
    q = QBit("q")
    allocate(1, q)

    theta = 1
    phi = 2
    lam = 1.5
    gam = 1.1
    U(theta, phi, lam, gam, q)


qmod = create_model(main)
write_qmod(qmod, "U")
qprog = synthesize(qmod)