
    z	i;                     x    S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
Jr  SSKJr  SSKJr   " S	 S
5      rg)z$Model for schema-conformant Results.    N)QuantumCircuit)QiskitError)statevector)ExperimentResult	MeasLevel)postprocess)Countsc            	           \ rS rSrSr0 rSSSSSSSSS.S jrS rS rS r	\
S	 5       rSS
 jrSS jrSS jrSS jrSS jrSS jrSrg)Result   a  Model for Results.

Attributes:
    backend_name (str): backend name.
    backend_version (str): backend version, in the form X.Y.Z.
    job_id (str): unique execution id from the backend.
    success (bool): True if complete input executed correctly. (Implies
        each experiment success)
    results (list[ExperimentResult]): corresponding results for array of
        experiments of the input
    date (str): optional date field
    status (str): optional status field
    header (dict): an optional free form dictionary header
N)backend_namebackend_versionjob_idsuccessresultsdatestatusheaderc                    0 U l         Xl        X l        X0l        X@l        XPl        X`l        Xpl        Xl        U R                   R                  U	5        g N)
	_metadatar   r   r   r   r   r   r   r   update)
selfr   r   r   r   r   r   r   r   kwargss
             N/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/result/result.py__init__Result.__init__,   sG     (.	f%    c           
         SU R                    SU R                   SU R                   SU R                   SU R                   3
nUSU R
                   SU R                   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Result(backend_name='z', backend_version='z', job_id='z', success=z
, results=z, date=z	, status=z	, header=', =))r   r   r   r   r   r   r   r   r   items
isinstancestrrepr)r   outkeyvalue	value_strs        r   __repr__Result.__repr__D   s    #D$5$5#66J4K_K_J` a}K~ >~' 	
 	9T[[M4;;-PP....0JC%%%waL	 K	RuAi[))C 1 	s

r   c                 8   U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                   Vs/ s H  oR                  5       PM     snS.nUR                  U R                  5        U$ s  snf )znReturn a dictionary format representation of the Result

Returns:
    dict: The dictionary form of the Result
)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   to_dictr   r   )r   xout_dicts      r   r/   Result.to_dictT   sv     !--#33IIkkkkkk||-1\\:\		\:	
 	' ;s   B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)r   KeyErrorAttributeError)r   nameexs      r   __getattr__Result.__getattr__g   s?    	M>>$'' 	M :dV?!CD"L	Ms    
0+0c                     [         R                   " U5      nUR                  S5       Vs/ s H  n[        R                  " U5      PM     snUS'   U " S0 UD6$ s  snf )a)  Create a new ExperimentResultData object from a dictionary.

Args:
    data (dict): A dictionary representing the Result to create. It
                 will be in the same format as output by
                 :meth:`to_dict`.
Returns:
    Result: The ``Result`` object from the input dictionary.

r    )copypopr   	from_dict)clsdatain_datar0   s       r   r>   Result.from_dictm   sT     ))D/EL[[QZE[\E[.88;E[\	~W~ ]s    Ac                      U R                  U5      R                  R                  5       $ ! [        [        4 a  n[        S[        U5       S35      UeSnAff = f)aK  Get the raw data for an experiment.

Note this data will be a single classical and quantum register and in a
format required by the results schema. We recommend that most users use
the get_xxx method, and the data will be post-processed for the data type.

Args:
    experiment (str or QuantumCircuit or int or None): the index of the
        experiment. Several types are accepted for convenience::
        * str: the name of the experiment.
        * QuantumCircuit: the name of the circuit instance will be used.
        * int: the position of the experiment.
        * None: if there is only one experiment, returns it.

Returns:
    dict: A dictionary of results data for an experiment. The data
    depends on the backend it ran on and the settings of `meas_level`,
    `meas_return` and `memory`.

    OpenQASM backends return a dictionary of dictionary with the key
    'counts' and  with the counts, with the second dictionary keys
    containing a string in hex format (``0x123``) and values equal to
    the number of times this outcome was measured.

    Statevector backends return a dictionary with key 'statevector' and
    values being a list[list[complex components]] list of 2^num_qubits
    complex amplitudes. Where each complex number is represented as a 2
    entry list for each component. For example, a list of
    [0.5+1j, 0-1j] would be represented as [[0.5, 1], [0, -1]].

    Unitary backends return a dictionary with key 'unitary' and values
    being a list[list[list[complex components]]] list of
    2^num_qubits x 2^num_qubits complex amplitudes in a two entry list for
    each component. For example if the amplitude is
    [[0.5+0j, 0-1j], ...] the value returned will be
    [[[0.5, 0], [0, -1]], ...].

    The simulator backends also have an optional key 'snapshots' which
    returns a dict of snapshots specified by the simulator backend.
    The value is of the form dict[slot: dict[str: array]]
    where the keys are the requested snapshot slots, and the values are
    a dictionary of the snapshots.

Raises:
    QiskitError: if data for the experiment could not be retrieved.
zNo data for experiment ""N)_get_experimentr@   r/   r4   	TypeErrorr   r'   )r   
experimentr7   s      r   r@   Result.data~   s^    ^	V''
388@@BB)$ 	V 8j9I8J!LMSUU	Vs   (+ AAAc                     U R                  U5      n  UR                  nUR                  nU R                  U5      S   nU[        R                  :X  a  [        R                  " XS5      $ U[        R                  :X  a  [        R                  " U5      $ U[        R                  :X  a  [        R                  " U5      $ [        SU S35      e! [        [        4 a    Sn Nf = f! [         a  n[        S[        U5       S35      UeSnAff = f)a"  Get the sequence of memory states (readouts) for each shot
The data from the experiment is a list of format
['00000', '01000', '10100', '10100', '11101', '11100', '00101', ..., '01010']

Args:
    experiment (str or QuantumCircuit or int or None): the index of the
        experiment, as specified by ``data()``.

Returns:
    List[str] or np.ndarray: Either the list of each outcome, formatted according to
    registers in circuit or a complex numpy np.ndarray with shape:

        ============  =============  =====
        `meas_level`  `meas_return`  shape
        ============  =============  =====
        0             `single`       np.ndarray[shots, memory_slots, memory_slot_size]
        0             `avg`          np.ndarray[memory_slots, memory_slot_size]
        1             `single`       np.ndarray[shots, memory_slots]
        1             `avg`          np.ndarray[memory_slots]
        2             `memory=True`  list
        ============  =============  =====

Raises:
    QiskitError: if there is no memory data for the circuit.
NmemoryzMeasurement level z is not supportedzNo memory for experiment "z". Please verify that you either ran a measurement level 2 job with the memory flag set, eg., "memory=True", or a measurement level 0/1 job.)rE   r   r5   r   
meas_levelr@   r   
CLASSIFIEDr   format_level_2_memoryKERNELEDformat_level_1_memoryRAWformat_level_0_memoryr4   r'   )r   rG   
exp_resultr   rK   rJ   r7   s          r   
get_memoryResult.get_memory   s   4 ))*5
	#** $..JYYz*84FY111"88HHy111"88@@y}},"88@@!$6zlBS"TUU #K0    	,T*-=,> ?2 2
 	sG   C A	C% *)C% )C% >C% C"C% !C""C% %
D/DDc                 F   Uc  [        [        U R                  5      5      nOU/n/ nU GH?  nU R                  U5      n UR                  nSU R                  U5      R                  5       ;   ae  U(       a-  UR                  5        VVs0 s H  u  pxUS;   d  M  Xx_M     n	nnO0 n	UR                  [        U R                  U5      S   40 U	D65        M  SU R                  U5      R                  5       ;   a]  [        R                  " U R                  U5      S   5      n
UR                  [        R                  " U
5      R!                  SS95        GM*  [        S[#        U5       S35      e   [        U5      S	:X  a  US
   $ U$ ! [
        [        4 a    Sn GNMf = fs  snnf )aK  Get the histogram data of an experiment.

Args:
    experiment (str or QuantumCircuit or int or None): the index of the
        experiment, as specified by ``data([experiment])``.

Returns:
    dict[str, int] or list[dict[str, int]]: a dictionary or a list of
    dictionaries. A dictionary has the counts for each qubit with
    the keys containing a string in binary format and separated
    according to the registers in circuit (e.g. ``0100 1110``).
    The string is little-endian (cr[0] on the right hand side).

Raises:
    QiskitError: if there are no counts for the experiment.
Ncounts>   
creg_sizes
time_takenmemory_slotsr      decimalszNo counts for experiment "rD      r   )rangelenr   rE   r   r5   r   r@   keysr$   appendr	   r   format_statevectorr   Statevectorprobabilities_dictr'   )r   rG   exp_keys	dict_listr)   expr   kvcounts_headervecs              r   
get_countsResult.get_counts   s   " S./H"|H	C&&s+C 499S>..00 %+LLN%$2DA LL $2 " %M %'M  		#x(@!RM!RS$))C."5"5"77!44TYYs^M5RS  !8!8!=!P!PZ\!P!]^!$>tCyk"KLL+ 0 y>QQ</ #K0 
%s    F	FFFFc                      [         R                  " U R                  U5      S   US9$ ! [         a  n[	        S[        U5       S35      UeSnAff = f)a  Get the final statevector of an experiment.

Args:
    experiment (str or QuantumCircuit or int or None): the index of the
        experiment, as specified by ``data()``.
    decimals (int): the number of decimals in the statevector.
        If None, does not round.

Returns:
    list[complex]: list of 2^num_qubits complex amplitudes.

Raises:
    QiskitError: if there is no statevector for the experiment.
r   r[   zNo statevector for experiment "rD   N)r   rb   r@   r4   r   r'   r   rG   r\   r7   s       r   get_statevectorResult.get_statevector  sa    	]11		*%m4x   	] ?Z@P?QQRSTZ\\	]   &) 
AAAc                      [         R                  " U R                  U5      S   US9$ ! [         a  n[	        S[        U5       S35      UeSnAff = f)a  Get the final unitary of an experiment.

Args:
    experiment (str or QuantumCircuit or int or None): the index of the
        experiment, as specified by ``data()``.
    decimals (int): the number of decimals in the unitary.
        If None, does not round.

Returns:
    list[list[complex]]: list of 2^num_qubits x 2^num_qubits complex
        amplitudes.

Raises:
    QiskitError: if there is no unitary for the experiment.
unitaryr[   zNo unitary for experiment "rD   N)r   format_unitaryr@   r4   r   r'   ro   s       r   get_unitaryResult.get_unitary2  sZ     	Y--dii
.CI.NYabb 	Y ;D<L;MQOPVXX	Yrr   c                    Uc&  [        U R                  5      S:w  a  [        S5      eSn[        U[        5      (       a  UR
                  n[        U[        5      (       a   U R                  U   nOU R                   Vs/ s H7  n[        USS5      c  M  [        US5      R                  SS	5      U:X  d  M5  UPM9     nn[        U5      S:X  a  [        S
U S35      e[        U5      S:X  a  US   nO[        R                  " SU S35        US   n[        USS5      (       a  U$ [        U SS5      n[        USS5      n[        USU5      e! [         a  n[        SU S35      UeSnAff = fs  snf )am  Return a single experiment result from a given key.

Args:
    key (str or QuantumCircuit or int or None): the index of the
        experiment, as specified by ``data()``.

Returns:
    ExperimentResult: the results for an experiment.

Raises:
    QiskitError: if there is no data for the experiment, or an unhandled
        error occurred while fetching the data.
Nr]   zNYou have to select a circuit or schedule when there is more than one availabler   zResult for experiment "z" could not be found.r   r6    zData for experiment "z8Result object contained multiple results matching name "z_", only first match will be returned. Use an integer index to retrieve results for all entries.r   Fr   zResult was not successfulzExperiment was not successfulr!   )r_   r   r   r%   r   r6   int
IndexErrorgetattrgetwarningswarn)r   r)   rg   r7   resultresult_status
exp_statuss          r   rE   Result._get_experimentG  s    ;4<< A%!d  C c>**((Cc3`ll3' #ll*F68T2  FH-11&"=D *   3x1}!$9#>S"TUU3x1}!fNse T8 8
 !f 3	5))Jh0KLS(,KL
-z::;  `!$;C5@U"VW]__`s*   !E ?E.E.7E.
E+E&&E+)	r   r   r   r   r   r   r   r   r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   r   r,   r/   r8   classmethodr>   r@   rS   rl   rp   rv   rE   __static_attributes__r;   r   r   r   r      su     I
 &0 &M   2Vh4l2h],Y*:;r   r   )r   r<   r~   qiskit.circuit.quantumcircuitr   qiskit.exceptionsr   qiskit.quantum_info.statesr   qiskit.result.modelsr   r   qiskit.resultr   qiskit.result.countsr	   r   r;   r   r   <module>r      s.    +   8 ) 2 < % 'g; g;r   