Skip to content

Commit 32a368f

Browse files
Producing correct QFT circuits over linear connectivity with 32 or more qubits (#16004)
In the debug more, the previous code panicked (attempt to multiply with overflow) when raising 2_u32 to power 32 or more. And in the release mode, I believe, it silently produced incorrect circuits.
1 parent b739944 commit 32a368f

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

crates/synthesis/src/qft/qft_decompose_lnn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn synth_qft_line(
7474
for j in i..num_qubits - 1 {
7575
let q0 = num_qubits - j + i - 1;
7676
let q1 = num_qubits - j + i - 2;
77-
let phase = PI / (2_u32.pow((j - i + 2) as u32) as f64);
77+
let phase = PI / 2.0_f64.powi((j - i + 2) as i32);
7878

7979
if j - i + 2 < num_qubits - approximation_degree + 1 {
8080
append_phase(&mut instructions, q0, phase);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed :func:`.synth_qft_line` to correctly synthesize circuits with
5+
32 or more qubits.

test/python/synthesis/test_qft_synthesis.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def test_qft_lnn_approximated(self, num_qubits, do_swaps, approximation_degree):
5858
with self.subTest(msg="synthesized QFT circuit do not have LNN connectivity"):
5959
self.assertTrue(check_lnn_connectivity(qft_lnn))
6060

61+
@data(50, 100, 1000)
62+
def test_create_large_circuit(self, num_qubits):
63+
"""Test creating large QFT circuits."""
64+
qft = synth_qft_line(num_qubits)
65+
self.assertEqual(set(qft.count_ops()), {"p", "cx", "h"})
66+
6167

6268
@ddt
6369
class TestQFTFull(QiskitTestCase):
@@ -111,6 +117,12 @@ def test_synthesis_name(self, num_qubits):
111117
synthesized = synth_qft_full(num_qubits, name="SomeRandomName")
112118
self.assertEqual(original.name, synthesized.name)
113119

120+
@data(50, 100, 1000)
121+
def test_create_large_circuit(self, num_qubits):
122+
"""Test creating large QFT circuits."""
123+
qft = synth_qft_full(num_qubits)
124+
self.assertEqual(set(qft.count_ops()), {"cp", "h", "swap"})
125+
114126

115127
if __name__ == "__main__":
116128
unittest.main()

0 commit comments

Comments
 (0)