
    z	it                        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  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 Sampler V1 and V2 classes    )annotations)ABCabstractmethod)IterableSequence)copy)GenericTypeVar)QuantumCircuit)JobV1   )PrimitiveResult)SamplerPubLike)SamplerPubResult   )_validate_sampler_args)BasePrimitiveV1)BasePrimitiveJobT)boundc                  >    \ rS rSrSr\SS.     SS jj5       rSrg)BaseSamplerV2#   a  Base class for ``SamplerV2`` implementations.

A Sampler returns samples of quantum circuit outputs. Implementations of this
:class:`.BaseSamplerV2` interface must define their own :meth:`.run` method,
which is designed to take the following inputs:

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

        * A single :class:`~qiskit.circuit.QuantumCircuit`, possibly parameterized.

        * A collection parameter value sets to bind the circuit against if it is parametric.

        * Optionally, the number of shots to sample.

 * shots: the number of shots to sample. This specification is optional and will be overriden by
    the pub-wise shots if provided.

All sampler implementations must implement default value for the ``shots`` in the
:meth:`.run` method. This default value will be used any time ``shots=None`` is specified, which
can take place in the :meth:`.run` kwargs or at the pub level.
N)shotsc                   g)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.
N )selfpubsr   s      ]/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/primitives/base/base_sampler.pyrunBaseSamplerV2.run;   s        r   )r   zIterable[SamplerPubLike]r   z
int | Nonereturnz3BasePrimitiveJob[PrimitiveResult[SamplerPubResult]])__name__
__module____qualname____firstlineno____doc__r   r    __static_attributes__r   r"   r   r   r   #   s6    . EI,8B	< r"   r   c                  x   ^  \ 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$ )BaseSamplerV1M   a  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

    # This is a fictional import path.
    # There are currently no Sampler implementations in Qiskit.
    from sampler_v1_location import SamplerV1
    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)optionsc               $   > [         TU ]  U5        g)z@
Initialize ``SamplerV1``.

Args:
    options: Default options.
N)super__init__)r   r-   	__class__s     r   r0   BaseSamplerV1.__init__   s     	!r"   c                    [        X5      u  p[        U R                  5      nUR                  " S0 UD6  U R                  " UU40 UR
                  D6$ )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   )r   r   r-   update_options_run__dict__)r   circuitsparameter_valuesrun_optionsrun_optss        r   r    BaseSamplerV1.run   sY    * &<H%W" %.+.yy
 
 	
r"   c                    [        S5      e)Nz;The subclass of BaseSamplerV1 must implement `_run` method.)NotImplementedError)r   r7   r8   r9   s       r   r5   BaseSamplerV1._run   s     ""_``r"   r   )r-   zdict | None)N)r7   z)QuantumCircuit | Sequence[QuantumCircuit]r8   z2Sequence[float] | Sequence[Sequence[float]] | Noner#   r   )r7   ztuple[QuantumCircuit, ...]r8   ztuple[tuple[float, ...], ...]r#   r   )r$   r%   r&   r'   r(   __hash__r0   r    r   r5   r)   __classcell__)r1   s   @r   r+   r+   M   s    =~ H
  $" " "  PT
;
 M

 

B a,a 8a
 
a ar"   r+   N)!r(   
__future__r   abcr   r   collections.abcr   r   r   typingr	   r
   qiskit.circuitr   qiskit.providersr   Jobcontainers.primitive_resultr   containers.sampler_pubr   containers.sampler_pub_resultr   validation_v1r   base_primitive_v1r   base_primitive_jobr   r   r   r+   r   r"   r   <module>rN      s`    % " # .  # ) ) 9 3 < 1 . 0Cs'C 'TwaOWQZ war"   