σ
    Σz	iB  γ                  σ¬    S r SSKJr  SSKrSSKJrJr  SSKJr  SSK	J
r
Jr  SSKJr  SS	KJr  S
SKJr  \R$                  (       a  SSKr " S S\5      rg)zThe two-local gate circuit.ι    )ΪannotationsN)ΪCallableΪSequence)ΪQuantumCircuit)ΪGateΪInstruction)Ϊdeprecate_funcι   )ΪNLocalι   )Ϊget_standard_gate_name_mappingc                  σΎ   ^  \ rS rSrSr\" SSSS9            S                         SU 4S jjj5       rSS jr        SU 4S	 jjrS
r	U =r
$ )ΪTwoLocalι   u`!  The two-local circuit.

The two-local circuit is a parameterized circuit consisting of alternating rotation layers and
entanglement layers. The rotation layers are single qubit gates applied on all qubits.
The entanglement layer uses two-qubit gates to entangle the qubits according to a strategy set
using ``entanglement``. Both the rotation and entanglement gates can be specified as
string (e.g. ``'ry'`` or ``'cx'``), as gate-type (e.g. ``RYGate`` or ``CXGate``) or
as QuantumCircuit (e.g. a 1-qubit circuit or 2-qubit circuit).

A set of default entanglement strategies is provided:

* ``'full'`` entanglement is each qubit is entangled with all the others.
* ``'linear'`` entanglement is qubit :math:`i` entangled with qubit :math:`i + 1`,
  for all :math:`i \in \{0, 1, ... , n - 2\}`, where :math:`n` is the total number of qubits.
* ``'reverse_linear'`` entanglement is qubit :math:`i` entangled with qubit :math:`i + 1`,
  for all :math:`i \in \{n-2, n-3, ... , 1, 0\}`, where :math:`n` is the total number of qubits.
  Note that if ``entanglement_blocks = 'cx'`` then this option provides the same unitary as
  ``'full'`` with fewer entangling gates.
* ``'pairwise'`` entanglement is one layer where qubit :math:`i` is entangled with qubit
  :math:`i + 1`, for all even values of :math:`i`, and then a second layer where qubit :math:`i`
  is entangled with qubit :math:`i + 1`, for all odd values of :math:`i`.
* ``'circular'`` entanglement is linear entanglement but with an additional entanglement of the
  first and last qubit before the linear part.
* ``'sca'`` (shifted-circular-alternating) entanglement is a generalized and modified version
  of the proposed circuit 14 in `Sim et al. <https://arxiv.org/abs/1905.10876>`__.
  It consists of circular entanglement where the 'long' entanglement connecting the first with
  the last qubit is shifted by one each block.  Furthermore the role of control and target
  qubits are swapped every block (therefore alternating).

The entanglement can further be specified using an entangler map, which is a list of index
pairs, such as

>>> entangler_map = [(0, 1), (1, 2), (2, 0)]

If different entanglements per block should be used, provide a list of entangler maps.
See the examples below on how this can be used.

>>> entanglement = [entangler_map_layer_1, entangler_map_layer_2, ... ]

Barriers can be inserted in between the different layers for better visualization using the
``insert_barriers`` attribute.

For each parameterized gate a new parameter is generated using a
:class:`~qiskit.circuit.library.ParameterVector`. The name of these parameters can be chosen
using the ``parameter_prefix``.

Examples:

    >>> two = TwoLocal(3, 'ry', 'cx', 'linear', reps=2, insert_barriers=True)
    >>> print(two.decompose())  # decompose the layers into standard gates
         ββββββββββββ β            β ββββββββββββ β            β ββββββββββββ
    q_0: β€ Ry(ΞΈ[0]) βββββββ βββββββββββ€ Ry(ΞΈ[3]) βββββββ βββββββββββ€ Ry(ΞΈ[6]) β
         ββββββββββββ€ β βββ΄ββ      β ββββββββββββ€ β βββ΄ββ      β ββββββββββββ€
    q_1: β€ Ry(ΞΈ[1]) βββββ€ X ββββ ββββββ€ Ry(ΞΈ[4]) βββββ€ X ββββ ββββββ€ Ry(ΞΈ[7]) β
         ββββββββββββ€ β ββββββββ΄ββ β ββββββββββββ€ β ββββββββ΄ββ β ββββββββββββ€
    q_2: β€ Ry(ΞΈ[2]) ββββββββββ€ X βββββ€ Ry(ΞΈ[5]) ββββββββββ€ X βββββ€ Ry(ΞΈ[8]) β
         ββββββββββββ β      βββββ β ββββββββββββ β      βββββ β ββββββββββββ

    >>> two = TwoLocal(3, ['ry','rz'], 'cz', 'full', reps=1, insert_barriers=True, flatten=True)
    >>> qc = QuantumCircuit(3)
    >>> qc &= two
    >>> print(qc.draw())
         ββββββββββββββββββββββββ β           β ββββββββββββ ββββββββββββ
    q_0: β€ Ry(ΞΈ[0]) ββ€ Rz(ΞΈ[3]) ββββββ βββ ββββββββ€ Ry(ΞΈ[6]) βββ€ Rz(ΞΈ[9]) β
         ββββββββββββ€ββββββββββββ€ β  β  β     β ββββββββββββ€ββ΄βββββββββββ€
    q_1: β€ Ry(ΞΈ[1]) ββ€ Rz(ΞΈ[4]) ββββββ βββΌβββ βββββ€ Ry(ΞΈ[7]) ββ€ Rz(ΞΈ[10]) β
         ββββββββββββ€ββββββββββββ€ β     β  β  β ββββββββββββ€βββββββββββββ€
    q_2: β€ Ry(ΞΈ[2]) ββ€ Rz(ΞΈ[5]) βββββββββ βββ βββββ€ Ry(ΞΈ[8]) ββ€ Rz(ΞΈ[11]) β
         ββββββββββββββββββββββββ β           β βββββββββββββββββββββββββ

    >>> entangler_map = [[0, 1], [1, 2], [2, 0]]  # circular entanglement for 3 qubits
    >>> two = TwoLocal(3, 'x', 'crx', entangler_map, reps=1, flatten=True)
    >>> print(two)  # note: no barriers inserted this time!
            βββββ                             βββββββββββββββββ
    q_0: |0>β€ X βββββββ ββββββββββββββββββββββββ€ Rx(ΞΈ[2]) ββ€ X β
            βββββ€ββββββ΄ββββββ            ββββββββββββ¬ββββββββββ
    q_1: |0>β€ X ββ€ Rx(ΞΈ[0]) βββββββ βββββββ€ X ββββββββΌββββββββββ
            βββββ€ββββββββββββββββββ΄βββββββββββ      β     βββββ
    q_2: |0>β€ X ββββββββββββββ€ Rx(ΞΈ[1]) βββββββββββββ ββββββ€ X β
            βββββ            ββββββββββββ                 βββββ

    >>> entangler_map = [[0, 3], [0, 2]]  # entangle the first and last two-way
    >>> two = TwoLocal(4, [], 'cry', entangler_map, reps=1, flatten=True)
    >>> circuit = two.compose(two)
    >>> print(circuit.draw())  # note, that the parameters are the same!
    q_0: ββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββ
              β           β           β           β
    q_1: ββββββΌββββββββββββΌββββββββββββΌββββββββββββΌββββββ
              β      ββββββ΄ββββββ     β      ββββββ΄ββββββ
    q_2: ββββββΌβββββββ€ Ry(ΞΈ[1]) βββββββΌβββββββ€ Ry(ΞΈ[1]) β
         ββββββ΄ββββββββββββββββββββββββ΄ββββββββββββββββββ
    q_3: β€ Ry(ΞΈ[0]) ββββββββββββββ€ Ry(ΞΈ[0]) βββββββββββββ
         ββββββββββββ            ββββββββββββ

    >>> layer_1 = [(0, 1), (0, 2)]
    >>> layer_2 = [(1, 2)]
    >>> two = TwoLocal(3, 'x', 'cx', [layer_1, layer_2], reps=2, insert_barriers=True,
    ... flatten=True)
    >>> print(two)
         βββββ β            β βββββ β       β βββββ
    q_0: β€ X βββββββ βββββ ββββββ€ X βββββββββββββ€ X β
         βββββ€ β βββ΄ββ  β   β βββββ€ β       β βββββ€
    q_1: β€ X βββββ€ X ββββΌββββββ€ X βββββββ ββββββ€ X β
         βββββ€ β ββββββββ΄ββ β βββββ€ β βββ΄ββ β βββββ€
    q_2: β€ X ββββββββββ€ X βββββ€ X βββββ€ X βββββ€ X β
         βββββ β      βββββ β βββββ β βββββ β βββββ

z2.1z8Use the function qiskit.circuit.library.n_local instead.zin Qiskit 3.0)ΪsinceΪadditional_msgΪremoval_timelinec                σ6   > [         TU ]  UUUUUUUU	U
UUUS9  g)a
  
Args:
    num_qubits: The number of qubits of the two-local circuit.
    rotation_blocks: The gates used in the rotation layer. Can be specified via the name of
        a gate (e.g. ``'ry'``) or the gate type itself (e.g. :class:`.RYGate`).
        If only one gate is provided, the gate same gate is applied to each qubit.
        If a list of gates is provided, all gates are applied to each qubit in the provided
        order.
        See the Examples section for more detail.
    entanglement_blocks: The gates used in the entanglement layer. Can be specified in
        the same format as ``rotation_blocks``.
    entanglement: Specifies the entanglement structure. Can be a string (``'full'``,
        ``'linear'``, ``'reverse_linear'``, ``'circular'`` or ``'sca'``),
        a list of integer-pairs specifying the indices
        of qubits entangled with one another, or a callable returning such a list provided with
        the index of the entanglement layer.
        Default to ``'full'`` entanglement.
        Note that if ``entanglement_blocks = 'cx'``, then ``'full'`` entanglement provides the
        same unitary as ``'reverse_linear'`` but the latter option has fewer entangling gates.
        See the Examples section for more detail.
    reps: Specifies how often a block consisting of a rotation layer and entanglement
        layer is repeated.
    skip_unentangled_qubits: If ``True``, the single qubit gates are only applied to qubits
        that are entangled with another qubit. If ``False``, the single qubit gates are applied
        to each qubit in the ansatz. Defaults to ``False``.
    skip_final_rotation_layer: If ``False``, a rotation layer is added at the end of the
        ansatz. If ``True``, no rotation layer is added.
    parameter_prefix: The parameterized gates require a parameter to be defined, for which
        we use instances of :class:`~qiskit.circuit.Parameter`. The name of each parameter will
        be this specified prefix plus its index.
    insert_barriers: If ``True``, barriers are inserted in between each layer. If ``False``,
        no barriers are inserted. Defaults to ``False``.
    initial_state: A :class:`.QuantumCircuit` object to prepend to the circuit.
    flatten: Set this to ``True`` to output a flat circuit instead of nesting it inside multiple
        layers of gate objects. By default currently the contents of
        the output circuit will be wrapped in nested objects for
        cleaner visualization. However, if you're using this circuit
        for anything besides visualization its **strongly** recommended
        to set this flag to ``True`` to avoid a large performance
        overhead for parameter binding.

)Ϊ
num_qubitsΪrotation_blocksΪentanglement_blocksΪentanglementΪrepsΪskip_final_rotation_layerΪskip_unentangled_qubitsΪinsert_barriersΪinitial_stateΪparameter_prefixΪnameΪflattenN)ΪsuperΪ__init__)Ϊselfr   r   r   r   r   r   r   r   r   r   r   r    Ϊ	__class__s                Ϊb/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/n_local/two_local.pyr"   ΪTwoLocal.__init__   s<   ψ τX 	ΡΨ!Ψ+Ψ 3Ψ%ΨΨ&?Ψ$;Ψ+Ψ'Ψ-ΨΨπ 	ς 	
σ    c                σR   [        U[        5      (       a  U$ [        5       n[        U[        5      (       a   X!   n[        U[        5      (       aA  SnUR                  5        H  n[        XQ5      (       d  M  UnM     Uc  [        SU S35      eUn[        U[        5      (       aE  [        UR                  5      nUR                  U[        [        UR                  5      5      5        U$ [        S[        U5       S3S-   5      e! [         a  n[        SU S35      UeSnAff = f)aq  For a layer provided as str (e.g. ``'ry'``) or type (e.g. :class:`.RYGate`) this function
 returns the
 according layer type along with the number of parameters (e.g. ``(RYGate, 1)``).

Args:
    layer: The qubit layer.

Returns:
    The specified layer with the required number of parameters.

Raises:
    TypeError: The type of ``layer`` is invalid.
    ValueError: The type of ``layer`` is str but the name is unknown.
    ValueError: The type of ``layer`` is type but the layer type is unknown.

Note:
    Outlook: If layers knew their number of parameters as static property, we could also
    allow custom layer types.
zUnknown layer name `z`.NzUnknown layer type`zInvalid input type z. z.`layer` must be a type, str or QuantumCircuit.)Ϊ
isinstancer   r   ΪstrΪKeyErrorΪ
ValueErrorΪtypeΪvaluesr   r   ΪappendΪlistΪrangeΪ	TypeError)r#   ΪlayerΪvalid_layersΪexΪinstanceΪgateΪcircuits          r%   Ϊ_convert_to_blockΪTwoLocal._convert_to_blockη   s"   τ( e^Χ,Ρ,ΨLδ5Σ7τ eSΧ!Ρ!πKΨ$Ρ+τ
 eTΧ"Ρ"ΰHΨ$Χ+Ρ+Φ-άdΧ*Σ*Ψ#Hρ .π Ρά Π#6°u°gΈRΠ!@ΣAΠAΨEδe[Χ)Ρ)ά$ UΧ%5Ρ%5Σ6GΨNN5€$€u¨UΧ-=Ρ-=Σ'>Σ"?Τ@ΨNδΨ!€$ u£+ ¨bΠ1Π4dΡdσ
π 	
ψτ' σ Kά Π#7Έ°wΈbΠ!AΣBΘΠJϋπKϊs   ΈD Δ
D&ΔD!Δ!D&c                σH   > U R                   S::  a  / $ [        TU ]	  XU5      $ )zUOverloading to handle the special case of 1 qubit where the entanglement are ignored.r
   )r   r!   Ϊget_entangler_map)r#   Ϊrep_numΪ	block_numΪnum_block_qubitsr$   s       r%   r<   ΪTwoLocal.get_entangler_map  s)   ψ π ??aΣΨIάwΡ(¨Π=MΣNΠNr'   © )NNNΪfullι   FFu   ΞΈFNr   N)r   z
int | Noner   ϊstr | type | qiskit.circuit.Instruction | QuantumCircuit | list[str | type | qiskit.circuit.Instruction | QuantumCircuit] | Noner   rD   r   z2str | list[list[int]] | Callable[[int], list[int]]r   Ϊintr   Ϊboolr   rF   r   r*   r   rF   r   zQuantumCircuit | Noner   r*   r    zbool | NoneΪreturnΪNone)r3   z"str | type | Gate | QuantumCircuitrG   r   )r=   rE   r>   rE   r?   rE   rG   zSequence[Sequence[int]])Ϊ__name__Ϊ
__module__Ϊ__qualname__Ϊ__firstlineno__Ϊ__doc__r	   r"   r9   r<   Ϊ__static_attributes__Ϊ__classcell__)r$   s   @r%   r   r      s  ψ ρkρZ ΨΨQΨ(ρπ "&π π ΨKQΨΨ(-Ψ*/Ψ $Ψ %Ψ/3ΨΨ#π7T
ΰπT
ππ	T
ππT
π& Iπ'T
π( π)T
π* "&π+T
π, $(π-T
π. π/T
π0 π1T
π2 -π3T
π4 π5T
π6 π7T
π8 
χ9T
σπ
T
τl2
πhOΨπOΨ'*πOΨ>AπOΰ	 χOυ Or'   r   )rM   Ϊ
__future__r   ΪtypingΪcollections.abcr   r   Ϊqiskit.circuit.quantumcircuitr   Ϊqiskit.circuitr   r   Ϊqiskit.utils.deprecationr	   Ϊn_localr   Ϊstandard_gatesr   ΪTYPE_CHECKINGΪqiskitr   rA   r'   r%   Ϊ<module>rZ      s>   πρ "ε "Ϋ ί .ε 8ί ,έ 3ε έ ;ΰ	ΧΧΫτCOvυ COr'   