
    z	i                     T    S r SSKJr  SSKJr  S rS rS\S\SS	4S
 jr	S\S\4S jrg	)z:
Synthesis of a reverse permutation for LNN connectivity.
    )QuantumCircuit)!synth_permutation_reverse_lnn_kmsc                     [        US-  5       H  nU R                  SU-  SU-  S-   5        M      [        US-   S-  S-
  5       H!  nU R                  SU-  S-   SU-  S-   5        M#     U $ zA single layer of CX gates.      rangecxqcnis      n/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/synthesis/permutation/permutation_reverse_lnn.py_append_cx_stage1r      sm    16]
a!eQUQY AEa<!#$
a!eaiQ# %I    c                     [        US-  5       H  nU R                  SU-  S-   SU-  5        M      [        US-   S-  S-
  5       H!  nU R                  SU-  S-   SU-  S-   5        M#     U $ r   r	   r   s      r   _append_cx_stage2r      sm    16]
a!eaiQ AEa<!#$
a!eaiQ# %Ir   r   
num_qubitsreturnNc                     [        US-   S-  5       H  n[        X5        [        X5        M     US-  S:X  a  [        X5        gg)a  
Append reverse permutation to a QuantumCircuit 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:
    qc: The original quantum circuit.
    num_qubits: The number of qubits.

Returns:
    The quantum circuit with appended reverse permutation.

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>`_
r   r   r   N)r
   r   r   )r   r   _s      r   #_append_reverse_permutation_lnn_kmsr   (   sG    , JNq()")") * 	Q1") r   c                 >    [         R                  " [        U 5      SS9$ )a  
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>`_
T)legacy_qubits)r   _from_circuit_data'synth_permutation_reverse_lnn_kms_inner)r   s    r   r   r   E   s!    , ,,/
;4 r   )
__doc__qiskit.circuitr   (qiskit._accelerate.synthesis.permutationr   r   r   r   intr    r   r   <module>r#      sL    *
*N * *PT *:# . r   