# 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.

## Single Qubit Gates¶

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

### X Gate¶

The Pauli-X gate.

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

#### Syntax¶

Function: XGate

Parameters: None

{
"function": "XGate",
"function_params": {}
}

from classiq import Model, synthesize
from classiq.builtin_functions import XGate

model = Model()
x_params = XGate()
model.XGate(x_params)
quantum_program = synthesize(model.get_model())


## 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.

### RZ Gate¶

Rotation around the Z axis is by a given angle $$\varphi$$.

$\begin{split}{RZ(\varphi)} = \begin{pmatrix} {e^{-i\frac{\varphi}{2}}} & 0 \\ 0 & {e^{i\frac{\varphi}{2}}} \end{pmatrix}\end{split}$

#### Syntax¶

Function: RZGate

Parameters:

• phi: ParameterFloatType is the angle in a parameter type or a float.
{
"function": "RZGate",
"function_params": {"phi": 1.9},
}

from classiq import Model, synthesize
from classiq.builtin_functions import RZGate

model = Model()
rz_params = RZGate(phi=1.9)
model.RZGate(rz_params)
quantum_program = synthesize(model.get_model())


• RX: theta
• RY: theta
• RZ: phi

### 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}$

#### Syntax¶

Function: RGate

Parameters:

• theta: ParameterFloatType angle in a parameter type or a float.
• phi: ParameterFloatType angle in a parameter type or a float.
{
"function": "RGate",
"function_params": {"theta": 0.3, "phi": 1.4},
}

from classiq import Model, synthesize
from classiq.builtin_functions import RGate

model = Model()
r_params = RGate(theta=0.3, phi=1.4)
model.RGate(r_params)
quantum_program = synthesize(model.get_model())


### Phase Gate¶

Rotation about the Z axis by $$\lambda$$ with global phase of $$\lambda\2$$.

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

#### Syntax¶

Function: PhaseGate

Parameters:

• theta: ParameterFloatType is the angle in a parameter type or a float.
{
"function": "PhaseGate",
"function_params": {"theta": 0.8},
}

from classiq import Model, synthesize
from classiq.builtin_functions import PhaseGate

model = Model()
p_params = PhaseGate(theta=0.8)
model.PhaseGate(p_params)
quantum_program = synthesize(model.get_model())


## Double Qubits Rotation Gates¶

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

### RZZ Gate¶

$\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}$

#### Syntax¶

Function: RZZGate

Parameters:

• theta: ParameterFloatType is the angle in a parameter type or a float.
{
"function": "RZZGate",
"function_params": {
"theta": 0.5
}
}

from classiq import Model, synthesize
from classiq.builtin_functions import RZZGate

model = Model()
rzz_params = RZZGate(theta=0.5)
model.RZZGate(rzz_params)
quantum_program = synthesize(model.get_model())


## 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}$

#### Syntax¶

Function: CXGate

Parameters:

• ctrl_state: Optional[Union[str, PositiveOrZeroInt]] is the control state in decimal or as a bit string (e.g., ‘0’). If not specified, the control state is 1. The gate is performed if the state of the control qubits matches the control state.
{
"function": "CXGate",
"function_params": {
"ctrl_state": "0"
}
}

from classiq import Model, synthesize
from classiq.builtin_functions import CXGate

model = Model()
cx_params = CXGate(ctrl_state="0")
model.CXGate(cx_params)
quantum_program = synthesize(model.get_model())


## 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}$

#### Syntax¶

Function: CRXGate

Parameters:

• ctrl_state: Optional[Union[str, PositiveOrZeroInt]] is the control state in decimal or as a bit string (e.g., ‘0’). If not specified, the control state is 1. The gate is performed if the state of the control qubits matches the control state.
• theta: ParameterFloatType is the angle in a parameter type or a float.
{
"function": "CRXGate",
"function_params": {
"ctrl_state": "0",
"theta": 1.5
}
}

from classiq import Model, synthesize
from classiq.builtin_functions import CRXGate

model = Model()
crx_params = CRXGate(ctrl_state="0", theta=1.5)
model.CRXGate(crx_params)
quantum_program = synthesize(model.get_model())


## 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}$

#### Syntax¶

Function: SwapGate

Parameters: None

{
"function": "SwapGate",
"function_params": {}
}

from classiq import Model, synthesize
from classiq.builtin_functions import SwapGate

model = Model()
swap_params = SwapGate()
model.SwapGate(swap_params)
quantum_program = synthesize(model.get_model())


## Full Examples¶

This example shows a circuit built with several standard gates, both controlled and uncontrolled.

{
"functions": [
{
"name": "main",
"body": [
{
"function": "CCXGate",
"function_params": {},
"outputs": {"CTRL": "ccx_ctrl_out", "TARGET": "ccx_target_out"}
},
{
"function": "RZGate",
"function_params": {"phi": 1.9},
"inputs": "ccx_target_out"
},
{
"function": "SwapGate",
"function_params": {},
"inputs": "ccx_ctrl_out"
}
]
}
]
}

from classiq import Model, synthesize, show, set_constraints
from classiq.builtin_functions import CCXGate, SwapGate, RZGate
from classiq.model import Constraints

model = Model()

ccx_params = CCXGate()
ccx_out = model.CCXGate(ccx_params)
ccx_target_out = ccx_out["TARGET"]
ccx_ctrl_out = ccx_out["CTRL"]

rz_params = RZGate(phi=1.9)
model.RZGate(rz_params, in_wires={"TARGET": ccx_target_out})

swap_params = SwapGate()
model.SwapGate(swap_params, in_wires={"TARGET": ccx_ctrl_out})

serialized_model = model.get_model()
constraints = Constraints(max_width=4, max_depth=50)
serialized_model = set_constraints(serialized_model, constraints)

quantum_program = synthesize(model.get_model())

show(quantum_program)


This example include register slicing and concatenation on standard gates.

{
"functions": [
{
"name": "main",
"port_declarations": {
"IN": {
"name": "IN",
"size": {
"expr": "1"
},
"direction": "input"
}
},
"body": [
{
"function": "Identity",
"function_params": {
"arguments": [
{
"name": "reg",
"size": 2,
"bounds": [
0.0,
3.0
]
}
]
},
"inputs": {
"reg": "IN_in"
},
"outputs": {
"reg[0]": "reg_OUT_0",
"reg[1]": "reg_OUT_1"
}
},
{
"function": "CXGate",
"function_params": {},
"inputs": {
"TARGET": "reg_OUT_0"
},
"outputs": {
"CTRL": "cx_ctrl_out"
}
},
{
"function": "SwapGate",
"function_params": {},
"inputs": {
"TARGET[0]": "cx_ctrl_out",
"TARGET[1]": "reg_OUT_1"
}
}
]
}
]
}

from classiq.builtin_functions import CXGate, SwapGate
from classiq import Model, QReg, synthesize

model = Model()

inputs = model.create_inputs(inputs={"reg": QReg[2]})

cx_params = CXGate()
cx_out = model.CXGate(cx_params, in_wires={"TARGET": inputs["reg"][0]})

swap_params = SwapGate()
swap_input = QReg.concat(cx_out["CTRL"], inputs["reg"][1])
model.SwapGate(swap_params, in_wires={"TARGET": swap_input})
quantum_program = synthesize(model.get_model())


## Parametrized Rotations¶

Rotation gates can be performed on parameters. See Parameters.