
    z	iE                        S r SSKrSSKJr  SSKrSSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJr  \R&                  R(                               SS j5       r\R&                  R(                  \R,                  R(                              SS
S.S\S\\\      S\\\      4S jjj5       5       rSS jr\R&                  R(                  \R4                  R(                  SS j5       5       rg)z-A module for visualizing device coupling maps    N)List)graphviz_draw)QiskitError)	optionals)CouplingMap   )VisualizationErrorTc                    0 nSS/SS/SS/SS/SS//US'   SS/SS/SS/SS/SS/SS/SS//US'   SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS//US'   SS/SS/SS/SS/SS/SS/SS	/SS/SS	/SS/SS/SS/SS/SS/SS//US
'   SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS	//US'   SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS	/SS	/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS//US'   SS/SS/SS/SS/SS	/SS/SS	/SS/SS/SS/SS/SS/SS/SS	/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS/SS	/SS/SS//US'   / SS/PSS/PSS/PSS/PSS	/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS	/PS	S/PS	S/PS	S/PS	S/PS	S/PS	S/PS	S	/PS	S/PS	S/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS	/PUS'   / SS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PS	S/PS	S/PS	S/PS	S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/PSS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS
/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS /PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS
/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS /PSS/PSS	/PSS/PSS/PSS/PSS/PSS /PSS/PSS/PSS/PSS/PSS/PSS	/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS
/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS/PSS /PUS!'   U R                   nU R                  nU R                  nUc  S#U;   d  S$U;   a  UR                  US"5      nU(       a)  [	        U5      U:w  a  [        S%[	        U5       S&U 35      e[        UUUR                  5       UUUUUUUUU	U
UU[        R                  " UR                  R                  S'S(95      S)9$ )*ak  Plots the gate map of a device.

Args:
    backend (Backend): The backend instance that will be used to plot the device
        gate map.
    figsize (tuple): Output figure size (wxh) in inches.
    plot_directed (bool): Plot directed coupling map.
    label_qubits (bool): Label the qubits.
    qubit_size (float): Size of qubit marker.
    line_width (float): Width of lines.
    font_size (int): Font size of qubit labels.
    qubit_color (list): A list of colors for the qubits
    qubit_labels (list): A list of qubit labels
    line_color (list): A list of colors for each line from coupling_map.
    font_color (str): The font color for the qubit labels.
    ax (Axes): A Matplotlib axes instance.
    filename (str): file path to save image to.
    qubit_coordinates (Sequence): An optional sequence input (list or array being the
        most common) of 2d coordinates for each qubit. The length of the
        sequence much match the number of qubits on the backend. The sequence
        should be the planar coordinates in a 0-based square grid where each
        qubit is located.

Returns:
    Figure: A Matplotlib figure instance.

Raises:
    QiskitError: If you tried to pass a simulator or the backend is None,
        but one of num_qubits, mpl_data, or cmap is None.
    MissingOptionalLibraryError: If matplotlib not installed.

Example:

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

       from qiskit.providers.fake_provider import GenericBackendV2
       from qiskit.visualization import plot_gate_map

       backend = GenericBackendV2(num_qubits=5)

       plot_gate_map(backend)
r   r                                 	   
         5   A                                             i  Nibmfakez*The number of specified qubit coordinates z- does not match the device number of qubits: F
multigraphplanar)
num_qubitscoupling_mapnamegetlenr   plot_coupling_map	get_edgesrx	is_planargraphto_undirected)backendfigsizeplot_directedlabel_qubits
qubit_size
line_width	font_sizequbit_colorqubit_labels
line_color
font_coloraxfilenamequbit_coordinatesqubit_coordinates_mapr/   r0   r1   s                     W/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/visualization/gate_map.pyplot_gate_maprJ      s0   z !"AAAAAG!!"AAAAAAQRTUPVW! 
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A)!"0 
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A!"& 
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A!!"( 
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
B7!"> 
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A9!">6!	
A6!	
A6! 
A6! 
A	6!
 
A6! 
A6! 
A6! 
A6! 
A6! 
A6! 
A6! 
A6! 
A6! 
A6! 
A6!  
A!6!" 
A#6!$ 
A%6!& 
A'6!( 
A)6!* 
A+6!, 
A-6!. 
A/6!0 
A16!2 
A36!4 
A56!6 
A76!8 
A96!: 
A;6!< 
A=6!> 
A?6!@ 
AA6!B 
AC6!D 
AE6!F 
AG6!H 
AI6!J 
AK6!L 
AM6!N 
AO6!P 
AQ6!R 
AS6!T 
AU6!V 
AW6!X 
AY6!Z 
A[6!\ 
A]6!^ 
A_6!` 
Aa6!b 
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 
RCr"D 
REr"F 
RGr"H 
RIr"J 
RKr"L 
RMr"N 
ROr"P 
RQr"R 
RSr"T 
RUr"V 
RWr"X 
RYr"Z 
R[r"\ 
R]r"^ 
Q_r"` 
Qar"b 
Qcr"d 
Rer"f 
Rgr"h 
Rir"j 
Rkr"l 
Qmr"n 
Qor"p 
Qqr"r 
Qsr"t 
Qur"v 
Qwr"x 
Qyr"z 
Q{r"| 
Q}r"~ 
Qr"@ 
RAr"B 
RCr"D 
REr"F 
RGr"H 
RIr"J 
RKr"L 
RMr"N 
ROr"P 
RQr"R 
RSr"T 
RUr"V 
RWr"X 
RYr"Z 
R[r"\ 
R]r"^ 
R_r"` 
Rar"b 
Qcr"d 
Qer"f 
Rgr"h 
Rir"j 
Rkr"l 
Rmr"n 
Ror"p 
Qqr"r 
Qsr"t 
Qur"v 
Qwr"x 
Qyr"z 
Q{r"| 
Q}r"~ 
Qr"@ 
QAr"B 
RCr"D 
REr"F 
RGr"H 
RIr"J 
RKr"L 
RMr"N 
ROr"P 
RQr"R 
RSr"T 
RUr"V 
RWr"X 
RYr"Z 
R[r"\ 
R]r"^ 
R_r"` 
Rar"b 
Rcr"#h ##J''L<<D etmv~155j$G !Z/<SAR=S<T U??IlL   
||L..<<<NO!     r-   r/   rG   r0   c          	        ^^^^^	^
^^^! SSK Jn  SSKJn  SnU(       a  SnTc  SmT
c  [	        [        U 5      5      m
O[        T
5      U :w  a  [        S5      eU(       d  S	/U -  m
T	c  S
/U -  m	Tc  S
/[        U5      -  mU S:X  a'  [        R                  " 5       nUR                  S5        O[        U5      R                  nU(       dV  [        [        UR                  5       T5      5      nUR!                  SS9nUR                  5        Vs/ s H  nUU   PM
     snmUR#                  5        H  nUUU'   M
     UR%                  5        H  nUR'                  UU5        M     SUR(                  S   -  m!T(       a  T Vs/ s H  nUSSS2   PM     snmTc9  [+        S[+        S T
 5       5      5      nUS:X  a  SmOUS:X  a  SmOUS:X  a  SmOSmUUU!U	UU
U4S jnUU4S jnSnT(       d  U(       a  SSSS.nOSS0n[-        USUUUUS9nU(       a  gU(       d.  Uc  UR.                  u  nnUT!-  UT!-  4nUR1                  US9u  n nUR3                  S 5        UR5                  U5        U(       d
  U" W 5        U $ gs  snf s  snf )!a9  Plots an arbitrary coupling map of qubits (embedded in a plane).

Args:
    num_qubits (int): The number of qubits defined and plotted.
    qubit_coordinates (List[List[int]]): A list of two-element lists, with entries of each nested
        list being the planar coordinates in a 0-based square grid where each qubit is located.
    coupling_map (List[List[int]]): A list of two-element lists, with entries of each nested
        list being the qubit numbers of the bonds to be plotted.
    figsize (tuple): Output figure size (wxh) in inches.
    plot_directed (bool): Plot directed coupling map.
    label_qubits (bool): Label the qubits.
    qubit_size (float): Size of qubit marker.
    line_width (float): Width of lines.
    font_size (int): Font size of qubit labels.
    qubit_color (list): A list of colors for the qubits
    qubit_labels (list): A list of qubit labels
    line_color (list): A list of colors for each line from coupling_map.
    font_color (str): The font color for the qubit labels.
    ax (Axes): A Matplotlib axes instance.
    filename (str): file path to save image to.
    planar (bool): If the coupling map is planar or not. Default: ``True`` (i.e. it is planar)

Returns:
    Figure: A Matplotlib figure instance.

Raises:
    MissingOptionalLibraryError: If matplotlib or graphviz is not installed.
    QiskitError: If the length of qubit labels does not match the number of qubits.

Example:

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

        from qiskit.visualization import plot_coupling_map

        num_qubits = 8
        qubit_coordinates = [[0, 1], [1, 1], [1, 0], [1, 2], [2, 0], [2, 2], [2, 1], [3, 1]]
        coupling_map = [[0, 1], [1, 2], [2, 3], [3, 5], [4, 5], [5, 6], [2, 4], [6, 7]]
        plot_coupling_map(num_qubits, qubit_coordinates, coupling_map)
r   Nr   matplotlib_close_if_inlineFT   z7Length of qubit labels does not equal number of qubits. #648fffr+   gffffff?z
figure.dpic              3   J   #    U  H  n[        [        U5      5      v   M     g 7f)N)r3   str).0xs     rI   	<genexpr>$plot_coupling_map.<locals>.<genexpr>  s     #FACAKKs   !#r   r   r   r   r   c                 B  > T(       a6  [        TU    5      STU     S3STU     S3STU    S    STU    S    S3SS.nO [        TU    5      STU     S3STU     S3S.nSUS	'   S
US'   ST S3US'   S[        T5       S3US'   [        TT-  5      US'   SUS'   SUS'   U$ )N"r   ,r   True)labelcolor	fillcolorpospin)r]   r^   r_   filledstylecircleshape	fontcolorz!"fontsizeheight	fixedsizez"DejaVu Sans"fontnamerT   )	nodeout_dictrD   r@   pxrA   rG   rB   r>   s	     rI   
color_node%plot_coupling_map.<locals>.color_node$  s   \$/0[./q1 T!2 315,T2156a8I$8OPQ8R7SSTUH \$/0[./q1 T!2 315H
 %$"#J<q 1!"3y>"2"5 b1 &.rK   c                 B   > STU     S3STU     S3[        T5      S.nU$ )NrZ   )r^   r_   penwidthrk   )edgerm   rC   r?   s     rI   
color_edge%plot_coupling_map.<locals>.color_edge<  s<    D)*!,Z-.a0J

 rK   z-7prismsubset)overlap_scalingoverlapmodelry   trueneato)method
graph_attrnode_attr_fnedge_attr_fnrF   r;   off)matplotlib.pyplotpyplotutilsrN   listranger3   r   r6   	PyDiGraphadd_noder   r8   dictzip	edge_listr9   node_indicesedge_indicesupdate_edge_by_indexrcParamsmaxr   sizesubplotsaxisimshow)"r/   rG   r0   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   r.   pltrN   
input_axesr8   line_color_maprs   rl   
edge_indexcoordinatesmax_charactersro   rt   graph_attributesplotwidthrh   figrn   s"    `    ```````                    @rI   r4   r4     s   ~ $1J	

E*-.|
*WXXtj(  kJ.[3|#44
QqL)//c%//"3Z@A##u#57<7HI7HtnT*7HI
""$d % ((*
"":z: + 
\*	*BBSTBS;[2.BSTQ#F#F FGQIq Iq II 0 #'"!  6  #D ? IIME6rz6B;/G,,w,/RGGENIIdO"3'
 s J Us   I?Jc           
         U R                   c  [        S5      eUR                  nUR                  nUR                  R                  5       n/ nS/U-  nU R                   R                  R                  5        V	V
Vs0 s H  n	[        U	5        H
  u  pXU
S._M     M     nn
n	n[        U R                   R                  R                  5       5       H  u  pX;  d  M  SU
S.X'   M     US:X  a{  U R                   R                  R                  5       R                  5        HD  u  pX   S   nUb  UR                  S:w  d  M!  UR                  U5        [        X   S   5      X'   MF     OUS	:X  av  U R                   R                  R                  5       R                  5        H?  u  pX   S   nUb  UR                  S:w  d  M!  UR                  U5        [        U5      X'   MA     O[        S
5      eS/U-  nU H  nSUU'   M
     S/U-  n[        U5       H!  u  nnUS   U;   d  M  US   U;   d  M  SUU'   M#     [!        UUUUUS9nU$ s  snn
n	f )a  Plot the layout of a circuit transpiled for a given
target backend.

Args:
    circuit (QuantumCircuit): Input quantum circuit.
    backend (Backend): Target backend.
    view (str): How to label qubits in the layout. Options:

      - ``"virtual"``: Label each qubit with the index of the virtual qubit that
        mapped to it.
      - ``"physical"``: Label each qubit with the index of the physical qubit that it
        corresponds to on the device.

    qubit_coordinates (Sequence): An optional sequence input (list or array being the
        most common) of 2d coordinates for each qubit. The length of the
        sequence must match the number of qubits on the backend. The sequence
        should be the planar coordinates in a 0-based square grid where each
        qubit is located.

Returns:
    Figure: A matplotlib figure showing layout.

Raises:
    QiskitError: Invalid view type given.
    VisualizationError: Circuit has no layout attribute.

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

        from qiskit import QuantumCircuit, transpile
        from qiskit.providers.fake_provider import GenericBackendV2
        from qiskit.visualization import plot_circuit_layout

        ghz = QuantumCircuit(3, 3)
        ghz.h(0)
        for idx in range(1,3):
            ghz.cx(0,idx)
        ghz.measure(range(3), range(3))

        backend = GenericBackendV2(num_qubits=5)
        new_circ_lv3 = transpile(ghz, backend=backend, optimization_level=3)
        plot_circuit_layout(new_circ_lv3, backend)
Nz:Circuit has no layout. Perhaps it has not been transpiled.rP   )registerindexvirtualr   ancillar   physicalz,Layout view must be 'virtual' or 'physical'.rQ   blackr   r   )rA   rB   rC   rG   )_layoutr   r/   r0   r8   	num_edgesinitial_layoutget_registers	enumerateget_virtual_bitsitemsr1   appendrT   get_physical_bitsr	   rJ   )circuitr:   viewrG   r/   cmapcmap_lenqubitsrB   r   r   bitbit_locationsqubitkeyvalbit_registerqcolorsklcolorsidxrs   r   s                          rI   plot_circuit_layoutr   i  sS   \ VWW##JDzz##%HF4*$L  66DDFFH#H-JE 	U33- 	F  
 "'//"@"@"Q"Q"ST%04u#EM  U y66GGIOOQHC(-j9L#|'8'8I'Ec"$'(:7(C$D!	 R 
	66HHJPPRHC(-j9L#|'8'8I'Ec"$'H!	 S !!OPPkJ&G
  kH$Gt_	T7faF!2"GCL % !+C JWs   ;$Ic                    SSK nSSKJn  SSK JnJn  SSKnSSKJn	  UR                  SSS9n
U R                  nU R                  nU R                  n0 nS/U-  nS/U-  n/ nU R                  R                  5        H  u  nnUb  SU;   a  M  UR                  5        H  u  nnUc  M  US:X  a#  UR                  b  UR                  UUS   '   M2  M4  [        U5      S:X  a3  UR                  b$  [!        UUS      UR                  5      UUS   '   Mt  Mv  [        U5      S	:X  d  M  UR                  c  M  [!        UR#                  US5      UR                  5      UU'   M     M     U(       af  S
nUS:  a  U H  nUS   US   /U;  d  M  Sn  O   UR%                  5        H/  nUR#                  ['        U5      S5      nUR)                  U5        M1     S[*        R,                  " U5      -  n[*        R.                  " U5      nUR0                  R3                  [5        U5      [!        U5      S9nU Vs/ s H*  nUR0                  R7                  U
" U" U5      5      5      PM,     nnS
n/ nU(       a  S[*        R,                  " U5      -  n[*        R.                  " U5      nUR0                  R3                  [5        U5      [!        U5      S9nU Vs/ s H*  nUR0                  R7                  U
" U" U5      5      5      PM,     nnS[*        R,                  " U5      -  n[*        R.                  " U5      n [*        R                   " U5      n!UR9                  US9n"UR;                  S	SS9  UR;                  SSS/S-  S/-   / SQS9n#UR=                  U#S	S2SS24   5      n$UR=                  U#SS2SS24   5      n%UR=                  U#S	S2SS24   5      n&UR=                  U#SSS24   5      n'U(       a  UR=                  U#SSS24   5      n(Sn)US::  a  Sn)[?        U UUU)SUU%US9  U%RA                  S5        U%RC                  S5        U(       aq  URD                  RG                  U'U
USS9n*URI                  SS9n+U+U*l%        U*RM                  5         U*RM                  5         U'RO                  S [Q        US5       S!35        Uc/  U'RA                  S5        U'RO                  S"[Q        US5       35        U(       aa  URD                  RG                  W(U
WSS9n,URI                  SS9n+U+U,l%        U,RM                  5         U(RO                  S#[Q        WS5       S!35        US:  a  Un-Sn.O[R        RT                  " US	-  5      n-UU--
  n.U$RW                  [Y        U-5      USU- S$S%S&9  U$R[                  U S'S(S)9  U$R]                  [Y        U-5      5        U$R_                  S[Q        U S	5      [Q        U!S	5      /5        U$Ra                  [Y        U-5       V/s/ s H  n/[c        U/5      PM     sn/SS*9  U$Re                  5         U$RO                  S+SS*9  U$Rf                  Ri                  5        H  n0U0Rk                  S
5        M     U.(       Ga  U&RW                  [Y        U-U5      UU-S S$S%S&9  U&R[                  U S'S(S)9  U&R]                  [Y        U-U5      5        U&R_                  S[Q        U S	5      [Q        U!S	5      /5        U&Ra                  [Y        U-U5       V/s/ s H  n/[c        U/5      PM     sn/SS*9  U&Re                  5         U&Rm                  5         U&Rn                  Rq                  S,5        U&Rn                  Rs                  5         U&RO                  S+SS*9  OU&RA                  S5        U&Rf                  Ri                  5        H  n0U0Rk                  S
5        M     U(       a  U"Ru                  U S-3S.S/S09  U	" U"5        U"$ s  snf s  snf s  sn/f s  sn/f )1a  Plots the error map of a given backend.

Args:
    backend (Backend): Given backend.
    figsize (tuple): Figure size in inches.
    show_title (bool): Show the title or not.
    qubit_coordinates (Sequence): An optional sequence input (list or array being the
        most common) of 2d coordinates for each qubit. The length of the
        sequence much mast the number of qubits on the backend. The sequence
        should be the planar coordinates in a 0-based square grid where each
        qubit is located.

Returns:
    Figure: A matplotlib figure showing error map.

Raises:
    VisualizationError: The backend does not provide gate errors for the 'sx' gate.
    MissingOptionalLibraryError: If matplotlib or seaborn is not installed.

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

        from qiskit.visualization import plot_error_map
        from qiskit.providers.fake_provider import GenericBackendV2

        backend = GenericBackendV2(num_qubits=5)
        plot_error_map(backend)
r   N)gridspectickerr   rM   T)reverseas_cmapmeasurer   Fr   d   )vminvmaxr   r   )nrowsncolsr   r   g      ?)r   r   r   r   r   r   r   r   r   r   r   r   )height_ratioswidth_ratiosr   rR   r   r   r   )rA   rC   r>   r?   r<   rE   rG   r   
horizontal)r   normorientation)nbinszH error rate (%) [Avg. = ]zH error rate (%) = zCNOT error rate (%) [Avg. = centerz#DDBBBA)alignr^   z--z#212121)	linestyler^   )rg   zReadout Error (%)rightz
 Error Mapr&   g?)rg   y);
matplotlibr   r   r   r   seabornr   rN   cubehelix_paletter1   r/   r0   targetr   errorr3   r   r2   r5   tupler   npasarraymeancolors	Normalizeminto_hexfigureGridSpecsubplotrJ   r   
set_aspectcolorbarColorbarBaseMaxNLocatorlocatorupdate_ticks	set_titleroundmathceilbarhr   axvline
set_yticks
set_xticksset_yticklabelsrT   invert_yaxisspinesvaluesset_visibleinvert_xaxisyaxisset_label_position
tick_rightsuptitle)1r:   r;   
show_titlerG   r   r   r   r   snsrN   	color_mapbackend_namer/   r   two_q_error_mapsingle_gate_errorsread_err	cx_errorsgate	prop_dictqargs
inst_propsdirectedrs   lineerr
avg_1q_errsingle_normq_colorsline_colors
avg_cx_errcx_normavg_read_errmax_read_errr   	grid_specleft_axmain_axright_axbleft_ax	bright_axr>   	single_cbtick_locatorcx_cbnum_left	num_rightkkspines1                                                    rI   plot_error_mapr#    s   B #+1%%dD%AI<<L##JDOz)sZHI">>//1i	 1!*!2E:!y ##/)3)9)9HU1X& 0Uq##/36*584j6F6F4&uQx0 0 Uq##/-01D1DUA1NPZP`P`-aOE* "3 2" ?Qa)T1#H  NN$D!%%eDk15CS! %
 rzz*<==+,J##--#$3/A+B . K RddQc#
!!((;s3C)DEQcHdHK "**Y//	WWY'
##--3y>I-WT]^T]Sz((//	'#,0GHT]^RZZ))H778$L66(#L
**W*
%CAQ'!!
BqcBh#.=a " I kk)AbD"1"H-.Gkk)CRC2I./G{{9QrT23Y/0H{{9R!V,-HKK	"ab& 12	JQ
+	 LLq''449;L 5 
	 )))2(	  6uZ7K6LANO|e0z11E0FGH##00IG 1 
 )))2$:5Q;O:PPQRSB	99Z!^,)	LLx(9H"5XYLWOOLD	OBuX'5q15q3IJKuX?SW?"M)B7&&(%  ) (J'())<HT] 	 	
 	YGE(J78QlA 6lA8NOP  E(J4O!P4Ob#b'4O!P[] ^))'2!!#.<e'')%  * ~Z02Es#J] e _L @ "Qs   /1_.1_3_8_=)NFTNr   NNNNwhiteNNN)NFTNr   NNNNr$  NN)r   N))r   r   TN)__doc__r   typingr   numpyr   	rustworkxr6   rustworkx.visualizationr   qiskit.exceptionsr   qiskit.utilsr   
_optionalsqiskit.transpiler.couplingr   
exceptionsr	   HAS_MATPLOTLIBrequire_in_callrJ   HAS_GRAPHVIZintr4   r   HAS_SEABORNr#   rK   rI   <module>r5     sC   4     1 ) 0 2 * ** J +JZ **((
 z" #zzDIz tCy/z ) +zzcL **'' ( +rK   