
    z	i-                     2    S r SSKrSSKJr   " S S\5      rg)z$Container class for backend options.    N)Mappingc                      ^  \ rS rSrSrSrS rS rS rS r	\
S 5       rS	 rS
 rS rU 4S jrS rU 4S jrS rS rS rS rU 4S jrSrU =r$ )Options   a  Base options object

This class is what all backend options are based
on. The properties of the class are intended to be all dynamically
adjustable so that a user can reconfigure the backend on demand. If a
property is immutable to the user (eg something like number of qubits)
that should be a configuration of the backend class itself instead of the
options.

Instances of this class behave like dictionaries. Accessing an
option with a default value can be done with the `get()` method:

>>> options = Options(opt1=1, opt2=2)
>>> options.get("opt1")
1
>>> options.get("opt3", default="hello")
'hello'

Key-value pairs for all options can be retrieved using the `items()` method:

>>> list(options.items())
[('opt1', 1), ('opt2', 2)]

Options can be updated by name:

>>> options["opt1"] = 3
>>> options.get("opt1")
3

Runtime validators can be registered. See `set_validator`.
Updates through `update_options` and indexing (`__setitem__`) validate
the new value before performing the update and raise `ValueError` if
the new value is invalid.

>>> options.set_validator("opt1", (1, 5))
>>> options["opt1"] = 4
>>> options["opt1"]
4
>>> options["opt1"] = 10  # doctest: +ELLIPSIS
Traceback (most recent call last):
...
ValueError: ...
_fields	validatorc                      U R                   U   $ Nr   )selfkeys     R/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/providers/options.py__getitem__Options.__getitem__i   s    ||C      c                 ,    [        U R                  5      $ r   )iterr   r   s    r   __iter__Options.__iter__l   s    DLL!!r   c                 ,    [        U R                  5      $ r   )lenr   r   s    r   __len__Options.__len__o   s    4<<  r   c                 *    U R                   " S0 X0D6  g )N )update_optionsr   r   values      r   __setitem__Options.__setitem__t   s    +sl+r   c                     U R                   $ r   r   r   s    r   __dict__Options.__dict__y   s    ||r   c                 f     U R                   U   $ ! [         a  n[        SU S35      UeS nAff = f)NzOption z is not defined)r   KeyErrorAttributeError)r   nameexs      r   __getattr__Options.__getattr__   s?    	J<<%% 	J 74&!@ArI	Js    
0+0c                      X R                   U'   g r   r   r   s      r   __setattr__Options.__setattr__   s    !Sr   c                 2    U R                   U R                  4$ r   r   r   s    r   __getstate__Options.__getstate__   s    dnn--r   c                 N   > Uu  p#[         TU ]  SU5        [         TU ]  SU5        g Nr   r	   superr.   )r   stater   r	   	__class__s       r   __setstate__Options.__setstate__   s)    "Iw/K3r   c                     U R                  [        U 5      5      nUR                  U R                  R	                  5       U R
                  R	                  5       45        U$ )zmReturn a copy of the Options.

The returned option and validator values are shallow copies of the originals.
)__new__typer9   r   copyr	   )r   outs     r   __copy__Options.__copy__   sH    
 ll4:&$,,++-t~~/B/B/DEF
r   c                 F   > [         TU ]  SU5        [         TU ]  S0 5        g r4   r5   )r   kwargsr8   s     r   __init__Options.__init__   s!    Iv.K,r   c                     S U R                   R                  5        5       n[        U 5      R                   SSR	                  U5       S3$ )Nc              3   6   #    U  H  u  pU S U< 3v   M     g7f)=Nr   ).0kvs      r   	<genexpr>#Options.__repr__.<locals>.<genexpr>   s     ?*>$!A3au*>s   (z, ))r   itemsr=   __name__join)r   rP   s     r   __repr__Options.__repr__   sA    ?$,,*<*<*>?t*%%&a		%(8'9;;r   c                     [        U [        5      (       a.  [        U[        5      (       a  U R                  UR                  :H  $ [        $ r   )
isinstancer   r   NotImplemented)r   others     r   __eq__Options.__eq__   s4    dG$$E7)C)C<<5==00r   c                 v   XR                   ;  a  [        SU S35      e[        U[        5      (       a  [	        U5      S:w  a  [        S5      eO][        U[        5      (       a  [	        U5      S:X  a  [        S5      eO-[        U[        5      (       a  O[        [        U5       S35      eX R                  U'   g)	a  Set an optional validator for a field in the options

Setting a validator enables changes to an options values to be
validated for correctness when :meth:`~qiskit.providers.Options.update_options`
is called. For example if you have a numeric field like
``shots`` you can specify a bounds tuple that set an upper and lower
bound on the value such as::

    options.set_validator("shots", (1, 4096))

In this case whenever the ``"shots"`` option is updated by the user
it will enforce that the value is >=1 and <=4096. A ``ValueError`` will
be raised if it's outside those bounds. If a validator is already present
for the specified field it will be silently overridden.

Args:
    field (str): The field name to set the validator on
    validator_value (list or tuple or type): The value to use for the
        validator depending on the type indicates on how the value for
        a field is enforced. If a tuple is passed in it must have a
        length of two and will enforce the min and max value
        (inclusive) for an integer or float value option. If it's a
        list it will list the valid values for a field. If it's a
        ``type`` the validator will just enforce the value is of a
        certain type.
Raises:
    KeyError: If field is not present in the options object
    ValueError: If the ``validator_value`` has an invalid value for a
        given type
    TypeError: If ``validator_value`` is not a valid type
zField 'z'' is not present in this options object   zA tuple validator must be of the form '(lower, upper)' where lower and upper are the lower and upper bounds inclusive of the numeric valuer   z-A list validator must have at least one entryzG is not a valid validator type, it must be a tuple, list, or class/typeN)
r   r'   rV   tupler   
ValueErrorlistr=   	TypeErrorr	   )r   fieldvalidator_values      r   set_validatorOptions.set_validator   s    B $WUG+RSTTou--?#q( 5  ) ..?#q( !PQQ )..() *7 7  !0ur   c           
         UR                  5        H  u  p#U R                  R                  US5      n[        U[        5      (       a,  X4S   :  d  X4S   :  a  [        SU SUS    SUS    35      eMb  [        U[        5      (       a  X4;  a  [        SU SU 35      eM  [        U[        5      (       d  M  [        X45      (       a  M  [        SU S	U 35      e   U R                  R                  U5        g)
zUpdate options with kwargsN   r   zSpecified value for 'z"' is not a valid value, must be >=z or <=zSpecified value for z' is not a valid choice, must be one of z is not of required type )rP   r	   getrV   r]   r^   r_   r=   r`   r   update)r   fields
field_namera   field_validators        r   r   Options.update_options   s   !'J"nn00TBO/5111--9K1K$/
| <%%4Q%7$8q?Q>RT  2L
 OT22/$.zl ;**9):<  0
 OT22!%99#.zl:STcSde ! "0( 	F#r   c           
      F  > [         TU ]  5       nU R                  (       d  U$ [        R                  " 5       nUR                  U5        UR                  S5        U R                  R                  5        H  u  p4[        U[        5      (       a#  UR                  SU SUS    SUS    S35        M=  [        U[        5      (       a  UR                  SU SU S35        Ml  [        U[        5      (       d  M  UR                  SU S	U S35        M     UR                  5       $ )
Nz
Where:
	z is >= r   z and <= rf   
z is one of z is of type )r6   __str__r	   ioStringIOwriterP   rV   r]   r_   r=   getvalue)r   no_validatorout_strra   r    r8   s        r   rp   Options.__str__  s    w(~~kkmGMM,'MM,' $ 4 4 6eU++MMBugWU1XJhuQxjPR"STt,,MMBug[r"BCt,,MMBug\%"CD !7 ##%%r   r   )rQ   
__module____qualname____firstlineno____doc__	__slots__r   r   r   r!   propertyr$   r+   r.   r1   r9   r@   rD   rS   rY   rc   r   rp   __static_attributes____classcell__)r8   s   @r   r   r      sv    *b )I!"!
,
  
	J"
.4
-<
40l$0& &r   r   )r{   rq   collections.abcr   r   r   r   r   <module>r      s    + 	 #~&g ~&r   