Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
The Classiq platform provides many standard gates. Some key standard gates are shown here in detail.
All gates are covered in the reference manual.
from classiq import *

Single Qubit Gates

An example is given for XX gate. The gates II, XX, YY, ZZ, HH, TT are used in the same way.

For example: X

Function: X Arguments:
  • target: QBit
@qfunc
def main(q: Output[QBit]):
    allocate(q)

    X(q)


qmod = create_model(main)
qprog = synthesize(qmod)

Single Qubit Rotation Gates

An example is given for RZRZ gate. The gates RXRX, RYRY, RZRZ 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

RZ(θ)=(eiθ200eiθ2)\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
@qfunc
def main(q: Output[QBit]):
    allocate(q)

    theta = 1.9
    RZ(theta, q)


qmod = create_model(main)
qprog = synthesize(qmod)

R Gate

Rotation by θ\theta around the cos(ϕ)X+sin(ϕ)Ycos(\phi)X + sin(\phi)Y axis. R(θ,ϕ)=(cos(θ2)ieiϕsin(θ2)ieiϕsin(θ2)cos(θ2))\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
@qfunc
def main(q: Output[QBit]):
    allocate(q)

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


qmod = create_model(main)
qprog = synthesize(qmod)

Phase Gate

Rotation about the Z axis by λ\lambda with global phase of λ2\frac{\lambda}{2}. PHASE(λ)=(100eiλ)\begin{split}PHASE(\lambda) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\lambda} \end{pmatrix}\end{split} Parameters:
  • theta: CReal
  • target: QBit
@qfunc
def main(q: Output[QBit]):
    allocate(q)

    theta = 1
    PHASE(theta, q)


qmod = create_model(main)
qprog = synthesize(qmod)

Double Qubits Rotation Gates

An example is given for RZZRZZ gate. The gates RXXRXX, RYYRYY, RZZRZZ are used in the same way.

RZZ Gate

Rotation about ZZ. RZZ(θ)=(eiθ20000eiθ20000eiθ20000eiθ2)\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]
@qfunc
def main(q: Output[QArray]):
    allocate(2, q)

    theta = 1
    RZZ(theta, q)


qmod = create_model(main)
qprog = synthesize(qmod)

Controlled Gates

An example is given for CXCX gate. The gates CXCX, CYCY, CZCZ, CHCH, CSXCSX, CCXCCX are used in a similar way. In CCXCCX Gate the ctrl_state parameter receives a value suitable for 2 control qubits. for example: "01".

CX Gate

The Controlled XX gate. Applies XX Gate on the target qubit, based on the state of the control qubit (by default if the controlled state is 1|1\rangle). CX=(1000010000010010)\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
@qfunc
def main(q_target: Output[QBit], q_control: Output[QBit]):
    allocate(q_target)

    allocate(q_control)

    CX(q_control, q_target)


qmod = create_model(main)
qprog = synthesize(qmod)

Controlled Rotations

An example is given for CRXCRX gate. The gates CRXCRX, CRYCRY, CRZCRZ, CPhase are used in the same way.

CRX Gate

Controlled rotation around the X axis. CRX(θ)=(1000010000cos(θ2)isin(θ2)00isin(θ2)cos(θ2))\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
@qfunc
def main(q_target: Output[QBit], q_control: Output[QBit]):
    allocate(q_target)

    allocate(q_control)

    theta = 1
    CRX(theta, q_control, q_target)


qmod = create_model(main)
qprog = synthesize(qmod)

Swap Gate

Swaps between two qubit states. SWAP=(1000001001000001)\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
@qfunc
def main(q1: Output[QBit], q2: Output[QBit]):
    allocate(q1)

    allocate(q2)

    SWAP(q1, q2)


qmod = create_model(main)
qprog = synthesize(qmod)

U Gate

The single-qubit gate applies phase and rotation with three Euler angles. Matrix representation: U(γ,ϕ,θ,λ)=eiγ(cos(θ2)eiλsin(θ2)eiϕsin(θ2)ei(ϕ+λ)cos(θ2))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
@qfunc
def main(q: Output[QBit]):
    allocate(q)

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


qmod = create_model(main)
qprog = synthesize(qmod)