
    z	i                     N    S r SSKJr  SSKJr  SSKJr  SSKJr   " S S\5      r	g)	z_Splits each two-qubit gate in the `dag` into two single-qubit gates, if possible without error.    )TransformationPass)Layout)
DAGCircuit)split_2q_unitariesc                   N   ^  \ rS rSrSrS
S\S\4U 4S jjjrS\S\4S jr	S	r
U =r$ )Split2QUnitaries   a  Attempt to splits two-qubit unitaries in a :class:`.DAGCircuit` into two single-qubit gates.

This pass will analyze all :class:`.UnitaryGate` instances and determine whether the
matrix is actually a product of 2 single qubit gates. In these cases the 2q gate can be
simplified into two single qubit gates and this pass will perform this optimization and will
replace the two qubit gate with two single qubit :class:`.UnitaryGate`.

If some of the gates can be viewed as a swap joined by the product of 2 single qubit gates,
the pass will recreate the DAG, permuting the swapped qubits similar
to how it's done in :class:`ElidePermutations`.
fidelity
split_swapc                 :   > [         TU ]  5         Xl        X l        g)z
Args:
    fidelity: Allowed tolerance for splitting two-qubit unitaries and gate decompositions.
    split_swap: Whether to attempt to split swap gates, resulting in a permutation of the qubits.
N)super__init__requested_fidelityr   )selfr
   r   	__class__s      r/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/optimization/split_2q_unitaries.pyr   Split2QUnitaries.__init__"   s     	"*$    dagreturnc                 8   [        XR                  U R                  5      nUc  U$ Uu  p4[        UR                  5       VVs0 s H  u  pVXe_M	     nnn[        U5      U R                  S'   U R                  S   c  XpR                  S'   [        [        U5       VV	s0 s H  u  pUR                  U	   U_M     sn	n5      n
U R                  S   =n(       a*  U
R                  XR                  5      U R                  S'   U$ XR                  S'   U$ s  snnf s  sn	nf )z'Run the Split2QUnitaries pass on `dag`.original_layoutoriginal_qubit_indicesvirtual_permutation_layout)r   r   r   	enumeratequbitsr   property_setcompose)r   r   resultnew_dagqubit_mappingindexqubitinput_qubit_mappingidxout
new_layoutcurrent_layouts               r   runSplit2QUnitaries.run,   s   #C)@)@$//R>J#) @I#**@UV@Uu|@UV/56I/J+,56>:M67)MBZ[BZhcSZZ_c1BZ[\
!../KLL>L>H>P>P

?D:;
  ?I:; W
 \s   DD
)r   r   )g?F)__name__
__module____qualname____firstlineno____doc__floatboolr   r   r)   __static_attributes____classcell__)r   s   @r   r   r      s8    
% %$ % %z j  r   r   N)
r/   qiskit.transpiler.basepassesr   qiskit.transpiler.layoutr   qiskit.dagcircuit.dagcircuitr   %qiskit._accelerate.split_2q_unitariesr   r    r   r   <module>r9      s$    f ; + 3 D*) *r   