
    i%                     l    S r SSKJrJrJr  SSKJrJr  SSKJ	r	J
r
JrJr  \S   r\ " S S5      5       rg	)
z-Zero noise extrapolation mitigation options..    )UnionSequenceLiteral)field_validatormodel_validator   )Unset	UnsetTypeprimitive_dataclassskip_unset_validation)linearexponentialdouble_exponentialpolynomial_degree_1polynomial_degree_2polynomial_degree_3polynomial_degree_4polynomial_degree_5polynomial_degree_6polynomial_degree_7fallbackc                   2   \ rS rSr% Sr\r\\\	S   4   \
S'    \r\\\\   4   \
S'    \r\\\\\   4   \
S'    \r\\\\   4   \
S'    S\\   4S	 jr\S\\   4S
 j5       r\" S5      \\S\\   S\\   4S j5       5       5       r\" SS9SS j5       rSrg)
ZneOptions$   a  Zero noise extrapolation mitigation options. This is only used by the V2 Estimator.

.. note::

    Any V2 estimator is guaranteed to return data fields called ``evs`` and ``stds`` that
    report the desired expectation value estimates and errors, respectively.
    When ZNE options are enabled in the runtime estimator, additional data is returned.

    In particular, suppose an input pub has observable array shape ``obs_shape`` and parameter
    values shape ``par_shape``, with corresponding pub shape
    ``shape=np.broadcast_shapes(obs_shape, par_shape)``. Then the corresponding pub result will
    additionally contain:

    1. `pub_result.data.evs_extrapolated` and `pub_result.data.stds_extrapolated`,
        both with shape ``(*shape, num_extrapolators, num_evaluation_points)``, where
        ``num_extrapolators`` is the length of the list of
        ``options.resilience.zne.extrapolators``, and ``num_evaluation_points`` is the length of
        the list ``options.resilience.extrapolated_noise_factors``. These values provide
        evaluations of every extrapolator at every specified noise extrapolation value.
    2. ``pub_result.data.evs_noise_factors``, ``pub_result.data.stds_noise_factors``, and
       ``ensemble_stds_noise_factors`` all have shape ``(*shape, num_noise_factors)`` where
       ``num_noise_factors`` is the length of ``options.resilience.zne.noise_factors``. These
       values provide raw expectation values, averaged over twirling if applicable,
       at each of the noise amplifications; you can base your own fitting routines off of these
       values. In the case of no twirling, both ``*stds*`` arrays will be equal, otherwise,
       ``stds_noise_factors`` is derived from the spread over twirling samples, whereas
       ``ensemble_stds_noise_factors`` assumes only shot noise and no drift.

    Technical note: for single observables with multiple basis terms it might turn out that
    multiple extrapolation methods are used in *the same* expectation value, for example, ``XX``
    gets linearly extrapolated but ``XY`` gets exponentially extrapolated in the observable
    ``{"XX": 0.5, "XY": 0.5}``. Let's call this a *heterogeneous fit*. The data from (2) is
    evaluated from heterogeneous fits by selecting the best fit for every individual distinct
    term, whereas data from (1) is evaluated from forced homogenous fits, one for each provided
    extrapolator. If your work requires a nuanced distinction in this regard, we presently
    recommend that you use single-term observables in addition to your multi-term observables.

References:
    1. Z. Cai, *Multi-exponential error extrapolation and combining error mitigation techniques
       for NISQ applications*,
       `npj Quantum Inf 7, 80 (2021) <https://www.nature.com/articles/s41534-021-00404-3>`_
)gate_foldinggate_folding_frontgate_folding_backpea	amplifiernoise_factorsextrapolatorextrapolated_noise_factorsreturnc                 *    U R                   S:X  a  S$ S$ )Nr   )r   g      ?   g      @   )r   r&      )r   )selfs    `/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/options/zne_options.py_default_noise_factors!ZneOptions._default_noise_factors   s    &*nn&="L9L    c                     g)N)r   r    )clss    r)   _default_extrapolator ZneOptions._default_extrapolator   s    (r,   factorsc                 J    [        S U 5       5      (       a  [        S5      eU$ )zValidate noise_factors.c              3   *   #    U  H	  oS :  v   M     g7f)r   Nr.   ).0is     r)   	<genexpr>9ZneOptions._validate_zne_noise_factors.<locals>.<genexpr>   s     &g1ugs   z,noise_factors` option value must all be >= 1)any
ValueError)r/   r2   s     r)   _validate_zne_noise_factors&ZneOptions._validate_zne_noise_factors   s&    
 &g&&&KLLr,   after)modec                    U R                   [        :w  a  U R                   OU R                  5       nU R                  [        :w  a  U R                  OU R	                  5       nSSSSS.n[        SS5       H  nUS-   USU 3'   M     [        U[        5      (       a  U/OUnU H'  n[        U5      X6   :  d  M  [        U SX6    S35      e   U $ )	z@Check that there are enough noise factors for all extrapolators.r%      r   )r   r   r   r      polynomial_degree_z requires at least z noise_factors)
r    r	   r*   r!   r0   range
isinstancestrlenr:   )r(   r    r!   required_factorsidxextrapolatorsextraps          r)   _validate_optionsZneOptions._validate_options   s     #'"4"4"=D4C^C^C` 	 "&!2!2e!;DA[A[A] 	
 "#	
 A;C;>71#78 
 ,,, N 	
 $F=!$4$<< h12B2J1K>Z  $
 r,   r.   N)r#   r   )__name__
__module____qualname____firstlineno____doc__r	   r   r   r
   r   __annotations__r    r   floatr!   ExtrapolatorTyper"   r*   classmethodr0   r   r   r;   r   rK   __static_attributes__r.   r,   r)   r   r   $   s#   )Z 	 u7[\\ . 8=M5HUO34< TYL%	#3X>N5OOPX* EJi%&@ AIM M )h/?&@ ) ) _%(5/ huo    & '" #r,   r   N)rQ   typingr   r   r   pydanticr   r   utilsr	   r
   r   r   rT   r   r.   r,   r)   <module>rZ      sE    4 + + 5 O O
  W W Wr,   