§
    º³Ùg  ã                   óL   — d Z ddlZddlmZmZ ddlmZ ddlm	Z	m
Z
 h d£Zd„ ZdS )	zDRoutines for computing expectation values from sampled distributionsé    N)Úsampled_expval_floatÚsampled_expval_complex)ÚQiskitErroré   )ÚQuasiDistributionÚProbDistribution>   Ú0Ú1ÚIÚZc                 ó$  ‡— ddl m} ddlm}m} t          | t          t          f¦  «        r|                      ¦   «         } t          | |t          f¦  «        st          d¦  «        ‚t          |t          ¦  «        r+|                     ¦   «         g}t          j        dg¦  «        }n�t          ||¦  «        r+|                     ¦   «         g}t          j        dg¦  «        }nRt          ||¦  «        r3|j                             ¦   «         }t          j        |j        ¦  «        }nt          d¦  «        ‚t'          t)          t+          | ¦  «        ¦  «        ¦  «        Št-          ˆfd„|D ¦   «         ¦  «        rt          d	‰› d
�¦  «        ‚|D ]<}t/          |¦  «                             t2          ¦  «        rt          d|› d�¦  «        ‚Œ=|j        t          j        t6          ¦  «        j        k    rt;          ||| ¦  «        S t=          ||| ¦  «        S )a&  Computes expectation value from a sampled distribution

    Note that passing a raw dict requires bit-string keys.

    Parameters:
        dist (Counts or QuasiDistribution or ProbDistribution or dict): Input sampled distribution
        oper (str or Pauli or PauliOp or PauliSumOp or SparsePauliOp): The operator for
                                                                       the observable

    Returns:
        float: The expectation value
    Raises:
        QiskitError: if the input distribution or operator is an invalid type
    r   )ÚCountsr   )ÚPauliÚSparsePauliOpzInvalid input distribution typeg      ð?zInvalid operator typec              3   ó>   •K  — | ]}t          |¦  «        ‰k    V — Œd S )N)Úlen)Ú.0ÚopÚbitstring_lens     €úR/granary/edev/quantum/lib/python3.11/site-packages/qiskit/result/sampled_expval.pyú	<genexpr>z,sampled_expectation_value.<locals>.<genexpr>@   s.   øè è € Ð
8Ð
8¨�3ˆr‰7Œ7�mÒ#Ð
8Ð
8Ð
8Ð
8Ð
8Ð
8ó    z'One or more operators not same length (z) as input bitstringszInput operator z is not diagonal)Úcountsr   Úqiskit.quantum_infor   r   Ú
isinstancer   r   Úbinary_probabilitiesÚdictr   ÚstrÚupperÚnpÚasarrayÚto_labelÚpaulisÚ	to_labelsÚcoeffsr   ÚnextÚiterÚanyÚsetÚ
differenceÚOPERSÚdtypeÚcomplexÚtyper   r   )	ÚdistÚoperr   r   r   Ú	oper_strsr%   r   r   s	           @r   Úsampled_expectation_valuer2      s"  ø€ ð ÐÐÐÐÐØ8Ð8Ð8Ð8Ð8Ð8Ð8Ð8õ �$Õ*Õ,<Ð=Ñ>Ô>ð +Ø×(Ò(Ñ*Ô*ˆå�d˜V¥T˜NÑ+Ô+ð =ÝÐ;Ñ<Ô<Ð<Ý�$�ÑÔð 
3Ø—Z’Z‘\”\�Nˆ	Ý”˜S˜EÑ"Ô"ˆˆÝ	�D˜%Ñ	 Ô	 ð 3Ø—]’]‘_”_Ð%ˆ	Ý”˜S˜EÑ"Ô"ˆˆÝ	�D˜-Ñ	(Ô	(ð 3Ø”K×)Ò)Ñ+Ô+ˆ	Ý”˜DœKÑ(Ô(ˆˆåÐ1Ñ2Ô2Ð2õ ��T $™ZœZÑ(Ô(Ñ)Ô)€MÝ
Ð
8Ð
8Ð
8Ð
8¨iÐ
8Ñ
8Ô
8Ñ8Ô8ð 
ÝØZ°mÐZÐZÐZñ
ô 
ð 	
ð ð Fð FˆÝˆr‰7Œ7×Ò�eÑ$Ô$ð 	FÝÐD°ÐDÐDÐDÑEÔEÐEð	Fð „|•r”x¥Ñ(Ô(Ô-Ò-Ð-Ý% i°¸Ñ>Ô>Ð>å# I¨v°tÑ<Ô<Ð<r   )Ú__doc__Únumpyr    Ú"qiskit._accelerate.sampled_exp_valr   r   Úqiskit.exceptionsr   Údistributionsr   r   r+   r2   © r   r   ú<module>r9      s‚   ðð KÐ JØ Ð Ð Ð à [Ð [Ð [Ð [Ð [Ð [Ð [Ð [Ø )Ð )Ð )Ð )Ð )Ð )Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >ð 	ÐÐ€ð1=ð 1=ð 1=ð 1=ð 1=r   