
    z	i"                    
   S r SSKJr  SSKJrJr  SSKJrJr  SSK	J	r	  SSK
JrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJrJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  \" S\S9r# " S S\5      r$ " S S\ \\#   5      r%g)z Base Estimator V1 and V2 classes    )annotations)abstractmethodABC)IterableSequence)copy)GenericTypeVar)QuantumCircuit)JobV1)SparsePauliOp)BaseOperator   )DataBinEstimatorPubLikePrimitiveResult	PubResult)EstimatorPub   )_validate_estimator_args)BasePrimitiveV1)BasePrimitiveJobT)boundc                  R    \ rS rSrSr\SS j5       r\SS.     S	S jj5       rSr	g)
BaseEstimatorV2)   ag  Base class for ``EstimatorV2`` implementations.

An estimator calculates expectation values for provided quantum circuit and
observable combinations. Implementations of this :class:`.BaseEstimatorV2`
interface must define their own :meth:`.run` method, which is designed to
take the following inputs:

 * pubs: list of pubs (Primitive Unified Blocs). An estimator pub is a list
    or tuple of two to four elements that define the unit of work for the
    estimator. These are:

    * A single :class:`~qiskit.circuit.QuantumCircuit`, possibly parametrized,
        whose final state we define as :math:`\psi(\theta)`.

    * One or more observables (specified as any :class:`~.ObservablesArrayLike`, including
        :class:`~.quantum_info.Pauli`, :class:`~.SparsePauliOp`, ``str``) that specify which
        expectation values to estimate, denoted :math:`H_j`.

    * A collection parameter value sets to bind the circuit against, :math:`\theta_k`

    * Optionally, the estimation precision.

 * precision: the estimation precision. This specification is optional and will be overriden by
    the pub-wise shots if provided.

All estimator implementations must implement default value for the ``precision`` in the
:meth:`.run` method. This default value will be used any time ``precision=None`` is specified, which
can take place in the :meth:`.run` kwargs or at the pub level.
c                    [         $ N)r   )_s    _/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/primitives/base/base_estimator.py_make_data_binBaseEstimatorV2._make_data_binH   s	         N)	precisionc                   g)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.
N )selfpubsr%   s      r!   runBaseEstimatorV2.runN   s    r$   r'   )r    r   returnztype[DataBin])r)   zIterable[EstimatorPubLike]r%   zfloat | Noner,   z,BasePrimitiveJob[PrimitiveResult[PubResult]])
__name__
__module____qualname____firstlineno____doc__staticmethodr"   r   r*   __static_attributes__r'   r$   r!   r   r   )   sJ    <  
 MQ.>J	5 r$   r   c                     ^  \ rS rSrSrSrSS. S	U 4S jjjr S
       SS jjr\        SS j5       r	Sr
U =r$ )BaseEstimatorV1`   a	  Base class for ``EstimatorV1`` implementations.

Note that the reference estimator in Qiskit follows the ``EstimatorV2``
interface specifications instead.

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

Implementations of :class:`.BaseEstimatorV1` should define their own
:meth:`.BaseEstimatorV1._run` method
that will be called by the public-facing :meth:`qiskit.primitives.BaseEstimatorV1.run`,
which takes the following inputs:

* 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 a :class:`.BaseEstimatorV1` would be used:

.. code-block:: python

    # This is a fictional import path.
    # There are currently no EstimatorV1 implementations in Qiskit.
    from estimator_v1_location import EstimatorV1
    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 = EstimatorV1()

    # 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)optionsc               $   > [         TU ]  U5        g)zB
Initialize ``EstimatorV1``.

Args:
    options: Default options.
N)super__init__)r(   r7   	__class__s     r!   r:   BaseEstimatorV1.__init__   s     	!r$   c                    [        XU5      u  pn[        U R                  5      nUR                  " S0 UD6  U R                  " UUU40 UR
                  D6$ )a  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'   )r   r   r7   update_options_run__dict__)r(   circuitsobservablesparameter_valuesrun_optionsrun_optss         r!   r*   BaseEstimatorV1.run   sg    X 3K#33
//
 %.+.yy
 	
 	
r$   c                    [        S5      e)Nz=The subclass of BaseEstimatorV1 must implement `_run` method.)NotImplementedError)r(   rA   rB   rC   rD   s        r!   r?   BaseEstimatorV1._run   s     ""abbr$   r'   )r7   zdict | Noner   )rA   z)Sequence[QuantumCircuit] | QuantumCircuitrB   z1Sequence[BaseOperator | str] | BaseOperator | strrC   z:Sequence[Sequence[float]] | Sequence[float] | float | Noner,   r   )rA   ztuple[QuantumCircuit, ...]rB   ztuple[SparsePauliOp, ...]rC   ztuple[tuple[float, ...], ...]r,   r   )r-   r.   r/   r0   r1   __hash__r:   r*   r   r?   r3   __classcell__)r;   s   @r!   r5   r5   `   s    BH H
  $" " "" X\	9
;9
 G9
 U	9
 
9
v c,c /c 8	c 
c cr$   r5   N)&r1   
__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   
containersr   r   r   r   containers.estimator_pubr   validation_v1r   base_primitive_v1r   base_primitive_jobr   r   r   r5   r'   r$   r!   <module>rZ      sl    ' " # .  # ) ) 7 D  4 3 . 0Cs4c 4nWcowqz Wcr$   