§
    º³Ùgö  ã                   óB   — d Z ddlmZ ddlmZmZ  G d„ de¦  «        ZdS )zURearrange the direction of the 2-qubit gate nodes to match the directed coupling map.é    )ÚTransformationPass)Úfix_gate_direction_couplingÚfix_gate_direction_targetc                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )ÚGateDirectionu´  Modify asymmetric gates to match the hardware coupling direction.

    This pass supports replacements for the `cx`, `cz`, `ecr`, `swap`, `rzx`, `rxx`, `ryy` and
    `rzz` gates, using the following identities::

                             â”Œâ”€â”€â”€â”�â”Œâ”€â”€â”€â”�â”Œâ”€â”€â”€â”�
        q_0: â”€â”€â– â”€â”€      q_0: â”¤ H â”œâ”¤ X â”œâ”¤ H â”œ
             â”Œâ”€â”´â”€â”�  =        â”œâ”€â”€â”€â”¤â””â”€â”¬â”€â”˜â”œâ”€â”€â”€â”¤
        q_1: â”¤ X â”œ      q_1: â”¤ H â”œâ”€â”€â– â”€â”€â”¤ H â”œ
             â””â”€â”€â”€â”˜           â””â”€â”€â”€â”˜     â””â”€â”€â”€â”˜


                          global phase: 3Ï€/2
             â”Œâ”€â”€â”€â”€â”€â”€â”�           â”Œâ”€â”€â”€â”� â”Œâ”€â”€â”€â”€â”�â”Œâ”€â”€â”€â”€â”€â”�â”Œâ”€â”€â”€â”€â”€â”€â”�â”Œâ”€â”€â”€â”�
        q_0: â”¤0     â”œ     q_0: â”€â”¤ S â”œâ”€â”¤ âˆšX â”œâ”¤ Sdg â”œâ”¤1     â”œâ”¤ H â”œ
             â”‚  ECR â”‚  =       â”Œâ”´â”€â”€â”€â”´â”�â”œâ”€â”€â”€â”€â”¤â””â”¬â”€â”€â”€â”¬â”˜â”‚  Ecr â”‚â”œâ”€â”€â”€â”¤
        q_1: â”¤1     â”œ     q_1: â”¤ Sdg â”œâ”¤ âˆšX â”œâ”€â”¤ S â”œâ”€â”¤0     â”œâ”¤ H â”œ
             â””â”€â”€â”€â”€â”€â”€â”˜          â””â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”€â”˜ â””â”€â”€â”€â”˜ â””â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”˜
        Note: This is done in terms of less-efficient S/SX/Sdg gates instead of the more natural
        `RY(pi /2)` so we have a chance for basis translation to keep things in a discrete basis
        during resynthesis, if that's what's being asked for.


             â”Œâ”€â”€â”€â”€â”€â”€â”�          â”Œâ”€â”€â”€â”�â”Œâ”€â”€â”€â”€â”€â”€â”�â”Œâ”€â”€â”€â”�
        q_0: â”¤0     â”œ     q_0: â”¤ H â”œâ”¤1     â”œâ”¤ H â”œ
             â”‚  RZX â”‚  =       â”œâ”€â”€â”€â”¤â”‚  RZX â”‚â”œâ”€â”€â”€â”¤
        q_1: â”¤1     â”œ     q_1: â”¤ H â”œâ”¤0     â”œâ”¤ H â”œ
             â””â”€â”€â”€â”€â”€â”€â”˜          â””â”€â”€â”€â”˜â””â”€â”€â”€â”€â”€â”€â”˜â””â”€â”€â”€â”˜

        cz, swap, rxx, ryy and rzz directions are fixed by reversing their qargs order.

    This pass assumes that the positions of the qubits in the :attr:`.DAGCircuit.qubits` attribute
    are the physical qubit indices. For example if ``dag.qubits[0]`` is qubit 0 in the
    :class:`.CouplingMap` or :class:`.Target`.
    Nc                 ód   •— t          ¦   «                              ¦   «          || _        || _        dS )a  GateDirection pass.

        Args:
            coupling_map (CouplingMap): Directed graph representing a coupling map.
            target (Target): The backend target to use for this pass. If this is specified
                it will be used instead of the coupling map
        N)ÚsuperÚ__init__Úcoupling_mapÚtarget)Úselfr   r   Ú	__class__s      €úc/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/utils/gate_direction.pyr
   zGateDirection.__init__8   s.   ø€ õ 	‰Œ×ÒÑÔÐØ(ˆÔØˆŒˆˆó    c                 ó¢   — | j         €4t          |t          | j                             ¦   «         ¦  «        ¦  «        S t          || j         ¦  «        S )a•  Run the GateDirection pass on `dag`.

        Flips the cx nodes to match the directed coupling map. Modifies the
        input dag.

        Args:
            dag (DAGCircuit): DAG to map.

        Returns:
            DAGCircuit: The rearranged dag for the coupling map

        Raises:
            TranspilerError: If the circuit cannot be mapped just by flipping the
                cx nodes.
        )r   r   Úsetr   Ú	get_edgesr   )r   Údags     r   ÚrunzGateDirection.runD   sE   € ð  Œ;ÐÝ.¨sµC¸Ô8I×8SÒ8SÑ8UÔ8UÑ4VÔ4VÑWÔWÐWÝ(¨¨d¬kÑ:Ô:Ð:r   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Ú__classcell__)r   s   @r   r   r      sW   ø€ € € € € ð"ð "ðH
ð 
ð 
ð 
ð 
ð 
ð;ð ;ð ;ð ;ð ;ð ;ð ;r   r   N)r   Úqiskit.transpiler.basepassesr   Ú!qiskit._accelerate.gate_directionr   r   r   © r   r   ú<module>r      sw   ðð \Ð [à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø dÐ dÐ dÐ dÐ dÐ dÐ dÐ dðC;ð C;ð C;ð C;ð C;Ð&ñ C;ô C;ð C;ð C;ð C;r   