
    z	i                          S r SSKrSSKJrJr  SSKJr   " S S\\5      r " S S\5      r	 " S	 S
5      r
 " S S5      rg)z7Schema and helper models for schema-conformant Results.    N)EnumIntEnum)QiskitErrorc                        \ rS rSrSrSrSrSrg)MeasReturnType   z]meas_return allowed values defined by legacy PulseQobjConfig object but still used by Result.avgsingle N)__name__
__module____qualname____firstlineno____doc__AVERAGESINGLE__static_attributes__r       N/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/result/models.pyr   r      s    gGFr   r   c                   $    \ rS rSrSrSrSrSrSrg)	MeasLevel   z[MeasLevel allowed values defined by legacy PulseQobjConfig object but still used by Result.r         r   N)	r   r   r   r   r   RAWKERNELED
CLASSIFIEDr   r   r   r   r   r      s    e
CHJr   r   c                   @    \ rS rSrSr S	S jrS rS r\S 5       r	Sr
g)
ExperimentResultData$   z)Class representing experiment result dataNc                    / U l         Ub!  U R                   R                  S5        Xl        Ub!  U R                   R                  S5        X l        Ub!  U R                   R                  S5        X0l        Ub!  U R                   R                  S5        X@l        Ub!  U R                   R                  S5        XPl        UR                  5        H,  u  px[        XU5        U R                   R                  U5        M.     g)a  Initialize an ExperimentalResult Data class

Args:
    counts (dict): A dictionary where the keys are the result in
        hexadecimal as string of the format "0xff" and the value
        is the number of counts for that result
    snapshots (dict): A dictionary where the key is the snapshot
        slot and the value is a dictionary of the snapshots for
        that slot.
    memory (list): A list of results per shot if the run had
        memory enabled
    statevector (list or numpy.array): A list or numpy array of the
        statevector result
    unitary (list or numpy.array): A list or numpy array of the
        unitary result
    kwargs (any): additional data key-value pairs.
Ncounts	snapshotsmemorystatevectorunitary)	_data_attributesappendr"   r#   r$   r%   r&   itemssetattr)	selfr"   r#   r$   r%   r&   kwargskeyvalues	            r   __init__ExperimentResultData.__init__'   s    ( !#!!((2 K !!((5&N!!((2 K"!!((7*!!((3"L ,,.JCDu%!!((- )r   c           	          / nU R                    H"  nUR                  U S[        X5       35        M$     SSR                  U5       S3$ )N=zExperimentResultData(, ))r'   r(   getattrjoin)r+   string_listfields      r   __repr__ExperimentResultData.__repr__O   sO    **E%'$*>)?@A +&tyy'=&>a@@r   c                 J    0 nU R                    H  n[        X5      X'   M     U$ )zReturn a dictionary format representation of the ExperimentResultData

Returns:
    dict: The dictionary form of the ExperimentResultData
)r'   r5   )r+   out_dictr8   s      r   to_dictExperimentResultData.to_dictU   s*     **E%d2HO +r   c                 >    [         R                   " U5      nU " S0 UD6$ )ak  Create a new ExperimentResultData object from a dictionary.

Args:
    data (dict): A dictionary representing the ExperimentResultData to
                 create. It will be in the same format as output by
                 :meth:`to_dict`
Returns:
    ExperimentResultData: The ``ExperimentResultData`` object from the
                          input dictionary.
r   )copy)clsdatain_datas      r   	from_dictExperimentResultData.from_dict`   s     ))D/~W~r   )r'   r"   r$   r#   r%   r&   )NNNNN)r   r   r   r   r   r/   r9   r=   classmethodrD   r   r   r   r   r   r   $   s1    3 SW&.PA	  r   r   c                   f    \ rS rSrSr0 r\R                  SSSS4S jrS r	S r
S r\S 5       rS	rg)
ExperimentResultp   a)  Class representing an Experiment Result.

Attributes:
    shots (int or tuple): the starting and ending shot for this data.
    success (bool): if true, we can trust results for this experiment.
    data (ExperimentResultData): results information.
    meas_level (int): Measurement result level.
Nc	                     0 U l         Xl        X l        X0l        X@l        Ub  Xl        Ub  XPl        Ub  X`l        Ub$  U[        [        5      ;  a  [        S5      eXpl        U R                   R                  U	5        g)a  Initialize an ExperimentResult object.

Args:
    shots(int or tuple): if an integer the number of shots or if a
        tuple the starting and ending shot for this data
    success (bool): True if the experiment was successful
    data (ExperimentResultData): The data for the experiment's
        result
    meas_level (int): Measurement result level
    status (str): The status of the experiment
    seed (int): The seed used for simulation (if run on a simulator)
    meas_return (str): The type of measurement returned
    header (dict): A free form dictionary header for the experiment
    kwargs: Arbitrary extra fields

Raises:
    QiskitError: If meas_return or meas_level are not valid values
Nz %s not a valid meas_return value)	_metadatashotssuccessrB   
meas_levelheaderstatusseedlistr   r   meas_returnupdate)
r+   rL   rM   rB   rN   rP   rQ   rS   rO   r,   s
             r   r/   ExperimentResult.__init__|   sw    < 
	$ K KI"$~"66!"DEE*f%r   c                 >   SU R                    SU R                   SU R                   SU R                   3n[	        U S5      (       a  USU R
                   3-  n[	        U S5      (       a  USU R                   3-  n[	        U S	5      (       a  US
U R                   3-  n[	        U S5      (       a  USU R                   3-  nU R                  R                  5        H7  u  p#[        U[        5      (       a  SU S3nO[        U5      nUSU SU 3-  nM9     US-  nU$ )NzExperimentResult(shots=z
, success=z, meas_level=z, data=rO   z	, header=rP   z	, status=rQ   z, seed=rS   z, meas_return='r3   r2   r4   )rL   rM   rN   rB   hasattrrO   rP   rQ   rS   rK   r)   
isinstancestrrepr)r+   outr-   r.   	value_strs        r   r9   ExperimentResult.__repr__   s+   %djj\DLL> J??+7499+? 	 4""Yt{{m,,C4""Yt{{m,,C4  WTYYK((C4''^D$4$4#566C....0JC%%%waL	 K	RuAi[))C 1 	s

r   c                 f     U R                   U   $ ! [         a  n[        SU S35      UeS nAff = f)Nz
Attribute z is not defined)rK   KeyErrorAttributeError)r+   nameexs      r   __getattr__ExperimentResult.__getattr__   s?    	M>>$'' 	M :dV?!CD"L	Ms    
0+0c                    U R                   U R                  U R                  R                  5       U R                  S.n[        U S5      (       a  U R                  US'   [        U S5      (       a  U R                  US'   [        U S5      (       a  U R                  US'   [        U S5      (       a  U R                  US'   UR                  U R                  5        U$ )zReturn a dictionary format representation of the ExperimentResult

Returns:
    dict: The dictionary form of the ExperimentResult
)rL   rM   rB   rN   rO   rP   rQ   rS   )rL   rM   rB   r=   rN   rX   rO   rP   rQ   rS   rT   rK   )r+   r<   s     r   r=   ExperimentResult.to_dict   s     ZZ||II%%'//	
 4""!%HX4""!%HX4  #yyHV4''&*&6&6H]#'r   c                     [         R                   " U5      n[        R                  UR                  S5      5      nUR                  S5      nUR                  S5      nU " XEU40 UD6$ )aX  Create a new ExperimentResult object from a dictionary.

Args:
    data (dict): A dictionary representing the ExperimentResult to
                 create. It will be in the same format as output by
                 :meth:`to_dict`

Returns:
    ExperimentResult: The ``ExperimentResult`` object from the input
                      dictionary.
rB   rL   rM   )r@   r   rD   pop)rA   rB   rC   data_objrL   rM   s         r   rD   ExperimentResult.from_dict   sX     ))D/'11'++f2EFG$++i(587w77r   )	rK   rB   rO   rN   rS   rQ   rL   rP   rM   )r   r   r   r   r   rK   r   r   r/   r9   rd   r=   rF   rD   r   r   r   r   rH   rH   p   sO     I ''-&^,M. 8 8r   rH   )r   r@   enumr   r   qiskit.exceptionsr   rZ   r   r   r   rH   r   r   r   <module>rn      sF    >   )S$  I IXA8 A8r   