Qiskit: X Gate

The X Gate is one of the most important gates in Quantum Computing. It is often considered equivalent to the NOT Gate in Classical Computing. Like many other gates in Quantum Computing, X Gate is a Pauli Gate. Qiskit provides a method for applying X Gate on a Qubit. In this chapter of the Qiskit Tutorial, you will learn about X Gate and how to apply X Gate on a Qubit in Qiskit.


X Gate

The X Gate acts on a single Qubit. In terms of its effect on a state represented in terms of the standard basis pairs |0> and |1>, it maps the coefficient of |0> to |1>, and |1> to |0>. This is results in an exchange of probabilities of getting |0> and |1>. It is for this reason, that it considered the equivalent of a NOT gate.

Note– The X Gate is also known as Bit flip Gate.

Example

For a Qubit in state Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>, the application of X Gate will change the state of the Qubit to Ψ = sqrt(2/3) |0> + 1/sqrt(3) |1>.

Before the X Gate was applied to the Qubit, the probabilities of getting |0> and |1> were 1/3 and 2/3 respectively. After the X Gate was applied on the Qubit, the probabilities of getting |0> and |1> were 2/3 and 1/3 respectively. This is demonstrated in the table below-

Before applying X GateAfter applying X Gate
Probability of Getting 0 on measurement1/32/3
Probability of Getting 1 on measurement2/31/3

Notice how the probabilities of getting |0> and |1> were exchanged after the X Gate was applied on the Qubit.


X Gate: Bloch Sphere

The X Gate performs a rotation of 180° or π radians about the X-axis on the Bloch Sphere.

Example

In this example, we will look at how the application of X gate on the Qubit affects its representation on the Bloch Sphere. Remember how X Gate performs a rotation of 180° or π radians about the X-axis on the Bloch Sphere.

In the below figure, the X Gate is applied on a Qubit in the state Ψ = |0>, and the resulting state of the Qubit is Ψ = |1>.

Qiskit X Gate Effect
Applying X Gate on Qubits in state |0>

In the below figure, the X Gate is applied on a Qubit in the state Ψ = |i> and the resulting state of the Qubit is Ψ = |-i>.

Qiskit X Gate Effect
Applying X Gate on Qubits in state |i>

Note– Since X Gate performs rotation about the X-axis, it will have no effect on a vector that lies on the X-axis.


X Gate: Pauli Matrix

The X Gate in Quantum Computing is represented by the matrix X or σx

Pauli Matrix of X Gate

The resulting state of a Qubit after the application of X Gate can also be calculated by multiplying the Matrix for X Gate with the vector representing the state of the Qubit.

Example

In this example, we will apply the X gate to a Qubit, and calculate the resulting state by Multiplying it with the Pauli Matrix for X Gate.

Let the state of the Qubit be Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>

After Applying the X Gate, the resulting state of the Qubit can be calculated by-

Calculating result of X Gate applied on a Qubit

Similarly as before, the probability of getting |0> and |1> are reversed.


Inverse of X Gate

The X is its own inverse. Therefore, applying X Gate to the same Qubit twice will result in the original state of the Qubit.

Example

For a Qubit in state Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>, the application of X Gate will change the state of the Qubit to Ψ = sqrt(2/3) |0> + 1/sqrt(3) |1>.

After application of the X Gate again to the same Qubit, the resulting state of the Qubit will be Ψ = 1/sqrt(3) |0> + sqrt(2/3) |1>.

Since applying X Gate twice to the same Qubit results in the same state, X Gate is its own inverse.


X Gate in Qiskit

The X Gate in Qiskit can be applied to any Qubit by calling the x() method on the Quantum Circuit(an instance of QuantumCircuit class) and passing it an integer for the Qubit on which X Gate is to be applied.

Example

In this example, we will be applying X Gate on the first Qubit in the Quantum Circuit, which will contain 2 Qubits.

# Creating a Quantum Register with 2 Qubit
qr = qiskit.QuantumRegister(2)

# Creating a Quantum Circuit
circuit = QuantumCircuit(qr)

# Applying X Gate on the first Qubit
circuit.x(0)

# Drawing the Quantum Circuit
circuit.draw()

This will result in the following Quantum Circuit being drawn-

Notice that the X Gate is applied to the first Qubit. Also notice, that Qubits follow a 0 based indexing.