Skip to content

Commit 108776f

Browse files
Fixed failed examples
1 parent 1e468c1 commit 108776f

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

quantum/q_fourier_transform.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
https://en.wikipedia.org/wiki/Quantum_Fourier_transform
1111
https://qiskit.org/textbook/ch-algorithms/quantum-fourier-transform.html
1212
"""
13-
1413
import math
1514

1615
import numpy as np
@@ -20,8 +19,6 @@
2019

2120
def quantum_fourier_transform(number_of_qubits: int = 3) -> qiskit.result.counts.Counts:
2221
"""
23-
# >>> quantum_fourier_transform(2)
24-
# {'00': 2500, '01': 2500, '11': 2500, '10': 2500}
2522
# quantum circuit for number_of_qubits = 3:
2623
┌───┐
2724
qr_0: ──────■──────────────────────■───────┤ H ├─X─
@@ -36,8 +33,24 @@ def quantum_fourier_transform(number_of_qubits: int = 3) -> qiskit.result.counts
3633
Returns:
3734
qiskit.result.counts.Counts: distribute counts.
3835
39-
>>> quantum_fourier_transform(2)
40-
{'00': 2500, '01': 2500, '10': 2500, '11': 2500}
36+
>>> result = quantum_fourier_transform(2)
37+
>>> 2350<=result['10']<=2600
38+
True
39+
>>> 2350<=result['00']<=2600
40+
True
41+
>>> 2350<=result['11']<=2600
42+
True
43+
>>> 2350<=result['01']<=2600
44+
True
45+
>>> res = quantum_fourier_transform(3)
46+
>>> 1150<=res['000']<=1350 and 1150<=res['001']<=1350
47+
True
48+
>>> 1150<=res['010']<=1350 and 1150<=res['100']<=1350
49+
True
50+
>>> 1150<=res['101']<=1350 and 1150<=res['110']<=1350
51+
True
52+
>>> 1150<=res['011']<=1350 and 1150<=res['111']<=1350
53+
True
4154
>>> quantum_fourier_transform(-1)
4255
Traceback (most recent call last):
4356
...

0 commit comments

Comments
 (0)