
    iS                       S r SSKJr  SSKJrJrJrJr  SSK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  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  \R:                  " \5      r " S S5      r  " S S\\   \ \5      r!g)zEstimator primitive.    )annotations)OptionalDictUnionIterableN)	BackendV2)BaseEstimatorV2)EstimatorPubLike)EstimatorPub   )RuntimeJobV2)EstimatorOptions)BasePrimitiveV2)validate_estimator_pubs)Session)Batchc                      \ rS rSrSrSrSrg)	Estimator&   z(Base class for Qiskit Runtime Estimator.r    N)__name__
__module____qualname____firstlineno____doc__version__static_attributes__r       V/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/estimator.pyr   r   &   s
    2Gr   r   c                  r    \ rS rSrSr\rSr  S   SS jjrSS.     SS jjr	SS jr
\SS	 j5       rS
rg)EstimatorV2,   a  Class for interacting with Qiskit Runtime Estimator primitive service.

Qiskit Runtime Estimator primitive service estimates expectation values of quantum circuits and
observables.

The :meth:`run` can be used to submit circuits, observables, and parameters
to the Estimator primitive.

Following construction, an estimator is used by calling its :meth:`run` method
with a list of PUBs (Primitive Unified Blocs). Each PUB contains four values that, together,
define a computation unit of work for the estimator to complete:

* 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:`~.Pauli`, :class:`~.SparsePauliOp`, ``str``) that specify which expectation values to
  estimate, denoted :math:`H_j`, and

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

* an optional target precision for expectation value estimates.

Here is an example of how the estimator is used.

.. code-block:: python

    from qiskit.circuit.library import real_amplitudes
    from qiskit.quantum_info import SparsePauliOp
    from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
    from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2 as Estimator

    service = QiskitRuntimeService()
    backend = service.least_busy(operational=True, simulator=False)

    psi = real_amplitudes(num_qubits=2, reps=2)
    hamiltonian = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)])
    theta = [0, 1, 1, 2, 3, 5]

    pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
    isa_psi = pm.run(psi)
    isa_observables = hamiltonian.apply_layout(isa_psi.layout)

    estimator = Estimator(mode=backend)

    # calculate [ <psi(theta)|hamiltonian|psi(theta)> ]
    job = estimator.run([(isa_psi, isa_observables, [theta])])
    pub_result = job.result()[0]
    print(f"Expectation values: {pub_result.data.evs}")
   Nc                    [         R                  " U 5        [        R                  U 5        [        R                  " XUS9  g)aP  Initializes the Estimator primitive.

Args:
    mode: The execution mode used to make the primitive query. It can be:

        * A :class:`Backend` if you are using job mode.
        * A :class:`Session` if you are using session execution mode.
        * A :class:`Batch` if you are using batch execution mode.

        Refer to the
        `Qiskit Runtime documentation
        <https://quantum.cloud.ibm.com/docs/guides/execution-modes>`_.
        for more information about the ``Execution modes``.

    options: Estimator options, see :class:`EstimatorOptions` for detailed description.

)modeoptionsN)r	   __init__r   r   )selfr%   r&   s      r   r'   EstimatorV2.__init__d   s0    , 	  &4   'Br   )	precisionc                   Ub  US::  a  [        S5      eU Vs/ s H  n[        R                  " X25      PM     nn[        U5        U R	                  U5      $ s  snf )a  Submit a request to the estimator primitive.

Args:
    pubs: An iterable of pub-like (primitive unified bloc) 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:
    Submitted job.

Raises:
    ValueError: if precision value is not strictly greater than 0.
r   z4The precision value must be strictly greater than 0.)
ValueErrorr   coercer   _run)r(   pubsr*   pubcoerced_pubss        r   runEstimatorV2.run   sY    $  A~ !WXXGKLt++C;tL-yy&& Ms    Ac                    UR                  S0 5      R                  SS5      SL aO  U R                  bA  U R                  R                  5       R                  SL a  US   S   (       d  [	        S5      egggg)	zValidate that primitive inputs (options) are valid

Raises:
    ValidationError: if validation fails.
    ValueError: if validation fails.

resiliencepec_mitigationFTN	simulatorcoupling_mapzZWhen the backend is a simulator and pec_mitigation is enabled, a coupling map is required.)get_backendconfigurationr7   r,   )r(   r&   s     r   _validate_optionsEstimatorV2._validate_options   s     KKb)--.>F$N)++-774?K(8.  9 @ * Or   c                    g)zReturn the program ID.	estimatorr   )clss    r   _program_idEstimatorV2._program_id   s     r   r   )NN)r%   z/Optional[Union[BackendV2, Session, Batch, str]]r&   z'Optional[Union[Dict, EstimatorOptions]])r/   zIterable[EstimatorPubLike]r*   zfloat | Nonereturnr   )r&   dictrC   None)rC   str)r   r   r   r   r   r   _options_classr   r'   r2   r<   classmethodrA   r   r   r   r   r!   r!   ,   su    1f &NG AE;?C=C 9C8 NR'.'>J'	'2&  r   r!   )"r   
__future__r   typingr   r   r   r   loggingqiskit.providersr   qiskit.primitives.baser	   qiskit.primitives.containersr
   *qiskit.primitives.containers.estimator_pubr   runtime_job_v2r   options.estimator_optionsr   base_primitiver   utilsr   sessionr   batchr   	getLoggerr   loggerr   r!   r   r   r   <module>rX      sh     " 2 2  & 2 9 C ( 7 + *  			8	$ B/"23Y Br   