
    z	i4                        S r SSKrSSKJrJr  SSKJr  SSK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Jr  SS	KJr  SS
KJr  SSKJr  SSKJrJr  SSKJr  SSKJ r   \RB                  RD                  S1SS.S jj5       r#\RB                  RD                   S2S j5       r$\RB                  RD                    S3SSSSSS.S jj5       r%\RB                  RD                        S4SS.S jj5       r&\RB                  RD                  S1SS.S jj5       r'S r(S r)S r*S r+\RB                  RD                  \RX                  RD                       S5SS.S jj5       5       r-\RB                  RD                  S 5       r.S r/S6S jr0 S7S \\\4   S!\1S"\2S#\24S$ jjr3S8S%\\4   S&\5S#\\2   4S' jjr6 S9S(\\4   S)\5S*\2S&\5S#\24
S+ jjr7 " S, S-5      r8S6S. jr9S/ r:S0 r;g):z-
Visualization functions for quantum states.
    N)ListUnion)reduce)user_config)Statevector)Operator)	PauliListSparsePauliOp)DensityMatrix)	optionals)pi_check   )_num_to_latexarray_to_latex)matplotlib_close_if_inline)VisualizationError)filenamec          	         SSK Jn  [        U 5      nUR                  nUc  [	        S5      eS[
        R                  " [
        R                  " [        R                  " UR                  5      R                  5       5      5      -  n	[        R                  " UR                  5      n
[        R                  " UR                  5      nUc  SnU(       d  U(       d  UR                  SSUS9u  nu  pO,U(       a  UR                  5       nOUR                  5       nUnUn[!        SU-  5       Vs/ s H   n[#        U5      SS R%                  U5      PM"     nn[!        SU-  5       Vs/ s H   n[#        U5      SS R%                  U5      PM"     snSSS	2   nU
R&                  u  nnU(       Ga  UR(                  R+                  S
5        UR-                  SS5        UR.                  R1                  UR3                  5       5        UR4                  R1                  UR3                  5       5        [        R6                  " U
5       H  u  u  nnnUUU-
  S-
  nnUS:  a  SOSn[        R8                  " [        R                  " U5      U	-  5      nUR;                  SU-   US-  -
  SU-   US-  -
  /UUUUS9nUR=                  U5        M     UR?                  S[        R@                  " U5      -   5        URC                  S[        R@                  " U5      -   5        URE                  SU/5        URG                  SU/5        URI                  USS9  URK                  USSS9  URM                  SSS9  U(       Ga  UR(                  R+                  S
5        UR-                  SS5        UR.                  R1                  UR3                  5       5        UR4                  R1                  UR3                  5       5        [        R6                  " U5       H  u  u  nnnUUU-
  S-
  nnUS:  a  SOSn[        R8                  " [        R                  " U5      U	-  5      nUR;                  SU-   US-  -
  SU-   US-  -
  /UUUUS9nUR=                  U5        M     UR?                  S[        R@                  " U5      -   5        URC                  S[        R@                  " U5      -   5        URE                  SU/5        URG                  SU/5        URI                  USS9  URK                  USSS9  URM                  SSS9  URO                  5         U(       a  URQ                  USS9  Uc  Uc  [S        U5        Uc  U$ URU                  U5      $ s  snf s  snf )a  Plot a hinton diagram for the density matrix of a quantum state.

The hinton diagram represents the values of a matrix using
squares, whose size indicate the magnitude of their corresponding value
and their color, its sign. A white square means the value is positive and
a black one means negative.

Args:
    state (Statevector or DensityMatrix or ndarray): An N-qubit quantum state.
    title (str): a string that represents the plot title
    figsize (tuple): Figure size in inches.
    filename (str): file path to save image to.
    ax_real (matplotlib.axes.Axes): An optional Axes object to be used for
        the visualization output. If none is specified a new matplotlib
        Figure will be created and used. If this is specified without an
        ax_imag only the real component plot will be generated.
        Additionally, if specified there will be no returned Figure since
        it is redundant.
    ax_imag (matplotlib.axes.Axes): An optional Axes object to be used for
        the visualization output. If none is specified a new matplotlib
        Figure will be created and used. If this is specified without an
        ax_imag only the real component plot will be generated.
        Additionally, if specified there will be no returned Figure since
        it is redundant.

Returns:
    :class:`matplotlib:matplotlib.figure.Figure` :
        The matplotlib.Figure of the visualization if
        neither ax_real or ax_imag is set.

Raises:
    MissingOptionalLibraryError: Requires matplotlib.
    VisualizationError: Input is not a valid N-qubit state.

Examples:
    .. plot::
       :alt: Output from the previous code.
       :include-source:

        import numpy as np
        from qiskit import QuantumCircuit
        from qiskit.quantum_info import DensityMatrix
        from qiskit.visualization import plot_state_hinton

        qc = QuantumCircuit(2)
        qc.h([0, 1])
        qc.cz(0,1)
        qc.ry(np.pi/3 , 0)
        qc.rx(np.pi/5, 1)

        state = DensityMatrix(qc)
        plot_state_hinton(state, title="New Hinton Plot")

r   pyplotN)Input is not a multi-qubit quantum state.   )      r   figsizegrayequalboxwhiteblack      ?)	facecolor	edgecolor   fontsizeZ   r(   rotationz
Re[$\rho$]z
Im[$\rho$]   )+
matplotlibr   r   
num_qubitsr   mathceillog2npabsdatamaxrealimagsubplots
get_figurerangebinzfillshapepatchset_facecolor
set_aspectxaxisset_major_locatorNullLocatoryaxisndenumeratesqrt	Rectangle	add_patch
set_xticksarange
set_yticksset_xlimset_ylimset_yticklabelsset_xticklabels	set_titletight_layoutsuptitler   savefig)statetitler   ax_realax_imagr   pltrhonum
max_weightdatarealdataimagfigax1ax2icolumn_names	row_nameslylxxywplot_xplot_ycolorsizerects                               b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/visualization/state_visualization.pyplot_state_hintonro   '   s   p ) 
C
..C
{ !LMMdii		"&&*:*>*>*@ ABBJwwsxx Hwwsxx H7,,q!W,=Zc3$$&C$$&C38C=A=aCF12J$$S)=LA05af>1Q!!#&>ttDI^^FB
		'w&		##COO$56		##COO$561IFQAQ
FF 1uG'E77266!9z12D==vq(#,*AB ! D MM$ 2 	sRYYr]*+sRYYr]*+aWaWI3L2Cmb1
		'w&		##COO$56		##COO$561IFQAQ
FF 1uG'E77266!9z12D==vq(#,*AB ! D MM$ 2 	sRYYr]*+sRYYr]*+aWaWI3L2Cmb1UR(7?"3'
{{8$$G B>s   +'V$'V
c                    SSK Jn  Uc  SnU" X%S9nUS:X  a  U S   U S   U S   pnU[        R                  " U	5      -  [        R                  " U
5      -  U S'   U[        R                  " U	5      -  [        R                  " U
5      -  U S'   U[        R                  " U	5      -  U S'   UR                  U 5        UR                  US	9  Uc1  UR                  nUR                  US   US   5        [        U5        U$ g)
a  Plot the Bloch sphere.

Plot a Bloch sphere with the specified coordinates, that can be given in both
cartesian and spherical systems.

Args:
    bloch (list[double]): array of three elements where [<x>, <y>, <z>] (Cartesian)
        or [<r>, <theta>, <phi>] (spherical in radians)
        <theta> is inclination angle from +z direction
        <phi> is azimuth from +x direction
    title (str): a string that represents the plot title
    ax (matplotlib.axes.Axes): An Axes to use for rendering the bloch
        sphere
    figsize (tuple): Figure size in inches. Has no effect is passing ``ax``.
    coord_type (str): a string that specifies coordinate type for bloch
        (Cartesian or spherical), default is Cartesian
    font_size (float): Font size.

Returns:
    :class:`matplotlib:matplotlib.figure.Figure` : A matplotlib figure instance if ``ax = None``.

Raises:
    MissingOptionalLibraryError: Requires matplotlib.

Examples:
    .. plot::
       :alt: Output from the previous code.
       :include-source:

       from qiskit.visualization import plot_bloch_vector

       plot_bloch_vector([0,1,0], title="New Bloch Sphere")

    .. plot::
       :alt: Output from the previous code.
       :include-source:

       import numpy as np
       from qiskit.visualization import plot_bloch_vector

       # You can use spherical coordinates instead of cartesian.

       plot_bloch_vector([1, np.pi/2, np.pi/3], coord_type='spherical')

r   )BlochN)r   r   )axes	font_size	sphericalr   r   )rU   )
blochrq   r2   sincosadd_vectorsrenderr^   set_size_inchesr   )ru   rU   axr   
coord_typers   rq   Brthetaphir^   s               rn   plot_bloch_vectorr      s    b 2+A[ a%(E!H#rvve}$rvvc{2arvve}$rvvc{2arvve}$aMM%HH5H	zeeGAJ
3"3'
    F)reverse_bitsr   rs   title_font_size	title_padc          	      f   SSK Jn  U(       a  [        U 5      SSS2   O
[        U 5      n	[        U	5      n
Ub	  Uu  pX-  nOUR	                  SU
-  5      u  p[        U5      S:  a  USUS-  -   -  nUb  UOSnUb  UOUnUR                  X4S9n[        U
5       HB  nU(       a  U
S-
  U-
  OUnUR                  SXS-   S	S
9n[        X   S[        U5      -   UX%S9  MD     UR                  XSS9  [        U5        Uc   UR                  5         U$ UR                  U5      $ ! [         a     U$ f = f)a  Plot a Bloch sphere for each qubit.

Each component :math:`(x,y,z)` of the Bloch sphere labeled as 'qubit i' represents the expected
value of the corresponding Pauli operator acting only on that qubit, that is, the expected value
of :math:`I_{N-1} \otimes\dotsb\otimes I_{i+1}\otimes P_i \otimes I_{i-1}\otimes\dotsb\otimes
I_0`, where :math:`N` is the number of qubits, :math:`P\in \{X,Y,Z\}` and :math:`I` is the
identity operator.

Args:
    state (Statevector or DensityMatrix or ndarray): an N-qubit quantum state.
    title (str): a string that represents the plot title
    figsize (tuple): size of each individual Bloch sphere figure, in inches.
    reverse_bits (bool): If True, plots qubits following Qiskit's convention [Default:False].
    font_size (float): Font size for the Bloch ball figures.
    title_font_size (float): Font size for the title.
    title_pad (float): Padding for the title (suptitle ``y`` position is ``0.98``
    and the image height will be extended by ``1 + title_pad/100``).

Returns:
    :class:`matplotlib:matplotlib.figure.Figure` :
        A matplotlib figure instance.

Raises:
    MissingOptionalLibraryError: Requires matplotlib.
    VisualizationError: if input is not a valid N-qubit state.

Examples:
    .. plot::
       :alt: Output from the previous code.
       :include-source:

        from qiskit import QuantumCircuit
        from qiskit.quantum_info import Statevector
        from qiskit.visualization import plot_bloch_multivector

        qc = QuantumCircuit(2)
        qc.h(0)
        qc.x(1)

        state = Statevector(qc)
        plot_bloch_multivector(state)

    .. plot::
       :alt: Output from the previous code.
       :include-source:

       from qiskit import QuantumCircuit
       from qiskit.quantum_info import Statevector
       from qiskit.visualization import plot_bloch_multivector

       qc = QuantumCircuit(2)
       qc.h(0)
       qc.x(1)

       # You can reverse the order of the qubits.

       from qiskit.quantum_info import DensityMatrix

       qc = QuantumCircuit(2)
       qc.h([0, 1])
       qc.t(1)
       qc.s(0)
       qc.cx(0,1)

       matrix = DensityMatrix(qc)
       plot_bloch_multivector(matrix, title='My Bloch Spheres', reverse_bits=True)

r   r   Nr   r   d   r,   r   3d
projectionzqubit )r{   r   rs   g\(\?)r(   rg   )r-   r   _bloch_multivector_datalen	figaspectfigurer:   add_subplotr   strrR   r   rQ   AttributeErrorrS   )rT   rU   r   r   r   rs   r   r   rX   
bloch_datarZ   widthheightdefault_title_font_sizer^   ra   posr{   s                     rn   plot_bloch_multivectorr     s\   ` ) 1=&tt,BYZ_B`  j/Ca#g.
5zA~!i#o%%+4+@ib)8)DoJaO
**e_*
-C3Z)cAgkq__QUt_<M8c#h.2w	
  LLDL9s#	 
{{8$$	  	
	s   ?D" "
D0/D0c                D   SSK Jn  SSKJn	  SSKJn
  [        U 5      nUR                  nUc  [        S5      e[        R                  " UR                  5      n[        R                  " UR                  5      n[        SU-  5       Vs/ s H   n[        U5      SS R                  U5      PM"     nn[        SU-  5       Vs/ s H   n[        U5      SS R                  U5      PM"     nnUR                   SS u  nn[        R"                  " SUS5      n[        R"                  " SUS5      n[        R$                  " US-   US-   5      u  nnUR'                  5       nUR'                  5       n[        R(                  " UU-  5      nS	[        R*                  " U5      -  nUR-                  5       nUR'                  5       nUR'                  5       nUc  S
u  nnO4[/        U5      S:w  a  [1        S5      eUS   c  SOUS   nUS   c  SOUS   nUc?  Uc<  Uc  SnU	R3                  USS9nUR5                  SSSSSS9nUR5                  SSSSSS9nO,Ub  UR7                  5       nUnUnOUR7                  5       nSnUnUR9                  5         [        R:                  " U5      n [        R:                  " U5      n!UR=                  5       u  n"n#[?        U"S-  U#5      n$[A        SU$-  5      n%SS[        RB                  " U$5      -   -  n&UUUS4UUUS44 GH  u  n'n(n)n*U'c  M  [        R:                  " U(5      n+[        R>                  " U(5      n,[E        U)[F        5      (       a'  U)RI                  S5      (       a  URK                  U)5      n)U(S:  n-[        RL                  " U-5      (       a\  [O        UU-   UU-   UU-   UU-   UU-   U(U-   U)5      n.U'RQ                  UU-   UU-   UU-   UU-   UU-   U(U-   USS9n/U/RS                  U.5        U,Ss=:  a  U+:  ao  O  OlSU/SU/n1n0[U        [W        U0U0SSS2   -   [        RX                  " U1S5      S/S-  5      5      /n2U
" U2SSSS9n3U3R[                  S5        U'R]                  U35        U(S:  n4[        RL                  " U45      (       a\  [O        UU4   UU4   UU4   UU4   UU4   U(U4   U)5      n.U'RQ                  UU4   UU4   UU4   UU4   UU4   U(U4   US S9n5U5RS                  U.5        U'R_                  U* S!3U%S"9  U'Ra                  [        R"                  " S	US	-   S5      5        U'Rc                  [        R"                  " S	US	-   S5      5        U+U,:w  a*  U'Rd                  Rg                  U,[;        U S#-   U!5      5        OIU,S:X  a*  U'Rd                  Rg                  U,[;        U S#-   U!5      5        OU'Rd                  Rg                  S$S%9  U'Ri                  5         U'Rj                  Rm                  UU%S&S'S(S)9  U'Rn                  Rm                  UU%S*S+S,S)9  U'Rp                  Rs                  5        HT  n6U6Rt                  Rw                  U%5        U6Rt                  Ry                  S+5        U6Rt                  R{                  S-5        MV     U'R}                  S.U&S/9  U'R                  S5        U'R                  S5        GM     UR                  UU%S0-  S"9  UR                  S1SSSSSS29  Uc  Uc  [        U5        Uc  U$ UR                  U5      $ s  snf s  snf )3a
  Plot the cityscape of quantum state.

Plot two 3d bar graphs (two dimensional) of the real and imaginary
part of the density matrix rho.

Args:
    state (Statevector or DensityMatrix or ndarray): an N-qubit quantum state.
    title (str): a string that represents the plot title
    figsize (tuple): Figure size in inches.
    color (list): A list of len=2 giving colors for real and
        imaginary components of matrix elements.
    alpha (float): Transparency value for bars
    ax_real (matplotlib.axes.Axes): An optional Axes object to be used for
        the visualization output. If none is specified a new matplotlib
        Figure will be created and used. If this is specified without an
        ax_imag only the real component plot will be generated.
        Additionally, if specified there will be no returned Figure since
        it is redundant.
    ax_imag (matplotlib.axes.Axes): An optional Axes object to be used for
        the visualization output. If none is specified a new matplotlib
        Figure will be created and used. If this is specified without an
        ax_real only the imaginary component plot will be generated.
        Additionally, if specified there will be no returned Figure since
        it is redundant.

Returns:
    :class:`matplotlib:matplotlib.figure.Figure` :
        The matplotlib.Figure of the visualization if the
        ``ax_real`` and ``ax_imag`` kwargs are not set

Raises:
    MissingOptionalLibraryError: Requires matplotlib.
    ValueError: When 'color' is not a list of len=2.
    VisualizationError: if input is not a valid N-qubit state.

Examples:
    .. plot::
       :alt: Output from the previous code.
       :include-source:

       # You can choose different colors for the real and imaginary parts of the density matrix.

       from qiskit import QuantumCircuit
       from qiskit.quantum_info import DensityMatrix
       from qiskit.visualization import plot_state_city

       qc = QuantumCircuit(2)
       qc.h(0)
       qc.cx(0, 1)

       state = DensityMatrix(qc)
       plot_state_city(state, color=['midnightblue', 'crimson'], title="New State City")

    .. plot::
       :alt: Output from the previous code.
       :include-source:

       # You can make the bars more transparent to better see the ones that are behind
       # if they overlap.

       import numpy as np
       from qiskit.quantum_info import Statevector
       from qiskit.visualization import plot_state_city
       from qiskit import QuantumCircuit

       qc = QuantumCircuit(2)
       qc.h(0)
       qc.cx(0, 1)


       qc = QuantumCircuit(2)
       qc.h([0, 1])
       qc.cz(0,1)
       qc.ry(np.pi/3, 0)
       qc.rx(np.pi/5, 1)

       state = Statevector(qc)
       plot_state_city(state, alpha=0.6)

r   Nr   )Poly3DCollectionr   r   r   g      ?r#   )#648fffr   z 'color' must be a list of len=2.r   )r,   r   rh   )r   r$   r   F)r   computed_zorderg      @   
   Real	Imaginary#g      ?)alphazorderr      k)r   r$   
linewidths      ?g      ?u    Amplitude (ρ)r'   g&.>T)auto-   righttop)r(   r+   havag     6leftcenterbottom)r   r   r   )aspectzoomg      ?g?)r   r   r   r   hspacewspace)Ematplotlib.colorscolorsr-   r   mpl_toolkits.mplot3d.art3dr   r   r.   r   r2   r6   r4   r7   r:   r;   r<   r=   rJ   meshgridflattenzeros	ones_likecopyr   
ValueErrorr   r   r9   rQ   r5   get_size_inchesminintrF   
isinstancer   
startswithto_rgba_arrayanygenerate_facecolorsbar3dr?   listziprepeat
set_zorderadd_collection3drP   rI   rK   rr   
set_zlim3dget_autoscalez_onrA   set_ticklabelsrD   zaxisget_major_tickslabel1set_fontsizeset_horizontalalignmentset_verticalalignmentset_box_aspectset_xmarginset_ymarginrR   subplots_adjustr   rS   )7rT   rU   r   rk   r   rV   rW   r   mcolorsrX   r   rY   rZ   r\   r]   ra   rb   rc   rd   re   xposyposzposdxdydzrdzi
real_color
imag_colorr^   r_   r`   max_dzrmax_dzi	fig_width
fig_heightmax_plot_sizemax_font_sizemax_zoomr{   dzcolzlabelmax_dzmin_dzdznfcnegative_barsxlimylimvertsplanedzppositive_barsticks7                                                          rn   plot_state_cityr   t  s   x ((;

C
..C
{ !LMM wwsxx Hwwsxx H 49C=A=aCF12J$$S)=LA05af>1Q!!#&I>^^BQFB99QAD99QADTD[$+6JD$<<>D<<>D88BGD	r||D!	!B	B



C



C}!5
Ju:??@@"'("2Ya
"'("2Ya
7??GjjCj8ooaA$oNooaA$oN		  "  "ffSkGffSkG  //1Iz	D(*5MM)*MR"''-001H 
c:v&	c:{+ BV
 :c3CNN3$7$7'',C1f66#;;$S	49d3iC"S'2c7CB HHS	S	S	333 % 	M ''+AR1b'$D#dT$B$Z/41CaS1WMNOE$U$#RSTET"&Ag66#;;$S	49d3iC"S'2c7CB HHS	S	S	333 % 	M ''+
x/-H
biiR#Xq12
biiR#Xq12VGGvs7T>7'CD{""63w~w+GH"""-

w5 	  	
 	=5VPX 	  	
 HH,,.DKK$$]3KK//7KK--h7 /
 	:
q
qe h LL!5L6C1QO7?"3'
{{8$$a B>s   '\'\c                   SSK Jn  [        U 5      u  px[        U5      n	Uc  SnUc  Sn[        R
                  " U	5      n
SnUc  SnUR                  US9u  pOSnUR                  5       nUR                  SS	S
S9  UR                  XXSS9  UR                  S	SS9  UR                  SSS9  UR                  U
5        UR                  / SQ5        UR                  USSS9  UR                  SSS9  UR!                  SS	/5        UR#                  S5        UR$                  R'                  5       UR(                  R'                  5       -    H  nUR*                  R-                  S5        M      UR/                  USS9  U(       a  [1        U5        Uc   UR3                  5         U$ UR7                  U5      $ ! [4         a     U$ f = f)a	  Plot the Pauli-vector representation of a quantum state as bar graph.

The Pauli-vector of a density matrix :math:`\rho` is defined by the expectation of each
possible tensor product of single-qubit Pauli operators (including the identity), that is

.. math ::

    \rho = \frac{1}{2^n} \sum_{\sigma \in \{I, X, Y, Z\}^{\otimes n}}
           \mathrm{Tr}(\sigma \rho) \sigma.

This function plots the coefficients :math:`\mathrm{Tr}(\sigma\rho)` as bar graph.

Args:
    state (Statevector or DensityMatrix or ndarray): an N-qubit quantum state.
    title (str): a string that represents the plot title
    figsize (tuple): Figure size in inches.
    color (list or str): Color of the coefficient value bars.
    ax (matplotlib.axes.Axes): An optional Axes object to be used for
        the visualization output. If none is specified a new matplotlib
        Figure will be created and used. Additionally, if specified there
        will be no returned Figure since it is redundant.

Returns:
     :class:`matplotlib:matplotlib.figure.Figure` :
        The matplotlib.Figure of the visualization if the
        ``ax`` kwarg is not set

Raises:
    MissingOptionalLibraryError: Requires matplotlib.
    VisualizationError: if input is not a valid N-qubit state.

Examples:
    .. plot::
       :alt: Output from the previous code.
       :include-source:

       # You can set a color for all the bars.

       from qiskit import QuantumCircuit
       from qiskit.quantum_info import Statevector
       from qiskit.visualization import plot_state_paulivec

       qc = QuantumCircuit(2)
       qc.h(0)
       qc.cx(0, 1)

       state = Statevector(qc)
       plot_state_paulivec(state, color='midnightblue', title="New PauliVec plot")

    .. plot::
       :alt: Output from the previous code.
       :include-source:

       # If you introduce a list with less colors than bars, the color of the bars will
       # alternate following the sequence from the list.

       import numpy as np
       from qiskit.quantum_info import DensityMatrix
       from qiskit import QuantumCircuit
       from qiskit.visualization import plot_state_paulivec

       qc = QuantumCircuit(2)
       qc.h(0)
       qc.cx(0, 1)

       qc = QuantumCircuit(2)
       qc.h([0, 1])
       qc.cz(0, 1)
       qc.ry(np.pi/3, 0)
       qc.rx(np.pi/5, 1)

       matrix = DensityMatrix(qc)
       plot_state_paulivec(matrix, color=['crimson', 'midnightblue', 'seagreen'])
r   r   )   r   r   r#   Tr   Fr   z--)r   	linewidth	linestyler   rk   r   r   )r   rk   Coefficientsr&   r'   )r   g      r   r#   r   F   r*   Paulir   z#eeeeeer,   )r-   r   _paulivec_datar   r2   rJ   r8   r9   gridbaraxhline
set_ylabelrI   rK   rO   
set_xlabelrM   r?   rA   r   rD   r   r   rP   r   rQ   r   rS   )rT   rU   r   rk   r{   r   rX   labelsvaluesnumelemindr   
return_figr^   r   s                  rn   plot_state_paulivecr  q  s   X )#E*NF&kG}
))G
CE	z
,,w,/R
mmoGG1TG2FF31F5JJ#J&MM.2M.MM#MM'(vR8MM'BM'KKQY((*RXX-E-E-GG  $ HLLL$"3'	 
{{8$$	  	
	s   F5 5
GGc                 ~    U S:X  a  g[        S [        [        X-
  S-   U S-   5      [        SUS-   5      5      S5      $ )zReturn the number of combinations for n choose k.

Args:
    n (int): the total number of options .
    k (int): The number of elements.

Returns:
    int: returns the binomial coefficient
r   c                     XS   -  US   -  $ )Nr   r    )rf   rg   s     rn   <lambda>n_choose_k.<locals>.<lambda>  s    qQ4x!A$r   r   )r   r   r:   )nr   s     rn   
n_choose_kr    sE     	Av.E!%!)QU4KUSTVWZ[V[_0]_`aar   c                    ^^ [        U5      T:w  a  [        S5      eU Vs/ s H
  o0S-
  U-
  PM     snm[        UU4S j[        T5       5       5      n[	        U5      $ s  snf )a  Return  the lex index of a combination..

Args:
    n (int): the total number of options .
    k (int): The number of elements.
    lst (list): list

Returns:
    int: returns int index for lex order

Raises:
    VisualizationError: if length of list is not equal to k
zlist should have length kr   c              3   T   >#    U  H  n[        TTS -
  U-
     US -   5      v   M     g7f)r   N)r  ).0ra   combr   s     rn   	<genexpr>lex_index.<locals>.<genexpr>	  s+     EHq
4A	?AE22Hs   %()r   r   sumr:   r   )r  r   lstrf   dualmr  s    `   @rn   	lex_indexr    sY     3x1} !<=="#s!EAIs#DEE!HEEEu: $s   Ac                     [        U 5      nU R                  S5      nU R                  S5      X-
  :w  a  [        S5      e[        U 5       VVs/ s H  u  p4US:X  d  M  UPM     nnn[	        XU5      $ s  snnf )z*Return the index of a string of 0s and 1s.10zs must be a string of 0 and 1)r   countr   	enumerater  )sr  r   r   charoness         rn   bit_string_indexr&    sh    AA	Awws|qu !@AA!*1=ICCD=Q4   >s   A2A2c                     [         R                  " U 5      [         R                  S-  S-  -   [         R                  S-  -  n[        R                  " U[         R                  S-  -  SS5      nU$ )zMap a phase of a complexnumber to a color in (r,g,b).

complex_number is phase is first mapped to angle in the range
[0, 2pi] and then to the HSL color wheel
r   r   r   r#   )r2   anglepicolorsys
hls_to_rgb)complex_numberanglesrgbs      rn   phase_to_rgbr/    sV     hh~&"%%!)a-8RUUQYGF


f	2C
=CJr   c                   SSK Jn  SSK Jn  SSKJn	  SSKn
SSKJn  SSKJ	n  [        U 5      nUR                  nUc  [        S	5      eUR                  UR                  5      u  nnUc  S
nUc  SnUR                  US9nOSnUR!                  5       nUR#                  SSS9nUR%                  USS2SS24   SS9nUR&                  R)                  SS5        UR&                  R+                  SS5        UR&                  R-                  SS5        UR&                  R/                  S5        UR1                  SSS9  [3        UR&                  S5      (       a  UR&                  R5                  S5        [6        R8                  " SS[6        R:                  -  S5      n[6        R8                  " S[6        R:                  S5      n[6        R<                  " [6        R>                  " U5      [6        R@                  " U5      5      n[6        R<                  " [6        R@                  " U5      [6        R@                  " U5      5      n[6        R<                  " [6        RB                  " [6        RD                  " U5      5      [6        R>                  " U5      5      nURG                  UUUSSURH                  S   SSS9  URJ                  RM                  S5        URN                  RM                  S5        URP                  RM                  S5        URJ                  RR                  RU                  S5        URN                  RR                  RU                  S5        URP                  RR                  RU                  S5        URW                  / 5        URY                  / 5        UR[                  / 5        []        UR^                  S   S-
  SS5       GH  nUU   S :  Ga  USS2U4   n [6        R`                  " U 5      Rc                  5       n[6        Rd                  " U U   5      S[6        R:                  -  -   S[6        R:                  -  -  n[6        Rf                  " S!U-  5      nUU -  n Un[]        SU-  5       GHt  n[i        U5      SS Rk                  U5      nURm                  S"5      n S#U -  U-  S-   n![o        UU 5      n"[q        U5      n#[s        U 5      U-  [6        R:                  S-  -  U#S-  [6        R:                  U"-  -  -   n$U US-  :  d  U US-  :X  a3  U#U"S-  :  a*  [6        R:                  U$-
  S[6        R:                  -  U"-  -
  n$[6        Rt                  " SU!S-  -
  5      [6        R>                  " U$5      -  n%[6        Rt                  " SU!S-  -
  5      [6        R@                  " U$5      -  n&[6        Rv                  " [6        Rx                  " U U   U U   R{                  5       5      5      n'[}        U'S5      n'[        U U   5      n(Sn)U&S$:  a  SU&-
  n)[6        R                  " U'S5      (       Gdb  U(       GaZ  S%n*[6        R                  " [6        Rt                  " SU!S-  -
  5      U!5      n+U*[6        R@                  " U+5      -  [6        R>                  " U$5      -  n,U*[6        R@                  " U+5      -  [6        R@                  " U$5      -  n-U*[6        R>                  " U+5      -  n.S&U-   S'-   n/U(       a  [6        Rd                  " U U   5      [6        R:                  S(-  -   [6        R:                  S-  -  n0U(       a  U/S)U0S*-  [6        R:                  -  S+ S,3-  n/O#[        U0SS-9R                  S.S/5      n0U/S)U0 S03-  n/UR                  U,U-U.U/S1S1S2S39  UR                  U%/U&/U!/U(U(S4[6        Rt                  " U'5      S5-  U)S69  U" SU%/SU&/SU!/S7U'S8U(SS99n1UR                  U15        GMw     []        US-   5       H  n [6        R8                  " S#[6        R:                  -  S[6        R:                  -  S:5      n2S#U -  U-  S-   n[6        Rt                  " SUS-  -
  5      n3U3[6        R>                  " U25      -  nU3[6        R@                  " U25      -  nUR                  UUUS;SS<S=S>9  M     UR                  S/S/S/S;S;S4SSS69  GM    O   S?n4[6        RB                  " U45      n2U
R                  U45      n5UR%                  USS2SS24   5      n6U6R                  U2U5SU4-  S@-  S U5SSU4-  S@-   -   SASB9  U6R                  U	" SCS=SDSSE95        SFn7U(       a  / SGQn8O/ SHQn8U6R                  SSU8S   S1S1SISJ9  U6R                  U7SU8S   S1S1SISJ9  U6R                  SU7U8S   S1S1SISJ9  U6R                  U7* SU8S   S1S1SISJ9  U6R                  SU7* U8S(   S1S1SISJ9  U(       a  [        U5        Uc  U$ UR                  U5      $ )Ka  Plot the qsphere representation of a quantum state.
Here, the size of the points is proportional to the probability
of the corresponding term in the state and the color represents
the phase.

Args:
    state (Statevector or DensityMatrix or ndarray): an N-qubit quantum state.
    figsize (tuple): Figure size in inches.
    ax (matplotlib.axes.Axes): An optional Axes object to be used for
        the visualization output. If none is specified a new matplotlib
        Figure will be created and used. Additionally, if specified there
        will be no returned Figure since it is redundant.
    show_state_labels (bool): An optional boolean indicating whether to
        show labels for each basis state.
    show_state_phases (bool): An optional boolean indicating whether to
        show the phase for each basis state.
    use_degrees (bool): An optional boolean indicating whether to use
        radians or degrees for the phase values in the plot.

Returns:
    :class:`matplotlib:matplotlib.figure.Figure` :
        A matplotlib figure instance if the ``ax`` kwarg is not set

Raises:
    MissingOptionalLibraryError: Requires matplotlib.
    VisualizationError: Input is not a valid N-qubit state.

    QiskitError: Input statevector does not have valid dimensions.

Examples:
    .. plot::
       :alt: Output from the previous code.
       :include-source:

       from qiskit import QuantumCircuit
       from qiskit.quantum_info import Statevector
       from qiskit.visualization import plot_state_qsphere

       qc = QuantumCircuit(2)
       qc.h(0)
       qc.cx(0, 1)

       state = Statevector(qc)
       plot_state_qsphere(state)

    .. plot::
       :alt: Output from the previous code.
       :include-source:

       # You can show the phase of each state and use
       # degrees instead of radians

       from qiskit.quantum_info import DensityMatrix
       import numpy as np
       from qiskit import QuantumCircuit
       from qiskit.visualization import plot_state_qsphere

       qc = QuantumCircuit(2)
       qc.h([0, 1])
       qc.cz(0,1)
       qc.ry(np.pi/3, 0)
       qc.rx(np.pi/5, 1)
       qc.z(1)

       matrix = DensityMatrix(qc)
       plot_state_qsphere(matrix,
            show_state_phases = True, use_degrees = True)
r   )gridspecr   )CircleN)linalgr   )Arrow3Dr   )r   r   Tr   Fr   )nrowsncolsr   r   g            ?r   i  )elevazimr   r   r   r   r      z
grid.colorg?)rstridecstriderk   r   r   )r7  r7  r7  g        r   gMbP?y             r  g?g?z$\vertz\rangle$r   z
$   z.1fz^\circ$)ndigitsr)  z\pi$r      )r   r   rl   o   )markerfacecolormarkeredgecolormarker
markersizer      -)mutation_scaler   
arrowstylerk   lwr   )r#   r#   r#   :r#   )rk   rM  lsr   @   r   r   )r   radius)r   r   r!   r   gffffff?)zPhase
(Deg)r   90z180   270)Phasez$0$z$\pi/2$z$\pi$z$3\pi/2$r&   )horizontalalignmentverticalalignmentr(   )Kr-   r1  r   matplotlib.patchesr2  seabornscipyr3  ru   r4  r   r.   r   eighr4   r   r9   GridSpecr   rr   
set_xlim3d
set_ylim3dr   r  	view_inithasattrr   r2   linspacer)  outerrw   rv   r%  rl   plot_surfacercParamsrA   set_pane_colorrD   r   line	set_colorrI   rK   
set_zticksr:   r=   absoluteargmaxr(  expr;   r<   r!  r  r&  floatrF   r6   dotconjr   r/  isclosearctan2r   replacetextplot
add_artisthls_palettepier   rS   )9rT   r   r{   show_state_labelsshow_state_phasesuse_degreesr   r1  rX   r2  snsr3  r4  rY   rZ   eigvalseigvecsr  r^   gsuvrf   rg   zidxlocr-  anglesetdra   elementweightzvaluenumber_of_divisionsweight_orderr(  xvalueyvalueprob
colorstatealfarprimeangle_thetaxvalue_textyvalue_textzvalue_textelement_textelement_anglear   r~   r  r   r`   offsetr  s9                                                            rn   plot_state_qspherer  "  s   ` $()

C
..C
{ !LMM{{388,GW	z
jjj)
mmo			!		,B	AaC1H$	7BGGtS!GGtS!GGtS!GGLLLLacL" rww())
y) 	Aq255y"%A
Aruub!A
BFF1I&A
BFF1I&A
$bffQi0AOO	1aAS\\,-Gs^_  
 HH01HH01HH01 HHMM01HHMM01HHMM01 MM"MM"MM" W]]1%)2r23<%AsFOE++e$++-ChhuSz*QY61ruu9EFvvcFl+Hu$EA1c6]a&***3/ s+fq1,&0F&;#/8v*ruuqy9 1$0C(CD QUNq1u_<;NQR;R+REEEMQY9L-LMEVQY/"&&-?VQY/"&&-? wwrvveAha@A4|)%(3
S=<Dzz$**/@ F"$**RWWQ]-CV"LK"(266++>">"NK"(266++>">"NK"(266++>">K#,w#6#DL()+%();ruuqy)IbeeVWi(X&(c-#2E2Mc1RRZ,[[L,4]A,N,V,VW[]c,dM(c-,BBLGG###$##   HHH$.$.!wwt}r1  	 KKK#%"$	 a S #X  A,BJBEE	3?K!Oa'GGA1H%u%u%1a1CP ' GG / /  	 W 3Z 	AGGAJE__QF
//"QRV*
%CGGE&Q!.!a%1*1EEdGSNN6&#WQ?@F=DHHQ6!9(hacHdHH6!9(hac   HH	66!9(hac   HH	F1I8xbd   HH	F7F1I8xbd   "3'
{{8$$r   c                    SSK Jn  [        R                  " / SQ5      n[        R                  " U R
                  UR
                  -   5      n	SX4SX4SX%44 H_  u  pnUS[        R                  [        R                  4   nUS[        R                  [        R                  4   nXUSU
4   -  -   U	SU
4'   Ma     U	R                  SU	R
                  SS -   5      n	/ n[        U5      [        U 5      :X  a  U H  nUR                  U/S-  5        M     OC[        UR                  U5      5      n[        U5      [        U 5      :  a  US[        U 5      -  -  n[        U	5      n[        X5      $ )	a  Generates shaded facecolors for shaded bars.

This is here to work around a Matplotlib bug
where alpha does not work in Bar3D.

Args:
    x (array_like): The x- coordinates of the anchor point of the bars.
    y (array_like): The y- coordinates of the anchor point of the bars.
    z (array_like): The z- coordinates of the anchor point of the bars.
    dx (array_like): Width of bars.
    dy (array_like): Depth of bars.
    dz (array_like): Height of bars.
    color (array_like): sequence of valid color specifications, optional
Returns:
    list: Shaded colors for bars.
Raises:
    MissingOptionalLibraryError: If matplotlib is not installed
r   N))r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r:  r   r   r   )r  r  r  r  )r  r  r:  r  )r  r  r  r  )r  r  r:  r  r   r   .)r      )r   r   r2   arrayemptyr=   newaxisreshaper   extendr   r   _generate_normals_shade_colors)rf   rg   r  r   r   r   rk   r   cuboidpolysra   pdp
facecolorscnormalss                   rn   r   r   D  sH   ( (XX+	
-F` HHQWWv||+,EZ!QaZ8bc2::rzz)*RZZ+,Q//c1f 9 MM%%++ab/12EJ
5zSVAqcAg&  '//67
z?SV#!c!f*$J&G--r   c                 6   [        U [        R                  5      (       aH  U R                  S   nSUS-  SU-  S-  pCnU SUSS24   U SUSS24   -
  nU SUSS24   U SUSS24   -
  nO[        R                  " [        U 5      S45      n[        R                  " [        U 5      S45      n[        U 5       HL  u  px[        U5      nSUS-  SU-  S-  pCnXSS24   XSS24   -
  XWSS24'   XSS24   XSS24   -
  XgSS24'   MN     [        R                  " XV5      $ )a   Takes a list of polygons and return an array of their normals.

Normals point towards the viewer for a face with its vertices in
counterclockwise order, following the right hand rule.
Uses three points equally spaced around the polygon.
This normal of course might not make sense for polygons with more than
three points not lying in a plane, but it's a plausible and fast
approximation.

Args:
    polygons (list): list of (M_i, 3) array_like, or (..., M, 3) array_like
        A sequence of polygons to compute normals for, which can have
        varying numbers of vertices. If the polygons all have the same
        number of vertices and array is passed, then the operation will
        be vectorized.
Returns:
    normals: (..., 3) array_like
        A normal vector estimated for the polygon.
r>  r   r   r   .N)r   r2   ndarrayr=   r  r   r"  cross)	polygonsr  i1i2i3v1v2poly_ipss	            rn   r  r    s&   ( (BJJ'' NN2QA
c2qj!HS"aZ$88c2qj!HS"aZ$88 XXs8}a()XXs8}a()#H-JFBAAFAEQJBB1uIq5	1BqyM1uIq5	1BqyM	 . 88Br   c                    SSK JnJn  SSK Jn  Uc  U" SSS9nS n[        R
                  " U Vs/ s HH  ov" U5      (       a)  [        R                  " Xv" U5      -  UR                  5      O[        R                  PMJ     sn5      n[        R                  " U5      ) n	U	R                  5       (       ay  U" [        X   5      [        X   5      5      n
[        X   5      X) '   UR                  U 5      n U SS2S4   nS	U
" U5      SS2[        R                  4   S	-  -   U -  nXSS2S4'   U$ [        R                  " U 5      R!                  5       nU$ s  snf )
zv
Shade *color* using normal vectors given by *normals*.
*color* can also be an array of the same length as *normals*.
r   )	NormalizeLightSourceN   g-x3@)azdegaltdegc                 ^    [         R                  " U S   S-  U S   S-  -   U S   S-  -   5      $ )Nr   r   r   )r2   rF   )r~  s    rn   mod_shade_colors.<locals>.mod  s3    wwqtqy1Q419,qtqy899r   r   r#   )r   r  r  r   r2   r  rl  	directionnanisnanr   r   r5   r   r  
asanyarrayr   )rk   r  lightsourcer  r  r   r  r  shademasknormr   r   s                rn   r  r    s0   
 9'!G<: HHRYZRYQc!ffCF
K11	2"&&	HRYZE HHUODxxzzU[)3u{+;<5;'e%%e, adUArzzM2S88EAq!t M u%**,M# 	[s   AErT   dims
conventionreturnc                    Uc#  [        U R                  5       5      S1:X  a  SnOSnSnSnU(       a"  SnU R                  R                  5       nSU S3nU R                  n[	        UR                  5       5      S:H  =(       a    [        UR                  5       5      S1:H  nUS	:X  a  U(       a  [        U R                  40 UD6n	O[        U R                  4S
S0UD6n	XI-   U-   $ )a  Return a Latex representation of a state. Wrapper function
for `qiskit.visualization.array_to_latex` for convention 'vector'.
Adds dims if necessary.
Intended for use within `state_drawer`.

Args:
    state: State to be drawn
    dims (bool): Whether to display the state's `dims`
    convention (str): Either 'vector' or 'ket'. For 'ket' plot the state in the ket-notation.
            Otherwise plot as a vector
    **args: Arguments to be passed directly to `array_to_latex` for convention 'ket'

Returns:
    Latex representation of the state
    MissingOptionalLibrary: If SymPy isn't installed and ``'latex'`` or
        ``'latex_source'`` is selected for ``output``.

r   FT z\begin{align}
z\\
\text{dims=z}
\end{align}r   ketsource)	setr  	_op_shapedims_lr   dims_r_state_to_latex_ket_datar   )
rT   r  r  argsprefixsuffixdims_stroperator_shapeis_qubit_statevector	latex_strs
             rn   state_to_latexr    s    * |uzz|#DDFF#??))+&xj0BC__N ~44671<d^EZEZE\A]bcadAdU3'<t<	"5;;DtDtD	&&r   numbersdecimalsc                 \    Sn/ nU  H!  n[        XAUSS9nUR                  U5        SnM#     U$ )a"  Convert a list of numbers to latex formatted terms

The first non-zero term is treated differently. For this term a leading + is suppressed.

Args:
    numbers: List of numbers to format
    decimals: Number of decimal places to round to (default: 10).
Returns:
    List of formatted terms
T)r  
first_termcoefficientF)r   append)r  r  r  termsnumberterms         rn   _numbers_to_latex_termsr    s?     JEV:[_`T
  Lr   r4   max_sizer  c                   ^ [        [        R                  " [        U 5      5      5      mU4S jn[        R
                  " X5      n [        R                  " U S:g  5      S   R                  5       n[        U5      U:  a.  USUS-   S/-   XQ* S-  S-   S -   n[        X   U5      nSXQS-  '   O[        X   U5      nSn[        U5       H%  u  pU	c  US-  nM  Xh   n
U" U	5      nXz SU S	3-  nM'     X'-   $ )
a  Convert state vector to latex representation

Args:
    data: State vector
    max_size: Maximum number of non-zero terms in the expression. If the number of
             non-zero terms is larger than the max_size, then the representation is truncated.
    prefix: Latex string to be prepended to the latex, intended for labels.
    decimals: Number of decimal places to round to (default: 10).

Returns:
    String with LaTeX representation of the state vector
c                 >   > [        U 5      SS  R                  T5      $ )Nr   )r;   r<   )ra   rZ   s    rn   ket_name%_state_to_latex_ket.<locals>.ket_nameA  s    1vabz$$r   r   Nr   r   r  z
 + \ldots z |z\rangle)
r   r/   r1   r   r2   aroundwheretolistr  r"  )r4   r  r  r  r  nonzero_indiceslatex_termsr  r  ket_idxr  r  rZ   s               @rn   r  r  0  s    diiD	"
#C% 99T$Dhhtqy)!,335O
?h&Oh!m,s2_YRS^VWEWEY5ZZ 	 .d.CXN)-A&-d.CXNI!/2?&I#D7#C6C511I 3 r   c                   .    \ rS rSrSrSS jrS rS rSrg)	
TextMatrixiZ  zaText representation of an array, with `__str__` method so it
displays nicely in Jupyter notebooksNc                 p   Xl         X l        Uc  [        U[        [        45      (       a  [        UR                  5       5      S1:X  d  [        U[        5      (       av  [        UR                  5       5      [        UR                  5       5      :X  aB  [        UR                  5       5      [        UR                  5       5      s=:X  a  S1:X  a  O  OSnOSnX0l        X@l        XPl        [        U[        5      (       a  X l        g [        U[        5      (       a  [        U5      S-  U l        g US   U l        g )Nr   FTr   )rT   r  r   r   r   r  r  r   r   
input_dimsoutput_dimsr  r  r   r   )selfrT   r  r  r  r  s         rn   __init__TextMatrix.__init__^  s    
 <5;">??C

DUZ[Y\D\5(++((*+s53D3D3F/GG((*+s53D3D3F/GNA3N	h$$$M}--  MQ.DM$QKDMr   c                 J   U R                   n[        R                  " U R                  R                  U R
                  USS9nSnU R                  (       a  US-  nUS[        U R
                  5      -  -  n[        U R                  [        [        45      (       a+  USU R                  R                  R                  5        3-  nOAUSU R                  R                  5        S3-  nUS	U R                  R                  5        3-  nU R
                  U-   U-   U R                  -   $ )
N,)r  	threshold	separatorr  z,
 zdims=zinput_dims=z, zoutput_dims=)r  r2   array2stringrT   r  r  r  r   r   r   r   r  r  r  r  r  )r  r  r4   dimstrs       rn   __str__TextMatrix.__str__v  s    MM	JJT[[IQT
 99EMDcC,,,F$**{M&BCCE$**"6"6"="="?!@AAK

(=(=(?'@CCL)?)?)A(BCC{{T!F*T[[88r   c                 "    U R                  5       $ N)r  )r  s    rn   __repr__TextMatrix.__repr__  s    ||~r   )r  r  r  rT   r  )r   Nr  r  )	__name__
__module____qualname____firstlineno____doc__r  r  r  __static_attributes__r  r   rn   r  r  Z  s    ,(09"r   r  c           	         [         R                  " 5       nSnUc  U(       a  UR                  SS5      nUnUR                  5       n[        [
        [        [        [        [        [        S.nUS:X  a=  [        R                  R                  S5        SSKJn  US   nU" S	U" U 40 UD6 S	35      $ US:X  a  U R!                  5       $  XQ   nU" U 40 UD6$ ! ["         a+  n[%        S
U S['        U 5      R(                   S35      UeSnAff = f)a  Returns a visualization of the state.

**repr**: ASCII TextMatrix of the state's ``_repr_``.

**text**: ASCII TextMatrix that can be printed in the console.

**latex**: An IPython Latex object for displaying in Jupyter Notebooks.

**latex_source**: Raw, uncompiled ASCII source to generate array using LaTeX.

**qsphere**: Matplotlib figure, rendering of statevector using `plot_state_qsphere()`.

**hinton**: Matplotlib figure, rendering of statevector using `plot_state_hinton()`.

**bloch**: Matplotlib figure, rendering of statevector using `plot_bloch_multivector()`.

**city**: Matplotlib figure, rendering of statevector using `plot_state_city()`.

**paulivec**: Matplotlib figure, rendering of statevector using `plot_state_paulivec()`.

Args:
    output (str): Select the output method to use for drawing the
        circuit. Valid choices are ``text``, ``latex``, ``latex_source``,
        ``qsphere``, ``hinton``, ``bloch``, ``city`` or ``paulivec``.
        Default is `'text`'.
    drawer_args: Arguments to be passed to the relevant drawer. For
        'latex' and 'latex_source' see ``array_to_latex``

Returns:
    :class:`matplotlib.figure` or :class:`str` or
    :class:`TextMatrix` or :class:`IPython.display.Latex`:
    Drawing of the state.

Raises:
    MissingOptionalLibraryError: when `output` is `latex` and IPython is not installed.
        or if SymPy isn't installed and ``'latex'`` or ``'latex_source'`` is selected for
        ``output``.

    ValueError: when `output` is not a valid selection.
reprNstate_drawer)rq  latex_sourceqspherehintonru   citypauliveclatexr   )Latexr  z$$'z$' is not a valid option for drawing z
             objects. Please choose from:
            'text', 'latex', 'latex_source', 'qsphere', 'hinton',
            'bloch', 'city' or 'paulivec'.)r   
get_configgetlowerr  r  r  ro   r   r   r  
_optionalsHAS_IPYTHONrequire_nowIPython.displayr  r  KeyErrorr   typer
  )	rT   outputdrawer_argsconfigdefault_outputdrawersr  	draw_funcerrs	            rn   r  r    s   R ##%FN~#ZZ?N\\^F &%#''G **>:)N+	r)E9[9:"=>>~~	O	.+.. &=d5k>R>R=S T+ .

 	s   C 
D&DDc                 V   [        U 5      nUR                  nUc  [        S5      e[        / SQ5      n/ n[	        U5       H  nUS:  a^  [        R
                  " [        R                  " SUS-
  4[        S9[        R                  " SUS-
  4[        S95      R                  XSSS9nOUnUR                  5        Vs/ s HK  n[        R                  " [        R                  " [        R                  " XqR                  5      5      5      PMM     nnUR                  U5        M     U$ s  snf )zReturn list of Bloch vectors for each qubit

Args:
    state (DensityMatrix or Statevector): an N-qubit state.

Returns:
    list: list of Bloch vectors (x, y, z) for each qubit.

Raises:
    VisualizationError: if input is not an N-qubit state.
r   )XYZr   r   )dtypeT)qubit)r   r.   r   r	   r:   from_symplecticr2   r   boolinsertmatrix_iterr6   tracerl  r4   r  )	rT   rY   rZ   pauli_singlesr   ra   paulismatbloch_states	            rn   r   r     s     
C
..C
{ !LMMo.MJ3Z7..!cAgt4bhhC!G~UY6ZfQTf2  #FKQK]K]K_`K_CrwwrxxsHH(=>?K_`+&   as   ;AD&c                    [         R                  " [        U 5      5      nUR                  c  [	        S5      eUR
                  R                  5       [        R                  " UR                  SUR                  -  -  5      4$ )zReturn paulivec data for plotting.

Args:
    state (DensityMatrix or Statevector): an N-qubit state.

Returns:
    tuple: (labels, values) for Pauli vector.

Raises:
    VisualizationError: if input is not an N-qubit state.
r   r   )
r
   from_operatorr   r.   r   r7  	to_labelsr2   r6   coeffs)rT   rY   s     rn   r  r    sb     
%
%mE&:
;C
~~ !LMM::!2773::3>>8I+I#JJJr   )r  NNN)r  NN	cartesianN)r  N)r  NNr   NN)NNTFFr  )Nr  )r   )rB  r  r   )<r  r/   typingr   r   	functoolsr   r*  numpyr2   qiskitr   &qiskit.quantum_info.states.statevectorr   &qiskit.quantum_info.operators.operatorr   (qiskit.quantum_info.operators.symplecticr	   r
   (qiskit.quantum_info.states.densitymatrixr   qiskit.utilsr   r  qiskit.circuit.tools.pi_checkr   r  r   r   utilsr   
exceptionsr   HAS_MATPLOTLIBrequire_in_callro   r   r   r   r  r  r  r&  r/  HAS_SEABORNr  r   r  r  r2  r   r  complexr   r  r  r  r  r   r  r  r   rn   <module>rO     s          > ; M B 0 2 0 - * **Q%]a Q% +Q%h **NRA +AH ** o%
 o% +o%d ** 

y% y% +y%x **t%X\ t% +t%nb*! **'' ]% ]% ( +]%@	 **[. +[.|%P!J TY*'m+,*'48*'MP*'*'ZT'] c 4PS9 * PR'
w-'#&'58'IL''T. .bOd<Kr   