ó
    Óz	iÍ8  ã                  óÒ   • S r SSKJ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Jr  SSKJr  SS	KJrJr  SS
KJr          S                   SS jjr " S S\5      rg)z)The ExcitationPreserving 2-local circuit.é    )Úannotations)ÚCallableÚIterable)Úpi)ÚQuantumCircuitÚ	Parameter)ÚRZGateÚXXPlusYYGate)Údeprecate_funcé   )Ún_localÚBlockEntanglement)ÚTwoLocalÚExcitationPreservingc	                óH  • SS/n	X;  a  [        SU SU	 35      e[        S5      n
U S:”  a`  [        SSS	9nUR                  [	        SU
-  5      S
S/5        US:X  a  [        S5      nUR                  US
S5        UR                  5       /nO/ n[        U S/UUUUUSUUU5      $ )a€
  The heuristic excitation-preserving wave function ansatz.

The ``excitation_preserving`` circuit preserves the ratio of :math:`|00\rangle`,
:math:`|01\rangle + |10\rangle` and :math:`|11\rangle` states. To this end, this circuit
uses two-qubit interactions of the form

.. math::

    \newcommand{\rotationangle}{\theta/2}

    \begin{pmatrix}
    1 & 0 & 0 & 0 \\
    0 & \cos\left(\rotationangle\right) & -i\sin\left(\rotationangle\right) & 0 \\
    0 & -i\sin\left(\rotationangle\right) & \cos\left(\rotationangle\right) & 0 \\
    0 & 0 & 0 & e^{-i\phi}
    \end{pmatrix}

for the mode ``"fsim"`` or with :math:`e^{-i\phi} = 1` for the mode ``"iswap"``.

Note that other wave functions, such as UCC-ansatzes, are also excitation preserving.
However these can become complex quickly, while this heuristically motivated circuit follows
a simpler pattern.

This trial wave function consists of layers of :math:`Z` rotations with 2-qubit entanglements.
The entangling is creating using :math:`XX+YY` rotations and optionally a controlled-phase
gate for the mode ``"fsim"``.

Examples:

With linear entanglement, this circuit is given by:

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

    from qiskit.circuit.library import excitation_preserving

    ansatz = excitation_preserving(3, reps=1, insert_barriers=True, entanglement="linear")
    ansatz.draw("mpl")

The entanglement structure can be explicitly specified with the ``entanglement``
argument. The ``"fsim"`` mode includes an additional parameterized :class:`.CPhaseGate`
in each block:

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

    ansatz = excitation_preserving(3, reps=1, mode="fsim", entanglement=[[0, 2]])
    ansatz.draw("mpl")

Args:
    num_qubits: The number of qubits.
    mode: Choose the entangler mode, can be `"iswap"` or `"fsim"`.
    reps: Specifies how often the structure of a rotation layer followed by an entanglement
        layer is repeated.
    entanglement: The indices specifying on which qubits the input blocks act.
        See :func:`.n_local` for detailed information.
    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.
    parameter_prefix: The name of the free parameters.
    insert_barriers: If True, barriers are inserted in between each layer. If False,
        no barriers are inserted.
    name: The name of the circuit.

Returns:
    An excitation-preserving circuit.
ÚiswapÚfsimúUnsupported mode ú, choose one of õ   Î¸r   é   ÚInteraction©Únamer   õ   Ï†ÚrzT)Ú
ValueErrorr   r   Úappendr
   ÚcpÚto_gater   )Ú
num_qubitsÚmodeÚentanglementÚrepsÚskip_unentangled_qubitsÚskip_final_rotation_layerÚparameter_prefixÚinsert_barriersr   Úsupported_modesÚthetaÚswapÚphiÚentanglement_blockss                 Ún/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/n_local/excitation_preserving.pyÚexcitation_preservingr/      sÌ   € ðl  Ð'€OØÓ"ÜÐ,¨T¨FÐ2BÀ?ÐBSÐTÓUÐUäd‹O€EØAƒ~Ü˜a mÑ4ˆØ‰”L  U¡Ó+¨a°¨VÔ4Ø6‹>Ü˜D“/ˆCØG‰GC˜˜AÔØ#Ÿ|™|›~Ð.Ñà ÐäØØ	ˆØØØØØØØ!ØØóð ó    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S	r	U =r
$ )r   éŽ   u  The heuristic excitation-preserving wave function ansatz.

The ``ExcitationPreserving`` circuit preserves the ratio of :math:`|00\rangle`,
:math:`|01\rangle + |10\rangle` and :math:`|11\rangle` states. To this end, this circuit
uses two-qubit interactions of the form

.. math::

    \newcommand{\rotationangle}{\theta/2}

    \begin{pmatrix}
    1 & 0 & 0 & 0 \\
    0 & \cos\left(\rotationangle\right) & -i\sin\left(\rotationangle\right) & 0 \\
    0 & -i\sin\left(\rotationangle\right) & \cos\left(\rotationangle\right) & 0 \\
    0 & 0 & 0 & e^{-i\phi}
    \end{pmatrix}

for the mode ``'fsim'`` or with :math:`e^{-i\phi} = 1` for the mode ``'iswap'``.

Note that other wave functions, such as UCC-ansatzes, are also excitation preserving.
However these can become complex quickly, while this heuristically motivated circuit follows
a simpler pattern.

This trial wave function consists of layers of :math:`Z` rotations with 2-qubit entanglements.
The entangling is creating using :math:`XX+YY` rotations and optionally a controlled-phase
gate for the mode ``'fsim'``.

See :class:`~qiskit.circuit.library.RealAmplitudes` for more detail on the possible arguments
and options such as skipping unentanglement qubits, which apply here too.

The rotations of the ExcitationPreserving ansatz can be written as

Examples:

    >>> ansatz = ExcitationPreserving(3, reps=1, insert_barriers=True, entanglement='linear')
    >>> print(ansatz.decompose())  # show the circuit
         â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â” â–‘ â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”                             â–‘ â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
    q_0: â”¤ RZ(Î¸[0]) â”œâ”€â–‘â”€â”¤0           â”œâ”¤0           â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â–‘â”€â”¤ RZ(Î¸[5]) â”œ
         â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤ â–‘ â”‚  RXX(Î¸[3]) â”‚â”‚  RYY(Î¸[3]) â”‚â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â” â–‘ â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    q_1: â”¤ RZ(Î¸[1]) â”œâ”€â–‘â”€â”¤1           â”œâ”¤1           â”œâ”¤0           â”œâ”¤0           â”œâ”€â–‘â”€â”¤ RZ(Î¸[6]) â”œ
         â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤ â–‘ â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â”‚  RXX(Î¸[4]) â”‚â”‚  RYY(Î¸[4]) â”‚ â–‘ â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    q_2: â”¤ RZ(Î¸[2]) â”œâ”€â–‘â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤1           â”œâ”¤1           â”œâ”€â–‘â”€â”¤ RZ(Î¸[7]) â”œ
         â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜ â–‘                             â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜ â–‘ â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

    >>> ansatz = ExcitationPreserving(2, reps=1, flatten=True)
    >>> qc = QuantumCircuit(2)  # create a circuit and append the RY variational form
    >>> qc.cry(0.2, 0, 1)  # do some previous operation
    >>> qc.compose(ansatz, inplace=True)  # add the excitation-preserving
    >>> qc.draw()
                    â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
    q_0: â”€â”€â”€â”€â”€â– â”€â”€â”€â”€â”€â”¤ RZ(Î¸[0]) â”œâ”¤0           â”œâ”¤0           â”œâ”¤ RZ(Î¸[3]) â”œ
         â”Œâ”€â”€â”€â”€â”´â”€â”€â”€â”€â”â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤â”‚  RXX(Î¸[2]) â”‚â”‚  RYY(Î¸[2]) â”‚â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    q_1: â”¤ RY(0.2) â”œâ”¤ RZ(Î¸[1]) â”œâ”¤1           â”œâ”¤1           â”œâ”¤ RZ(Î¸[4]) â”œ
         â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

    >>> ansatz = ExcitationPreserving(3, reps=1, mode='fsim', entanglement=[[0,2]],
    ... insert_barriers=True, flatten=True)
    >>> print(ansatz.decompose())
         â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â” â–‘ â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”        â–‘ â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
    q_0: â”¤ RZ(Î¸[0]) â”œâ”€â–‘â”€â”¤0           â”œâ”¤0           â”œâ”€â– â”€â”€â”€â”€â”€â”€â–‘â”€â”¤ RZ(Î¸[5]) â”œ
         â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤ â–‘ â”‚            â”‚â”‚            â”‚ â”‚      â–‘ â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    q_1: â”¤ RZ(Î¸[1]) â”œâ”€â–‘â”€â”¤  RXX(Î¸[3]) â”œâ”¤  RYY(Î¸[3]) â”œâ”€â”¼â”€â”€â”€â”€â”€â”€â–‘â”€â”¤ RZ(Î¸[6]) â”œ
         â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤ â–‘ â”‚            â”‚â”‚            â”‚ â”‚Î¸[4]  â–‘ â”œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¤
    q_2: â”¤ RZ(Î¸[2]) â”œâ”€â–‘â”€â”¤1           â”œâ”¤1           â”œâ”€â– â”€â”€â”€â”€â”€â”€â–‘â”€â”¤ RZ(Î¸[7]) â”œ
         â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜ â–‘ â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜        â–‘ â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

.. seealso::

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

z2.1zFUse the function qiskit.circuit.library.excitation_preserving instead.zin Qiskit 3.0)ÚsinceÚadditional_msgÚremoval_timelinec                ó$  >• SS/nX,;  a  [        SU SU 35      e[        S5      n[        SSS9nUR                  [	        SU-  5      S	S
/5        US:X  a  [        S5      nUR                  US	S
5        [        T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 ExcitationPreserving circuit.
    mode: Choose the entangler mode, can be `'iswap'` or `'fsim'`.
    reps: Specifies how often the structure of a rotation layer followed by an entanglement
        layer is repeated.
    entanglement: Specifies the entanglement structure. Can be a string ('full', 'linear'
        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.
        See the Examples section of :class:`~qiskit.circuit.library.TwoLocal` for more
        detail.
    initial_state: A `QuantumCircuit` object to prepend to the circuit.
    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 True, a rotation layer is added at the end of the
        ansatz. If False, no rotation layer is added. Defaults to True.
    parameter_prefix: The parameterized gates require a parameter to be defined, for which
        we use :class:`~qiskit.circuit.ParameterVector`.
    insert_barriers: If True, barriers are inserted in between each layer. If False,
        no barriers are inserted.
    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 the selected mode is not supported.
r   r   r   r   r   r   r   r   r   r   r   )r!   Úrotation_blocksr-   r#   r$   r%   r&   r'   r(   Úinitial_stater   ÚflattenN)	r   r   r   r   r
   r   ÚsuperÚ__init__r	   )Úselfr!   r"   r#   r$   r%   r&   r'   r(   r8   r   r9   r)   r*   r+   r,   Ú	__class__s                   €r.   r;   ÚExcitationPreserving.__init__Ø   s·   ø€ ðh # FÐ+ˆØÓ&ÜÐ0°°Ð6FÀÐFWÐXÓYÐYä˜$“ˆÜ˜a mÑ4ˆØ‰”L  U¡Ó+¨a°¨VÔ4Ø6‹>Ü˜D“/ˆCØG‰GC˜˜AÔä‰ÑØ!Ü"Ø $Ø%ØØ$;Ø&?Ø-Ø+Ø'ØØð 	ò 	
r0   c                ó8   • U R                   [        * [        4/-  $ )zAReturn the parameter bounds.

Returns:
    The parameter bounds.
)Únum_parametersr   )r<   s    r.   Úparameter_boundsÚ%ExcitationPreserving.parameter_bounds&  s   € ð ×"Ñ"¬ s¬B i [Ñ0Ð0r0   © )Nr   Úfullé   FFr   FNr   N)r!   z
int | Noner"   Ústrr#   z2str | list[list[int]] | Callable[[int], list[int]]r$   Úintr%   Úboolr&   rH   r'   rF   r(   rH   r8   zQuantumCircuit | Noner   rF   r9   zbool | NoneÚreturnÚNone)rI   zlist[tuple[float, float]])Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r;   ÚpropertyrA   Ú__static_attributes__Ú__classcell__)r=   s   @r.   r   r   Ž   sé   ø† ñGñR ØØ_Ø(ñð "&ØØKQØØ(-Ø*/Ø $Ø %Ø/3Ø*Ø#ðG
àðG
ð ðG
ð Ið	G
ð
 ðG
ð "&ðG
ð $(ðG
ð ðG
ð ðG
ð -ðG
ð ðG
ð ðG
ð 
÷G
óð
G
ðR ó1ó ö1r0   N)r   rD   rE   FFr   Fr   )r!   rG   r"   rF   r#   zrBlockEntanglement | Iterable[BlockEntanglement] | Callable[[int], BlockEntanglement | Iterable[BlockEntanglement]]r$   rG   r%   rH   r&   rH   r'   rF   r(   rH   r   rF   rI   r   )rO   Ú
__future__r   Úcollections.abcr   r   Únumpyr   Úqiskit.circuitr   r   Ú%qiskit.circuit.library.standard_gatesr	   r
   Úqiskit.utils.deprecationr   r   r   Ú	two_localr   r/   r   rC   r0   r.   Ú<module>rZ      s¾   ðñ 0å "ß .Ý ç 4ß FÝ 3ß /Ý ð
 ð
 	ØØ$)Ø&+Ø Ø!Ø&ðqØðqà
ðqð	Kð	qð ðqð "ðqð  $ðqð ðqð ðqð ðqð õqôh_1˜8õ _1r0   