Skip to content

Commit db3ccd5

Browse files
committed
barriers added
1 parent 4c03cfd commit db3ccd5

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

Bernstein-Vazirani Algorithm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,32 @@
1919

2020
circuit.x(qr[3]) # initialize the ancilla qubit in the |1> state
2121

22+
circuit.barrier()
23+
2224
# First step of quantum algorithms - Prepare the superposition
2325
# For superposition, we apply the Hadamard gate on all qubits
2426
circuit.h(qr[0])
2527
circuit.h(qr[1])
2628
circuit.h(qr[2])
2729
circuit.h(qr[3])
2830

31+
circuit.barrier()
32+
2933
# Oracle function
3034
circuit.cx(qr[0], qr[3])
3135
circuit.cx(qr[1], qr[3])
3236
circuit.cx(qr[2], qr[3])
3337

38+
circuit.barrier()
39+
3440
# Apply Hadamard gates after querying oracle function
3541
circuit.h(qr[0])
3642
circuit.h(qr[1])
3743
circuit.h(qr[2])
3844
circuit.h(qr[3])
3945

46+
circuit.barrier()
47+
4048
# Measure qubit
4149
circuit.measure(qr[0], cr[0])
4250
circuit.measure(qr[1], cr[1])

Deutsch's Algorithm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@
2525

2626
circuit.x(qr[1]) # initialize the ancilla qubit in the |1> state
2727

28+
circuit.barrier()
29+
2830
# First step of quantum algorithms - Prepare the superposition
2931
# For superposition, we apply the Hadamard gate on both qubits
3032
circuit.h(qr[0])
3133
circuit.h(qr[1])
3234

35+
circuit.barrier()
36+
3337
# Oracle function
3438
circuit.cx(qr[0], qr[1])
3539

40+
circuit.barrier()
41+
3642
# Apply Hadamard gates after querying oracle function
3743
circuit.h(qr[0])
3844
circuit.h(qr[1])
3945

46+
circuit.barrier()
47+
4048
# Measure qubit
4149
circuit.measure(qr[0], cr[0])
4250

Deutsch-Jozsa Algorithm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,37 @@
2020

2121
circuit.x(qr[2]) # initialize the ancilla qubit in the |1> state
2222

23+
circuit.barrier()
24+
2325
# First step of quantum algorithms - Prepare the superposition
2426
# For superposition, we apply the Hadamard gate on all qubits
2527
circuit.h(qr[0])
2628
circuit.h(qr[1])
2729
circuit.h(qr[2])
2830

31+
circuit.barrier()
32+
2933
# Oracle function
3034
circuit.h(qr[0])
3135
circuit.cx(qr[1], qr[0])
3236
circuit.z(qr[2])
3337
circuit.h(qr[0])
3438

39+
circuit.barrier()
40+
3541
# Apply Hadamard gates after querying oracle function
3642
circuit.h(qr[0])
3743
circuit.h(qr[1])
3844
circuit.h(qr[2])
3945

46+
circuit.barrier()
47+
4048
# Measure qubit
4149
circuit.measure(qr[0], cr[0])
4250
circuit.measure(qr[1], cr[1])
4351

52+
circuit.barrier()
53+
4454
# Run our circuit with local simulator
4555
backend = BasicAer.get_backend('qasm_simulator')
4656
shots = 1024

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ Quantum computing examples with Qiskit.
2121
2222
![Bernstein-Vazirani Algorithm](./circuit_diagrams/03_bernstein_vazirani.png)
2323

24-
<!--stackedit_data:
25-
eyJoaXN0b3J5IjpbLTg0NDI4OTY5OF19
26-
-->
24+
**Simon's Algorithm**
25+
26+
> Problem. For given an oracle function f : {0, 1}^n -> {0, 1}^n which has period `a` like following: ∃!a != 0: ∀x f(x) = f(y) => y = x ⊕ a. Determine a.

Simon's Algorithm.py

Whitespace-only changes.

0 commit comments

Comments
 (0)