Monday, December 8, 2025

thumbnail

Getting Started with Qiskit: Your First Quantum Program

 Getting Started with Qiskit: Your First Quantum Program


Qiskit is an open-source Python framework developed by IBM for writing quantum programs, simulating them, and running them on real quantum hardware.


This tutorial shows you how to:


Install Qiskit


Build and run your first quantum circuit


Visualize results


(Optional) Run on a real IBM Quantum device


Let’s begin!


๐Ÿ”ถ 1. Install Qiskit


Make sure Python ≥ 3.8 is installed.


Open a terminal and run:


pip install qiskit



To upgrade:


pip install --upgrade qiskit


๐Ÿ”ถ 2. Import Qiskit


In a Python script or Jupyter notebook:


from qiskit import QuantumCircuit, transpile

from qiskit.visualization import plot_histogram

from qiskit_aer import AerSimulator


๐Ÿ”ถ 3. Create Your First Quantum Circuit


We will create:


1 qubit


1 classical bit


Apply a Hadamard (H) gate → creates superposition


Measure the result


qc = QuantumCircuit(1, 1)


qc.h(0)          # Put qubit 0 into superposition

qc.measure(0, 0) # Measure into classical bit 0


qc.draw('mpl')



This circuit prepares a qubit in the state:


๐œ“

=

0

+

1

2

∣ฯˆ⟩=

2


∣0⟩+∣1⟩


๐Ÿ”ถ 4. Run the Circuit on a Simulator


We run the circuit on Qiskit's built-in simulator.


sim = AerSimulator()


compiled_circuit = transpile(qc, sim)

result = sim.run(compiled_circuit, shots=1024).result()


counts = result.get_counts()

print(counts)


Expected output:

{'0': 500, '1': 524}   # values vary



Results should be roughly 50% |0⟩ and 50% |1⟩ because the Hadamard gate creates equal superposition.


๐Ÿ”ถ 5. Visualize Results

plot_histogram(counts)



You'll see a bar graph with two bars of nearly equal height.


๐Ÿ”ถ 6. Try a More Interesting Circuit


Let’s create entanglement using two qubits:


qc2 = QuantumCircuit(2, 2)


qc2.h(0)       # superposition

qc2.cx(0, 1)   # CNOT: entangle qubits

qc2.measure([0, 1], [0, 1])


qc2.draw('mpl')



Running this on the simulator produces outputs like:


{'00': 520, '11': 504}



Notice only 00 and 11 appear.

This means the qubits are entangled.


๐Ÿ”ถ 7. (Optional) Run on Real IBM Quantum Hardware

Step 1: Install IBM Quantum provider

pip install qiskit-ibm-runtime


Step 2: Save your IBM Quantum API token


Get a token from https://quantum.ibm.com

 → Account → API token.


Run:


from qiskit_ibm_runtime import QiskitRuntimeService


QiskitRuntimeService.save_account(token="YOUR_API_TOKEN")


Step 3: Use a real device

from qiskit_ibm_runtime import QiskitRuntimeService


service = QiskitRuntimeService()

backend = service.least_busy(simulator=False)


result = backend.run(qc, shots=1024).result()

print(result.get_counts())



Because real quantum hardware is noisy, you may not get perfect 50/50 results. This is normal.


๐Ÿ”ถ 8. Summary Checklist


✔ Installed Qiskit


✔ Created your first quantum circuit


✔ Applied a Hadamard gate


✔ Measured superposition


✔ Simulated results


✔ Visualized output


✔ (Optional) Ran on a real quantum processor


You now understand the basic workflow of quantum programming in Qiskit!

Learn Quantum Computing Training in Hyderabad

Read More

Quantum Programming & Tools

Why Quantum Algorithms Are Faster: Exploring Quantum Parallelism

Introduction to Quantum Teleportation Protocols

What is Quantum Noise and How Do Quantum Computers Combat It?

Visit Our Quality Thought Training Institute 

Get Directions

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

About

Search This Blog

Powered by Blogger.

Blog Archive