
    z	i                    ^   S r SSKJr  SSKrSSKrSSKrSSKJrJrJ	r	J
r
  SSKrSSKJr  SSKJrJr  SSKJrJr  SSKJr  SS	KJrJrJrJr  SS
KJr  SSKJr  SSKJr  SSK J!r!J"r"J#r$  SSK%J&r&  \RN                  (       a  SSK(r(\RR                  \*\
\
\+      4   r,        S                       SS jjr- " S S\&5      r.SS jr/ S          S!S jjr#\R`                  " SS5      r1\" 5       r2S"S jr3      S#S jr4        S$S jr5    S%S jr6    S%S jr7S r8g)&zThe n-local circuit class.    )annotationsN)CallableMappingSequenceIterable)Gate)QuantumCircuitParameterValueType)ParameterVectorParameterVectorElement)QuantumRegister)Instruction	ParameterParameterExpressionCircuitInstruction)QiskitError)get_standard_gate_name_mapping)deprecate_func)Block
py_n_localget_entangler_map   )BlueprintCircuitc                    US:  a  [        SU 35      e[        5       n[        XU5      n[        X+U5      n[        U[	        U5      5      n[        U UUUUUUUU	S9	n[        R                  " USU
S9nU$ )u  Construct an n-local variational circuit.

The structure of the n-local circuit are alternating rotation and entanglement layers.
In both layers, parameterized circuit-blocks act on the circuit in a defined way.
In the rotation layer, the blocks are applied stacked on top of each other, while in the
entanglement layer according to the ``entanglement`` strategy.
The circuit blocks can have arbitrary sizes (smaller equal to the number of qubits in the
circuit). Each layer is repeated ``reps`` times, and by default a final rotation layer is
appended.

For instance, a rotation block on 2 qubits and an entanglement block on 4 qubits using
``"linear"`` entanglement yields the following circuit.

.. parsed-literal::

    ┌──────┐ ░ ┌──────┐                      ░ ┌──────┐
    ┤0     ├─░─┤0     ├──────────────── ... ─░─┤0     ├
    │  Rot │ ░ │      │┌──────┐              ░ │  Rot │
    ┤1     ├─░─┤1     ├┤0     ├──────── ... ─░─┤1     ├
    ├──────┤ ░ │  Ent ││      │┌──────┐      ░ ├──────┤
    ┤0     ├─░─┤2     ├┤1     ├┤0     ├ ... ─░─┤0     ├
    │  Rot │ ░ │      ││  Ent ││      │      ░ │  Rot │
    ┤1     ├─░─┤3     ├┤2     ├┤1     ├ ... ─░─┤1     ├
    ├──────┤ ░ └──────┘│      ││  Ent │      ░ ├──────┤
    ┤0     ├─░─────────┤3     ├┤2     ├ ... ─░─┤0     ├
    │  Rot │ ░         └──────┘│      │      ░ │  Rot │
    ┤1     ├─░─────────────────┤3     ├ ... ─░─┤1     ├
    └──────┘ ░                 └──────┘      ░ └──────┘

    |                                 |
    +---------------------------------+
           repeated reps times

Entanglement:

The entanglement describes the connections of the gates in the entanglement layer.
For a two-qubit gate for example, the entanglement contains pairs of qubits on which the
gate should acts, e.g. ``[[ctrl0, target0], [ctrl1, target1], ...]``.
A set of default entanglement strategies is provided and can be selected by name:

* ``"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).

If an entanglement layer contains multiple blocks, then the entanglement should be
given as list of entanglements for each block. For example::

    entanglement_blocks = ["rxx", "ryy"]
    entanglement = ["full", "linear"]  # full for rxx and linear for ryy

or::

    structure_rxx = [[0, 1], [2, 3]]
    structure_ryy = [[0, 2]]
    entanglement = [structure_rxx, structure_ryy]

Finally, the entanglement can vary in each repetition of the circuit. For this, we
support passing a callable that takes as input the layer index and returns the entanglement
for the layer in the above format. See the examples below for a concrete example.

Examples:

The rotation and entanglement gates can be specified via single strings, if they
are made up of a single block per layer:

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context:

    from qiskit.circuit.library import n_local

    circuit = n_local(3, "ry", "cx", "linear", reps=2, insert_barriers=True)
    circuit.draw("mpl")

Multiple gates per layer can be set by passing a list. Here, for example, we use
Pauli-Y and Pauli-Z rotations in the rotation layer:

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context: close-figs

    circuit = n_local(3, ["ry", "rz"], "cz", "full", reps=1, insert_barriers=True)
    circuit.draw("mpl")

To omit rotation or entanglement layers, the block can be set to an empty list:

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context: close-figs

    circuit = n_local(4, [], "cry", reps=2)
    circuit.draw("mpl")

The entanglement can be set explicitly via the ``entanglement`` argument:

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context: close-figs

    entangler_map = [[0, 1], [2, 0]]
    circuit = n_local(3, "x", "crx", entangler_map, reps=2)
    circuit.draw("mpl")

We can set different entanglements per layer, by specifing a callable that takes
as input the current layer index, and returns the entanglement structure. For example,
the following uses different entanglements for odd and even layers:

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context: close-figs

    def entanglement(layer_index):
        if layer_index % 2 == 0:
            return [[0, 1], [0, 2]]
        return [[1, 2]]

    circuit = n_local(3, "x", "cx", entanglement, reps=3, insert_barriers=True)
    circuit.draw("mpl")


Args:
    num_qubits: The number of qubits of the circuit.
    rotation_blocks: The blocks used in the rotation layers. If multiple are passed,
        these will be applied one after another (like new sub-layers).
    entanglement_blocks: The blocks used in the entanglement layers. If multiple are passed,
        these will be applied one after another.
    entanglement: The indices specifying on which qubits the input blocks act. This is
        specified by string describing an entanglement strategy (see the additional info)
        or a list of qubit connections.
        If a list of entanglement blocks is passed, different entanglement for each block can
        be specified by passing a list of entanglements. To specify varying entanglement for
        each repetition, pass a callable that takes as input the layer and returns the
        entanglement for that layer.
        Defaults to ``"full"``, meaning an all-to-all entanglement structure.
    reps: Specifies how often the rotation blocks and entanglement blocks are repeated.
    insert_barriers: If ``True``, barriers are inserted in between each layer. If ``False``,
        no barriers are inserted.
    parameter_prefix: The prefix used if default parameters are generated.
    overwrite_block_parameters: If the parameters in the added blocks should be overwritten.
        If ``False``, the parameters in the blocks are not changed.
    skip_final_rotation_layer: Whether a final rotation layer is added to the circuit.
    skip_unentangled_qubits: If ``True``, the rotation gates act only on qubits that
        are entangled. If ``False``, the rotation gates act on all qubits.
    name: The name of the circuit.

Returns:
    An n-local circuit.
r   z"reps must be non-negative, but is )	
num_qubitsrotation_blocksentanglement_blocksentanglementrepsinsert_barriersparameter_prefixskip_final_rotation_layerskip_unentangled_qubitsT)legacy_qubitsname)
ValueErrorr   _normalize_blocks_normalize_entanglementlenr   r	   _from_circuit_data)r   r   r   r   r   r    r!   overwrite_block_parametersr"   r#   r%   supported_gatesdatacircuits                 `/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/n_local/n_local.pyn_localr0   6   s    p ax=dVDEE46O'*DO ,.H +<=P9QRL'/!')"; 7
D //DtTGN    c                    ^  \ 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5       r\R                  S0S	 j5       r\S1S
 j5       r
\
R                  S2S j5       r
S3S jr\S4S j5       r\R                      S5S j5       r\S4S j5       r\R                      S5S j5       r\  S6S j5       r\R                      S7S j5       r\S/S j5       rS8S9S jjr\S:S j5       r\R                  S;S j5       r\S1S j5       r\R                  S<S j5       rS=S jr\S/S j5       r\S/S j5       r\R                  S>S j5       rS?S jr\S@S j5       r        SAS jr\SBS  j5       r\R                  SCS! j5       r\SDS" j5       r\R                  SES# j5       r  SF       SGS$ jjr SH     SIU 4S% jjjr SJS& jrS' rS( rS) r SKU 4S* jjr!SLS+ jr"S,r#U =r$$ )MNLocali  uB	  The n-local circuit class.

The structure of the n-local circuit are alternating rotation and entanglement layers.
In both layers, parameterized circuit-blocks act on the circuit in a defined way.
In the rotation layer, the blocks are applied stacked on top of each other, while in the
entanglement layer according to the ``entanglement`` strategy.
The circuit blocks can have arbitrary sizes (smaller equal to the number of qubits in the
circuit). Each layer is repeated ``reps`` times, and by default a final rotation layer is
appended.

For instance, a rotation block on 2 qubits and an entanglement block on 4 qubits using
``'linear'`` entanglement yields the following circuit.

.. code-block:: text

    ┌──────┐ ░ ┌──────┐                      ░ ┌──────┐
    ┤0     ├─░─┤0     ├──────────────── ... ─░─┤0     ├
    │  Rot │ ░ │      │┌──────┐              ░ │  Rot │
    ┤1     ├─░─┤1     ├┤0     ├──────── ... ─░─┤1     ├
    ├──────┤ ░ │  Ent ││      │┌──────┐      ░ ├──────┤
    ┤0     ├─░─┤2     ├┤1     ├┤0     ├ ... ─░─┤0     ├
    │  Rot │ ░ │      ││  Ent ││      │      ░ │  Rot │
    ┤1     ├─░─┤3     ├┤2     ├┤1     ├ ... ─░─┤1     ├
    ├──────┤ ░ └──────┘│      ││  Ent │      ░ ├──────┤
    ┤0     ├─░─────────┤3     ├┤2     ├ ... ─░─┤0     ├
    │  Rot │ ░         └──────┘│      │      ░ │  Rot │
    ┤1     ├─░─────────────────┤3     ├ ... ─░─┤1     ├
    └──────┘ ░                 └──────┘      ░ └──────┘

    |                                 |
    +---------------------------------+
           repeated reps times

If specified, barriers can be inserted in between every block.
If an initial state object is provided, it is added in front of the NLocal.

.. seealso::

    The :func:`.n_local` function constructs a functionally equivalent circuit, but faster.

z2.1z}This applies to NLocal subclasses too. Use the corresponding function from the module qiskit.circuit.library.n_local instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelinec                6  > [         TU ]  US9  SU l        X`l        XPl        / U l        / U l        / U l        / U l        / U l	        / U l
        SU l        SU l        [        US9U l        Xl        Xl        Xl        SU l        SU l        SU l        Xl        [-        U R.                  SS5      [0        R.                  L U l        [5        U5      U:w  a  [7        S5      eUS:  a  [9        S5      eUb  Xl        Ub  X0l        Ub  X l        Ub  X@l         Ub  Xl!        gg)a0  
Args:
    num_qubits: The number of qubits of the circuit.
    rotation_blocks: The blocks used in the rotation layers. If multiple are passed,
        these will be applied one after another (like new sub-layers).
    entanglement_blocks: The blocks used in the entanglement layers. If multiple are passed,
        these will be applied one after another. To use different entanglements for
        the sub-layers, see :meth:`get_entangler_map`.
    entanglement: The indices specifying on which qubits the input blocks act. If ``None``, the
        entanglement blocks are applied at the top of the circuit.
    reps: Specifies how often the rotation blocks and entanglement blocks are repeated.
    insert_barriers: If ``True``, barriers are inserted in between each layer. If ``False``,
        no barriers are inserted.
    parameter_prefix: The prefix used if default parameters are generated.
    overwrite_block_parameters: If the parameters in the added blocks should be overwritten.
        If ``False``, the parameters in the blocks are not changed.
    skip_final_rotation_layer: Whether a final rotation layer is added to the circuit.
    skip_unentangled_qubits: If ``True``, the rotation gates act only on qubits that
        are entangled. If ``False``, the rotation gates act on all qubits.
    initial_state: A :class:`.QuantumCircuit` object which can be used to describe an initial
        state prepended to the NLocal circuit.
    name: The name of 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.

Raises:
    ValueError: If ``reps`` parameter is less than or equal to 0.
    TypeError: If ``reps`` parameter is not an int value.
r%   N__func__zThe value of reps should be intr   z5The value of reps should be larger than or equal to 0)"super__init___num_qubits_insert_barriers_reps_entanglement_blocks_rotation_blocks_prepended_blocks_prepended_entanglement_appended_blocks_appended_entanglement_entanglement_entangler_mapsr   _ordered_parameters_overwrite_block_parameters_skip_final_rotation_layer_skip_unentangled_qubits_initial_state_initial_state_circuit_bounds_flattengetattr_parameter_generatorr3    _allow_fast_path_parametrizationint	TypeErrorr&   r   r   r   r   initial_state)selfr   r   r   r   r   r    r!   r+   r"   r#   rT   r%   flatten	__class__s                 r/   r;   NLocal.__init__7  s?   H 	d#'+ /
:<!6879DF$68CE#!#FU!G
  ,F(*C'(?%59=A#GK D--z4@FD_D__ 	- t9=>>!8TUU!(O*':$&#2 # ,$!. %r1   c                8    U R                   b  U R                   $ S$ )zRReturns the number of qubits in this circuit.

Returns:
    The number of qubits.
r   )r<   rU   s    r/   r   NLocal.num_qubits  s      $(#3#3#?tFQFr1   c                r    U R                   U:w  a'  U R                  5         Xl         [        USS9/U l        gg)zWSet the number of qubits for the n-local circuit.

Args:
    The new number of qubits.
qr8   N)r<   _invalidater   qregs)rU   r   s     r/   r   r[     s:     z)))*3?@DJ	 *r1   c                ,    [        U R                  5      $ )zQReturns whether the circuit is wrapped in nested gates/instructions or flattened.)boolrN   rZ   s    r/   rV   NLocal.flatten  s     DMM""r1   c                0    U R                  5         Xl        g N)r^   rN   )rU   rV   s     r/   rV   rb     s    r1   c                   [        U[        5      (       a  U$ [        U[        5      (       aE  [        UR                  5      nUR	                  U[        [        UR                  5      5      5        U$  [        UR                  5      nUR	                  UR                  5       [        [        UR                  5      5      5        U$ ! [         a     Of = f[        S[        U5       S35      e)zTry to convert ``layer`` to a QuantumCircuit.

Args:
    layer: The object to be converted to an NLocal block / Instruction.

Returns:
    The layer converted to a circuit.

Raises:
    TypeError: If the input cannot be converted to a circuit.
z	Adding a z to an NLocal is not supported.)
isinstancer	   r   r   appendlistrangeto_instructionAttributeErrorrS   type)rU   layerr.   s      r/   _convert_to_blockNLocal._convert_to_block  s     e^,,Le[))$U%5%56GNN5$uU-=-='>"?@N	$U%5%56GNN5//14e>N>N8O3PQN 		 )DK=0OPQQs   3AC 
CCc                    U R                   $ )zTThe blocks in the rotation layers.

Returns:
    The blocks in the rotation layers.
)r@   rZ   s    r/   r   NLocal.rotation_blocks       $$$r1   c                    [        U[        [        R                  45      (       d  U/nU R	                  5         U Vs/ s H  o R                  U5      PM     snU l        gs  snf )zbSet the blocks in the rotation layers.

Args:
    blocks: The new blocks for the rotation layers.
N)rf   rh   numpyndarrayr^   rn   r@   rU   blocksblocks      r/   r   rq     sP     &4"788XFLR SF5!7!7!>F S S   A c                    U R                   $ )z\The blocks in the entanglement layers.

Returns:
    The blocks in the entanglement layers.
)r?   rZ   s    r/   r   NLocal.entanglement_blocks	  s     (((r1   c                    [        U[        [        R                  45      (       d  U/nU R	                  5         U Vs/ s H  o R                  U5      PM     snU l        gs  snf )zjSet the blocks in the entanglement layers.

Args:
    blocks: The new blocks for the entanglement layers.
N)rf   rh   rt   ru   r^   rn   r?   rv   s      r/   r   r{     sR     &4"788XFPV$WPVu%;%;E%BPV$W!$Wry   c                    U R                   $ )zGet the entanglement strategy.

Returns:
    The entanglement strategy, see :meth:`get_entangler_map` for more detail on how the
    format is interpreted.
)rE   rZ   s    r/   r   NLocal.entanglement"  s    ( !!!r1   c                0    U R                  5         Xl        g)zSet the entanglement strategy.

Args:
    entanglement: The entanglement strategy. See :meth:`get_entangler_map` for more detail
        on the supported formats.
N)r^   rE   )rU   r   s     r/   r   r~   8  s    , 	)r1   c                V    SU R                   -  [        U R                  (       + 5      -   $ )zgReturn the number of layers in the n-local circuit.

Returns:
    The number of layers in the circuit.
r   )r>   rR   rI   rZ   s    r/   
num_layersNLocal.num_layersQ  s%     4::~(G(G$G HHHr1   c                    SnU R                   c  SnU(       a  [        S5      eU R                  c!  U R                  c  SnU(       a  [        S5      eU$ )a  Check if the configuration of the NLocal class is valid.

Args:
    raise_on_failure: Whether to raise on failure.

Returns:
    True, if the configuration is valid and the circuit can be constructed. Otherwise
    an ValueError is raised.

Raises:
    ValueError: If the blocks are not set.
    ValueError: If the number of repetitions is not set.
    ValueError: If the qubit indices are not set.
    ValueError: If the number of qubit indices does not match the number of blocks.
    ValueError: If an index in the repetitions list exceeds the number of blocks.
    ValueError: If the number of repetitions does not match the number of block-wise
        parameters.
    ValueError: If a specified qubit index is larger than the (manually set) number of
        qubits.
TFzNo number of qubits specified.zThe blocks are not set.)r   r&   r   r   )rU   raise_on_failurevalids      r/   _check_configurationNLocal._check_configurationZ  sY    * ??"E !ABB ##+0D0D0LE !:;;r1   c                    [        U R                  [        5      (       a:  U R                  R                  U R                  5        [        U R                  5      $ U R                  $ )u  The parameters used in the underlying circuit.

This includes float values and duplicates.

Examples:

    >>> # prepare circuit ...
    >>> print(nlocal)
         ┌───────┐┌──────────┐┌──────────┐┌──────────┐
    q_0: ┤ Ry(1) ├┤ Ry(θ[1]) ├┤ Ry(θ[1]) ├┤ Ry(θ[3]) ├
         └───────┘└──────────┘└──────────┘└──────────┘
    >>> nlocal.parameters
    {Parameter(θ[1]), Parameter(θ[3])}
    >>> nlocal.ordered_parameters
    [1, Parameter(θ[1]), Parameter(θ[1]), Parameter(θ[3])]

Returns:
    The parameters objects used in the circuit.
)rf   rG   r   resizenum_parameters_settablerh   rZ   s    r/   ordered_parametersNLocal.ordered_parameters}  sN    * d..@@$$++D,H,HI0011'''r1   c                    [        U[        5      (       d=  [        U5      U R                  :w  a$  [	        SU R                   S[        U5       35      eXl        U R                  5         g)aX  Set the parameters used in the underlying circuit.

Args:
    The parameters to be used in the underlying circuit.

Raises:
    ValueError: If the length of ordered parameters does not match the number of
        parameters in the circuit and they are not a ``ParameterVector`` (which could
        be resized to fit the number of parameters).
zdThe length of ordered parameters must be equal to the number of settable parameters in the circuit (z
), but is N)rf   r   r)   r   r&   rG   r^   )rU   
parameterss     r/   r   r     sj     :77J4#?#??77;7S7S6T Uz?+- 
 $. r1   c                    U R                   $ )zIf barriers are inserted in between the layers or not.

Returns:
    ``True``, if barriers are inserted in between the layers, ``False`` if not.
)r=   rZ   s    r/   r    NLocal.insert_barriers  rr   r1   c                N    XR                   La  U R                  5         Xl         gg)zSpecify whether barriers should be inserted in between the layers or not.

Args:
    insert_barriers: If True, barriers are inserted, if False not.
N)r=   r^   )rU   r    s     r/   r    r     s'     "7"77$3! 8r1   c           
     l   [        5       n[        U R                  5       Hi  n[        U R                  5       HM  u  p4U R                  X#UR                  5      nUR                  U VVs/ s H  of  H  owPM     M     snn5        MO     Mk     [        [        U R                  5      5      U-
  nU$ s  snnf )zVGet the indices of unentangled qubits in a set.

Returns:
    The unentangled qubits.
)setri   r>   	enumerater   r   r   update)	rU   entangled_qubitsijrx   entangler_mapindicesidxunentangled_qubitss	            r/   get_unentangled_qubitsNLocal.get_unentangled_qubits  s     5tzz"A%d&>&>? $ 6 6qU=M=M N ''M(]MU\cU\M(]^ @ # !t!78;KK!! )^s   )B0c                d   Sn[        U R                  5       H`  n[        U R                  5       HD  u  p4U R	                  X#UR
                  5      nU[        U5      [        [        U5      5      -  -  nMF     Mb     U R                  (       a  U R                  5       nSnU R                   H  n[        U R
                  UR
                  -  5       Vs/ s H4  n[        [        X4R
                  -  US-   UR
                  -  5      5      PM6     nnU R                  (       a3  U V	s/ s H&  n	[        U	5      R                  W5      (       d  M$  U	PM(     nn	U[        U5      [        [        U5      5      -  -  nM     XU R                  [        U R                  (       + 5      -   -  -  nU$ s  snf s  sn	f )a  The number of total parameters that can be set to distinct values.

This does not change when the parameters are bound or exchanged for same parameters,
and therefore is different from ``num_parameters`` which counts the number of unique
:class:`~qiskit.circuit.Parameter` objects currently in the circuit.

Returns:
    The number of parameters originally available in the circuit.

Note:
    This quantity does not require the circuit to be built yet.
r      )ri   r>   r   r   r   r   r)   get_parametersrJ   r   r   rh   r   
isdisjointrR   rI   )
rU   numr   r   rx   r   r   num_rotblock_indicesr   s
             r/   r   NLocal.num_parameters_settable  s    tzz"A%d&>&>? $ 6 6qU=M=M Ns=)Cu0E,FFF @ #
 ((!%!<!<!>))E t%2B2BBCCA U1///!a%5;K;K1KLMC   ,, $1!#07|../AB #0  !
 s=)Cu0E,FFFG * 	$**st/N/N+N'OOPP

!s   ;F($#F-F-c                    U R                   $ )zkThe number of times rotation and entanglement block are repeated.

Returns:
    The number of repetitions.
)r>   rZ   s    r/   r   NLocal.reps  s     zzr1   c                r    US:  a  [        S5      eXR                  :w  a  U R                  5         Xl        gg)a%  Set the repetitions.

If the repetitions are `0`, only one rotation layer with no entanglement
layers is applied (unless ``self.skip_final_rotation_layer`` is set to ``True``).

Args:
    repetitions: The new repetitions.

Raises:
    ValueError: If reps setter has parameter repetitions < 0.
r   z3The repetitions should be larger than or equal to 0N)r&   r>   r^   )rU   repetitionss     r/   r   r     s7     ?RSS**$$J %r1   c                    SU R                   R                   S3nSnU R                  R                  5        H  u  p4US   S:X  d  M  USUSS  S	U S3-  nM!     X -  nU$ )
z~Returns information about the setting.

Returns:
    The class name and the attributes/parameters of the instance as ``str``.
zNLocal: 
 r   _z-- r   Nz: )rW   __name____dict__items)rU   retparamskeyvalues        r/   print_settingsNLocal.print_settings  sv     0014----/JC1v}CABy5'44 0 	
r1   c                    g)zThe initial points for the parameters. Can be stored as initial guess in optimization.

Returns:
    The initial values for the parameters, or None, if none have been set.
N rZ   s    r/   preferred_init_pointsNLocal.preferred_init_points)  s     r1   c           	        XUpenU R                   nUc  [        [        U5      5      /$ [        U5      (       a  U" U5      n[	        U[
        5      (       a  [        X`R                  XtS9$ [	        U[        [        45      (       d  [        SU 35      e[        U5      n[        S U 5       5      (       a  [        X`R                  XtU-     US9$ [        S U 5       5      (       a  U V	s/ s H  n	[        U	5      PM     sn	/$ [        S U 5       5      (       d  [        SU 35      e[        XtU-     5      n
[        S U 5       5      (       a  [        X`R                  XtU-     XZ-     US9$ [        S U 5       5      (       a1  [        U5       H   u  p[        [        [        U	5      5      X{'   M"     U$ [        S U 5       5      (       d  [        SU 35      e[        S	 U 5       5      (       a?  U H2  n	[        U	5       H   u  p[        [        [        U5      5      X'   M"     M4     XtU-     $ [        S
 U 5       5      (       d  [        SU 35      e[        S U 5       5      (       aM  U H;  n	U	 H2  n[        U5       H   u  p[        [        [        U5      5      X'   M"     M4     M=     XtU-     XZ-     $ [        SU 35      es  sn	f )aj  Get the entangler map for in the repetition ``rep_num`` and the block ``block_num``.

The entangler map for the current block is derived from the value of ``self.entanglement``.
Below the different cases are listed, where ``i`` and ``j`` denote the repetition number
and the block number, respectively, and ``n`` the number of qubits in the block.

=================================== ========================================================
entanglement type                   entangler map
=================================== ========================================================
``None``                            ``[[0, ..., n - 1]]``
``str`` (e.g ``'full'``)            the specified connectivity on ``n`` qubits
``List[int]``                       [``entanglement``]
``List[List[int]]``                 ``entanglement``
``List[List[List[int]]]``           ``entanglement[i]``
``List[List[List[List[int]]]]``     ``entanglement[i][j]``
``List[str]``                       the connectivity specified in ``entanglement[i]``
``List[List[str]]``                 the connectivity specified in ``entanglement[i][j]``
``Callable[int, str]``              same as ``List[str]``
``Callable[int, List[List[int]]]``  same as ``List[List[List[int]]]``
=================================== ========================================================


Note that all indices are to be taken modulo the length of the array they act on, i.e.
no out-of-bounds index error will be raised but we re-iterate from the beginning of the
list.

Args:
    rep_num: The current repetition we are in.
    block_num: The block number within the entanglement layers.
    num_block_qubits: The number of qubits in the block.

Returns:
    The entangler map for the current block in the current repetition.

Raises:
    ValueError: If the value of ``entanglement`` could not be cast to a corresponding
        entangler map.
)offsetzInvalid value of entanglement: c              3  B   #    U  H  n[        U[        5      v   M     g 7frd   rf   str.0ens     r/   	<genexpr>+NLocal.get_entangler_map.<locals>.<genexpr>q  s     :\rz"c""\   c              3  b   #    U  H%  n[        U[        [        R                  45      v   M'     g 7frd   )rf   rR   rt   integerr   s     r/   r   r   u  s#     Klz"sEMM233ls   -/c              3  N   #    U  H  n[        U[        [        45      v   M     g 7frd   rf   tuplerh   r   s     r/   r   r   y  s     H<R:b5$-00<s   #%c              3  T   #    U  H  o  H  n[        U[        5      v   M     M      g 7frd   r   r   r   e2s      r/   r   r   ~  s#     G\rBbz"c""B"\s   &(c              3     #    U  H=  o  H4  n[        U[        [        R                  [        R                  45      v   M6     M?     g 7frd   rf   rR   rt   int32int64r   s      r/   r   r     s5     c2`bZ\z"sEKK=>>`b>s   AAc              3  `   #    U  H$  o  H  n[        U[        [        45      v   M     M&     g 7frd   r   r   s      r/   r   r     s)     U<RRTB:b5$-00RT0<s   ,.c           	   3     #    U  HH  nU  H>  nU  H4  n[        U[        [        R                  [        R                  45      v   M6     M@     MJ     g 7frd   r   r   r   r   e3s       r/   r   r     sL      
" rCekk:;;  < <"s   AAc              3  r   #    U  H-  o  H$  o"  H  n[        U[        [        45      v   M     M&     M/     g 7frd   r   r   s       r/   r   r     s5     b<RRTB_aY[:b5$-00_a0RT0<s   57c           
   3     #    U  HR  nU  HH  nU  H>  nU  H4  n[        U[        [        R                  [        R                  45      v   M6     M@     MJ     MT     g 7frd   r   )r   r   r   r   e4s        r/   r   r     s[      
"	 rCekk:;; 	 <  < <"s   AA)rE   rh   ri   callablerf   r   r   r   r   r&   r)   allrR   r   map)rU   rep_num	block_numnum_block_qubitsr   r   nr   num_ir   num_jindr   r   s                 r/   r   NLocal.get_entangler_map3  s   R &6a)) qN## L!!'?L lC(($QPP ,66>|nMNNL! :\:::$Q%i9PYZ[[ KlKKK'34|SW|455 H<HHH>|nMNNLU+, G\GGG$??LU$;AI$Fq 
 cccc$\2$)#c2,$7! 3 U<UUU>|nMNN  
"
 
 
 #(}GC#CRL1BG  - #  E	** b<bbb>|nMNN  
"
 
 
 #B#,R="'C"5 $1  #  E	*1955:<.IJJk 5s   *Kc                    U R                   $ )ziReturn the initial state that is added in front of the n-local circuit.

Returns:
    The initial state.
)rK   rZ   s    r/   rT   NLocal.initial_state  s     """r1   c                0    Xl         U R                  5         g)zSet the initial state.

Args:
    initial_state: The new initial state.

Raises:
    ValueError: If the number of qubits has been set before and the initial state
        does not match the number of qubits.
N)rK   r^   )rU   rT   s     r/   rT   r     s     ,r1   c                \    U R                   (       d  U R                  5         U R                  $ )a  The parameter bounds for the unbound parameters in the circuit.

Returns:
    A list of pairs indicating the bounds, as (lower, upper). None indicates an unbounded
    parameter in the corresponding direction. If ``None`` is returned, problem is fully
    unbounded.
)	_is_built_buildrM   rZ   s    r/   parameter_boundsNLocal.parameter_bounds  s     ~~KKM||r1   c                    Xl         g)zGSet the parameter bounds.

Args:
    bounds: The new parameter bounds.
N)rM   )rU   boundss     r/   r   r     s	     r1   c                   U R                  U5      nUc   [        [        UR                  5      5      /nO0[	        U[        5      (       a  [	        US   [        5      (       d  U/nU(       a-  U =R
                  U/-  sl        U =R                  U/-  sl        O,U =R                  U/-  sl        U =R                  U/-  sl        [	        U[        5      (       a:  S[        S U 5       5      -   nXPR                  :  a  U R                  5         XPl        USL a  U R                  (       a  U R                  (       a)  [        U R                  5      S:  a  U R                  5         [	        U[         5      (       a"  [#        UR                  U R                  U5      nOUnU HE  nU R$                  [        ['        U5      5      * S nU R)                  XHS9n	U R+                  XSSS9  MG     U $ U R                  5         U $ )	a  Append another layer to the NLocal.

Args:
    other: The layer to compose, can be another NLocal, an Instruction or Gate,
        or a QuantumCircuit.
    entanglement: The entanglement or qubit indices.
    front: If True, ``other`` is appended to the front, else to the back.

Returns:
    self, such that chained composes are possible.

Raises:
    TypeError: If `other` is not compatible, i.e. is no Instruction and does not have a
        `to_instruction` method.
Nr   r   c              3  8   #    U  H  n[        U5      v   M     g 7frd   )max)r   r   s     r/   r   #NLocal.add_layer.<locals>.<genexpr>  s      J\'W\s   F)r   Tinplacecopy)rn   rh   ri   r   rf   rA   rB   rC   rD   r   r^   r   r=   r)   r-   barrierr   r   r   r   _parameterize_blockcompose)
rU   otherr   frontrx   r   r   r   r   parameterized_blocks
             r/   	add_layerNLocal.add_layer  s   * &&u- u'7'7!89:Ld++J|APT4U4U(>L""ug-"((\N:(!!eW,!''L>9'lD))S J\ JJJJOO+  "", E>dnn$$TYY!);,,,9J$$doo|: !-"00#nU6K2L1L1NO&*&>&>u&>&T#0TN #  r1   c                   > Ub  [        U5      S:X  a  U $ U R                  (       d  U R                  5         [        TU ]  " U4SU0UD6$ )a  Assign parameters to the n-local circuit.

This method also supports passing a list instead of a dictionary. If a list
is passed, the list must have the same length as the number of unbound parameters in
the circuit. The parameters are assigned in the order of the parameters in
:meth:`ordered_parameters`.

Returns:
    A copy of the NLocal circuit with the specified parameters.

Raises:
    AttributeError: If the parameters are given as list and do not match the number
        of parameters.
r   r   )r)   r   r   r:   assign_parameters)rU   r   r   kwargsrW   s       r/   r   NLocal.assign_parameters  sE    , ZA!5K~~KKMw(OWOOOr1   c                J   U R                   (       a~  Uc  U R                  X4U5      nUc6  [        [        [	        U5      5      5       Vs/ s H  n[        U5      PM     nn[        [        UR                  U5      5      nUR                  U5      $ UR                  5       $ s  snf )zUConvert ``block`` to a circuit of correct width and parameterized using the iterator.)rH   rP   ri   r)   r   nextdictzipr   r   r   )	rU   rx   
param_iterr   r   r   r   r   r   s	            r/   r   NLocal._parameterize_block6  s     ++ ~227wO~49#nU>S:T4UV4Uq$z*4UV#e..78F**622zz| Ws   	B c                |  ^^^ U R                   (       a  U R                  5       nO
[        5       nUR                  m[	        U R
                  5       GH]  u  nmU Vs1 s H  ofTR                  -  iM     snmU R                  (       a  [        T5      =nb  UUU4S j[        U R                  TR                  -  5       5       nU HK  n	[        UR                  " [        R                  " X'R                  5      6 U	5      n
UR                  U
5        MM     M  [        U R                  TR                  -  5       Vs/ s H=  nUT;  d  M  [!        [        UTR                  -  US-   TR                  -  5      5      PM?     nnU H'  nU R#                  TX#X]5      nUR%                  XSSS9  M)     GM`     gs  snf s  snf )zBuild a rotation layer.Nc              3     >#    U  H8  nUT;  d  M  [        TUTR                  -  US -   TR                  -   5      v   M:     g7f)r   N)r   r   )r   krx   skipped_blockstarget_qubitss     r/   r   /NLocal._build_rotation_layer.<locals>.<genexpr>X  sL      G. \E-E,<,<(<AIYIY?YZ[[Gs
   
A2Ar   TFr   )rJ   r   r   qubitsr   r   r   rQ   _stdlib_gate_from_simple_blockri   r   gate	itertoolsislice
num_params_appendrh   r   r   )rU   r.   r  r   skipped_qubitsr   qubitsimple_block
all_qubitsr  instrr
  r   r   r   rx   r  r  s                  @@@r/   _build_rotation_layerNLocal._build_rotation_layerG  s    ((!88:N UN "$"6"67HAuEST^Eu'7'77^TN55%CE%JJ\W"4??e6F6F#FG

 )F.$))9+;+;JH_H_+`aE OOE* ) #4??e6F6F#FG!G. RDq5#3#33a!eu?O?O5OPQG  !  -G*.*B*B5*YZ*d'OO$7$UZO[  -1 8T"!s   F4;
F9	6F9c                   UR                   n[        U R                  5       H  u  pVU R                  WXVR                  5      nU R
                  (       a}  [        U5      =nbo  U Hg  n	[        UR                  " [        R                  " X(R                  5      6 [        U	 Vs/ s H  o4U   PM	     sn5      5      n
UR                  U
5        Mi     M  U H'  n	U R                  XbX5U	5      nUR                  XSSS9  M)     M     gs  snf )zBuild an entanglement layer.NTFr   )r  r   r   r   r   rQ   r  r   r  r  r  r  r   r  r   r   )rU   r.   r  r   r  r   rx   r   r  r   r  r   s               r/   _build_entanglement_layer NLocal._build_entanglement_layern  s      !$":":;HA 221a9I9IJM55%CE%JJ\W,G /$))9+;+;JH_H_+`aAAQ/ABE OOE*  -  -G*.*B*B5VW\c*d'OO$7$UZO[  -# < Bs   !Dc           	        US:X  a  U R                   nU R                  nO<US:X  a+  [        U R                  5      n[        U R                  5      nO[        S5      e[        X45       HU  u  pV[        U[        5      (       a!  [        UR                  U R                  U5      nU H  nUR                  XWSSS9  M     MW     g )Nappended	prependedz1`which` must be either `appended` or `prepended`.TFr   )rC   rD   reversedrA   rB   r&   r  rf   r   r   r   r   )rU   r.   whichrw   entanglementsrx   entr   s           r/   _build_additional_layersNLocal._build_additional_layers  s    J**F 77Mk!d445F$T%A%ABMPQQf4JE#s##'(8(8$//3O5I  5r1   c                2  > U R                   (       a  g[        TU ]	  5         U R                  S:X  a  gU R                  (       d   [        U R                  SU R                  06nOU nU R                  (       a)  UR                  U R                  R                  5       SSS9  [        U R                  5      nU R                  US5        [        U R                  5       H  nU R                   (       a/  US:  d  [#        U R$                  5      S:  a  UR'                  5         U R)                  XU5        U R                   (       a)  [#        U R*                  5      S:  a  UR'                  5         U R-                  XU5        M     U R.                  (       dM  U R0                  (       a   U R                  S:  a  UR'                  5         U R)                  XU R                  5        U R                  US5        [3        UR4                  [6        5      (       a   [9        UR4                  5      Ul        U R                  (       d,   UR=                  5       nU RC                  X@RD                  SS	9  gg! [:         a     NJf = f! [>         a    URA                  5       n NHf = f)
z(If not already built, build the circuit.Nr   r%   TFr   r!  r   )r   )#r   r:   r   r   rN   r	   r_   r%   rT   r   r   iterr   r&  ri   r   r=   r)   rA   r   r  r@   r  rI   r    rf   global_phaser   floatrS   to_gater   rj   rg   r  )rU   r.   r  r   rx   rW   s        r/   r   NLocal._build  s   >>??a}}$djjAtyyAGG OOD..335t%OP$112
 	%%g{; tyy!A$$!a%3t7M7M3NQR3R! &&wA> $$T-B-B)Ca)G! **7B "  ..##		A!&&wDIIF 	%%gz: g**,?@@',W-A-A'B$
 }}1) KK{{K7 	    1..01s$   I) =I9 )
I65I69JJc                    g)zNIf certain blocks should use certain parameters this method can be overridden.Nr   )rU   reprx   r   s       r/   rP   NLocal._parameter_generator  s    r1   )rQ   rC   rD   rM   rE   r?   rF   rN   rK   rL   r=   r<   rG   rH   rA   rB   r>   r@   rI   rJ   r   r   rT   r   r_   r   )NNNNr   F   θTFFNnlocalN)r   z
int | Noner   lQuantumCircuit | list[QuantumCircuit] | qiskit.circuit.Instruction | list[qiskit.circuit.Instruction] | Noner   r3  r   z"list[int] | list[list[int]] | Noner   rR   r    ra   r!   r   r+   zbool | list[list[Parameter]]r"   ra   r#   ra   rT   QuantumCircuit | Noner%   
str | NonerV   zbool | NonereturnNone)r6  rR   )r   rR   r6  r7  )r6  ra   )rV   ra   r6  r7  )rm   z
typing.Anyr6  r	   )r6  zlist[QuantumCircuit])rw   zGQuantumCircuit | list[QuantumCircuit] | Instruction | list[Instruction]r6  r7  )r6  zstr | list[str] | list[list[str]] | list[int] | list[list[int]] | list[list[list[int]]] | list[list[list[list[int]]]] | Callable[[int], str] | Callable[[int], list[list[int]]])r   zstr | list[str] | list[list[str]] | list[int] | list[list[int]] | list[list[list[int]]] | list[list[list[list[int]]]] | Callable[[int], str] | Callable[[int], list[list[int]]] | Noner6  r7  )T)r   ra   r6  ra   )r6  list[Parameter])r   z!ParameterVector | list[Parameter]r6  r7  )r    ra   r6  r7  )r6  zset[int])r   rR   r6  r7  )r6  r   )r6  zlist[float] | None)r   rR   r   rR   r   rR   r6  zSequence[Sequence[int]])r6  r	   )rT   r	   r6  r7  )r6  z list[tuple[float, float]] | None)r   zlist[tuple[float, float]]r6  r7  )NF)r   z+QuantumCircuit | qiskit.circuit.Instructionr   z(list[int] | str | list[list[int]] | Noner   ra   r6  z'NLocal')F)r   zWMapping[Parameter, ParameterExpression | float] | Sequence[ParameterExpression | float]r   ra   r6  r4  )NNNNN)r6  r7  )r/  rR   rx   rR   r   z	list[int]r6  zParameter | None)%r   
__module____qualname____firstlineno____doc__r   r;   propertyr   setterrV   rn   r   r   r   r   r   r   r    r   r   r   r   r   r   rT   r   r   r   r   r  r  r&  r   rP   __static_attributes____classcell__)rW   s   @r/   r3   r3     s&   (T B(	 "&  ;? % $CG*/(-/3##5t/t/	t/t/" 9#t/$ %t/& 't/( )t/* %A+t/, $(-t/. "&/t/0 -1t/2 3t/4 5t/6 
7t/t/l G G 
A 
A # # ^^   R: % % T]T	T T ) ) X]X	X  X "	+" "* *	* 
* *0 I I!F ( (4  . % % 
4 
4" ' 'R   
[[% %$  xKxK'*xK>AxK	 xKt # #   
 
   BF	<:< ?< 	<
 
<F P dP
 P 
P P> Z^"%\N\2J ?8D r1   r3   c                    [        U [        5      (       a  [        U R                  5      $ U R                   Vs/ s H  n[        U[
        5      (       d  M  UPM     sn$ s  snf )a,  Return the list of Parameters objects inside a circuit or instruction.

This is required since, in a standard gate the parameters are not necessarily Parameter
objects (e.g. U3Gate(0.1, 0.2, 0.3).params == [0.1, 0.2, 0.3]) and instructions and
circuits do not have the same interface for parameters.
)rf   r	   rh   r   r   r   )rx   ps     r/   r   r     sH     %((E$$%% <<N<a:a9L+M<NNNs   AAc                X     [        XX#5      $ ! [         a  n[        S5      UeSnAff = f)a>  Get an entangler map for an arbitrary number of qubits.

Args:
    num_block_qubits: The number of qubits of the entangling block.
    num_circuit_qubits: The number of qubits of the circuit.
    entanglement: The entanglement strategy.
    offset: The block offset, can be used if the entanglements differ per block.
        See mode ``sca`` for instance.

Returns:
    The entangler map using mode ``entanglement`` to scatter a block of ``num_block_qubits``
    qubits on ``num_circuit_qubits`` qubits.

Raises:
    ValueError: If the entanglement mode ist not supported.
z5Something went wrong in Rust space, here's the error:N)fast_entangler_map	Exceptionr&   )r   num_circuit_qubitsr   r   excs        r/   r   r     s7    &[!"4]] [PQWZZ[s    
)$)_StdlibGateResult)r  r  c                X   U R                   S:w  d  [        U 5      S:w  a  g U R                  S   nUR                  (       d  [	        UR
                  5      [	        U R
                  5      :w  d  [        [        R                  UR                  R                  5      SS 5      UR                  R                  Ld6  [	        UR                  R                  5      [	        U R                  5      :w  a  g [        UR                  R                  [        UR                  R                  5      5      $ )Ng        r   r   
base_class)r*  r)   r-   clbitsr   r  rO   _STANDARD_GATE_MAPPINGget	operationr%   rJ  r   r   rH  )rx   instructions     r/   r  r  	  s    S CJ!O**Q-K 	##$ell(;;*..{/D/D/I/IJLZ^_((334 &&--.%8H8H2II[22==s;CXCXC_C_?`aar1   c           	     N  ^ ^ [        T [        5      (       a  T /T-  $ [        T 5      (       a  U U4S j$ [        T 5      S:X  a  / /$  [        T S   S   [        [
        R                  45      (       a  T /m [        T 5      T:w  a  [        S[        T 5       ST S35      e/ nT  HV  n[        U[        5      (       a  UR                  U5        M+  UR                  U Vs/ s H  n[        U5      PM     sn5        MX     U$ ! [         a  n[        ST  S35      UeSnAff = fs  snf )	zDIf the entanglement is Iterable[Iterable], normalize to list[tuple].c                (   > [        T" U 5      T5      $ rd   )r(   )r   r   num_entanglement_blockss    r/   <lambda>)_normalize_entanglement.<locals>.<lambda>+  s    5l66JLcdr1   r   zInvalid entanglement type: .NzNumber of block-entanglements (z,) must match number of entanglement blocks (z)!)rf   r   r   r)   rR   rt   r   rS   r   rg   r   )r   rR  rG  
normalizedrx   connectionss   ``    r/   r(   r(     s7    ,$$~ 777dd <AtPl1oa(3*>??(>L
 <33-c,.?-@ A$$;#<B@
 	
 JeS!!e$UKUku[1UKL	  %  P5l^1EFCOP  Ls   .D  D"
 
D
DDc                   [        U [        [        [        45      (       a  U /n / nU  GH3  n[        U[        5      (       a  [	        S5      eSn[        U[        5      (       a  XA;  a  [	        SU 35      eX   nSnOb[        U[        5      (       aM  [        USS 5      b?  [        UR                  5      S:X  a  SnO#U(       a  [        S UR                   5       5      nU(       a!  [        R                  " UR                  5      nOCU(       a  [        U5      u  pgO[        U5      u  pg[        R                  " UR                  Xg5      nUR!                  U5        GM6     U$ )NzThe blocks should be of type Gate or str, but you passed a QuantumCircuit. You can call .to_gate() on the circuit to turn it into a Gate object.FzUnsupported gate: T_standard_gater   c              3  B   #    U  H  n[        U[        5      v   M     g 7frd   )rf   r   )r   rB  s     r/   r   $_normalize_blocks.<locals>.<genexpr>n  s     !QLq*Q	":":Lr   )rf   r   r   r	   r&   rO   r)   r   r   r   from_standard_gaterY  _get_gate_builder_trivial_builderfrom_callabler   rg   )rw   r,   r+   rV  rx   is_standardnum_parametersbuilders           r/   r'   r'   L  s=    &3n566J e^,,X 
 eS!!+ #5eW!=>>#*EKt$$8H$)O)[5<< A%"+ "!QELL!QQ,,U-A-ABE)*;E*B'*:5*A'''(8(8.RE% G J r1   c                   ^  U 4S jnSU4$ )Nc                >   > TR                  5       nXR                  4$ rd   )r   r   )r   copiedr  s     r/   rb  !_trivial_builder.<locals>.builder  s    }}$$r1   r   r   )r  rb  s   ` r/   r^  r^    s    % g:r1   c                   ^ ^ [        5       nT R                   H2  n[        U[        5      (       d  M  U[        UR                  5      -  nM4     [        U5      n[        U5      mU U4S jnX44$ )a.  Construct a callable that handles parameter-rebinding.

For a given gate, this return the number of free parameters and a callable that can be
used to obtain a re-parameterized version of the gate. For example::

    x, y = Parameter("x"), Parameter("y")
    gate = CUGate(x, 2 * y, 0.5, 0.)

    num_parameters, builder = _build_gate(gate)
    print(num_parameters)  # prints 2

    a, b = Parameter("a"), Parameter("b")
    new_gate, new_params = builder([a, b])
    print(new_gate)  # CUGate(a, 2 * b, 0.5, 0)
    print(new_params)  # [a, 2 * b, 0.5, 0]

c                  > TR                  5       n[        [        TU 5      5      nTR                  R                  5       n[	        TR                  5       HG  u  pE[        U[        5      (       d  M  UR                   H  nUR                  XbU   5      nM     XSU'   MI     X1l        UR                  b  UR                  R                  USS9  X4$ )NT)r   )r   r  r  r   r   rf   r   r   assign_definitionr   )	new_parametersout
param_dictbound_paramsr   expr	parameterr  sorted_parameterss	          r/   rb  "_get_gate_builder.<locals>.builder  s    iik #/@A
{{'') -GA$ 344!%I;;yY2GHD "1"&Q	 . "
 ??&OO--j$-G  r1   )r   r   rf   r   r   r)   _sort_parameters)r  free_parametersrB  ra  rb  rq  s   `    @r/   r]  r]    sb    ( eO[[a,--s1<<00O  )N(9!( ""r1   c                    S n[        XS9$ )z!Sort a list of Parameter objects.c                    [        U [        5      (       a"  U R                  R                  U R                  4$ U R                  4$ rd   )rf   r   vectorr%   index)rp  s    r/   r   _sort_parameters.<locals>.key  s8    i!788$$))9??;;  r1   )r   )sorted)r   r   s     r/   rs  rs    s    !
 *&&r1   )full   Fr1  TFFr2  )r   rR   r   !str | Gate | Iterable[str | Gate]r   r}  r   rBlockEntanglement | Iterable[BlockEntanglement] | Callable[[int], BlockEntanglement | Iterable[BlockEntanglement]]r   rR   r    ra   r!   r   r+   ra   r"   ra   r#   ra   r%   r5  r6  r	   )rx   zQuantumCircuit | Instructionr6  r8  )r   )
r   rR   rF  rR   r   r   r   rR   r6  zSequence[tuple[int, ...]])rx   r	   r6  z_StdlibGateResult | None)r   r~  rR  rR   r6  zLlist[str | list[tuple[int]]] | Callable[[int], list[str | list[tuple[int]]]])rw   r}  r,   zdict[str, Gate]r+   ra   r6  zlist[Block])r  r   r6  zLtuple[int, Callable[list[Parameter], tuple[Gate, list[ParameterValueType]]]])9r<  
__future__r   collectionsr  typingcollections.abcr   r   r   r   rt   qiskit.circuit.gater   qiskit.circuit.quantumcircuitr	   r
   qiskit.circuit.parametervectorr   r   qiskit.circuitr   r   r   r   r   qiskit.exceptionsr   %qiskit.circuit.library.standard_gatesr   qiskit.utils.deprecationr   "qiskit._accelerate.circuit_libraryr   r   r   rD  blueprintcircuitr   TYPE_CHECKINGqiskitUnionr   rR   BlockEntanglementr0   r3   r   
namedtuplerH  rL  r  r(   r'   r^  r]  rs  r   r1   r/   <module>r     s   ! "    A A  $ L R *  * P 3  0 
 LLhx}&=!=>  	! '+&+$)SS6S ;S
	KS S S S !%S  $S "S S  !SlO Od
O VW[[/2[BE[OR[[4  **+>@VW 79 b*+	K+ !+ R+\0-0$0 !%0 	0f
Q1#
1#Q1#h'r1   