Skip to content

Commit f643ca1

Browse files
Merge pull request #91 from lsolbach/main
tweaks and release
2 parents 8e76457 + 4f4b138 commit f643ca1

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/qclojure/examples/bell_state_circuit.clj

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
^{:kindly/hide-code true
22
:clay {:title "Bell State Circuit"
33
: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]}}}
89
(ns qclojure.examples.bell-state-circuit
910
(:require
1011
[scicloj.kindly.v4.kind :as kind]))
@@ -135,53 +136,53 @@ result
135136
(def ideal-simulator (ideal-sim/create-simulator))
136137

137138
;; 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}}})
140142

141143
;; Now we can execute the circuit using the ideal simulator and the defined options.
142144
(def ideal-result
143145
(backend/execute-circuit ideal-simulator bell-state-circuit options))
144146

145-
;; The result is a map that contains the measurement results and other information
146-
;; about the execution.
147-
ideal-result
148-
149147
;; We can visualize the frequencies of the measurements obtained from the
150148
;; ideal simulator as a histogram.
151149
^kind/hiccup
152150
(viz/visualize-measurement-histogram :svg (get-in ideal-result [:results :measurement-results :frequencies]))
153151

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.
155153
;; The hardware simulator simulates the quantum circuit with noise and errors
156154
;; that are present in real quantum hardware.
157155
(def hardware-simulator (hw-sim/create-hardware-simulator))
158156

159157
;; We can also select a specific quantum device to simulate. We choose the
160158
;; 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.
162160
(backend/select-device hardware-simulator :ibm-lagos)
163161

164162
;; We execute the circuit using the hardware simulator and the defined options.
165163
(def hardware-result
166164
(backend/execute-circuit hardware-simulator bell-state-circuit options))
167165

168-
;; Here is the result of the hardware simulation.
169-
hardware-result
170-
171166
;; We can visualize the result of the hardware simulation as a histogram of the
172167
;; measurement frequencies to compare it with the ideal simulation result.
173168
^kind/hiccup
174169
(viz/visualize-measurement-histogram :svg (get-in hardware-result [:results :measurement-results :frequencies]))
175170

176171
;; 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.
182178
;;
183179
;; ## Conclusion
184180
;; In this example, we created a simple quantum circuit that generates a Bell state,
185181
;; 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

Comments
 (0)