§
    ¹³Ùgu  ã                  óæ   — d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZmZmZ  ej        e¦  «        ZeZ G d	„ d
e¦  «        Z G d„ dee¦  «        Z G d„ dee¦  «        ZdS )z:Baseclasses for the Qiskit passmanager optimization tasks.é    )ÚannotationsN)ÚabstractmethodÚABC)ÚIterableÚCallableÚ	Generator)ÚAnyé   )ÚRunStateÚPassManagerStateÚPropertySetc                  ó.   — e Zd ZdZe	 ddd„¦   «         ZdS )ÚTaskzáAn interface of the pass manager task.

    The task takes a Qiskit IR, and outputs new Qiskit IR after some operation on it.
    A task can rely on the :class:`.PropertySet` to communicate intermediate data among tasks.
    NÚpassmanager_irÚPassManagerIRÚstater   Úcallbackr   Úreturnú&tuple[PassManagerIR, PassManagerState]c                ó   — dS )a|  Execute optimization task for input Qiskit IR.

        Args:
            passmanager_ir: Qiskit IR to optimize.
            state: State associated with workflow execution by the pass manager itself.
            callback: A callback function which is caller per execution of optimization task.

        Returns:
            Optimized Qiskit IR and state of the workflow.
        N© )Úselfr   r   r   s       úS/granary/edev/quantum/lib/python3.11/site-packages/qiskit/passmanager/base_tasks.pyÚexecutezTask.execute%   s	   € ð" 	ˆó    ©N©r   r   r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      sH   € € € € € ðð ð ð
 "ð	ð ð ð ñ „^ðð ð r   r   c                  óL   — e Zd ZdZd„ Zdd„Z	 ddd„Zdd„Zedd„¦   «         Z	dS )ÚGenericPassz«Base class of a single pass manager task.

    A pass instance can read and write to the provided :class:`.PropertySet`,
    and may modify the input pass manager IR.
    c                ó:   — t          ¦   «         | _        g | _        d S r   )r   Úproperty_setÚrequires©r   s    r   Ú__init__zGenericPass.__init__@   s   € Ý'™MœMˆÔØ(*ˆŒˆˆr   r   Ústrc                ó   — | j         j        S )zName of the pass.)Ú	__class__r   r'   s    r   ÚnamezGenericPass.nameD   s   € àŒ~Ô&Ð&r   Nr   r   r   r   r   r   r   c           	     ó–  — |j         | _         | j        r/ddlm}  || j        ¦  «                             |||¬¦  «        \  }}d }d }t          j        ¦   «         }	 | |j        j        vr"|                      |¦  «        }t          j
        }nt          j        }n# t          $ r t          j        }‚ w xY w|p|}|t          j        k    rht          j        ¦   «         |z
  }t                               d|                      ¦   «         |dz  ¦  «         |� || ||j         ||j        j        ¬¦  «         nƒ# |p|}|t          j        k    rit          j        ¦   «         |z
  }t                               d|                      ¦   «         |dz  ¦  «         |�! || ||j         ||j        j        ¬¦  «         w w w xY w||                      ||¦  «        fS )Nr
   )ÚFlowControllerLinear©r   r   r   zPass: %s - %.5f (ms)iè  )Útaskr   r%   Úrunning_timeÚcount)r%   r&   Úflow_controllersr.   r   ÚtimeÚworkflow_statusÚcompleted_passesÚrunr   ÚSUCCESSÚSKIPÚ	ExceptionÚFAILÚloggerÚinfor,   r2   Úupdate_status)	r   r   r   r   r.   Ú	run_stateÚretÚ
start_timer1   s	            r   r   zGenericPass.executeH   s  € ð "Ô.ˆÔàŒ=ð 	à>Ð>Ð>Ð>Ð>Ð>à$8Ð$8¸¼Ñ$GÔ$G×$OÒ$OØ-ØØ!ð %Pñ %ô %Ñ!ˆN˜Eð ˆ	ØˆÝ”Y‘[”[ˆ
ð	Ø˜5Ô0ÔAÐAÐAØ—h’h˜~Ñ.Ô.�Ý$Ô,�	�	å$œM�	øøÝð 	ð 	ð 	Ý œˆIØð	øøøð Ð'˜ˆCØ�HœMÒ)Ð)Ý#œy™{œ{¨ZÑ7�Ý—’Ð2°D·I²I±K´KÀÐPTÑATÑUÔUÐUØÐ'Ø�HØ!Ø'*Ø%*Ô%7Ø%1Ø#Ô3Ô9ðñ ô ð øøð Ð'˜ˆCØ�HœMÒ)Ð)Ý#œy™{œ{¨ZÑ7�Ý—’Ð2°D·I²I±K´KÀÐPTÑATÑUÔUÐUØÐ'Ø�HØ!Ø'*Ø%*Ô%7Ø%1Ø#Ô3Ô9ðñ ô ð ð ð	 *ð (øøøð �D×&Ò& u¨iÑ8Ô8Ð8Ð8s   Á<B ÂD0 ÂB0Â0D0 Ä0B F0r?   r   c                ó¦   — ||j         _        |t          j        k    r4|j         xj        dz  c_        |j         j                             | ¦  «         |S )zÔUpdate workflow status.

        Args:
            state: Pass manager state to update.
            run_state: Completion status of current task.

        Returns:
            Updated pass manager state.
        r
   )r5   Úprevious_runr   r8   r2   r6   Úadd)r   r   r?   s      r   r>   zGenericPass.update_statusx   sS   € ð .7ˆÔÔ*Ø�Ô(Ò(Ð(ØÔ!Ð'Ô'¨1Ñ,Ð'Ô'ØÔ!Ô2×6Ò6°tÑ<Ô<Ð<Øˆr   c                ó   — dS )z”Run optimization task.

        Args:
            passmanager_ir: Qiskit IR to optimize.

        Returns:
            Optimized Qiskit IR.
        Nr   )r   r   s     r   r7   zGenericPass.runŒ   s	   € ð 	ˆr   )r   r)   r   r   )r   r   r?   r   r   r   )r   r   r   r   )
r   r   r    r!   r(   r,   r   r>   r   r7   r   r   r   r#   r#   9   s”   € € € € € ðð ð+ð +ð +ð'ð 'ð 'ð 'ð "ð	.9ð .9ð .9ð .9ð .9ð`ð ð ð ð( ðð ð ñ „^ðð ð r   r#   c                  óB   — e Zd ZdZ	 ddd„Zedd
„¦   «         Z	 ddd„ZdS )ÚBaseControllera9  Base class of controller.

    A controller is built with a collection of pass manager tasks,
    and a subclass provides a custom logic to choose next task to run.
    Note a controller can be nested into another controller,
    and a controller itself doesn't provide any subroutine to modify the input IR.
    NÚoptionsúdict[str, Any] | Nonec                ó   — |pi | _         dS )ziCreate new flow controller.

        Args:
            options: Option for this flow controller.
        N)Ú_options)r   rH   s     r   r(   zBaseController.__init__¥   s   € ð  ˜ 2ˆŒˆˆr   r   r   r   ú'Generator[Task, PassManagerState, None]c                ó   — dS )aV  A custom logic to choose a next task to run.

        Controller subclass can consume the state to build a proper task pipeline.  The updated
        state after a task execution will be fed back in as the "return" value of any ``yield``
        statements.  This indicates the order of task execution is only determined at running time.
        This method is not allowed to mutate the given state object.

        Args:
            state: The state of the passmanager workflow at the beginning of this flow controller's
                execution.

        Receives:
            state: the state of pass manager after the execution of the last task that was yielded.
                The generator does not need to inspect this if it is irrelevant to its logic, nor
                update it.

        Yields:
            Task: Next task to run.
        Nr   )r   r   s     r   Ú
iter_taskszBaseController.iter_tasks°   s	   € ð0 	ˆr   r   r   r   r   r   c                ó  — |                       |¦  «        }	 |                     d ¦  «        }n# t          $ r ||fcY S w xY w	 |                     |||¬¦  «        \  }}	 |                     |¦  «        }n# t          $ r Y nw xY wŒC||fS )NTr/   )rN   ÚsendÚStopIterationr   )r   r   r   r   Útask_generatorÚ	next_tasks         r   r   zBaseController.executeÊ   sÖ   € ð Ÿš¨Ñ/Ô/ˆð	)Ø&×+Ò+¨DÑ1Ô1ˆIˆIøÝð 	)ð 	)ð 	)Ø! 5Ð(Ð(Ð(Ð(ð	)øøøð	Ø$-×$5Ò$5Ø-ØØ!ð %6ñ %ô %Ñ!ˆN˜Eð
ð +×/Ò/°Ñ6Ô6�	�	øÝ ð ð ð Ø�ðøøøð	ð ˜uÐ$Ð$s   —- ­>½>ÁA4 Á4
BÂ Br   )rH   rI   )r   r   r   rL   r   )r   r   r    r!   r(   r   rN   r   r   r   r   rG   rG   œ   sz   € € € € € ðð ð *.ð	&ð 	&ð 	&ð 	&ð 	&ð ðð ð ñ „^ðð: "ð	%ð %ð %ð %ð %ð %ð %r   rG   )r!   Ú
__future__r   Úloggingr4   Úabcr   r   Úcollections.abcr   r   r   Útypingr	   Úcompilation_statusr   r   r   Ú	getLoggerr   r<   r   r   r#   rG   r   r   r   ú<module>r[      sP  ðð AÐ @Ø "Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø Ð Ð Ð Ð Ð à GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ Gà	ˆÔ	˜8Ñ	$Ô	$€ð €ðð ð ð ð ˆ3ñ ô ð ð6`ð `ð `ð `ð `�$˜ñ `ô `ð `ðFJ%ð J%ð J%ð J%ð J%�T˜3ñ J%ô J%ð J%ð J%ð J%r   