Skip to content

Commit 4f007ac

Browse files
committed
added components of quantum circuit
1 parent 00c9bfd commit 4f007ac

12 files changed

Lines changed: 1745 additions & 10 deletions

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ When you go to the [live website](https://quantummlhandbook.vercel.app/) or loca
5656
- [x] SWAP gate.
5757
- [x] Fredkin gate.
5858
- [ ] Quantum circuits.
59-
- [ ] Components of a quantum circuit.
60-
- [ ] Qubits.
61-
- [ ] Gates.
62-
- [ ] Circuits.
63-
- [ ] Measurements.
64-
- [ ] Quantum Fourier Transform.
65-
- [ ] Inverse Quantum Fourier Transform.
66-
- [ ] Quantum Phase Estimation.
67-
- [ ] Quantum Variational Circuit.
68-
- [ ] Quantum Circuit for Grover's algorithm.
59+
- [x] Components of a quantum circuit.
60+
- [x] Qubits.
61+
- [x] Gates.
62+
- [x] Circuits.
63+
- [x] Measurements.
64+
- [x] Quantum Fourier Transform.
65+
- [x] Inverse Quantum Fourier Transform.
66+
- [x] Quantum Phase Estimation.
67+
- [x] Quantum Variational Circuit.
68+
- [x] Quantum Circuit for Grover's algorithm.
6969
- [ ] Quantum Circuit for Shor's algorithm.
7070
- [ ] Quantum Circuit for Simon's algorithm.
7171
- [ ] Quantum Circuit for Deutsch-Jozsa algorithm.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "2. Components of a Quantum Circuit",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "This section breaks a quantum circuit into simple parts: the wires that carry qubits, the gates that change them, the measurements that read them, and the bigger circuit patterns that appear again and again in algorithms."
7+
}
8+
}
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
---
2+
sidebar_position: 4
3+
sidebar_label: 5. Circuits
4+
---
5+
6+
# Circuits
7+
8+
## What a circuit means
9+
10+
A quantum circuit is a planned sequence of quantum operations.
11+
12+
It tells us:
13+
14+
* how many qubits we use,
15+
* which gates are applied,
16+
* in what order they are applied,
17+
* and when we measure.
18+
19+
If a single gate is one sentence, then a circuit is the whole paragraph.
20+
21+
## You might be thinking: why draw a circuit instead of writing one giant matrix?
22+
23+
In theory, we could describe the whole computation by one big matrix.
24+
25+
In practice, that is a terrible way to think.
26+
27+
A circuit diagram is useful because it shows:
28+
29+
* the order of operations,
30+
* which qubits interact,
31+
* where subcircuits start and end,
32+
* and how the algorithm can actually be built on hardware.
33+
34+
It is similar to software design. You could describe a whole program as a giant low-level transformation, but readable code is far more useful than that.
35+
36+
## Reading a circuit from left to right
37+
38+
In most quantum circuit diagrams, time moves from left to right.
39+
40+
That means:
41+
42+
* gates on the left happen earlier,
43+
* gates on the right happen later.
44+
45+
For example:
46+
47+
```plaintext
48+
q0: ---H---Z---M
49+
```
50+
51+
This means:
52+
53+
1. start with the qubit,
54+
2. apply Hadamard,
55+
3. apply Z,
56+
4. measure.
57+
58+
It is like reading a recipe line by line or reading code from top to bottom.
59+
60+
## Width and depth of a circuit
61+
62+
Two basic ideas help us describe a circuit:
63+
64+
### Width
65+
Width means how many qubits the circuit uses.
66+
67+
A 2-qubit circuit has width 2. A 20-qubit circuit has width 20.
68+
69+
### Depth
70+
Depth means how many time-layers of operations the circuit has.
71+
72+
Imagine a group photo where several people stand side by side in one row. If two gates act on different qubits and do not interfere with each other, they can often happen in the same time-layer.
73+
74+
So depth is not always equal to the total number of gates.
75+
76+
This matters because on real hardware, deeper circuits are usually harder to run well. Noise gets more chances to disturb the system.
77+
78+
That answers another common doubt: "Why should I care about depth if the math is correct?" Because real machines are noisy. A mathematically correct long circuit may still perform badly if it is too deep for the hardware.
79+
80+
## Parallel gates
81+
82+
Suppose we have:
83+
84+
```plaintext
85+
q0: ---H-------
86+
q1: -------X---
87+
```
88+
89+
These gates happen at different times.
90+
91+
But if we draw:
92+
93+
```plaintext
94+
q0: ---H---
95+
q1: ---X---
96+
```
97+
98+
then both gates can be understood as happening in the same layer.
99+
100+
That is similar to parallel computation in classical systems. Independent tasks can be done at the same time.
101+
102+
## A circuit is more than a drawing
103+
104+
The visual diagram is useful, but a circuit is not just a picture. It is also a mathematical object.
105+
106+
Each gate has a matrix. When we place gates in sequence, the full circuit represents a combined transformation.
107+
108+
So a circuit is:
109+
110+
* a visual plan,
111+
* a mathematical transformation,
112+
* and an executable program for a quantum device.
113+
114+
You might be thinking: "So is a circuit just a picture for humans?" No. The picture is only one view. The same circuit is also a real computational object that a compiler and a quantum device can use.
115+
116+
## Example: a simple two-qubit circuit
117+
118+
Consider this circuit:
119+
120+
```plaintext
121+
q0: ---H---o---M
122+
|
123+
q1: -------X---M
124+
```
125+
126+
Let us read it carefully.
127+
128+
### Step 1: Initial state
129+
130+
Usually we begin with:
131+
132+
$$
133+
|q_0q_1\rangle = |00\rangle
134+
\tag{1}
135+
$$
136+
137+
### Step 2: Apply Hadamard on the first qubit
138+
139+
$$
140+
(H \otimes I)|00\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |10\rangle)
141+
\tag{2}
142+
$$
143+
144+
### Step 3: Apply CNOT
145+
146+
$$
147+
CNOT\left(\frac{1}{\sqrt{2}}(|00\rangle + |10\rangle)\right)
148+
=
149+
\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)
150+
\tag{3}
151+
$$
152+
153+
### Step 4: Measure both qubits
154+
155+
Now we do not always get one fixed answer. Instead:
156+
157+
* we may get `00`,
158+
* or we may get `11`.
159+
160+
Each outcome appears with probability $1/2$.
161+
162+
This is a good example of how a circuit takes a simple starting state and turns it into a structured quantum state.
163+
164+
## Circuit composition
165+
166+
Large circuits are usually built by combining smaller circuits.
167+
168+
This is exactly like software engineering:
169+
170+
* small functions become modules,
171+
* modules become systems.
172+
173+
In quantum computing:
174+
175+
* a gate is a basic unit,
176+
* a short pattern of gates becomes a subcircuit,
177+
* subcircuits combine into algorithms.
178+
179+
For example:
180+
181+
* one subcircuit may prepare a state,
182+
* one may apply an oracle,
183+
* one may estimate a phase,
184+
* one may perform readout.
185+
186+
## Why circuits are useful
187+
188+
Circuits give us a clean way to think about quantum computation.
189+
190+
Instead of saying "the whole quantum computer does something mysterious," we can ask:
191+
192+
* what is the input state?
193+
* what is the next gate?
194+
* what state does that create?
195+
* what happens when we measure?
196+
197+
This is important because quantum ideas become manageable only when we break them into steps.
198+
199+
## Connection to machine learning
200+
201+
A circuit is a lot like a model pipeline.
202+
203+
Think of:
204+
205+
* input embedding,
206+
* hidden transformations,
207+
* output layer,
208+
* prediction.
209+
210+
Quantum circuits have a similar flow:
211+
212+
* initial state,
213+
* sequence of gates,
214+
* final state,
215+
* measurement result.
216+
217+
In both cases, the full behavior is not found in one step. It comes from the composition of many steps.
218+
219+
## Key idea to remember
220+
221+
A quantum circuit is not just "some gates on some lines."
222+
223+
It is an organized process that moves a quantum state from:
224+
225+
* preparation,
226+
* to transformation,
227+
* to readout.

0 commit comments

Comments
 (0)