OpenQASM provides built-in support for only two Quantum Gates, the CX or CNOT gate and the U Gate. Though the combination of these Gates can be used to create any Quantum Gate, it is not always convenient to perform operations using these two Quantum Gates. Therefore, it makes sense to create standard Quantum Gates by using these Gates. The qelib1.inc file is a commonly used file when writing Quantum Algorithms in OpenQASM because it contains definitions of various standard Quantum Gates. In this chapter of the OpenQASM Tutorial, you will go through the Quantum Gates described in the qelib1.inc file.
Note– Not all of the Quantum Gates might be useful to you. In fact, many won’t be useful to you. The below section is just for reference and feel free to skip parts of it.
Quantum Gates in qelib1.inc File
The following table covers the Quantum Gates which are included in the qelib1.inc file.
Gate Name | Gate in OpenQASM 2 | Brief Description |
---|---|---|
U3 Gate | u3 | 3-parameter 2-pulse single qubit gate. |
U2 Gate | u2 | 2-parameter 1-pulse single qubit gate |
U1 Gate | u1 | 1-parameter 0-pulse single qubit gate |
CX Gate | cx | controlled-NOT. Equivalent to CX Gate in OpenQASM. |
Id or I Gate | id | Identity Gate |
U0 Gate | u0 | Identity Gate |
U Gate | u | Generic single qubit gate |
P Gate | p | Phase Gate |
X Gate | x | Bit Flip Gate or NOT Gate |
Y Gate | y | Bit and Phase Flip Gate |
Z Gate | z | Phase Flip Gate |
H Gate | h | Hadamard Gate |
S Gate | s | The S Gate. Also known as Square-root of Z Gate. |
S – Dagger Gate | sdg | The Sdg Gate, inverse of S Gate. |
T Gate | t | The T Gate. Also known as fourth-root of Z Gate. |
T – Dagger Gate | tdg | The Tdg Gate, inverse of T Gate. |
RX Gate | rx | The RX Gate, performs rotation about X axis on Bloch Sphere. |
RY Gate | ry | The RY Gate, performs rotation about Y axis on Bloch Sphere. |
RZ Gate | rz | The RZ Gate, performs rotation about Z axis on Bloch Sphere. |
SX Gate | sx | The SX Gate. Also known as the Square-root of X Gate. |
SX – Dagger Gate | sxdg | The SXdg Gate, inverse of SX Gate. |
CZ Gate | cz | The CZ Gate or controlled-Phase change Gate. |
CY Gate | cy | The CY Gate or controlled-Y Gate. |
Swap Gate | swap | Swaps the state of two Qubits. |
CH Gate | ch | The CH or controlled-H Gate. |
C3 or Toffoli Gate | ccx | The CC-NOT Gate or Toffoli Gate. |
CSwap or Fredkin Gate | cswap | The CSwap or controlled Swap Gate. |
CRX Gate | crx | The Controlled RX Gate. |
CRY Gate | cry | The Controlled RY Gate. |
CRZ Gate | crz | The Controlled RZ Gate. |
CP Gate | cu1 | The Controlled Phase Rotation |
CP Gate | cp | The Controlled Phase Rotation |
CU Gate | cu3 | The Controlled U3 Gate |
CSX Gate | csx | The Controlled SX Gate. |
CU Gate | cu | The Controlled U3 Gate |
RXX Gate | rxx | Two Qubit XX Rotation |
RZZ Gate | rzz | Two Qubit ZZ Rotation |
RCCX Gate | rccx | The relative phase CCX Gate. |
RC3X Gate | rc3x | The relative-phase 3-controlled X gate. |
C3X Gate | c3x | The 3-controlled X gate. |
C3SX Gate | c3sqrtx | The 3-controlled SX gate |
C4X Gate | c4x | 4-controlled X gate |
Including the qelib1.inc File
The qelib1.inc file can be parsed inside another OpenQASM file by using the following syntax-
include "qelib1.inc";