§
    ¹³ÙgN  ã                  óÎ   — d Z ddlmZ ddlmZ ddlmZ ddlZddl	m
Z
 ddlmZ ddlmZ dd	lmZ d
dlmZmZ d
dlmZ d
dlmZmZmZmZ  G d„ deee                  ¦  «        ZdS )z'
Estimator V1 reference implementation
é    )Úannotations)ÚSequence)ÚAnyN)ÚQuantumCircuit)ÚQiskitError)ÚBaseOperator)Údeprecate_funcé   )ÚBaseEstimatorÚEstimatorResult)ÚPrimitiveJob)Ú_circuit_keyÚ_observable_keyÚ_statevector_from_circuitÚinit_observablec                  ó`   ‡ — e Zd ZdZ edd¬¦  «        ddœdˆ fd	„¦   «         Zdd„Zdd„Zˆ xZS )Ú	Estimatora½  
    Reference implementation of :class:`BaseEstimator` (V1).

    :Run Options:

        - **shots** (None or int) --
          The number of shots. If None, it calculates the expectation values
          with full state vector simulation.
          Otherwise, it samples from normal distributions with standard errors as standard
          deviations using normal distribution approximation.

        - **seed** (np.random.Generator or int) --
          Set a fixed seed or generator for the normal distribution. If shots is None,
          this option is ignored.

    .. note::
        The result of this class is exact if the circuit contains only unitary operations.
        On the other hand, the result could be stochastic if the circuit contains a non-unitary
        operation such as a reset for a some subsystems.
        The stochastic result can be made reproducible by setting ``seed``, e.g.,
        ``Estimator(options={"seed":123})``.
    z1.2z¶All implementations of the `BaseEstimatorV1` interface have been deprecated in favor of their V2 counterparts. The V2 alternative for the `Estimator` class is `StatevectorEstimator`.)ÚsinceÚadditional_msgN©Úoptionsr   údict | Nonec               ó’   •— t          ¦   «                              |¬¦  «         g | _        g | _        g | _        i | _        i | _        dS )z�
        Args:
            options: Default options.

        Raises:
            QiskitError: if some classical bits are not used for measurements.
        r   N)ÚsuperÚ__init__Ú	_circuitsÚ_parametersÚ_observablesÚ_circuit_idsÚ_observable_ids)Úselfr   Ú	__class__s     €úQ/granary/edev/quantum/lib/python3.11/site-packages/qiskit/primitives/estimator.pyr   zEstimator.__init__>   sM   ø€ õ 	‰Œ×Ò ÐÑ)Ô)Ð)ØˆŒØˆÔØˆÔØˆÔØ!ˆÔÐÐó    ÚcircuitsúSequence[int]ÚobservablesÚparameter_valuesúSequence[Sequence[float]]Úreturnr   c                ó<  ‡ — |                      dd ¦  «        }|                      dd ¦  «        }|€t          j                             ¦   «         }nAt	          |t          j        j        ¦  «        r|}nt          j                             |¦  «        }d„ t          t          |¦  «        ¦  «        D ¦   «         }g }	t          ||¦  «        D ]ä\  }
}t          |¦  «        t          ‰ j	        |
         ¦  «        k    r;t          dt          |¦  «        › dt          ‰ j	        |
         ¦  «        › d�¦  «        ‚|	                     t          |¦  «        dk    r‰ j        |
         nE‰ j        |
                              t          t          ‰ j	        |
         |¦  «        ¦  «        ¦  «        ¦  «         Œåˆ fd„|D ¦   «         }g }t          |	||¦  «        D �],\  }}}|j        |j        k    r t          d	|j        › d
|j        › d�¦  «        ‚t!          ||¦  «        }|                     |¦  «        }|€|                     |¦  «         Œtt          j        |¦  «        }||z                       d¬¦  «        }t          j        |                     |¦  «        ¦  «        }||dz  z
  }t)          |d¦  «        }t          j        ||z  ¦  «        }|                     ||¦  «        }|                     |¦  «         ||d<   ||d<   �Œ.t/          t          j        |¦  «        |¦  «        S )NÚshotsÚseedc                ó   — g | ]}i ‘ŒS © r/   )Ú.0Ú_s     r#   ú
<listcomp>z#Estimator._call.<locals>.<listcomp>d   s   € Ð)KÐ)KÐ)K°¨"Ð)KÐ)KÐ)Kr$   zThe number of values (z+) does not match the number of parameters (z).r   c                ó*   •— g | ]}‰j         |         ‘ŒS r/   )r   )r0   Úir!   s     €r#   r2   z#Estimator._call.<locals>.<listcomp>r   s!   ø€ ÐHÐHÐH°q˜dÔ/°Ô2ÐHÐHÐHr$   z#The number of qubits of a circuit (z7) does not match the number of qubits of a observable ()Úatolé   Úvariance)ÚpopÚnpÚrandomÚdefault_rngÚ
isinstanceÚ	GeneratorÚrangeÚlenÚzipr   r   Úappendr   Úassign_parametersÚdictÚ
num_qubitsr   Úexpectation_valueÚreal_if_closeÚsimplifyÚmaxÚsqrtÚnormalr   )r!   r%   r'   r(   Úrun_optionsr,   r-   ÚrngÚmetadataÚbound_circuitsr4   ÚvalueÚsorted_observablesÚexpectation_valuesÚcircÚobsÚ	metadatumÚfinal_staterE   Úsq_obsÚ
sq_exp_valr7   Ústandard_errorÚexpectation_value_with_errors   `                       r#   Ú_callzEstimator._callS   sR  ø€ ð —’ ¨Ñ.Ô.ˆØ�Š˜v tÑ,Ô,ˆØˆ<Ý”)×'Ò'Ñ)Ô)ˆCˆCÝ˜�bœiÔ1Ñ2Ô2ð 	.ØˆCˆCå”)×'Ò'¨Ñ-Ô-ˆCð *LÐ)Kµe½CÀ¹M¼MÑ6JÔ6JÐ)KÑ)KÔ)KˆàˆÝ˜HÐ&6Ñ7Ô7ð 
	ð 
	‰HˆAˆuÝ�5‰zŒz�S Ô!1°!Ô!4Ñ5Ô5Ò5Ð5Ý!ðN­S°©Z¬Zð Nð NÝ14°TÔ5EÀaÔ5HÑ1IÔ1IðNð Nð Nñô ð ð ×!Ò!å�u‘:”: ’?�?ð ”˜qÔ!Ð!à”^ AÔ&×8Ò8½½cÀ$ÔBRÐSTÔBUÐW\Ñ>]Ô>]Ñ9^Ô9^Ñ_Ô_ñô ð ð ð
 IÐHÐHÐH¸KÐHÑHÔHÐØÐÝ$'¨Ð8JÈHÑ$UÔ$Uð 	+ñ 	+Ñ ˆD�#�yØŒ #¤.Ò0Ð0Ý!ðP¸$¼/ð Pð PØ=@¼^ðPð Pð Pñô ð õ 4°D¸#Ñ>Ô>ˆKØ +× =Ò =¸cÑ BÔ BÐØˆ}Ø"×)Ò)Ð*;Ñ<Ô<Ð<Ð<å$&Ô$4Ð5FÑ$GÔ$GÐ!Ø ™)×-Ò-°1Ð-Ñ5Ô5�ÝÔ-¨k×.KÒ.KÈFÑ.SÔ.SÑTÔT�
Ø%Ð(9¸1Ñ(<Ñ<�Ý˜x¨Ñ+Ô+�Ý!#¤¨°EÑ)9Ñ!:Ô!:�Ø/2¯zªzÐ:KÈ^Ñ/\Ô/\Ð,Ø"×)Ò)Ð*FÑGÔGÐGØ(0�	˜*Ñ%Ø%*�	˜'Ñ"Ñ"å�rÔ/Ð0BÑCÔCÀXÑNÔNÐNr$   útuple[QuantumCircuit, ...]útuple[BaseOperator, ...]útuple[tuple[float, ...], ...]c                ó^  — g }|D ]¿}t          |¦  «        }| j                             |¦  «        }|�|                     |¦  «         ŒC|                     t	          | j        ¦  «        ¦  «         t	          | j        ¦  «        | j        |<   | j                             |¦  «         | j                             |j        ¦  «         ŒÀg }	|D ]º}
t          |
¦  «        }
| j	                             t          |
¦  «        ¦  «        }|�|	                     |¦  «         ŒP|	                     t	          | j        ¦  «        ¦  «         t	          | j        ¦  «        | j	        t          |
¦  «        <   | j                             |
¦  «         Œ»t          | j        ||	|fi |¤Ž}|                     ¦   «          |S )N)r   r   ÚgetrA   r?   r   r   Ú
parametersr   r    r   r   r   rZ   Ú_submit)r!   r%   r'   r(   rK   Úcircuit_indicesÚcircuitÚkeyÚindexÚobservable_indicesÚ
observableÚjobs               r#   Ú_runzEstimator._runŒ   s³  € ð ˆØð 		<ð 		<ˆGÝ˜wÑ'Ô'ˆCØÔ%×)Ò)¨#Ñ.Ô.ˆEØÐ Ø×&Ò& uÑ-Ô-Ð-Ð-à×&Ò&¥s¨4¬>Ñ':Ô':Ñ;Ô;Ð;Ý),¨T¬^Ñ)<Ô)<�Ô! #Ñ&Ø”×%Ò% gÑ.Ô.Ð.ØÔ ×'Ò'¨Ô(:Ñ;Ô;Ð;Ð;ØÐØ%ð 	5ð 	5ˆJÝ(¨Ñ4Ô4ˆJØÔ(×,Ò,­_¸ZÑ-HÔ-HÑIÔIˆEØÐ Ø"×)Ò)¨%Ñ0Ô0Ð0Ð0à"×)Ò)­#¨dÔ.?Ñ*@Ô*@ÑAÔAÐAÝDGÈÔHYÑDZÔDZ�Ô$¥_°ZÑ%@Ô%@ÑAØÔ!×(Ò(¨Ñ4Ô4Ð4Ð4ÝØŒJ˜Ð);Ð=Mð
ð 
ØQ\ð
ð 
ˆð 	�Š‰ŒˆØˆ
r$   )r   r   )r%   r&   r'   r&   r(   r)   r*   r   )r%   r[   r'   r\   r(   r]   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   rZ   ri   Ú__classcell__)r"   s   @r#   r   r   &   s¬   ø€ € € € € ðð ð. €^ØðRðñ ô ð 26ð "ð "ð "ð "ð "ð "ð "ñô ð"ð7Oð 7Oð 7Oð 7Oðr ð  ð  ð  ð  ð  ð  ð  r$   r   )rm   Ú
__future__r   Úcollections.abcr   Útypingr   Únumpyr9   Úqiskit.circuitr   Úqiskit.exceptionsr   Ú+qiskit.quantum_info.operators.base_operatorr   Úqiskit.utils.deprecationr	   Úbaser   r   Úprimitive_jobr   Úutilsr   r   r   r   r   r/   r$   r#   ú<module>rz      sI  ððð ð #Ð "Ð "Ð "Ð "Ð "à $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð à Ð Ð Ð à )Ð )Ð )Ð )Ð )Ð )Ø )Ð )Ð )Ð )Ð )Ð )Ø DÐ DÐ DÐ DÐ DÐ DØ 3Ð 3Ð 3Ð 3Ð 3Ð 3à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'ðð ð ð ð ð ð ð ð ð ð ð ðFð Fð Fð Fð F�˜l¨?Ô;Ô<ñ Fô Fð Fð Fð Fr$   