
    z	i              	          S r SSKJr  SSKrSSKJrJr  SSKJr	  SSK
JrJr  SSKJr  SSKJr  SS	KJr  \R)                  S
S
SSSSS.5      r " S S\5      rg)zHCancel the redundant (self-adjoint) gates through commutation relations.    )annotationsN)GateQubit)SessionCommutationChecker)	PauliGateZGate)
DAGCircuit)TransformationPass)calc_final_opsXYZ)+-lr01c                  d   ^  \ rS rSrSrSS	U 4S jjjr\S
S j5       r    SS jrSS jr	Sr
U =r$ )	LightCone   zRemove the gates that do not affect the outcome of a measurement on a circuit.

Pass for computing the light-cone of an observable or measurement. The Pass can handle
either an observable one would like to measure or a measurement on a set of qubits.
c                D  > [         TU ]  5         1 SknSU l        Ub}  U(       d  [        S5      e[	        U5      R                  U5      (       d  [        SU S35      e[        U5      [        U5      :w  a  [        S5      eUR                  [        5      U l        X l	        g)a]  
Args:
    bit_terms: If ``None`` the light-cone will be computed for the set of measurements
        in the circuit. If a string is specified, the light-cone will correspond to the
        reduced circuit with the same expectation value for the observable.
    indices: list of non-trivial indices corresponding to the observable in ``bit_terms``.
>	   r   r   r   r   r   r   r   r   r   Nz7`indices` must be non-empty when providing `bit_terms`.z.`bit_terms` should contain only characters in .z1`bit_terms` must be the same length as `indices`.)
super__init__	bit_terms
ValueErrorsetissubsetlen	translatetranslation_tableindices)selfr   r#   valid_characters	__class__s       j/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/optimization/light_cone.pyr   LightCone.__init__!   s     	H  !Z[[y>**+;<< DEUDVVWX  9~W- !TUU&001BCDN    c                v    [        U S15      n[        5       nU H  nU[        UR                  5      -  nM     U$ )Nmeasure)r   r   qargs)dagfinal_nodesqubits_measurednodes       r'   _find_measurement_qubits"LightCone._find_measurement_qubits8   s9    $S9+6%Ds4::.O  r)   c                   U R                  U5      nU R                  c  U Vs/ s H  n[        5       U/4PM     nnO[        UR                  5      [        U R                  5      S-   :  a  [        S5      eU(       a  [        S5      eU R                   Vs/ s H  oQR                  U   PM     nn[        U R                  5      U4/n[        U5      U4$ s  snf s  snf )zReturns the initial light-cone.
If observable is `None`, the light-cone is the set of measured qubits.
If a `bit_terms` is provided, the qubits corresponding to the
non-trivial Paulis define the light-cone.
   z2`indices` contains values outside the qubit range.znThe circuit contains measurements and an observable has been given: remove the observable or the measurements.)
r1   r   r   r    qubitsmaxr#   r   r   r   )r$   r-   lightcone_qubitsqubit_indexlightcone_operationsis         r'   _get_initial_lightcone LightCone._get_initial_lightcone@   s      88=>>!P`#aP`UW{m$<P` #a  3::T\\!2Q!66 !UVV A  8<||D|!

1|D%.t~~%>@P$Q#R #$&::: $b  Es   CCc                   U R                  U5      u  p#UR                  5       n[        [        UR	                  5       5      5       GH;  nUR                  UR                  5      (       d  M&  SnU H  n[        [        US   5      [        UR                  5      5      nUS:  a  [        R                  " SU S3[        S9  [        R                  " US   US   / UR                  UR                  / US9n	U	(       a  M  UR                  UR                  5        UR!                  UR                  UR                  45        S	n  O   U(       a  GM
  UR#                  UR                  UR                  UR$                  5        GM>     U$ )
zRun the LightCone pass on `dag`.

Args:
    dag: The DAG to reduce.

Returns:
    The DAG reduced to the light-cone of the observable.
Tr4   
   z;LightCone pass is checking commutation ofoperators of size z.This operation can be slow.)categoryr   )max_num_qubitsF)r;   copy_empty_likereversedlisttopological_op_nodesintersectionr,   r6   r    warningswarnRuntimeWarningscccommuteopupdateappendapply_operation_frontcargs)
r$   r-   r7   r9   new_dagr0   commutes_boolrK   r@   commute_bools
             r'   runLightCone.runZ   sN    261L1LS1Q. %%' T#":":"<=>D,,TZZ88 $.B%(RUS_%EN%* 11?0@ A:: &4	 $';;1r!ub$''4::rR`$L (<(//

;,33TWWdjj4IJ(-# /* %}11$''4::tzzR7 ?8 r)   )r   r#   )NN)r   z
str | Noner#   zlist[int] | NonereturnNone)r-   r	   rU   z
set[Qubit])r-   r	   rU   z1tuple[set[Qubit], list[tuple[Gate, list[Qubit]]]])r-   r	   rU   r	   )__name__
__module____qualname____firstlineno____doc__r   staticmethodr1   r;   rS   __static_attributes____classcell__)r&   s   @r'   r   r      sE     .  ;;	:;4- -r)   r   )r[   
__future__r   rF   qiskit.circuitr   r   "qiskit.circuit.commutation_libraryr   rI   qiskit.circuit.libraryr   r   qiskit.dagcircuitr	   qiskit.transpiler.basepassesr
   8qiskit.transpiler.passes.utils.remove_final_measurementsr   str	maketransr"   r    r)   r'   <module>ri      sP    O "  & O 3 ( ; SMM#CcPSZ]"^_ m" mr)   