§
    ¹³Ùg  ã                  óF  — 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 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 Sampler V1 and V2 classesé    )Úannotations)ÚABCÚabstractmethod)ÚIterableÚSequence)Úcopy)ÚGenericÚTypeVar)ÚQuantumCircuit)ÚJobV1)Údeprecate_funcé   )ÚPrimitiveResult)ÚSamplerPubLike)ÚSamplerPubResulté   )Ú
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 )ÚBaseSamplerV1aÞ  Sampler V1 base class

    Base class of Sampler that calculates quasi-probabilities of bitstrings from quantum circuits.

    A sampler is initialized with an empty parameter set. The sampler is used to
    create a :class:`~qiskit.providers.JobV1`, via the :meth:`qiskit.primitives.Sampler.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)

    * parameter values (:math:`\theta_k`): list of sets of parameter 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 a :class:`~qiskit.primitives.SamplerResult`
    object, which contains probabilities or quasi-probabilities of bitstrings,
    plus optional metadata like error bars in the samples.

    Here is an example of how sampler is used.

    .. code-block:: python

        from qiskit.primitives import Sampler
        from qiskit import QuantumCircuit
        from qiskit.circuit.library import RealAmplitudes

        # a Bell circuit
        bell = QuantumCircuit(2)
        bell.h(0)
        bell.cx(0, 1)
        bell.measure_all()

        # two parameterized circuits
        pqc = RealAmplitudes(num_qubits=2, reps=2)
        pqc.measure_all()
        pqc2 = RealAmplitudes(num_qubits=2, reps=3)
        pqc2.measure_all()

        theta1 = [0, 1, 1, 2, 3, 5]
        theta2 = [0, 1, 2, 3, 4, 5, 6, 7]

        # initialization of the sampler
        sampler = Sampler()

        # Sampler runs a job on the Bell circuit
        job = sampler.run(circuits=[bell], parameter_values=[[]], parameters=[[]])
        job_result = job.result()
        print([q.binary_probabilities() for q in job_result.quasi_dists])

        # Sampler runs a job on the parameterized circuits
        job2 = sampler.run(
            circuits=[pqc, pqc2],
            parameter_values=[theta1, theta2],
            parameters=[pqc.parameters, pqc2.parameters])
        job_result = job2.result()
        print([q.binary_probabilities() for q in job_result.quasi_dists])

    N©Úoptionsr   údict | Nonec               óJ   •— t          ¦   «                              |¦  «         dS )ú=
        Args:
            options: Default options.
        N©ÚsuperÚ__init__©Úselfr   Ú	__class__s     €úY/granary/edev/quantum/lib/python3.11/site-packages/qiskit/primitives/base/base_sampler.pyr!   zBaseSamplerV1.__init__d   s#   ø€ õ 	‰Œ×Ò˜Ñ!Ô!Ð!Ð!Ð!ó    Úcircuitsú)QuantumCircuit | Sequence[QuantumCircuit]Úparameter_valuesú2Sequence[float] | Sequence[Sequence[float]] | NoneÚreturnr   c                óœ   — t          j        ||¦  «        \  }}t          | j        ¦  «        } |j        di |¤Ž  | j        ||fi |j        ¤ŽS )a  Run the job of the sampling of bitstrings.

        Args:
            circuits: One of more circuit objects.
            parameter_values: Parameters to be bound to the circuit.
            run_options: Backend runtime options used for circuit execution.

        Returns:
            The job object of the result of the sampler. The i-th result corresponds to
            ``circuits[i]`` evaluated with parameters bound as ``parameter_values[i]``.

        Raises:
            ValueError: Invalid arguments are given.
        © )r   Ú_validate_sampler_argsr   r   Úupdate_optionsÚ_runÚ__dict__)r#   r'   r)   Úrun_optionsÚrun_optss        r%   ÚrunzBaseSamplerV1.runo   su   € õ* &0Ô%FÀxÐQaÑ%bÔ%bÑ"ˆÐ"õ ˜œÑ%Ô%ˆØˆÔÐ.Ð. +Ð.Ð.Ð.àˆtŒyØØð
ð 
ð Ôð
ð 
ð 	
r&   útuple[QuantumCircuit, ...]útuple[tuple[float, ...], ...]c                ó    — t          d¦  «        ‚)Nz9The subclass of BaseSampler must implement `_run` method.)ÚNotImplementedError)r#   r'   r)   r2   s       r%   r0   zBaseSamplerV1._run�   s   € õ "Ð"]Ñ^Ô^Ð^r&   ©r   r   )N)r'   r(   r)   r*   r+   r   )r'   r5   r)   r6   r+   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__hash__r!   r4   r   r0   Ú__classcell__©r$   s   @r%   r   r   $   s§   ø€ € € € € ð;ð ;ðz €Hð
  $ð	"ð 	"ð 	"ð 	"ð 	"ð 	"ð 	"ð 	"ð PTð
ð 
ð 
ð 
ð 
ðB ð_ð _ð _ñ „^ð_ð _ð _ð _ð _r&   r   c                  óP   ‡ — e Zd ZdZ edd¬¦  «        ddœd
ˆ fd	„¦   «         Zˆ xZS )ÚBaseSamplerzcDEPRECATED. Type alias for Sampler V1 base class

    See :class:`.BaseSamplerV1` for details.
    z1.2ar  The `BaseSampler` class is a type alias for the `BaseSamplerV1` interface that has been deprecated in favor of explicitly versioned interface classes. It is recommended to migrate all implementations to use `BaseSamplerV2`. However, for implementations incompatible with `BaseSamplerV2`, `BaseSampler` can be replaced with the explicitly versioned `BaseSamplerV1` class.)ÚsinceÚadditional_msgNr   r   r   c               óL   •— t          ¦   «                              |¬¦  «         dS )r   r   Nr   r"   s     €r%   r!   zBaseSampler.__init__    s&   ø€ õ" 	‰Œ×Ò ÐÑ)Ô)Ð)Ð)Ð)r&   r9   )r:   r;   r<   r=   r   r!   r?   r@   s   @r%   rB   rB   š   s   ø€ € € € € ðð ð
 €^ØðKðñ ô ð  $ð	*ð 	*ð 	*ð 	*ð 	*ð 	*ð 	*ñô ð	*ð 	*ð 	*ð 	*ð 	*r&   rB   c                  ó0   — e Zd ZdZeddœdd
„¦   «         ZdS )ÚBaseSamplerV2a  Sampler V2 base class.

    A Sampler returns samples of quantum circuit outputs.

    All sampler implementations must implement default value for the ``shots`` in the
    :meth:`.run` method if ``None`` is given both as a ``kwarg`` and in all of the pubs.
    N)ÚshotsÚpubsúIterable[SamplerPubLike]rH   ú
int | Noner+   ú3BasePrimitiveJob[PrimitiveResult[SamplerPubResult]]c               ó   — dS )a  Run and collect samples from each pub.

        Args:
            pubs: An iterable of pub-like objects. For example, a list of circuits
                  or tuples ``(circuit, parameter_values)``.
            shots: The total number of shots to sample for each sampler pub that does
                   not specify its own shots. If ``None``, the primitive's default
                   shots value will be used, which can vary by implementation.

        Returns:
            The job object of Sampler's result.
        Nr-   )r#   rI   rH   s      r%   r4   zBaseSamplerV2.run½   s   € € € r&   )rI   rJ   rH   rK   r+   rL   )r:   r;   r<   r=   r   r4   r-   r&   r%   rG   rG   ´   sK   € € € € € ðð ð àEIðð ð ð ð ñ „^ðð ð r&   rG   N)$r=   Ú
__future__r   Úabcr   r   Úcollections.abcr   r   r   Útypingr	   r
   Úqiskit.circuitr   Úqiskit.providersr   ÚJobÚqiskit.utils.deprecationr   Úcontainers.primitive_resultr   Úcontainers.sampler_pubr   Úcontainers.sampler_pub_resultr   Ú r   Úbase_primitiver   Úbase_primitive_jobr   r   r   rB   rG   r-   r&   r%   ú<module>r\      sÓ  ðð %Ð $à "Ð "Ð "Ð "Ð "Ð "à #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ð Ð Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #à )Ð )Ð )Ð )Ð )Ð )Ø )Ð )Ð )Ð )Ð )Ð )Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3à 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø <Ð <Ð <Ð <Ð <Ð <Ø Ð Ð Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0à€GˆC�sÐÑÔ€ðs_ð s_ð s_ð s_ð s_�M 7¨1¤:ñ s_ô s_ð s_ðl*ð *ð *ð *ð *�- Ô"ñ *ô *ð *ð4ð ð ð ð �Cñ ô ð ð ð r&   