- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 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 the concept of classical NOT logic gates implemented with quantum circuits using 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. In other words, 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 Circuit Implementation

Here are two code examples that show how to implement the NOT gate in quantum computing using Qiskit.

### Example 1

Consider the code shown below.

from qiskit import QuantumCircuit # Create a quantum circuit with one qubit qc = QuantumCircuit(1) # Apply the X gate to the qubit qc.x(0) # Draw the circuit qc.draw() # Print the output of the draw function print(qc.draw())

### Explanation

Import the necessary

**QuantumCircuit**class from the**qiskit**module.Create a quantum circuit with one qubit,

**qc = QuantumCircuit(1)**The

**QuantumCircuit()**function is used to create a quantum circuit. Here, we pass 1 as the argument to specify that we want to create a circuit with one qubit.Apply the X gate (quantum NOT gate) to the qubit,

**qc.x(0)**The

**x()**method is used to apply the X gate (quantum NOT gate) to the qubit at index 0. This gate flips the state of the qubit from 0 to 1 or vice versa.Draw the circuit,

**qc.draw()**. The**draw()**method is used to visualize the quantum circuit. It generates a textual representation of the circuit.Print the output of the draw function,

**print(qc.draw())**. The**print()**function is used to display the textual representation of the circuit generated by the**draw()**method.

### Output

The output of the print() statement will show the textual representation of the quantum circuit, which depicts the application of the X gate to the qubit. This is how it will appear −

The circuit diagram will include labels for the qubits, gates, and their connections.

### Example 2

Here is another example of how you can implement the NOT gate in quantum computing using Qiskit. Consider the code shown below.

from qiskit import QuantumCircuit # Create a quantum circuit with one qubit and one classical bit qc = QuantumCircuit(1, 1) # Initialize the qubit to the state |0⟩ qc.reset(0) # Apply the X gate to the qubit qc.x(0) # Measure the qubit qc.measure(0, 0) # Draw the circuit print(qc.draw())

### Explanation

Import the necessary

**QuantumCircuit**class from the**qiskit**module.Create a quantum circuit with one qubit and one classical bit.

**qc = QuantumCircuit(1, 1)**The

**QuantumCircuit()**function is used to create a quantum circuit. Here, we pass 1 as the first argument to specify that we want to create a circuit with one qubit, and 1 as the second argument to indicate that we want to allocate one classical bit to store measurement results.Initialize the qubit to the state |0⟩. The

**reset()**method is used to set the qubit at index 0 to the state |0⟩. This operation resets the qubit to its initial state.Apply the X gate (quantum NOT gate) to the qubit,

**qc.x(0)**. The**x()**method is used to apply the X gate (quantum NOT gate) to the qubit at index 0. This gate flips the state of the qubit from 0 to 1 or vice versa.Measure the qubit and store the result in the classical bit. The

**measure()**method is used to measure the qubit at index 0. The first argument 0 indicates the index of the qubit to be measured, and the second argument 0 indicates the index of the classical bit where the measurement result will be stored.Draw the circuit. The

**draw()**method is used to visualize the quantum circuit. It generates a textual representation of the circuit.

### Output

The output of the **print()** statement will show the textual representation of the quantum circuit, which depicts the application of the X gate to the qubit. This is how it will appear −

The circuit diagram will include labels for the qubits, gates, and their connections.

## Conclusion

In this tutorial, we explored the concept of classical NOT logic gates implemented with quantum circuits using Qiskit in Python. By leveraging the power of quantum computing, we were able to simulate classical logic gates and observe their behavior.