§
    ¹³Ùg<"  ã                  ó^  — d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m	Z	 ddl
mZm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 ddlmZmZmZmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$  ede¬¦  «        Z% G d„ de"ee%         ¦  «        Z& G d„ de&e%         ¦  «        Z' G d„ de¦  «        Z(dS )z Base Estimator V1 and V2 classesé    )Úannotations)ÚabstractmethodÚABC)ÚIterableÚSequence)Úcopy)ÚGenericÚTypeVar)ÚQuantumCircuit)ÚJobV1)ÚSparsePauliOp)ÚBaseOperator)Údeprecate_funcé   )ÚDataBinÚEstimatorPubLikeÚPrimitiveResultÚ	PubResult)ÚEstimatorPubé   )Ú
validation)ÚBasePrimitive)ÚBasePrimitiveJobÚT)Úboundc                  óR   ‡ — e Zd ZdZdZddœdˆ fd„Z	 ddd„Zedd„¦   «         Zˆ xZ	S )ÚBaseEstimatorV1ad	  Estimator V1 base class.

    Base class for Estimator that estimates expectation values of quantum circuits and observables.

    An estimator is initialized with an empty parameter set. The estimator is used to
    create a :class:`~qiskit.providers.JobV1`, via the
    :meth:`qiskit.primitives.Estimator.run()` method. This method is called
    with the following parameters

    * quantum circuits (:math:`\psi_i(\theta)`): list of (parameterized) quantum circuits
      (a list of :class:`~qiskit.circuit.QuantumCircuit` objects).

    * observables (:math:`H_j`): a list of :class:`~qiskit.quantum_info.SparsePauliOp`
      objects.

    * parameter values (:math:`\theta_k`): list of sets of values
      to be bound to the parameters of the quantum circuits
      (list of list of float).

    The method returns a :class:`~qiskit.providers.JobV1` object, calling
    :meth:`qiskit.providers.JobV1.result()` yields the
    a list of expectation values plus optional metadata like confidence intervals for
    the estimation.

    .. math::

        \langle\psi_i(\theta_k)|H_j|\psi_i(\theta_k)\rangle

    Here is an example of how the estimator is used.

    .. code-block:: python

        from qiskit.primitives import Estimator
        from qiskit.circuit.library import RealAmplitudes
        from qiskit.quantum_info import SparsePauliOp

        psi1 = RealAmplitudes(num_qubits=2, reps=2)
        psi2 = RealAmplitudes(num_qubits=2, reps=3)

        H1 = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)])
        H2 = SparsePauliOp.from_list([("IZ", 1)])
        H3 = SparsePauliOp.from_list([("ZI", 1), ("ZZ", 1)])

        theta1 = [0, 1, 1, 2, 3, 5]
        theta2 = [0, 1, 1, 2, 3, 5, 8, 13]
        theta3 = [1, 2, 3, 4, 5, 6]

        estimator = Estimator()

        # calculate [ <psi1(theta1)|H1|psi1(theta1)> ]
        job = estimator.run([psi1], [H1], [theta1])
        job_result = job.result() # It will block until the job finishes.
        print(f"The primitive-job finished with result {job_result}")

        # calculate [ <psi1(theta1)|H1|psi1(theta1)>,
        #             <psi2(theta2)|H2|psi2(theta2)>,
        #             <psi1(theta3)|H3|psi1(theta3)> ]
        job2 = estimator.run([psi1, psi2, psi1], [H1, H2, H3], [theta1, theta2, theta3])
        job_result = job2.result()
        print(f"The primitive-job finished with result {job_result}")
    N©Úoptionsr   údict | Nonec               óJ   •— t          ¦   «                              |¦  «         dS )zþ
        Creating an instance of an Estimator V1, or using one in a ``with`` context opens a session that
        holds resources until the instance is ``close()`` ed or the context is exited.

        Args:
            options: Default options.
        N©ÚsuperÚ__init__©Úselfr   Ú	__class__s     €ú[/granary/edev/quantum/lib/python3.11/site-packages/qiskit/primitives/base/base_estimator.pyr$   zBaseEstimatorV1.__init__k   s#   ø€ õ 	‰Œ×Ò˜Ñ!Ô!Ð!Ð!Ð!ó    Úcircuitsú)Sequence[QuantumCircuit] | QuantumCircuitÚobservablesú1Sequence[BaseOperator | str] | BaseOperator | strÚparameter_valuesú:Sequence[Sequence[float]] | Sequence[float] | float | NoneÚreturnr   c                ó¢   — t          j        |||¦  «        \  }}}t          | j        ¦  «        } |j        di |¤Ž  | j        |||fi |j        ¤ŽS )aa  Run the job of the estimation of expectation value(s).

        ``circuits``, ``observables``, and ``parameter_values`` should have the same
        length. The i-th element of the result is the expectation of observable

        .. code-block:: python

            obs = observables[i]

        for the state prepared by

        .. code-block:: python

            circ = circuits[i]

        with bound parameters

        .. code-block:: python

            values = parameter_values[i]

        Args:
            circuits: one or more circuit objects.
            observables: one or more observable objects. Several formats are allowed;
                importantly, ``str`` should follow the string representation format for
                :class:`~qiskit.quantum_info.Pauli` objects.
            parameter_values: concrete parameters to be bound.
            run_options: runtime options used for circuit execution.

        Returns:
            The job object of EstimatorResult.

        Raises:
            TypeError: Invalid argument type given.
            ValueError: Invalid argument values given.
        © )r   Ú_validate_estimator_argsr   r   Úupdate_optionsÚ_runÚ__dict__)r&   r*   r,   r.   Úrun_optionsÚrun_optss         r(   ÚrunzBaseEstimatorV1.runy   s‚   € õX 3=Ô2UØ�kÐ#3ñ3
ô 3
Ñ/ˆ�+Ð/õ
 ˜œÑ%Ô%ˆØˆÔÐ.Ð. +Ð.Ð.Ð.àˆtŒyØØØð
ð 
ð Ôð	
ð 
ð 	
r)   útuple[QuantumCircuit, ...]útuple[SparsePauliOp, ...]útuple[tuple[float, ...], ...]c                ó    — t          d¦  «        ‚)Nz;The subclass of BaseEstimator must implement `_run` method.)ÚNotImplementedError)r&   r*   r,   r.   r7   s        r(   r5   zBaseEstimatorV1._run´   s   € õ "Ð"_Ñ`Ô`Ð`r)   ©r   r    ©N)r*   r+   r,   r-   r.   r/   r0   r   )r*   r:   r,   r;   r.   r<   r0   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__hash__r$   r9   r   r5   Ú__classcell__©r'   s   @r(   r   r   *   s§   ø€ € € € € ð<ð <ð| €Hð
  $ð"ð "ð "ð "ð "ð "ð "ð "ð$ X\ð	9
ð 9
ð 9
ð 9
ð 9
ðv ðað að añ „^ðað að að að ar)   r   c                  óP   ‡ — e Zd ZdZ edd¬¦  «        ddœd
ˆ fd	„¦   «         Zˆ xZS )ÚBaseEstimatorzhDEPRECATED. Type alias for Estimator V1 base class.

    See :class:`.BaseEstimatorV1` for details.
    z1.2a~  The `BaseEstimator` class is a type alias for the `BaseEstimatorV1` interface that has been deprecated in favor of explicitly versioned interface classes. It is recommended to migrate all implementations to use `BaseEstimatorV2`. However, for implementations incompatible with `BaseEstimatorV2`, `BaseEstimator` can be replaced with the explicitly versioned `BaseEstimatorV1` class.)ÚsinceÚadditional_msgNr   r   r    c               óL   •— t          ¦   «                              |¬¦  «         dS )zû
        Creating an instance of an Estimator, or using one in a ``with`` context opens a session that
        holds resources until the instance is ``close()`` ed or the context is exited.

        Args:
            options: Default options.
        r   Nr"   r%   s     €r(   r$   zBaseEstimator.__init__Å   s&   ø€ õ( 	‰Œ×Ò ÐÑ)Ô)Ð)Ð)Ð)r)   r?   )rA   rB   rC   rD   r   r$   rF   rG   s   @r(   rI   rI   ¿   s   ø€ € € € € ðð ð
 €^ØðMðñ ô ð  $ð*ð *ð *ð *ð *ð *ð *ñô ð*ð *ð *ð *ð *r)   rI   c                  óH   — e Zd ZdZedd„¦   «         Zeddœdd„¦   «         ZdS )ÚBaseEstimatorV2ap  Estimator V2 base class.

    An estimator estimates expectation values for provided quantum circuit and
    observable combinations.

    An Estimator implementation must treat the :meth:`.run` method ``precision=None``
    kwarg as using a default ``precision`` value.  The default value and methods to
    set it can be determined by the Estimator implementor.
    Ú_r   r0   útype[DataBin]c                ó   — t           S r@   )r   )rO   s    r(   Ú_make_data_binzBaseEstimatorV2._make_data_binç   s	   € õ ˆr)   N)Ú	precisionÚpubsúIterable[EstimatorPubLike]rS   úfloat | Noneú,BasePrimitiveJob[PrimitiveResult[PubResult]]c               ó   — dS )a@  Estimate expectation values for each provided pub (Primitive Unified Bloc).

        Args:
            pubs: An iterable of pub-like objects, such as tuples ``(circuit, observables)``
                  or ``(circuit, observables, parameter_values)``.
            precision: The target precision for expectation value estimates of each
                       run Estimator Pub that does not specify its own precision. If None
                       the estimator's default precision value will be used.

        Returns:
            A job object that contains results.
        Nr2   )r&   rT   rS   s      r(   r9   zBaseEstimatorV2.runí   s   € € € r)   )rO   r   r0   rP   )rT   rU   rS   rV   r0   rW   )rA   rB   rC   rD   ÚstaticmethodrR   r   r9   r2   r)   r(   rN   rN   Ü   sk   € € € € € ðð ð ðð ð ñ „\ðð
 àMQðð ð ð ð ñ „^ðð ð r)   rN   N))rD   Ú
__future__r   Úabcr   r   Úcollections.abcr   r   r   Útypingr	   r
   Úqiskit.circuitr   Úqiskit.providersr   ÚJobÚqiskit.quantum_info.operatorsr   Ú+qiskit.quantum_info.operators.base_operatorr   Úqiskit.utils.deprecationr   Ú
containersr   r   r   r   Úcontainers.estimator_pubr   Ú r   Úbase_primitiver   Úbase_primitive_jobr   r   r   rI   rN   r2   r)   r(   ú<module>ri      s  ðð 'Ð &à "Ð "Ð "Ð "Ð "Ð "à #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ð Ð Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #à )Ð )Ð )Ð )Ð )Ð )Ø )Ð )Ð )Ð )Ð )Ð )Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø DÐ DÐ DÐ DÐ DÐ DØ 3Ð 3Ð 3Ð 3Ð 3Ð 3ðð ð ð ð ð ð ð ð ð ð ð ð 4Ð 3Ð 3Ð 3Ð 3Ð 3Ø Ð Ð Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0à€GˆC�sÐÑÔ€ðRað Rað Rað Rað Ra�m W¨Q¤Zñ Raô Rað Raðj*ð *ð *ð *ð *�O AÔ&ñ *ô *ð *ð: ð  ð  ð  ð  �cñ  ô  ð  ð  ð  r)   