σ
    Σz	i  γ                   σ:    S r SSKJr  SSKJrJr   " S S\5      rg)zURearrange the direction of the 2-qubit gate nodes to match the directed coupling map.ι    )ΪTransformationPass)Ϊfix_gate_direction_couplingΪfix_gate_direction_targetc                   σ6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )ΪGateDirectionι   uL  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`.
c                 σ:   > [         TU ]  5         Xl        X l        g)zξ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      Ϊg/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/utils/gate_direction.pyr   ΪGateDirection.__init__8   s   ψ τ 	ΡΤΨ(ΤΨσ    c                 σh   U R                   c/  [        U[        U R                  R	                  5       5      5        U$ [        U R                   R                  5      S:X  a=  [        U[        U R                   R                  5       R	                  5       5      5        U$ [        XR                   5        U$ )aE  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   r   Ϊsetr   Ϊ	get_edgesΪlenΪoperation_namesΪbuild_coupling_mapr   )r   Ϊdags     r   ΪrunΪGateDirection.runD   s    π$ ;;Ρά'¨¬S°Χ1BΡ1BΧ1LΡ1LΣ1NΣ-OΤPπ 
τ Χ,Ρ,Σ-°Σ2δ'¨¬S°·±Χ1OΡ1OΣ1QΧ1[Ρ1[Σ1]Σ-^Τ_π 
τ & c―;©;Τ7ΰ
r   )r   r   )N)	Ϊ__name__Ϊ
__module__Ϊ__qualname__Ϊ__firstlineno__Ϊ__doc__r   r   Ϊ__static_attributes__Ϊ__classcell__)r   s   @r   r   r      s   ψ ρ"χH
χπ r   r   N)r    Ϊqiskit.transpiler.basepassesr   Ϊ!qiskit._accelerate.gate_directionr   r   r   © r   r   Ϊ<module>r&      s    πρ \ε ;ί dτKΠ&υ Kr   