
    z	i                    2    S r SSKJr  SSKrSSKJr  SS jrg)z=A collection of useful functions for post processing results.    )annotationsN   )make_dict_observablec                    [        U[        5      (       d  [        U5      nSn[        U R	                  5       5      nU  H  nXA;   d  M
  X U   X   -  U-  -  nM     U$ )aw  Compute the mean value of an diagonal observable.

Takes in a diagonal observable in dictionary, list or matrix format and then
calculates the sum_i value(i) P(i) where value(i) is the value of the
observable for state i.

Args:
    counts (dict): a dict of outcomes from an experiment
    observable (dict or matrix or list): The observable to be averaged over.
    As an example, ZZ on qubits can be given as:
    * dict: {"00": 1, "11": 1, "01": -1, "10": -1}
    * matrix: [[1, 0, 0, 0], [0, -1, 0, 0, ], [0, 0, -1, 0], [0, 0, 0, 1]]
    * matrix diagonal (list): [1, -1, -1, 1]

Returns:
    Double: Average of the observable
r   )
isinstancedictr   sumvalues)counts
observabletemptotkeys        ^/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/analysis/average.pyaverage_datar      s_    $ j$'')*5
D
fmmo
C3K*/1C77D  K    )r   r   r   zdict | np.ndarray | listreturnfloat)__doc__
__future__r   numpynpmake_observabler   r    r   r   <module>r      s    D "  1r   