Lab 01 — आपका पहला quantum circuit
इस lab में आप अपनी machine setup करेंगे, Qiskit install करेंगे, और simulator पर एक असली quantum circuit चलाएँगे। आखिरी step तक एक qubit वह करेगा जो कोई classical bit नहीं कर सकता: कई runs में 0 और 1 — दोनों — measure होगा।
Python लाएँ
इस lab की हर चीज़ Python पर चलती है। सबसे आसान रास्ता Anaconda distribution है (Python के साथ scientific tools bundled), या python.org से सीधे Python लें — version 3.10 या नया।
python --version # दिखना चाहिए: Python 3.10 (या नया)
एक साफ़ कमरा बनाएँ
Quantum libraries बहुत सारी dependencies लाती हैं। उन्हें अपने environment में अलग रखें ताकि वे system Python से कभी न लड़ें:
conda create -n qc-lab python=3.11 conda activate qc-lab
conda नहीं है? Built-in तरीका भी वही काम करता है:
python -m venv qc-lab source qc-lab/bin/activate # Windows: qc-lab\Scripts\activate
(qc-lab) से शुरू हो।Jupyter install करें
Jupyter notebooks में code cell-by-cell चलता है और result तुरंत दिखता है — circuits के साथ experiment करने के लिए perfect:
pip install notebook jupyter --version
jupyter notebook चलाएँ — browser tab खुलना चाहिए।Quantum stack install करें
Notebook cell (या terminal) में Qiskit और उसका simulator install करें:
pip install qiskit qiskit-aer
Verify करें:
import qiskit print(qiskit.__version__)
2.x जैसा version print हो।--prefer-binary जोड़कर retry करें।Python warm-up (3 minute)
Qiskit एक Python library है, तो वे 3 constructs जगा लें जिन्हें आप बार-बार use करेंगे:
# variables + f-strings
shots = 1000
print(f"Running {shots} shots")
# loops
total = 0
for i in range(10):
total += i
print(total) # 45
# functions
def greet(name):
return f"Hello, {name}!"
print(greet("qubit")) Running 1000 shots, 45, Hello, qubit!।अपना पहला circuit बनाएँ
Quantum circuit में qubits (quantum registers) और classical bits (जहाँ measurement results जाते हैं) होते हैं। एक qubit, एक classical bit, एक measurement:
from qiskit import QuantumCircuit qc = QuantumCircuit(1, 1) # 1 qubit, 1 classical bit qc.measure(0, 0) # qubit 0 को measure करके bit 0 में डालें print(qc.draw())
Circuit diagram दिखना चाहिए:
┌─┐
q: ┤M├
└╥┘
c: 1/═╩═
0 M) qubit line को classical line से जोड़ता दिखे।Simulator पर चलाएँ
Quantum hardware की ज़रूरत नहीं — AerSimulator आपके laptop पर ideal quantum computer की
नकल करता है। Circuit को 1,000 बार चलाकर outcomes गिनें:
from qiskit_aer import AerSimulator sim = AerSimulator() job = sim.run(qc, shots=1000) counts = job.result().get_counts() print(counts)
{'0': 1000} — |0⟩ state वाला qubit हर बार 0 ही measure होगा। अभी तक boring classical जैसा। अब यह बदलेगा।आपकी बारी: qubit को flip करें
X gate quantum NOT है — |0⟩ को |1⟩ में flip करता है। इसे measurement से पहले लगाएँ। चलाने से पहले: ज़ोर से predict करें कि counts क्या आएँगे।
qc2 = QuantumCircuit(1, 1) qc2.x(0) # |0> को |1> में flip करें qc2.measure(0, 0) counts2 = sim.run(qc2, shots=1000).result().get_counts() print(counts2)
{'1': 1000} — हर shot 1, बिल्कुल आपके prediction जैसा। Prediction match हुआ? आप quantum programmer की तरह सोच रहे हैं।आपकी बारी: superposition
H (Hadamard) gate |0⟩ को superposition में डालता है — measure होने तक न 0, न 1। पहले predict करें, फिर चलाएँ:
qc3 = QuantumCircuit(1, 1) qc3.h(0) # |0> -> superposition qc3.measure(0, 0) counts3 = sim.run(qc3, shots=1000).result().get_counts() print(counts3)
{'0': 498, '1': 502} — लगभग आधा-आधा। यह कभी exactly 500/500 नहीं होगा, और हर run में अलग होगा। यह randomness bug नहीं है: यह quantum mechanics है, देखी हुई।{'0': 1000} दिखे, तो H gate measurement के बाद लग गया — order मायने रखता है। Gates ऊपर से नीचे apply होते हैं।Debrief — आपने क्या साबित किया?
3 छोटे circuits से आपने quantum computing के core facts verify किए: qubit |0⟩ से शुरू होता है, gates उसकी state बदलते हैं, measurement उसे classical bits में collapse करता है, और superposition सचमुच random outcomes देता है। Simulator theory से सहमत हुआ — एक बार में 1,000 shots।
आगे: 2 qubits, जहाँ चीज़ें entangled होती हैं — यह Lab 02 में। और H gate ऐसा क्यों करता है, यह समझने के लिए qubit वाला पाठ देखें।