Hot Posts

6/recent/ticker-posts

Quantum Gates and Basic Operations in Qiskit: From Hadamard to CNOT - 2

⏳ Estimated Reading Time: 3 min






Introduction

In our previous article (Article -1), we covered the installation of Qiskit and basic quantum concepts. In this article, we will focus on the fundamental building blocks of quantum computers, namely quantum gates. We will learn how to apply these gates using Qiskit and how entanglement is created in two-qubit circuits.

What Are Quantum Gates?

Quantum gates are the processing units of quantum computers. Unlike classical logic gates, quantum gates can change or connect the state of qubits. Quantum gates utilize quantum properties like superposition and entanglement.

Importance

Quantum gates are indispensable for implementing quantum algorithms and harnessing the power of quantum computers. Without them, quantum computers would remain purely theoretical.

Basic Quantum Gates

a. Pauli Gates

X (NOT) Gate: The quantum version of the classical NOT gate. It flips a qubit's state (0 -> 1, 1 -> 0).
circuit.x(0) # Changes the state of the 0th qubit{codeBox}

Y Gate: Changes the state of a qubit around a different axis, affecting the qubit's phase.
circuit.y(0) # Applies the Y gate to the 0th qubit{codeBox}

Z Gate: Changes the phase of a qubit but keeps its state (0 or 1) the same.
circuit.z(0) # Changes the phase of the 0th qubit{codeBox}

b. Hadamard (H) Gate

The Hadamard gate puts a qubit into superposition, equalizing its chance of being in state 0 or 1.
circuit.h(0) # Puts the 0th qubit into superposition{codeBox}

c. CNOT (Controlled-NOT) Gate

The CNOT gate uses one control qubit and one target qubit. If the control qubit is 1, it flips the state of the target qubit. This is one of the basic ways to create entanglement.
circuit.cx(control_qubit, target_qubit) # Flips the target qubit's state if the control qubit is 1{codeBox}

Two-Qubit Circuits and Entanglement

Entanglement: Creates such a connection between two or more qubits that the state of one affects the other.
Example Circuit: An example of creating entanglement with two qubits:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit.primitives import StatevectorSampler
from qiskit.visualization import plot_histogram

# Creating a two-qubit circuit
circuit = QuantumCircuit(2, 2)

# Putting the first qubit into superposition
circuit.h(0)

# Creating entanglement with CNOT gate
circuit.cx(0, 1)

# Measuring the qubits
circuit.measure_all()

# Visualizing the circuit
circuit.draw('mpl')

# Running in a simulator
simulator = AerSimulator()
sampler = StatevectorSampler()

# Running the circuit - we provide the circuit in a list
job = sampler.run([circuit])
result = job.result()

# Getting results - for StatevectorSampler, results are directly in 'result'
counts = result[0].data.meas.get_counts() # 'result' is a list with results for each QuantumCircuit

# Visualizing the results
plot_histogram(counts){codeBox}

Visualization and Analysis


Kernel Output:

Circuit Diagram:

This circuit demonstrates that both qubits are connected due to entanglement.

From the histogram, you can see that both qubits are in the same state (00 or 11), which is evidence of entanglement.

Conclusion and Future Articles

In this article, we learned about basic quantum gates and how to use them with Qiskit. Entanglement is one of the fundamental concepts in quantum computing, and we've seen how it's created using these gates. In the next articles of the series, we will explore more complex quantum gates, algorithms, and quantum error correction techniques.

Resources:

If you have any questions or suggestions, please note them in the comments section below.{alertSuccess}

Post a Comment

0 Comments