
    z	i5                         S r SSKrSSK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   " S	 S
\5      r " S S5      r SS\\\S4   S\\   S\S\S\S\S\\\4   4S jjrg)z&
Generic style visualization library.
    N)AnyUnion)warn)Path)user_config   )VisualizationErrorc                      ^  \ rS rSrSr\" 5       r0 r\" 5       rS\	S\	SS4U 4S jjr
S\	S\	4U 4S jjrU 4S	 jrS
rU =r$ )	StyleDict   aR  
Attributes:
    VALID_FIELDS (set): Set of valid field inputs to a function that supports a style parameter
    ABBREVIATIONS (dict): Mapping of abbreviation:field for abbreviated inputs to VALID_FIELDS
        (must exist in VALID FIELDS)
    NESTED_ATTRS (set): Set of fields that are dictionaries, and need to be updated with .update
keyvaluereturnNc                    > XR                   ;   a  U R                   U   nXR                  ;  a  [        SU S3[        S5        [        TU ]  X5      $ )Nzstyle option (z) is not supported   )ABBREVIATIONSVALID_FIELDSr   UserWarningsuper__setitem__)selfr   r   	__class__s      T/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/visualization/style.pyr   StyleDict.__setitem__)   sX    $$$$$S)C''' %78
 w"3..    c                 ^   > XR                   ;   a  U R                   U   n[        TU ]	  U5      $ N)r   r   __getitem__)r   r   r   s     r   r   StyleDict.__getitem__6   s/    $$$$$S)Cw"3''r   c                   >^  T R                   R                  UR                  5       5       H6  nUT R                  5       ;   a  T U   R                  X   5        M/  X   T U'   M8     [        TT ]  U 4S jUR                  5        5       5        g )Nc              3   R   >#    U  H  u  pUTR                   ;  d  M  X4v   M     g 7fr   )NESTED_ATTRS).0r   r   r   s      r   	<genexpr>#StyleDict.update.<locals>.<genexpr>F   s%     dm
sRVRcRcGc||ms   '
')r"   intersectionkeysupdater   items)r   otherattrr   s   `  r   r(   StyleDict.update=   sn     %%225::<@Dtyy{"T
!!%+."[T
	 A 	dekkmddr    )__name__
__module____qualname____firstlineno____doc__setr   r   r"   r   r   r   r(   __static_attributes____classcell__)r   s   @r   r   r      sV     5LM5L/s /3 /4 /(s (s (	e 	er   r   c                   &    \ rS rSrSrSrSrS rSrg)DefaultStyleI   z
Attributes:
    DEFAULT_STYLE_NAME (str): style name for the default style
    STYLE_PATH: file path where DEFAULT_STYLE_NAME.json is located
Nc                     [        5       er   )NotImplementedError)r   s    r   __init__DefaultStyle.__init__S   s    !##r   r-   )	r.   r/   r0   r1   r2   DEFAULT_STYLE_NAMEDEFAULT_STYLE_PATHr;   r4   r-   r   r   r7   r7   I   s     $r   r7   style
style_dictdefault_styleuser_config_optuser_config_path_optraise_error_if_not_foundr   c                    UR                   n[        R                  " 5       nU c  U(       a  UR                  X65      n OUn [	        U [
        5      (       a  U R                  SU5      nOW[	        U [        5      (       a  U R                  S5      (       a  U SS nO&U nO#[        SU  S[        U 5       S3[        S5        UnX4;   a  UR                  n	GOTUS-   n/ n
UR                  U-  nU
R                  U5        U(       a?  UR                  US	5      nU(       a&  U H   nU
R                  [        U5      U-  5        M"     [        S	5      U-  nU
R                  U5        U
 Hl  nUR                  5       n[         R"                  R%                  U5      (       d  M9   ['        U5       n[(        R*                  " U5      nSSS5        U" W5      n	  OX   U(       a  [3        SU 35      e[        SU SSR5                  [7        [        U
5      5       S3[        S5        UR                  n	[	        U [
        5      (       a  W	R9                  U 5        SnW	U4$ ! , (       d  f       N= f! [(        R,                   a-  n[        S
U S[        U5       S3[        S5         SnA  My  SnAf[.        [0        4 a    [        SU S3[        S5           M  f = f)a  Utility function to load style from json files.

Args:
    style: Depending on the type, this acts differently:

        * If a string, it can specify a supported style name (such
          as "iqp" or "clifford"). It can also specify the name of
          a custom color scheme stored as JSON file. This JSON file
          _must_ specify a complete set of colors.
        * If a dictionary, it may specify the style name via a
          ``{"name": "<desired style>"}`` entry. If this is not given,
          the default style will be used. The remaining entries in the
          dictionary can be used to override certain specs.
          E.g. ``{"name": "iqp", "ec": "#FF0000"}`` will use the ``"iqp"``
          color scheme but set the edgecolor to red.
    style_dict: The class used to define the options for loading styles
    default_style: DefaultStyle dictionary definition and documentation
    user_config_opt: User config field in the Qiskit User Configuration File
        used to define the style loaded
    user_config_path_opt: User config field in the Qiskit User Configuration File
        used to define the path to the style loaded
    raise_error_if_not_found: When True, load_style will throw a VisualizationError
        if the style parameter file is not found. When False, load_style will load
        the style passed in by the default_style parameter.


Returns:
    A tuple containing the style as dictionary and the default font ratio.
Nnamez.jsonzUnsupported style parameter "z
" of type z. Will use the default style.r    zCould not decode JSON in file 'z': z. Will use default style.zError loading JSON file 'z'. Will use default style.zInvalid style zStyle JSON file 'z'' not found in any of these locations: z, g      ?)r=   r   
get_configget
isinstancedictstrendswithr   typer   r?   r>   appendr   
expanduserospathisfileopenjsonloadJSONDecodeErrorOSErrorFileNotFoundErrorr	   joinmapr(   )r?   r@   rA   rB   rC   rD   defaultconfig
style_namecurrent_stylestyle_pathsdefault_pathconfig_pathrS   cwd_pathexp_userinfile
json_styleerrdef_font_ratios                       r   
load_stylerj   W   s   L ..G ##%F}JJ8EE %YYvw/
	E3		>>'""sJJ+E7*T%[M J* *		
 
Y%++  ')
$77*D<(  **%92>K'D&&tDzJ'>? ( 8j(8$D(Hww~~h''h6%)YYv%6
 ( %/z$:M  4 ((>*)FGG#J</V99Sk234 5**  *//M
 %U# N.((W (
 ++ 9$s3s8* M2 2#	 !23 3D69ST#
 s6   I$&I=I$
I!	I$$K8!J  (KK)F)r2   rV   rR   typingr   r   warningsr   pathlibr   qiskitr   
exceptionsr	   rL   r   r7   rM   rO   booltuplefloatrj   r-   r   r   <module>rs      s     	     **e *eZ$ $( &+H)sD!H)YH)  H) 	H)
 H) #H) 9eH)r   