§
    º³Ùgê  ã                  ó
  — d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlmZ d	d
lmZ d	dlmZ  e¦   «          e	¦   «          e
¦   «          e¦   «          eedz  ¦  «        dœZ G d„ de¦  «        ZdS )zAReplace each block of consecutive gates by a single Unitary node.é    )Úannotations)Úpi)ÚTwoQubitBasisDecomposer)ÚCXGateÚCZGateÚ	iSwapGateÚECRGateÚRXXGate)ÚTransformationPass)ÚPassManager)Úconsolidate_blocksé   )ÚCollect1qRuns)ÚCollect2qBlocksé   )ÚcxÚczÚiswapÚecrÚrxxc                  ó:   ‡ — e Zd ZdZ	 	 	 	 	 dˆ fd„	Zd„ Zd„ Zˆ xZS )	ÚConsolidateBlocksaÜ  Replace each block of consecutive gates by a single Unitary node.

    Pass to consolidate sequences of uninterrupted gates acting on
    the same qubits into a Unitary node, to be resynthesized later,
    to a potentially more optimal subcircuit.

    Notes:
        This pass assumes that the 'blocks_list' property that it reads is
        given such that blocks are in topological order. The blocks are
        collected by a previous pass, such as `Collect2qBlocks`.
    NFç      ð?c                ó&  •— t          ¦   «                              ¦   «          d| _        || _        |�t	          |¦  «        | _        || _        |�t          |¦  «        | _        dS |�Št           	                    ¦   «         |pg z  }|r7t          t          | 
                    ¦   «                  |pd¬¦  «        | _        dS d|v r&t          t          ¦   «         |pd¬¦  «        | _        dS d| _        dS t          t          ¦   «         ¦  «        | _        dS )aÎ  ConsolidateBlocks initializer.

        If ``kak_basis_gate`` is not ``None`` it will be used as the basis gate for KAK decomposition.
        Otherwise, if ``basis_gates`` is not ``None`` a basis gate will be chosen from this list.
        Otherwise, the basis gate will be :class:`.CXGate`.

        Args:
            kak_basis_gate (Gate): Basis gate for KAK decomposition.
            force_consolidate (bool): Force block consolidation.
            basis_gates (List(str)): Basis gates from which to choose a KAK gate.
            approximation_degree (float): a float between :math:`[0.0, 1.0]`. Lower approximates more.
            target (Target): The target object for the compilation target backend.
        Nr   )Úbasis_fidelityÚrzx)ÚsuperÚ__init__Úbasis_gatesÚtargetÚsetÚforce_consolidater   Ú
decomposerÚKAK_GATE_NAMESÚkeysÚpopr   )ÚselfÚkak_basis_gater"   r   Úapproximation_degreer    Ú	kak_gatesÚ	__class__s          €ún/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/optimization/consolidate_blocks.pyr   zConsolidateBlocks.__init__1   s  ø€ õ* 	‰Œ×ÒÑÔÐØˆÔØˆŒØÐ"Ý" ;Ñ/Ô/ˆDÔØ!2ˆÔØÐ%Ý5°nÑEÔEˆDŒOˆOˆOØÐ$Ý&×+Ò+Ñ-Ô-°Ð1BÀÑCˆIØð 	'Ý"9Ý" 9§=¢=¡?¤?Ô3ÐDXÐD_Ð\_ð#ñ #ô #�”��ð ˜+Ð%Ð%Ý"9Ý‘H”HÐ-AÐ-HÀSð#ñ #ô #�”��ð #'�”��å5µf±h´hÑ?Ô?ˆDŒOˆOˆOó    c           
     óp  — | j         €|S | j        d         }|�d„ |D ¦   «         }| j        d         }|�d„ |D ¦   «         }t          || j         j        | j         j        j        | j        | j        | j        ||¬¦  «         |  	                    |¦  «        }d| j        v r| j        d= d| j        v r| j        d= |S )z—Run the ConsolidateBlocks pass on `dag`.

        Iterate over each block and replace it with an equivalent Unitary
        on the same wires.
        NÚ
block_listc                ó&   — g | ]}d „ |D ¦   «         ‘ŒS )c                ó   — g | ]	}|j         ‘Œ
S © ©Ú_node_id©Ú.0Únodes     r,   ú
<listcomp>z4ConsolidateBlocks.run.<locals>.<listcomp>.<listcomp>h   s   € Ð7Ð7Ð7¨�t”}Ð7Ð7Ð7r-   r2   )r6   Úblocks     r,   r8   z)ConsolidateBlocks.run.<locals>.<listcomp>h   s'   € ÐLÐLÐL¸EÐ7Ð7°Ð7Ñ7Ô7ÐLÐLÐLr-   Úrun_listc                ó&   — g | ]}d „ |D ¦   «         ‘ŒS )c                ó   — g | ]	}|j         ‘Œ
S r2   r3   r5   s     r,   r8   z4ConsolidateBlocks.run.<locals>.<listcomp>.<listcomp>k   s   € Ð3Ð3Ð3 t�T”]Ð3Ð3Ð3r-   r2   )r6   Úruns     r,   r8   z)ConsolidateBlocks.run.<locals>.<listcomp>k   s'   € ÐDÐDÐD¸Ð3Ð3¨sÐ3Ñ3Ô3ÐDÐDÐDr-   )r    r   ÚblocksÚruns)
r#   Úproperty_setr   Ú_inner_decomposerÚgateÚnamer"   r    r   Ú_handle_control_flow_ops)r'   Údagr>   r?   s       r,   r=   zConsolidateBlocks.run]   sï   € ð Œ?Ð"ØˆJàÔ" <Ô0ˆØÐØLÐLÀVÐLÑLÔLˆFØÔ  Ô,ˆØÐØDÐD¸tÐDÑDÔDˆDåØØŒOÔ-ØŒOÔ Ô%ØÔ"Ø”;ØÔ(ØØð		
ñ 		
ô 		
ð 		
ð ×+Ò+¨CÑ0Ô0ˆð ˜Ô*Ð*Ð*ØÔ! *Ð-Ø˜4Ô,Ð,Ð,ØÔ! ,Ð/àˆ
r-   c                ó¦  ‡— t          ¦   «         Šd| j        v rB‰                     t          ¦   «         ¦  «         ‰                     t	          ¦   «         ¦  «         ‰                     | ¦  «         |                     ¦   «         }|�K|D ]H}|                     ||j                             ˆfd„|j        j	        D ¦   «         ¦  «        d¬¦  «         ŒI|S )zš
        This is similar to transpiler/passes/utils/control_flow.py except that the
        collect blocks is redone for the control flow blocks.
        r:   Nc              3  óB   •K  — | ]}‰                      |¦  «        V — Œd S )N)r=   )r6   r9   Úpass_managers     €r,   ú	<genexpr>z=ConsolidateBlocks._handle_control_flow_ops.<locals>.<genexpr>’   s1   øè è € Ð*_Ð*_Àu¨<×+;Ò+;¸EÑ+BÔ+BÐ*_Ð*_Ð*_Ð*_Ð*_Ð*_r-   F)Úpropagate_condition)
r   r@   Úappendr   r   Úcontrol_flow_op_nodesÚsubstitute_nodeÚopÚreplace_blocksr>   )r'   rE   Úcontrol_flow_nodesr7   rH   s       @r,   rD   z*ConsolidateBlocks._handle_control_flow_ops�   sç   ø€ õ #‘}”}ˆØ˜Ô*Ð*Ð*Ø×Ò¥¡¤Ñ0Ô0Ð0Ø×Ò¥Ñ 1Ô 1Ñ2Ô2Ð2à×Ò˜DÑ!Ô!Ð!Ø ×6Ò6Ñ8Ô8ÐØÐ)Ø*ð ð �Ø×#Ò#ØØ”G×*Ò*Ð*_Ð*_Ð*_Ð*_ÐPTÔPWÔP^Ð*_Ñ*_Ô*_Ñ_Ô_Ø(-ð $ñ ô ð ð ð
 ˆ
r-   )NFNr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r=   rD   Ú__classcell__)r+   s   @r,   r   r   $   s~   ø€ € € € € ð
ð 
ð ØØØ Øð*@ð *@ð *@ð *@ð *@ð *@ðX"ð "ð "ðHð ð ð ð ð ð r-   r   N)rT   Ú
__future__r   Úmathr   Úqiskit.synthesis.two_qubitr   Ú%qiskit.circuit.library.standard_gatesr   r   r   r	   r
   Úqiskit.transpiler.basepassesr   Úqiskit.transpiler.passmanagerr   Ú%qiskit._accelerate.consolidate_blocksr   Úcollect_1q_runsr   Úcollect_2q_blocksr   r$   r   r2   r-   r,   ú<module>r_      sH  ðð HÐ GØ "Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð à >Ð >Ð >Ð >Ð >Ð >Ø ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø DÐ DÐ DÐ DÐ DÐ Dà *Ð *Ð *Ð *Ð *Ð *Ø .Ð .Ð .Ð .Ð .Ð .ð ˆ&‰(Œ(Ø
ˆ&‰(Œ(ØˆY‰[Œ[Øˆ7‰9Œ9Øˆ7�2˜‘6‰?Œ?ðð €ðqð qð qð qð qÐ*ñ qô qð qð qð qr-   