§
    º³ÙgÞ  ã                  ój   — d Z ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ 	 	 	 ddd„ZdS )z 
Stabilizer to circuit function
é    )Úannotations)Ú
CollectionN)Ú	PauliList)ÚQiskitError)ÚQuantumCircuit)ÚCliffordFÚstabilizersúCollection[str]Úallow_redundantÚboolÚallow_underconstrainedÚinvertÚreturnr   c                ó  — t          | ¦  «        }t          j        |j        dz  ¦  «        rt	          d¦  «        ‚t          |                     |¦  «        ¦  «        t          |¦  «        k     rt	          d¦  «        ‚|j        }t          |¦  «        }d}t          |¦  «        D �]/\  }}	|	 
                    t          |¦  «        d¬¦  «        }
|}||k     r&|
|         j        s|
|         j        rn|dz  }||k     °&||k    r‚|
j                             ¦   «         rt	          d|› d	|	› d
�¦  «        ‚|
j        dk    rt	          d|› d	|	› d�¦  «        ‚|
j                             ¦   «         r|st	          d|› d	|	› d�¦  «        ‚Œà|
|         j        rŒ|
|         j        rj|                     |¦  «         |                     |¦  «         |                     |¦  «         |                     |¦  «         |                     |¦  «         n|                     |¦  «         t!          |¦  «        D �]@}||k    s|
|         j        s|
|         j        sŒ$|
|         j        |
|         j        dz  z   }|dk    rA|                     |¦  «         |                     ||¦  «         |                     |¦  «         Œ‰|dk    r|                     ||¦  «         Œ¦|dk    r”|                     |¦  «         |                     |¦  «         |                     |¦  «         |                     |¦  «         |                     ||¦  «         |                     |¦  «         |                     |¦  «         �ŒB||k    r|                     ||¦  «         |	 
                    t          |¦  «        d¬¦  «        }
|
j        dk    r|                     |¦  «         |dz  }�Œ1||k     r|st	          d¦  «        ‚|r|S |                     ¦   «         S )aH  Synthesis of a circuit that generates a state stabilized by the stabilizers
    using Gaussian elimination with Clifford gates.
    If the stabilizers are underconstrained, and ``allow_underconstrained`` is ``True``,
    the circuit will output one of the states stabilized by the stabilizers.
    Based on stim implementation.

    Args:
        stabilizers: List of stabilizer strings
        allow_redundant: Allow redundant stabilizers (i.e., some stabilizers
            can be products of the others)
        allow_underconstrained: Allow underconstrained set of stabilizers (i.e.,
            the stabilizers do not specify a unique state)
        invert: Return inverse circuit

    Returns:
        A circuit that generates a state stabilized by ``stabilizers``.

    Raises:
        QiskitError: if the stabilizers are invalid, do not commute, or contradict each other,
                     if the list is underconstrained and ``allow_underconstrained`` is ``False``,
                     or if the list is redundant and ``allow_redundant`` is ``False``.

    References:
        1. https://github.com/quantumlib/Stim/blob/c0dd0b1c8125b2096cd54b6f72884a459e47fe3e/src/stim/stabilizers/conversions.inl#L469
        2. https://quantumcomputing.stackexchange.com/questions/12721/how-to-calculate-destabilizer-group-of-toric-and-other-codes

    é   z&Some stabilizers have an invalid phasez Some stabilizers do not commute.r   Ús)Úframeé   zStabilizer z (z6) anti-commutes with some of the previous stabilizers.z/) contradicts some of the previous stabilizers.z”) is a product of the others and allow_redundant is False. Add allow_redundant=True to the function call if you want to allow redundant stabilizers.é   z®Stabilizers are underconstrained and allow_underconstrained is False. Add allow_underconstrained=True  to the function call if you want to allow underconstrained stabilizers.)r   ÚnpÚanyÚphaser   ÚlenÚcommutes_with_allÚ
num_qubitsr   Ú	enumerateÚevolver   ÚxÚzÚhr   ÚrangeÚcxÚswapÚinverse)r	   r   r   r   Ústabilizer_listr   ÚcircuitÚusedÚiÚ
stabilizerÚ	curr_stabÚpivotÚjÚps                 úd/granary/edev/quantum/lib/python3.11/site-packages/qiskit/synthesis/stabilizer/stabilizer_circuit.pyÚsynth_circuit_from_stabilizersr/      s€  € õD   Ñ,Ô,€OÝ	„vˆoÔ# aÑ'Ñ(Ô(ð DÝÐBÑCÔCÐCÝ
ˆ?×,Ò,¨_Ñ=Ô=Ñ>Ô>ÅÀ_ÑAUÔAUÒUÐUÝÐ<Ñ=Ô=Ð=à Ô+€JÝ˜ZÑ(Ô(€Gà€DÝ" ?Ñ3Ô3ð Dñ D‰ˆˆ:Ø×%Ò%¥h¨wÑ&7Ô&7¸sÐ%ÑCÔCˆ	ð ˆØ�jÒ Ð Ø˜ÔÔ!ð  Y¨uÔ%5Ô%7ð ØØ�Q‰JˆEð �jÒ Ð ð
 �JÒÐØŒ{�ŠÑ Ô ð Ý!ð0 !ð 0ð 0 zð 0ð 0ð 0ñô ð ð Œ !Ò#Ð#Ý!ð8 !ð 8ð 8 zð 8ð 8ð 8ñô ð ð Œ{�ŠÑ Ô ð ¨ð Ý!ðW !ð Wð W zð Wð Wð Wñô ð ð
 ð �UÔÔð 	!Ø˜ÔÔ!ð !Ø—	’	˜%Ñ Ô Ð Ø—	’	˜%Ñ Ô Ð Ø—	’	˜%Ñ Ô Ð Ø—	’	˜%Ñ Ô Ð Ø—	’	˜%Ñ Ô Ð Ð à—	’	˜%Ñ Ô Ð õ �zÑ"Ô"ð 	ñ 	ˆAØ�EŠzˆz )¨A¤,¤.ˆz°I¸a´L´NˆzØØ˜!”” ¨1¤¤°!Ñ!3Ñ3ˆAØ�AŠvˆvØ—	’	˜%Ñ Ô Ð Ø—
’
˜5 !Ñ$Ô$Ð$Ø—	’	˜%Ñ Ô Ð Ð Ø�a’�Ø—
’
˜1˜eÑ$Ô$Ð$Ð$Ø�a’�Ø—	’	˜%Ñ Ô Ð Ø—	’	˜!‘”�Ø—	’	˜!‘”�Ø—	’	˜!‘”�Ø—
’
˜5 !Ñ$Ô$Ð$Ø—	’	˜%Ñ Ô Ð Ø—	’	˜!‘”�ùð �DŠ=ˆ=Ø�LŠL˜ Ñ%Ô%Ð%ð ×%Ò%¥h¨wÑ&7Ô&7¸sÐ%ÑCÔCˆ	ØŒ?˜aÒÐØ�IŠI�d‰OŒOˆOØ�‰	ˆ‰àˆjÒÐÐ!7ÐÝðAñ
ô 
ð 	
ð
 ð ØˆØ�?Š?ÑÔÐó    )FFF)
r	   r
   r   r   r   r   r   r   r   r   )Ú__doc__Ú
__future__r   Úcollections.abcr   Únumpyr   Úqiskit.quantum_infor   Úqiskit.exceptionsr   Úqiskit.circuitr   Ú1qiskit.quantum_info.operators.symplectic.cliffordr   r/   © r0   r.   ú<module>r:      s¾   ððð ð #Ð "Ð "Ð "Ð "Ð "à &Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð à )Ð )Ð )Ð )Ð )Ð )Ø )Ð )Ð )Ð )Ð )Ð )Ø )Ð )Ð )Ð )Ð )Ð )Ø FÐ FÐ FÐ FÐ FÐ Fð
 "Ø#(Øð	zð zð zð zð zð zð zr0   