OpenQASM qelib1.inc

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 NameGate in OpenQASM 2Brief Description
U3 Gateu33-parameter 2-pulse single qubit gate.
U2 Gateu22-parameter 1-pulse single qubit gate
U1 Gateu11-parameter 0-pulse single qubit gate
CX Gatecxcontrolled-NOT. Equivalent to CX Gate in OpenQASM.
Id or I GateidIdentity Gate
U0 Gateu0Identity Gate
U GateuGeneric single qubit gate
P GatepPhase Gate
X GatexBit Flip Gate or NOT Gate
Y GateyBit and Phase Flip Gate
Z GatezPhase Flip Gate
H GatehHadamard Gate
S GatesThe S Gate. Also known as Square-root of Z Gate.
S – Dagger GatesdgThe Sdg Gate, inverse of S Gate.
T Gate tThe T Gate. Also known as fourth-root of Z Gate.
T – Dagger GatetdgThe Tdg Gate, inverse of T Gate.
RX GaterxThe RX Gate, performs rotation about X axis on Bloch Sphere.
RY GateryThe RY Gate, performs rotation about Y axis on Bloch Sphere.
RZ GaterzThe RZ Gate, performs rotation about Z axis on Bloch Sphere.
SX GatesxThe SX Gate. Also known as the Square-root of X Gate.
SX – Dagger GatesxdgThe SXdg Gate, inverse of SX Gate.
CZ GateczThe CZ Gate or controlled-Phase change Gate.
CY GatecyThe CY Gate or controlled-Y Gate.
Swap GateswapSwaps the state of two Qubits.
CH GatechThe CH or controlled-H Gate.
C3 or Toffoli GateccxThe CC-NOT Gate or Toffoli Gate.
CSwap or Fredkin GatecswapThe CSwap or controlled Swap Gate.
CRX GatecrxThe Controlled RX Gate.
CRY GatecryThe Controlled RY Gate.
CRZ GatecrzThe Controlled RZ Gate.
CP Gatecu1The Controlled Phase Rotation
CP GatecpThe Controlled Phase Rotation
CU Gatecu3The Controlled U3 Gate
CSX GatecsxThe Controlled SX Gate.
CU GatecuThe Controlled U3 Gate
RXX GaterxxTwo Qubit XX Rotation
RZZ GaterzzTwo Qubit ZZ Rotation
RCCX GaterccxThe relative phase CCX Gate.
RC3X Gaterc3xThe relative-phase 3-controlled X gate.
C3X Gatec3xThe 3-controlled X gate.
C3SX Gatec3sqrtxThe 3-controlled SX gate
C4X Gatec4x4-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";