Standard Gates¶
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.
from classiq import X
@qfunc
def main():
q = QBit("q")
allocate(1, q)
X(q)
qmod = create_model(main)
write_qmod(qmod, "X_example")
qprog = synthesize(qmod)
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
:QParam[float]
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_example")
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
:QParam[float]
phi
:QParam[float]
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_example")
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
:QParam[float]
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_example")
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
:QParam[float]
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_example")
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_example")
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
:QParam[float]
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_example")
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_example")
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
:QParam[float]
phi
:QParam[float]
lam
:QParam[float]
gam
:QParam[float]
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_example")
qprog = synthesize(qmod)