
    z	iT"                     F    S r SSKrSSKJr  SSKJr  SSKJr  S\S\4S jr	g)	z/
Circuit synthesis for the CNOTDihedral class.
    N)QuantumCircuit)QiskitError)CNOTDihedralelemreturnc                    [        U R                  5      nU R                  S:  a  [        S5      eU R                  S:X  a  U R                  R                  S:w  d  U R
                  S//:w  a  [        S5      eU R                  R                  S   nU R                  S   nUS:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        US:X  a  US:X  a  UR                  S5        U$ U R                  R                  S:w  a  [        S5      eU R                  R                  nU R                  R                  nU R
                  nU R                  nUSS/SS//:H  R                  5       (       GaW  Uu  p8US/:X  a  Uu  p)US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        US:X  a4  U	S:X  a.  US:X  a(  US:X  a"  UR                  S5        UR                  S5        US/:X  a  X8:X  d  US/:X  GaO  X8:w  GaI  US   SU-  -
  SU-  U-  -
  S	-  nUS   SU-  -
  SU-  U-  -
  S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR                  [        R                  S-  S/5        UR                  [        R                  S-  S/5        UR                  SS5        UR                  S
[        R                  -  S-  S/5        UR                  SS5        US/:X  a  X8:X  d  US/:X  GaR  X8:w  GaL  US   SU-  -
  SU-  U-  -
  S	-  nUS   SU-  -
  SU-  U-  -
  S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR                  S
[        R                  -  S-  S/5        UR                  S
[        R                  -  S-  S/5        UR                  SS5        UR                  [        R                  S-  S/5        UR                  SS5        US/:X  a  US   SU-  -
  S	-  nUS   SU-  -
  S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR!                  SS5        USS/SS//:H  R                  5       (       Ga"  US   nUS   U-   S-  nX8:X  a%  S	US   -
  S-  S-  n
US   U
-
  S	-  nUS   U
-
  S	-  n	O!US   S-  S-  n
US   U
-   S	-  nUS   U
-   S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR                  SS5        U
S:  a'  UR                  U
[        R                  -  S-  S/5        USS/SS//:H  R                  5       (       Ga"  US   nUS   U-   S-  nX8:X  a%  S	US   -
  S-  S-  n
US   U
-
  S	-  nUS   U
-
  S	-  n	O!US   S-  S-  n
US   U
-   S	-  nUS   U
-   S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR                  SS5        U
S:  a'  UR                  U
[        R                  -  S-  S/5        USS/SS//:H  R                  5       (       Ga4  US   nUS   U-   S-  nX8:X  a%  S	US   -
  S-  S-  n
US   U
-
  S	-  nUS   U
-
  S	-  n	O!US   S-  S-  n
US   U
-   S	-  nUS   U
-   S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR                  SS5        UR                  SS5        U
S:  a'  UR                  U
[        R                  -  S-  S/5        USS/SS//:H  R                  5       (       Ga4  US   nUS   U-   S-  nX8:X  a%  S	US   -
  S-  S-  n
US   U
-
  S	-  nUS   U
-
  S	-  n	O!US   S-  S-  n
US   U
-   S	-  nUS   U
-   S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR                  SS5        UR                  SS5        U
S:  a'  UR                  U
[        R                  -  S-  S/5        USS/SS//:H  R                  5       (       Ga@  US   nUS   nX8:X  a%  S	US   -
  S-  S-  n
US   U
-
  S	-  nUS   U
-
  S	-  n	O!US   S-  S-  n
US   U
-   S	-  nUS   U
-   S	-  n	US:  a'  UR                  U[        R                  -  S-  S/5        US:X  a  UR                  S5        U	S:  a'  UR                  U	[        R                  -  S-  S/5        US:X  a  UR                  S5        UR                  SS5        UR                  SS5        U
S:  a'  UR                  U
[        R                  -  S-  S/5        UR                  SS5        U$ )a9  Decompose a :class:`.CNOTDihedral` element on a single qubit and two
qubits into a :class:`.QuantumCircuit`.
This decomposition has an optimal number of :class:`.CXGate`\ s.

Args:
    elem: A :class:`.CNOTDihedral` element.

Returns:
    A circuit implementation of the :class:`.CNOTDihedral` element.

Raises:
    QiskitError: if the element in not 1-qubit or 2-qubit :class:`.CNOTDihedral`.

References:
    1. Shelly Garion and Andrew W. Cross, *On the structure of the CNOT-Dihedral group*,
       `arXiv:2006.12042 [quant-ph] <https://arxiv.org/abs/2006.12042>`_
   zoCannot decompose a CNOT-Dihedral element with more than 2 qubits. use synth_cnotdihedral_full function instead.   r   z&1-qubit element in not CNOT-Dihedral .   z&2-qubit element in not CNOT-Dihedral .         )r   
num_qubitsr   polyweight_0linearweight_1shiftpnppixidweight_2allcxcz)r   circuittpow0xpow0r   r   r   r   xpow1tpow1ms              y/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.pysynth_cnotdihedral_two_qubitsr%      s   & T__-G<
 	

 !99"dkkqcU&:FGG		""1%

119IIuruu}q(A3/A:IIaLA:%1*JJqM yyQBCCyy!!Hyy!!H[[FJJE 	Aq6Aq6""'')) s?%NUqy		5255=1,s3z		!qy		5255=1,s3z		!zeqjUaZEQJ

1

1 OHOa[1u9,q5y5/@@AEEa[1u9,q5y5/@@AEEqy		5255=1,s3z		!qy		5255=1,s3z		!IIruuqyA3'IIruuqyA3'JJq!IIq255y1}s+JJq! OHOa[1u9,q5y5/@@AEEa[1u9,q5y5/@@AEEqy		5255=1,s3z		!qy		5255=1,s3z		!IIq255y1}s+IIq255y1}s+JJq!IIruuqyA3'JJq! s?a[1u9,1Ea[1u9,1Eqy		5255=1,s3z		!qy		5255=1,s3z		!JJq! 	Aq6Aq6""''))aqE!Q&>hqk/Q&!+Aa[1_)Ea[1_)E!qA%Aa[1_)Ea[1_)E19IIuruu}q(A3/A:IIaL19IIuruu}q(A3/A:IIaL

1aq5IIq255y1}s+ 	Aq6Aq6""''))aqE!Q&>hqk/Q&!+Aa[1_)Ea[1_)E!qA%Aa[1_)Ea[1_)E19IIuruu}q(A3/A:IIaL19IIuruu}q(A3/A:IIaL

1aq5IIq255y1}s+ 	Aq6Aq6""''))aqE!Q&>hqk/Q&!+Aa[1_)Ea[1_)E!qA%Aa[1_)Ea[1_)E19IIuruu}q(A3/A:IIaL19IIuruu}q(A3/A:IIaL

1a

1aq5IIq255y1}s+ 	Aq6Aq6""''))aqE!Q&>hqk/Q&!+Aa[1_)Ea[1_)E!qA%Aa[1_)Ea[1_)E19IIuruu}q(A3/A:IIaL19IIuruu}q(A3/A:IIaL

1a

1aq5IIq255y1}s+ 	Aq6Aq6""''))aa>hqk/Q&!+Aa[1_)Ea[1_)E!qA%Aa[1_)Ea[1_)E19IIuruu}q(A3/A:IIaL19IIuruu}q(A3/A:IIaL

1a

1aq5IIq255y1}s+

1aN    )
__doc__numpyr   qiskit.circuitr   qiskit.exceptionsr   qiskit.quantum_infor   r%    r&   r$   <module>r-      s.     ) ) ,t t tr&   