Skip to content

Commit

Permalink
add do_swaps option
Browse files Browse the repository at this point in the history
  • Loading branch information
ShellyGarion committed Nov 14, 2023
1 parent 3908a6d commit 025a511
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
15 changes: 13 additions & 2 deletions qiskit/synthesis/qft/qft_decompose_lnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

import numpy as np
from qiskit.circuit import QuantumCircuit
from qiskit.synthesis.linear_phase.cz_depth_lnn import _append_cx_stage1, _append_cx_stage2


def synth_qft_line(num_qubits):
"""Synthesis of a QFT circuit for a linear nearest neighbor connectivity."""
def synth_qft_line(num_qubits, do_swaps=True):
"""Synthesis of a QFT circuit for a linear nearest neighbor connectivity.
Based on Fowler et al. Fig 2.b from https://arxiv.org/abs/quant-ph/0402196"""

qc = QuantumCircuit(num_qubits)

Expand All @@ -32,4 +34,13 @@ def synth_qft_line(num_qubits):
qc.cx(num_qubits - j + i - 1, num_qubits - j + i - 2)
qc.p(np.pi / 2 ** (j - i + 2), num_qubits - j + i - 1)

if not do_swaps:
# Add a reversal network for LNN connectivity in depth 2*n+2,
# based on Kutin at al., https://arxiv.org/abs/quant-ph/0701194, Section 5
for _ in range((num_qubits + 1) // 2):
qc = _append_cx_stage1(qc, num_qubits)
qc = _append_cx_stage2(qc, num_qubits)
if (num_qubits % 2) == 0:
qc = _append_cx_stage1(qc, num_qubits)

return qc
18 changes: 17 additions & 1 deletion test/python/synthesis/test_qft_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,35 @@
from qiskit.synthesis.qft import synth_qft_line
from qiskit.quantum_info import Operator

from qiskit.synthesis.linear.linear_circuits_utils import check_lnn_connectivity


@ddt
class TestQFTLNN(QiskitTestCase):
"""Tests for QFT synthesis functions."""

@combine(num_qubits=[4, 5, 6, 7])
@combine(num_qubits=[2, 3, 4, 5, 6, 7, 8])
def test_qft_lnn(self, num_qubits):
"""Assert that the original and synthesized QFT circuits are the same."""
qft_circ = QFT(num_qubits, do_swaps=True)
qft_lnn = synth_qft_line(num_qubits)

self.assertTrue(Operator(qft_circ).equiv(Operator(qft_lnn)))

# Check that the output circuit has LNN connectivity
self.assertTrue(check_lnn_connectivity(qft_lnn))

@combine(num_qubits=[2, 3, 4, 5, 6, 7, 8])
def test_qft_lnn_no_swaps(self, num_qubits):
"""Assert that the original and synthesized QFT circuits are the same w/o swaps."""
qft_circ = QFT(num_qubits, do_swaps=False)
qft_lnn = synth_qft_line(num_qubits, do_swaps=False)

self.assertTrue(Operator(qft_circ).equiv(Operator(qft_lnn)))

# Check that the output circuit has LNN connectivity
self.assertTrue(check_lnn_connectivity(qft_lnn))


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

0 comments on commit 025a511

Please sign in to comment.