forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpermutation_reverse_lnn.py
65 lines (52 loc) · 2.04 KB
/
permutation_reverse_lnn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# This code is part of Qiskit.
#
# (C) Copyright IBM 2024
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""
Synthesis of a reverse permutation for LNN connectivity.
"""
from qiskit.circuit import QuantumCircuit
def _append_cx_stage1(qc, n):
"""A single layer of CX gates."""
for i in range(n // 2):
qc.cx(2 * i, 2 * i + 1)
for i in range((n + 1) // 2 - 1):
qc.cx(2 * i + 2, 2 * i + 1)
return qc
def _append_cx_stage2(qc, n):
"""A single layer of CX gates."""
for i in range(n // 2):
qc.cx(2 * i + 1, 2 * i)
for i in range((n + 1) // 2 - 1):
qc.cx(2 * i + 1, 2 * i + 2)
return qc
def synth_permutation_reverse_lnn_kms(num_qubits: int) -> QuantumCircuit:
"""
Synthesize reverse permutation for linear nearest-neighbor architectures using
Kutin, Moulton, Smithline method.
Synthesis algorithm for reverse permutation from [1], section 5.
This algorithm synthesizes the reverse permutation on :math:`n` qubits over
a linear nearest-neighbor architecture using CX gates with depth :math:`2 * n + 2`.
Args:
num_qubits: The number of qubits.
Returns:
The synthesized quantum circuit.
References:
1. Kutin, S., Moulton, D. P., Smithline, L.,
*Computation at a distance*, Chicago J. Theor. Comput. Sci., vol. 2007, (2007),
`arXiv:quant-ph/0701194 <https://arxiv.org/abs/quant-ph/0701194>`_
"""
qc = QuantumCircuit(num_qubits)
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