§
    º³Ùg$  ã                   ó”   — d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ  G d„ d	e¦  «        Ze G d
„ d¦  «        ¦   «         ZdS )zMCheck if the DAG has reached a relative semi-stable point over previous runs.é    )Údeepcopy)Ú	dataclassN)ÚTuple)Ú
DAGCircuit)ÚTransformationPassc                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )ÚMinimumPointa3  Check if the DAG has reached a relative semi-stable point over previous runs

    This pass is similar to the :class:`~.FixedPoint` transpiler pass and is intended
    primarily to be used to set a loop break condition in the property set.
    However, unlike the :class:`~.FixedPoint` class which only sets the
    condition if 2 consecutive runs have the same value property set value
    this pass is designed to find a local minimum and use that instead. This
    pass is designed for an optimization loop where a fixed point may never
    get reached (for example if synthesis is used and there are multiple
    equivalent outputs for some cases).

    This pass will track the state of fields in the property set over its past
    executions and set a boolean field when either a fixed point is reached
    over the backtracking depth or selecting the minimum value found if the
    backtracking depth is reached. To do this it stores a deep copy of the
    current minimum DAG in the property set and when ``backtrack_depth`` number
    of executions is reached since the last minimum the output dag is set to
    that copy of the earlier minimum.

    Fields used by this pass in the property set are (all relative to the ``prefix``
    argument):

    * ``{prefix}_minimum_point_state`` - Used to track the state of the minimum point search
    * ``{prefix}_minimum_point`` - This value gets set to ``True`` when either a fixed point
        is reached over the ``backtrack_depth`` executions, or ``backtrack_depth`` was exceeded
        and an earlier minimum is restored.
    é   c                 óŒ   •— t          ¦   «                              ¦   «          || _        |› d�| _        |› d�| _        || _        dS )a	  Initialize an instance of this pass

        Args:
            property_set_list (list): A list of property set keys that will
                be used to evaluate the local minimum. The values of these
                property set keys will be used as a tuple for comparison
            prefix (str): The prefix to use for the property set key that is used
                for tracking previous evaluations
            backtrack_depth (int): The maximum number of entries to store. If
                this number is reached and the next iteration doesn't have
                a decrease in the number of values the minimum of the previous
                n will be set as the output dag and ``minimum_point`` will be set to
                ``True`` in the property set
        Ú_minimum_point_stateÚ_minimum_pointN)ÚsuperÚ__init__Úproperty_set_listÚbacktrack_nameÚminimum_reachedÚbacktrack_depth)Úselfr   Úprefixr   Ú	__class__s       €úb/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/utils/minimum_point.pyr   zMinimumPoint.__init__5   sS   ø€ õ 	‰Œ×ÒÑÔÐØ!2ˆÔà!'Ð=Ð=Ð=ˆÔØ"(Ð8Ð8Ð8ˆÔØ.ˆÔÐÐó    c                 ó(  ‡ — t          ˆ fd„‰ j        D ¦   «         ¦  «        }‰ j        ‰ j                 }|€@t	          dt
          j        ft          ‰ j        ¦  «        z  d¬¦  «        ‰ j        ‰ j        <   nœ||j        k    rG|xj	        dz  c_	        |j	        ‰ j
        k    r&d‰ j        ‰ j        <   ‰ j        ‰ j                 j        S nJ||j        k     r#d|_	        ||_        t          |¦  «        |_        n||j        k    rd‰ j        ‰ j        <   |S |S )z#Run the MinimumPoint pass on `dag`.c              3   ó2   •K  — | ]}‰j         |         V — Œd S )N)Úproperty_set)Ú.0Úxr   s     €r   ú	<genexpr>z#MinimumPoint.run.<locals>.<genexpr>M   s+   øè è € ÐKÐK¨q�dÔ'¨Ô*ÐKÐKÐKÐKÐKÐKr   Nr   ©ÚdagÚscoreÚsinceé   T)Útupler   r   r   Ú_MinimumPointStateÚmathÚinfÚlenr!   r"   r   r   r    r   )r   r    r!   Ústates   `   r   ÚrunzMinimumPoint.runK   s*  ø€ åÐKÐKÐKÐK°DÔ4JÐKÑKÔKÑKÔKˆØÔ! $Ô"5Ô6ˆð
 ˆ=Ý5GØ¥¤ ­c°$Ô2HÑ.IÔ.IÑ IÐQRð6ñ 6ô 6ˆDÔ˜dÔ1Ñ2Ð2ð
 �U”[Ò Ð ØˆKŒK˜1ÑˆKŒKØŒ{˜dÔ2Ò2Ð2Ø:>�Ô! $Ô"6Ñ7ØÔ(¨Ô)<Ô=ÔAÐAð 3ð �U”[Ò Ð ØˆEŒKØˆEŒKÝ  ™œˆEŒIˆIð
 �e”kÒ!Ð!Ø6:ˆDÔ˜dÔ2Ñ3ØˆJàˆ
r   )r
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   Ú__classcell__)r   s   @r   r	   r	      sV   ø€ € € € € ðð ð8/ð /ð /ð /ð /ð /ð,"ð "ð "ð "ð "ð "ð "r   r	   c                   óB   — e Zd ZU dZeed<   eedf         ed<   eed<   dS )r%   r   r    .r!   r"   N)	r+   r,   r-   Ú	__slots__r   Ú__annotations__r   ÚfloatÚint© r   r   r%   r%   p   s<   € € € € € € à)€Ià	€O€O�OØ�˜�ÔÐÐÑØ€J€J�J€J€Jr   r%   )r.   Úcopyr   Údataclassesr   r&   Útypingr   Úqiskit.dagcircuit.dagcircuitr   Úqiskit.transpiler.basepassesr   r	   r%   r5   r   r   ú<module>r;      sã   ðð TÐ Sà Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø €€€Ø Ð Ð Ð Ð Ð à 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;ðUð Uð Uð Uð UÐ%ñ Uô Uð Uðp ðð ð ð ð ñ ô ñ „ðð ð r   