
    z	i                    .    S r SSKJr  SSKrSSKrSS jrg)zCHelper functions for building dictionaries from matrices and lists.    )annotationsNc                2   0 n[         R                  " U 5      n[        U5      n[        R                  " [        R
                  " U5      5      nSU S3nUR                  S:X  a  UR                  5       n[        U5       H  n[        Xe5      nX&   X'   M     U$ )a  Convert an observable in matrix form to dictionary form.

Takes in a diagonal observable as a matrix and converts it to a dictionary
form. Can also handle a list sorted of the diagonal elements.

Args:
    matrix_observable (list): The observable to be converted to dictionary
    form. Can be a matrix or just an ordered list of observed values

Returns:
    Dict: A dictionary with all observable states as keys, and corresponding
    values being the observed value for that state
0b   )
nparraylenmathceillog2ndimdiagonalrangeformat)matrix_observabledict_observable
observableobservable_sizeobservable_bitsbinary_formatterstate_no	state_strs           f/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/analysis/make_observable.pymake_dict_observabler      s     O+,J*oOii		/ :;O?+1-!((*
/*86	%/%9" +     )r   zlist | np.ndarrayreturndict)__doc__
__future__r   r   numpyr   r    r   r   <module>r#      s    J "  r   