
    z	i                    ~    S r SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSKJr  SSKJr     S
         SS	 jjrg)z 
Stabilizer to circuit function
    )annotations)
CollectionN)	PauliList)QiskitError)QuantumCircuit)Cliffordc                   [        U 5      n[        R                  " UR                  S-  5      (       a  [	        S5      e[        UR                  U5      5      [        U5      :  a  [	        S5      eUR                  n[        U5      nSn[        U5       GH  u  pU	R                  [        U5      SS9n
UnX:  a3  X   R                  (       d  X   R                  (       a  OUS-  nX:  a  M3  X:X  a  U
R                  R                  5       (       a  [	        SU S	U	 S
35      eU
R                  S:X  a  [	        SU S	U	 S35      eU
R                  R                  5       (       a  U(       d  [	        SU S	U	 S35      eM  X   R                  (       az  X   R                  (       aV  UR                  U5        UR                  U5        UR                  U5        UR                  U5        UR                  U5        OUR                  U5        [!        U5       GH$  nX:X  d&  X   R                  (       d  X   R                  (       d  M1  X   R                  X   R                  S-  -   nUS:X  a5  UR                  U5        UR#                  X5        UR                  U5        M  US:X  a  UR#                  X5        M  US:X  d  M  UR                  U5        UR                  U5        UR                  U5        UR                  U5        UR#                  X5        UR                  U5        UR                  U5        GM'     X:w  a  UR%                  X5        U	R                  [        U5      SS9n
U
R                  S:X  a  UR                  U5        US-  nGM     Xu:  a  U(       d  [	        S5      eU(       a  U$ UR'                  5       $ )a  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.   zStabilizers 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)stabilizersallow_redundantallow_underconstrainedinvertstabilizer_listr   circuitusedi
stabilizer	curr_stabpivotjps                 h/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/synthesis/stabilizer/stabilizer_circuit.pysynth_circuit_from_stabilizersr,      sK   D  ,O	vvo##a'((BCC
?,,_=>_AUU<== ++JZ(GD"?3%%hw&7s%C	  !!Y%5%7%7QJE  
 {{  !!!Bzl 30 0  !#!!!Bzl 38 8  {{  !!!Bzl 3W W 
  !!		% 		% 		% 		% 		% 		%  z"Az),..ILNN!!33AAv		% 

5$		% a

1$a		% 		!		!		!

5$		% 		!# #( =LL% %%hw&7s%C	??aIIdO	I 4L !7A
 	

 ??    )FFF)
r   zCollection[str]r   boolr    r.   r!   r.   returnr   )__doc__
__future__r   collections.abcr   numpyr   qiskit.quantum_infor   qiskit.exceptionsr   qiskit.circuitr   1qiskit.quantum_info.operators.symplectic.cliffordr   r,    r-   r+   <module>r9      se    # &  ) ) ) F
 "#(	z zz !z 	z
 zr-   