
    ij#                       S r SSKJr  SSKJrJrJrJrJ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JrJr  SSKJr  SS	KJr  S
SKJr  \(       a  S
SKJr            SS jrSS jrSS jrS r S      S!S jjr  S      S!S jjr!S"S jr" " S S5      r# " S S5      r$\$" 5       r%\" \" SSSS9S9r&SSSSS.           S#S jjr'g)$zUtility functions for options.    )annotations)OptionalUnionCallableTYPE_CHECKINGAnyN)is_dataclassasdict)Real)
ConfigDictValidationInfofield_validator)	dataclass)Backend   )is_simulator)BaseOptionsc                B   [        U5      nU R                  S5      c7  U(       a,  U R                  S0 5      R                  S5      (       d  SU S'   OX S'   U R                  S5      c8  U(       a-  U R                  S0 5      R                  S5      (       d  SU S'   U $ X0S'   U $ )ag  Set default resilience and optimization levels.

Args:
    options: user passed in options.
    backend: backend the job will run on.
    default_optimization_level: the default optimization level from the options class
    default_resilience_level: the default resilience level from the options class

Returns:
    options with correct error level defaults.
optimization_level	simulatornoise_model   resilience_levelr   )r   get)optionsbackenddefault_optimization_leveldefault_resilience_levelis_sims        Z/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/options/utils.pyset_default_error_levelsr!   "   s    " '"F{{'(0'++k26::=II,-G(),F(){{%&.'++k26::=II*+G&' N +C&'N    c                    [        U R                  5       5       H@  u  p[        U[        5      (       a  X	 M  [        U[        5      (       d  M5  [        U5        MB     g)zRemove Unset values.N)listitems
isinstance	UnsetTypedictremove_dict_unset_valuesin_dictkeyvals      r    r)   r)   C   s@    )c9%%T""$S)	 *r"   c                    [        U R                  5       5       H9  u  p[        U[        5      (       d  M  U(       a  [	        U5        U(       a  M7  X	 M;     g)zRemove empty dictionaries.N)r$   r%   r&   r(   remove_empty_dictr*   s      r    r/   r/   L   s;    )c4  !#&3L *r"   c                    Uc  U " 5       $ [        X5      (       a  U$ [        U[        5      (       a  U " S0 UD6$ [        U S[        U5       SU  S35      e)Nz has an unspported type z. It can only be z or a dictionary. )r&   r(   	TypeErrortype)cls_datas     r    _to_objr6   V   sa    |v$$|d|
&(d4EdVK\] r"   c                2  ^ SSU4S jjjm[        U 5      (       a  [        U 5      nO7[        U [        5      (       a  [        R
                  " U 5      nO[        S5      eU(       d  U$ [        R
                  " U5      nT" X#5        UR                  U5        U$ )zMerge current options with the new ones.

Args:
    new_options: New options to merge.

Returns:
    Merged dictionary.

Raises:
    TypeError: if input type is invalid.
c                  > U(       d  U(       d  g U=(       d    0 nU R                  5        H  u  p4[        U[        5      (       a  UR                  U0 5      nT" XAU5        M7  X1R	                  5       ;   a  UR                  U5      X'   M_  X2R	                  5       ;   d  Mt  UR                  U5      X'   M     UR                  5        H	  u  p4X@U'   M     UR                  5         g N)r%   r&   r(   popkeysclear)oldnewmatchedr,   r-   new_matched_update_optionss         r    rA   &merge_options.<locals>._update_optionsq   s    7-R		HC#t$$!ggc2.+6
"773<&";;s+ $  HCH ( 	r"   4'old_options' can only be a dictionary or dataclass.r9   )r=   r(   r>   r(   r?   Optional[dict]returnNone)r	   r
   r&   r(   copydeepcopyr2   updateold_optionsnew_optionscombinednew_options_copyrA   s       @r    merge_optionsrO   b   s     * K  +&	K	&	&==-NOO}}[1 H/ OO$%Or"   c                  ^ SU4S jjm[        U 5      (       a  [        U 5      nO7[        U [        5      (       a  [        R
                  " U 5      nO[        S5      eU(       d  U$ [        R
                  " U5      nT" X#5        U$ )aL  Merge current options with the new ones for V2 primitives.

Unlike ``merge_options``, this function does not attempt to
merge values of the same keys from different nesting levels.

For example, if
``old_options`` is ``{"nested_foo": {"foo": "bar1"}}`` and
``new_options`` is ``{"foo": "bar2"}``, then
``merge_options()`` would return {'nested_foo': {'foo': 'bar2'}}
but ``merge_options_v2()`` would return ``{'nested_foo': {'foo': 'bar1'}, 'foo': 'bar2'}``.

Args:
    new_options: New options to merge.

Returns:
    Merged dictionary.

Raises:
    TypeError: if input type is invalid.
c                Z  > U(       d  g U R                  5        H[  u  p#X!R                  5       ;   d  M  [        U[        5      (       a  T" X1R	                  U5      5        MH  UR	                  U5      X'   M]     [        UR                  5       5       H  nUR	                  U5      X'   M     g r9   )r%   r;   r&   r(   r:   r$   )r=   r>   r,   r-   rA   s       r    rA   )merge_options_v2.<locals>._update_options   s{     		HChhj c4((#C6"wws|CH $ 
#Cwws|CH $r"   rC   )r=   r(   r>   r(   rE   rF   )r	   r
   r&   r(   rG   rH   r2   rJ   s       @r    merge_options_v2rS      sj    0$  K  +&	K	&	&==-NOO}}[1H/Or"   c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )z"Decorator used to skip unset valuec                J   > [        U[        5      (       a  U$ T" X/UQ70 UD6$ r9   )r&   r'   )clsr-   argskwargsfuncs       r    wrapper&skip_unset_validation.<locals>.wrapper   s*    c9%%JC.t.v..r"   )
rV   r   r-   r   rW   r   rX   r   rE   r   )	functoolswraps)rY   rZ   s   ` r    skip_unset_validationr^      s'     __T/ /
 Nr"   c                      \ rS rSrSrSrg)Dict   zFake Dict type.

This class is used to show dictionary as an acceptable type in docs without
attaching all the dictionary attributes in Jupyter's auto-complete.
r1   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r1   r"   r    r`   r`      s     	r"   r`   c                  D   ^  \ rS rSrSrSS jrSU 4S jjrS	S jrSrU =r	$ )
r'      z'Class used to represent an unset field.c                    g)NUnsetr1   selfs    r    __repr__UnsetType.__repr__   s    r"   c                f   > [        U S5      (       d  [        TU ]	  U 5      U l        U R                  $ )N	_instance)hasattrsuper__new__rq   )rV   	__class__s    r    rt   UnsetType.__new__   s*    sK((!GOC0CM}}r"   c                    g)NFr1   rl   s    r    __bool__UnsetType.__bool__   s    r"   r1   )rE   str)rE   z'UnsetType')rE   bool)
rb   rc   rd   re   rf   rn   rt   rx   rg   __classcell__)ru   s   @r    r'   r'      s    1
 r"   r'   Tforbid)validate_assignmentarbitrary_types_allowedextra)config)gegtleltc                d   ^ ^^^ [        USS06[        [        SU UUU4S jj5       5       5       nU$ )a=  Make a field validator that performs the give constraint if the value is numeric.
This differs to the one built-in to ``pydantic.Field`` in that it ignores non-Real types,
which lets us apply this to fields with annotations like ``int | Literal["auto"]``.
Args:
    field_names: The field names to check.
    ge: A number the value must be greater than or equal to.
    gt: A number the value must be strictly greater than.
    le: A number the value must be less than or equal to.
    lt: A number the value must be strictly less than.
Returns:
    A new field validator.
modebeforec           
       > [        U[        5      (       a  Tb1  UT:  a+  [        U R                   SUR                   ST SU S35      eTb1  UT::  a+  [        U R                   SUR                   ST SU S35      eTb1  UT:  a+  [        U R                   SUR                   ST SU S35      eTb1  UT:  a+  [        U R                   SUR                   ST SU S35      eU$ )N.z must be >=z, but is ==z
 must be >z must be <=z
 must be <)r&   r   
ValueErrorrb   
field_name)rV   valuevalidation_infor   r   r   r   s      r    	validator,make_constraint_validator.<locals>.validator  s)    eT""~52: ||nAo&@&@%ARDP[\a[bbcd  ~5B; ||nAo&@&@%AB4{[`Zaabc  ~52: ||nAo&@&@%ARDP[\a[bbcd  ~5B; ||nAo&@&@%AB4{[`Zaabc  r"   )rV   r   r   r   r   r   rE   r   )r   classmethodr^   )r   r   r   r   field_namesr   s   ````  r    make_constraint_validatorr      s>    ( k11    2( r"   )
r   r(   r   r   r   intr   r   rE   r(   )r+   r(   rE   rF   r9   )rK   zUnion[dict, 'BaseOptions']rL   rD   rE   r(   )rY   r   rE   r   )r   rz   r   Real | Noner   r   r   r   r   r   rE   r   )(rf   
__future__r   typingr   r   r   r   r   r\   rG   dataclassesr	   r
   numbersr   pydanticr   r   r   pydantic.dataclassesr   qiskit.providers.backendr   utils.utilsr   options.optionsr   r!   r)   r/   r6   rO   rS   r^   r`   r'   rk   primitive_dataclassr   r1   r"   r    <module>r      sH   % " @ @   ,  @ @ * , &- !$ "	
 
B*!	 LP5+5:H5	5r LP5+5:H5	5p		 	  	  $T\]  +++ 	+ 		+
 	+ +r"   