
    z	i%                    B   S r SSKJr  SSKJr  SSKrSSKJr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S
 jjr S     SS jjrSS jr S     SS jjr S     SS jjr    SS jr      SS jr      SS jrSS jrSS jrS S jrg)!zPrimitive V1 validation methods.

Note that these are not intended to be part of the public API of base primitives
but are here for backward compatibility with BaseSamplerV1 and BaseEstimatorV1 classes.
    )annotations)SequenceN)QuantumCircuitControlFlowOpMeasure)QiskitError)	PauliListSparsePauliOp)BaseOperator)	BasePaulic                    [        U 5      n [        U5      n[        US/[        U 5      -  S9n[	        X5        [        X5        XU4$ )a  Validate run arguments for BaseEstimatorV1.

Args:
    circuits: one or more circuit objects.
    observables: one or more observable objects.
    parameter_values: concrete parameters to be bound.

Returns:
    The formatted arguments ``(circuits, observables, parameter_values)``.

Raises:
    TypeError: If input arguments are invalid types.
    ValueError: if input arguments are invalid values.
 default)_validate_circuits_validate_observables_validate_parameter_valueslen)_cross_validate_circuits_parameter_values$_cross_validate_circuits_observables)circuitsobservablesparameter_valuess      ^/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/primitives/base/validation_v1.py_validate_estimator_argsr      sR    ( "(+H'4K1s8}$ .hI(?"222    c                `    [        U SS9n [        US/[        U 5      -  S9n[        X5        X4$ )aP  Validate run arguments for BaseSamplerV1.

Args:
    circuits: one or more circuit objects.
    parameter_values: concrete parameters to be bound.

Returns:
    The formatted arguments ``(circuits, parameter_values)``.

Raises:
    TypeError: If input arguments are invalid types.
    ValueError: if input arguments are invalid values.
T)requires_measurer   r   )r   r   r   r   )r   r   s     r   _validate_sampler_argsr   A   s?    $ "(TBH1s8}$ .hI%%r   c                    [        U [        5      (       a  U $ [        U [        5      (       a,  [        U [        5      (       d  [	        S[        U 5       35      e[        U [        5      (       a  [	        S[        U 5       35      e[        U 5      $ )a)  Initialize observable by converting the input to a :class:`~qiskit.quantum_info.SparsePauliOp`.

Args:
    observable: The observable.

Returns:
    The observable as :class:`~qiskit.quantum_info.SparsePauliOp`.

Raises:
    QiskitError: when observable type cannot be converted to SparsePauliOp.
zobservable type not supported: )
isinstancer
   r   r   r   typer	   )
observables    r   _init_observabler$   _   sz     *m,,	J	-	-jY6W6W;D<L;MNOOj),, ?Z@P?QRSSZ((r   c                   [        U [        5      (       a  U 4n OW[        U [        5      (       a  [        S U  5       5      (       d  [	        S5      e[        U [
        5      (       d  [        U 5      n [        U 5      S:X  a  [        S5      eU(       aR  [        U 5       HC  u  p#UR                  S:X  a  [        SU S35      e[        U5      (       a  M6  [        SU S35      e   U $ )Nc              3  B   #    U  H  n[        U[        5      v   M     g 7fN)r!   r   ).0cirs     r   	<genexpr>%_validate_circuits.<locals>.<genexpr>|   s      73;C
3''8   z4Invalid circuits, expected Sequence[QuantumCircuit].r   zNo circuits were provided.zThe zv-th circuit does not have any classical bit. Sampler requires classical bits, plus measurements on the desired qubits.zh-th circuit does not have Measure instruction. Without measurements, the circuit cannot be sampled from.)r!   r   r   all	TypeErrortupler   
ValueError	enumerate
num_clbits_has_measure)r   r   icircuits       r   r   r   v   s     (N++;(++3 73;7 4 4 NOO%((?
8}566#H-JA!!Q& 1# - - 
  (( 1# P P  . Or   c                   U c  Uc  [        S5      eUn [        U [        R                  5      (       a  U R	                  5       n O'[        U [
        5      (       a  [        S U  5       5      n [        U 5      (       a  U 44n O/[        U [
        5      (       a  [        S U  5       5      (       d  U 4n [        U [
        5      (       a.  [        S U  5       5      (       a  [        S U  5       5      (       d  [        S5      e[        S U  5       5      $ )Nz9No default `parameter_values`, optional input disallowed.c              3     #    U  H6  n[        U[        R                  5      (       a  UR                  5       OUv   M8     g 7fr'   )r!   npndarraytolistr(   vectors     r   r*   -_validate_parameter_values.<locals>.<genexpr>   s2      !
*  *&"**==FMMO6I*s   >A c              3  B   #    U  H  n[        U[        5      v   M     g 7fr'   r!   r   r;   s     r   r*   r=      s      <3C
68$$3Cr,   c              3  B   #    U  H  n[        U[        5      v   M     g 7fr'   r?   r;   s     r   r*   r=      s     O>NF:fh//>Nr,   c              3  F   #    U  H  n[        S  U 5       5      v   M     g7f)c              3  8   #    U  H  n[        U5      v   M     g 7fr'   )_isrealr(   values     r   r*   7_validate_parameter_values.<locals>.<genexpr>.<genexpr>   s     :6%wu~~6   N)r-   r;   s     r   r*   r=      s      ZIYv3:6:::IY   !z=Invalid parameter values, expected Sequence[Sequence[float]].c              3  F   #    U  H  n[        S  U 5       5      v   M     g7f)c              3  8   #    U  H  n[        U5      v   M     g 7fr'   )floatrD   s     r   r*   rF      s     8uU||rG   N)r/   r;   s     r   r*   r=      s      XGWV8888GWrH   )r0   r!   r8   r9   r:   r   r/   rC   anyr-   r.   )r   r   s     r   r   r      s   
 ?XYY" "BJJ//+224	$h	/	/  !
*!
 
   -/1	$h	/	/ <3C< 9 9 -. '22O>NOOOZIYZZZWXXXGWXXXr   c                    [        U [        5      (       d  [        U [        5      (       d  U 4n [        U 5      S:X  a  [	        S5      e[        S U  5       5      $ )Nr   zNo observables were provided.c              3  8   #    U  H  n[        U5      v   M     g 7fr'   )r$   )r(   obss     r   r*   (_validate_observables.<locals>.<genexpr>   s     >+3!#&&+rG   )r!   strr   r   r0   r/   )r   s    r   r   r      sN     +s##:k8+L+L"n
;1899>+>>>r   c           
     >   [        U 5      [        U5      :w  a$  [        S[        U 5       S[        U5       S35      e[        [        X5      5       HI  u  nu  p4[        U5      UR                  :w  d  M#  [        S[        U5       SUR                   SU S35      e   g )NThe number of circuits (z5) does not match the number of parameter value sets ().zThe number of values (z+) does not match the number of parameters (z
) for the z-th circuit.)r   r0   r1   zipnum_parameters)r   r   r4   r5   r<   s        r   r   r      s     8},--&s8}o 63367G3H2IM
 	
 !*#h*I JGv;'000(V 6--4-C-C,DJqcQ]_  !Kr   c                H   [        U 5      [        U5      :w  a$  [        S[        U 5       S[        U5       S35      e[        [        X5      5       HN  u  nu  p4UR                  UR                  :w  d  M$  [        SU SUR                   SU SUR                   S3	5      e   g )NrS   z,) does not match the number of observables (rT   zThe number of qubits of the z-th circuit (z-) does not match the number of qubits of the z-th observable ()r   r0   r1   rU   
num_qubits)r   r   r4   r5   r#   s        r   r   r      s     8}K((&s8}o 6**-k*:);2?
 	
 %.c(.H$I  G!6!66.qcw?Q?Q>R S99: <))*".  %Jr   c                |    [         [        R                  4n[        X5      =(       a    [        U [        5      (       + $ )zCheck if object is int.)intr8   integerr!   bool)obj	int_typess     r   _isintr_      s*    bjj!Ic%Cjd.C*CCr   c                    [         [        R                  4n[        U 5      =(       d9    [	        X5      =(       a'    [        S5      U s=:  =(       a    [        S5      :  $ s  $ )uL   Check if object is a real number: int or float except ``±Inf`` and ``NaN``.z-InfInf)rK   r8   floatingr_   r!   )r]   float_typess     r   rC   rC      sG    "++&K#;]*S6]5=3;];]QVW\Q];]];]]r   c                   [        U 5       Hu  n[        UR                  [        5      (       a    g[        UR                  [        5      (       d  ME  UR                  R
                   H  n[        U5      (       d  M      g   Mw     g)NTF)reversedr!   	operationr   r   blocksr3   )r5   instructionblocks      r   r3   r3      sc    (k++W55--}==$..55&& 6	 ) r   r'   )r   )Sequence[QuantumCircuit] | QuantumCircuitr   1Sequence[BaseOperator | str] | BaseOperator | strr   :Sequence[Sequence[float]] | Sequence[float] | float | NonereturnFtuple[tuple[QuantumCircuit], tuple[BaseOperator], tuple[tuple[float]]])r   rj   r   rl   rm   rn   )r#   zBaseOperator | strrm   r
   )F)r   rj   r   r\   rm   tuple[QuantumCircuit, ...])r   rl   r   z2Sequence[Sequence[float]] | Sequence[float] | Nonerm   tuple[tuple[float, ...], ...])r   rk   rm   ztuple[SparsePauliOp, ...])r   ro   r   rp   rm   None)r   ro   r   ztuple[BaseOperator, ...]rm   rq   )r]   z3Sequence[Sequence[float]] | Sequence[float] | floatrm   r\   )r5   r   rm   r\   )__doc__
__future__r   collections.abcr   numpyr8   qiskit.circuitr   r   r   qiskit.exceptionsr   qiskit.quantum_infor	   r
   +qiskit.quantum_info.operators.base_operatorr   3qiskit.quantum_info.operators.symplectic.base_paulir   r   r   r$   r   r   r   r   r   r_   rC   r3   r   r   r   <module>r{      s6   # $  A A ) 8 D I TX373B3 Q3 L	3H TX&7&P& L&<)2 #7  B CG#YP#Y?#Y ##YL?B??(<Y	 (7O	"D^r   