Classical NOT Logic Gates with Quantum Circuit using Qiskit in Python

Quantum computing is an emerging field that utilizes the principles of quantum mechanics to perform computations more efficiently than classical computers. Qiskit, a powerful open-source framework, provides a user-friendly platform to develop and execute quantum programs in Python. In this tutorial, we will explore how to implement classical NOT logic gates using quantum circuits with Qiskit.

Classical NOT Logic Gate

The classical NOT gate, also known as an inverter, is a fundamental logic gate that takes a single input and produces the logical complement of that input. If the input is 0, the output is 1, and vice versa.

The truth table for the classical NOT gate is as follows:

INPUT (A) OUTPUT (NOT A)
0 1
1 0

Quantum NOT Gate (X Gate)

In quantum computing, the equivalent of the classical NOT gate is the X gate (also called the Pauli-X gate). It flips the state of a qubit from |0? to |1? or from |1? to |0?.

Basic Quantum NOT Implementation

Here's how to create a simple quantum circuit that applies a NOT operation to a qubit:

from qiskit import QuantumCircuit

# Create a quantum circuit with one qubit
qc = QuantumCircuit(1)

# Apply the X gate (quantum NOT) to the qubit
qc.x(0)

# Draw the circuit
print(qc.draw())
     ?????
q_0: ? X ?
     ?????

How It Works

  • QuantumCircuit(1) creates a quantum circuit with one qubit

  • qc.x(0) applies the X gate to qubit at index 0

  • qc.draw() generates a visual representation of the circuit

Complete NOT Gate with Measurement

To observe the results, we need to add measurement to our quantum circuit:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

# Create a quantum circuit with one qubit and one classical bit
qc = QuantumCircuit(1, 1)

# Initialize the qubit to |0? state (optional, qubits start at |0?)
# qc.reset(0)

# Apply the X gate to flip the qubit
qc.x(0)

# Measure the qubit and store result in classical bit
qc.measure(0, 0)

# Draw the circuit
print("Quantum Circuit:")
print(qc.draw())

# Show the state before measurement
qc_no_measure = QuantumCircuit(1)
qc_no_measure.x(0)
state = Statevector.from_instruction(qc_no_measure)
print(f"\nState after X gate: {state}")
Quantum Circuit:
     ????? ? ???
q_0: ? X ?????M?
     ????? ? ???
c_0: ????????????

State after X gate: Statevector([0.+0.j, 1.+0.j],
            dims=(2,))

Testing Both Input States

Let's create circuits to test both possible input states (|0? and |1?):

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

# Test NOT gate with input |0?
print("NOT gate with input |0?:")
qc1 = QuantumCircuit(1, 1)
qc1.x(0)  # Apply NOT to |0?
qc1.measure(0, 0)
print(qc1.draw())

# Test NOT gate with input |1? 
print("\nNOT gate with input |1?:")
qc2 = QuantumCircuit(1, 1)
qc2.x(0)  # First X to create |1?
qc2.x(0)  # Second X to apply NOT to |1?
qc2.measure(0, 0)
print(qc2.draw())

# Show the states
print("\nState verification:")
# |0? ? X ? |1?
qc_test1 = QuantumCircuit(1)
qc_test1.x(0)
state1 = Statevector.from_instruction(qc_test1)
print(f"|0? after NOT: {state1}")

# |1? ? X ? |0?  
qc_test2 = QuantumCircuit(1)
qc_test2.x(0)  # Create |1?
qc_test2.x(0)  # Apply NOT
state2 = Statevector.from_instruction(qc_test2)
print(f"|1? after NOT: {state2}")
NOT gate with input |0?:
     ????? ? ???
q_0: ? X ?????M?
     ????? ? ???
c_0: ????????????

NOT gate with input |1?:
     ?????????? ? ???
q_0: ? X ?? X ?????M?
     ?????????? ? ???
c_0: ?????????????????

State verification:
|0? after NOT: Statevector([0.+0.j, 1.+0.j],
            dims=(2,))
|1? after NOT: Statevector([1.+0.j, 0.+0.j],
            dims=(2,))

Key Points

  • The quantum X gate is equivalent to the classical NOT gate

  • X gate flips |0? to |1? and |1? to |0?

  • Qubits start in the |0? state by default

  • Measurement collapses the quantum state to a classical bit

  • Multiple X gates can be chained (two X gates cancel each other)

Conclusion

The quantum X gate perfectly replicates classical NOT logic behavior, demonstrating how quantum circuits can implement classical operations. This foundation enables building more complex quantum algorithms that leverage both classical logic and quantum properties.

Updated on: 2026-03-27T14:19:22+05:30

602 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements