|
1 | 1 | ^{:kindly/hide-code true |
2 | 2 | :clay {:title "Bell State Circuit" |
3 | 3 | :quarto {:author :ludgersolbach |
4 | | - :draft true |
5 | | - :type :post |
6 | | - :image "bell_state_circuit.svg" |
7 | | - :date "2025-10-10"}}} |
| 4 | + :draft true |
| 5 | + :type :post |
| 6 | + :image "bell_state_circuit.svg" |
| 7 | + :date "2025-10-10" |
| 8 | + :tags [:qclojure :quantum-computing :quantum-circuit :simulation :bell-state]}}} |
8 | 9 | (ns qclojure.examples.bell-state-circuit |
9 | 10 | (:require |
10 | 11 | [scicloj.kindly.v4.kind :as kind])) |
@@ -135,53 +136,53 @@ result |
135 | 136 | (def ideal-simulator (ideal-sim/create-simulator)) |
136 | 137 |
|
137 | 138 | ;; We define some options for the execution, such as the results we want to obtain. |
138 | | -;; In this case, we want to measure the qubits 100 times (shots). |
139 | | -(def options {:result-specs {:measurements {:shots 100}}}) |
| 139 | +;; In this case, we want to measure the qubits 10000 times, which is called the |
| 140 | +;; number of shots. |
| 141 | +(def options {:result-specs {:measurements {:shots 10000}}}) |
140 | 142 |
|
141 | 143 | ;; Now we can execute the circuit using the ideal simulator and the defined options. |
142 | 144 | (def ideal-result |
143 | 145 | (backend/execute-circuit ideal-simulator bell-state-circuit options)) |
144 | 146 |
|
145 | | -;; The result is a map that contains the measurement results and other information |
146 | | -;; about the execution. |
147 | | -ideal-result |
148 | | - |
149 | 147 | ;; We can visualize the frequencies of the measurements obtained from the |
150 | 148 | ;; ideal simulator as a histogram. |
151 | 149 | ^kind/hiccup |
152 | 150 | (viz/visualize-measurement-histogram :svg (get-in ideal-result [:results :measurement-results :frequencies])) |
153 | 151 |
|
154 | | -;; Now we you the hardware simulator to execute the Bell state circuit. |
| 152 | +;; Now we use the hardware simulator to execute the Bell state circuit. |
155 | 153 | ;; The hardware simulator simulates the quantum circuit with noise and errors |
156 | 154 | ;; that are present in real quantum hardware. |
157 | 155 | (def hardware-simulator (hw-sim/create-hardware-simulator)) |
158 | 156 |
|
159 | 157 | ;; We can also select a specific quantum device to simulate. We choose the |
160 | 158 | ;; IBM Lagos quantum device for this example. The IBM Lagos is a 7-qubit quantum |
161 | | -;; computer that is available on the IBM Quantum Experience platform. |
| 159 | +;; computer that is available on the IBM Quantum platform. |
162 | 160 | (backend/select-device hardware-simulator :ibm-lagos) |
163 | 161 |
|
164 | 162 | ;; We execute the circuit using the hardware simulator and the defined options. |
165 | 163 | (def hardware-result |
166 | 164 | (backend/execute-circuit hardware-simulator bell-state-circuit options)) |
167 | 165 |
|
168 | | -;; Here is the result of the hardware simulation. |
169 | | -hardware-result |
170 | | - |
171 | 166 | ;; We can visualize the result of the hardware simulation as a histogram of the |
172 | 167 | ;; measurement frequencies to compare it with the ideal simulation result. |
173 | 168 | ^kind/hiccup |
174 | 169 | (viz/visualize-measurement-histogram :svg (get-in hardware-result [:results :measurement-results :frequencies])) |
175 | 170 |
|
176 | 171 | ;; We results are probabilistic, so we may not get exactly the same results every time we |
177 | | -;; execute the circuit. However, we should see that the results from the ideal simulator |
178 | | -;; are closer to the expected Bell state results (|00⟩ and |11⟩ with similar counts) compared to the |
179 | | -;; hardware simulator, which may show some deviations due to noise and errors. |
180 | | -;; This demonstrates the impact of quantum noise and errors on the execution of quantum circuits |
181 | | -;; on real quantum hardware. |
| 172 | +;; execute the circuit. Also the Bell state circuit is very simple, so the differences |
| 173 | +;; between the ideal and hardware simulation results may not be eminently visible. |
| 174 | +;; With a bit of 'luck', we would see a measurement of |01⟩ or |10⟩, because of a bit-flip |
| 175 | +;; caused by the noise of the hardware. However, with more complex circuits, the |
| 176 | +;; differences will show up on the hardware simulator and on real quantum hardware. |
| 177 | +;; We will explore more complex circuits in future examples. |
182 | 178 | ;; |
183 | 179 | ;; ## Conclusion |
184 | 180 | ;; In this example, we created a simple quantum circuit that generates a Bell state, |
185 | 181 | ;; visualized the circuit, and executed it using both an ideal simulator and a hardware |
186 | | -;; simulator provided by QClojure. We observed the differences in the measurement results |
187 | | -;; between the two simulators, highlighting the effects of noise and errors in quantum computing. |
| 182 | +;; simulator provided by QClojure. We also visualized the measurement results as histograms |
| 183 | +;; to compare the outcomes of the two simulations. |
| 184 | +;; |
| 185 | +;; This example demonstrates the basic concepts of quantum circuits, quantum gates, |
| 186 | +;; and quantum simulators using QClojure. You can build upon this foundation to explore |
| 187 | +;; more complex quantum algorithms and circuits. Please alos check out the tutorial in the |
| 188 | +;; [QClojure documentation](https://cljdoc.org/d/org.soulspace/qclojure). |
0 commit comments