§
    ¹³ÙgÎ  ã                   óT   — d Z ddlmZmZmZmZ ddlmZ ddlm	Z
  G d„ d¦  «        Z	dS )zXCode from commutative_analysis pass that checks commutation relations between DAG nodes.é    )ÚListÚUnionÚSetÚOptional)Ú	Operation)ÚCommutationCheckerc                   óÂ   — e Zd ZdZ	 	 dddœdededeee                  fd„Z		 dd
ede
fd„Z	 ddedededededed
ede
fd„Zd„ Zd„ Zdededededee
df         f
d„ZdS )r   au  This code is essentially copy-pasted from commutative_analysis.py.
    This code cleverly hashes commutativity and non-commutativity results between DAG nodes and seems
    quite efficient for large Clifford circuits.
    They may be other possible efficiency improvements: using rule-based commutativity analysis,
    evicting from the cache less useful entries, etc.
    Né@B )ÚgatesÚstandard_gate_commutationsÚcache_max_entriesr   c                ó2   — t          |||¦  «        | _        d S )N)ÚRustCheckerÚcc)Úselfr   r   r   s       úX/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/commutation_checker.pyÚ__init__zCommutationChecker.__init__   s   € õ Ð8Ð:KÈUÑSÔSˆŒˆˆó    é   Úmax_num_qubitsÚreturnc                 ó:   — | j                              |||¦  «        S )z!Checks if two DAGOpNodes commute.)r   Úcommute_nodes)r   Úop1Úop2r   s       r   r   z CommutationChecker.commute_nodes&   s   € ð Œw×$Ò$ S¨#¨~Ñ>Ô>Ð>r   r   Úqargs1Úcargs1r   Úqargs2Úcargs2c           	      óB   — | j                              |||||||¦  «        S )aX  
        Checks if two Operations commute. The return value of `True` means that the operations
        truly commute, and the return value of `False` means that either the operations do not
        commute or that the commutation check was skipped (for example, when the operations
        have conditions or have too many qubits).

        Args:
            op1: first operation.
            qargs1: first operation's qubits.
            cargs1: first operation's clbits.
            op2: second operation.
            qargs2: second operation's qubits.
            cargs2: second operation's clbits.
            max_num_qubits: the maximum number of qubits to consider, the check may be skipped if
                the number of qubits for either operation exceeds this amount.

        Returns:
            bool: whether two operations commute.
        )r   Úcommute)r   r   r   r   r   r   r   r   s           r   r!   zCommutationChecker.commute/   s$   € ð: Œw�Š˜s F¨F°C¸ÀÈÑXÔXÐXr   c                 ó4   — | j                              ¦   «         S )z Returns number of cached entries)r   Únum_cached_entries©r   s    r   r#   z%CommutationChecker.num_cached_entriesN   s   € àŒw×)Ò)Ñ+Ô+Ð+r   c                 ó8   — | j                              ¦   «          dS )z1Clears the dictionary holding cached commutationsN)r   Úclear_cached_commutationsr$   s    r   r&   z,CommutationChecker.clear_cached_commutationsR   s   € àŒ×)Ò)Ñ+Ô+Ð+Ð+Ð+r   Úfirst_opÚfirst_qargsÚ	second_opÚsecond_qargsc                 óF   — | j         j                             ||||¦  «        S )aX  Returns stored commutation relation if any

        Args:
            first_op: first operation.
            first_qargs: first operation's qubits.
            second_op: second operation.
            second_qargs: second operation's qubits.

        Return:
            bool: True if the gates commute and false if it is not the case.
        )r   ÚlibraryÚcheck_commutation_entries)r   r'   r(   r)   r*   s        r   r-   z,CommutationChecker.check_commutation_entriesV   s)   € ð$ ŒwŒ×8Ò8Ø�k 9¨lñ
ô 
ð 	
r   )Nr
   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdictÚintr   r   Ústrr   Úboolr   r   r   r!   r#   r&   r   r-   © r   r   r   r      s“  € € € € € ðð ð ,0Ø!&ðTð
 %)ðTð Tð Tà$(ðTð ðTð
 ˜˜CœÔ!ðTð Tð Tð Tð  ð	?ð ?ð ð	?ð
 
ð?ð ?ð ?ð ?ð"  ðYð YàðYð ðYð ð	Yð
 ðYð ðYð ðYð ðYð 
ðYð Yð Yð Yð>,ð ,ð ,ð,ð ,ð ,ð
àð
ð ð
ð ð	
ð
 ð
ð 
ˆt�TˆzÔ	ð
ð 
ð 
ð 
ð 
ð 
r   r   N)r1   Útypingr   r   r   r   Úqiskit.circuit.operationr   Ú&qiskit._accelerate.commutation_checkerr   r   r6   r   r   ú<module>r:      s’   ðð _Ð ^à -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à .Ð .Ð .Ð .Ð .Ð .Ø TÐ TÐ TÐ TÐ TÐ TðU
ð U
ð U
ð U
ð U
ñ U
ô U
ð U
ð U
ð U
r   