
    iN$                    z   S r SSKJr  SSKJrJr  SSKJrJrJ	r	J
r
JrJr  SSK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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#  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K0J1r1  \Rd                  " \35      r4\
" S\S9r5SSS jjr6 " S S\\\5   5      r7g))Base class for Qiskit Runtime primitives.    )annotations)ABCabstractmethod)DictOptionalUnionTypeVarGenericTypeN)asdictreplace)EstimatorPub)
SamplerPub)	BackendV2   )BaseOptions	OptionsV2)merge_options_v2)RuntimeJobV2)
IBMBackend)validate_isa_circuits$validate_no_dd_with_dynamic_circuitsvalidate_rzz_pubs)get_cm_session)is_simulator)DEFAULT_DECODERS)QiskitRuntimeService)QiskitRuntimeLocalService)Session)BatchOptionsT)boundc                L   [        U [        [        45      (       a  X R                  U R                  4$ [        U [
        5      (       am  [        5       (       aO  [        R                  S5        [        5       R                  U :w  a  [        S5      e[        5       U R                  U 4$ SU R                  U 4$ [        U [        5      (       a  S[        5       U 4$ U b  [        S5      e[        5       (       a&  [        5       n U R                  nU R                  nXU4$ [        S5      e)ai  
A utility function that returns mode, service, and backend for a given execution mode.

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.
zA backend was passed in as the mode but a session context manager is open so this job will run inside this session/batch instead of in job mode.zThe backend passed in to the primitive is different from the session backend. Please check which backend you intend to use or leave the mode parameter empty to use the session backend.Nz4mode must be of type Backend, Session, Batch or Nonez'A backend or session must be specified.)
isinstancer    r!   service_backendr   r   loggerwarning
ValueErrorr   r   )moder&   backends      [/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/base_primitive.py_get_mode_service_backendr.   1   s     $%())\\4==00	D*	%	%NN*
 ((D0 8 
 "#T\\477T\\4''	D)	$	$.0$66		OPP			,,--g%%BCC    c                      \ rS rSr% Sr\rS\S'   Sr  S   SS jjr	SS jr
\SS	 j5       r\SS
 j5       rSS jrSSS jjr\SS j5       r\\SS j5       5       rSrg)BasePrimitiveV2`   r   zType[OptionsT]_options_class   Nc                b    [        U5      u  U l        U l        U l        U R	                  U5        g)aL  Initializes the 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.

    options: Primitive options, see :class:`qiskit_ibm_runtime.options.EstimatorOptions`
        and :class:`qiskit_ibm_runtime.options.SamplerOptions` for detailed description
        on estimator and sampler options, respectively.

Raises:
    ValueError: Invalid arguments are given.
N)r.   _mode_servicer'   _set_options)selfr+   optionss      r-   __init__BasePrimitiveV2.__init__f   s*    * 4MT3R0
DM4='"r/   c           	        SU0n[        U R                  5      nU R                  U5        U R                  R	                  U5      nUR                  U5        U R                  R                  U5      n[        U Vs/ s H  ofR                  PM     snU R                  5        SnU R                  (       a  [        U R                  5      (       d  [        U5        U H  n[        U R                  SS5      (       aE  [        U R                  5      (       d+  [        UR                  /U R                  R                  5        [        U R                  [         5      (       d  M  U R                  R#                  UR                  5        M     [        U R                  SS5      n[$        R'                  SU5        U R(                  (       aM  U R(                  R+                  U R-                  5       UU[.        R0                  " U R-                  5       5      US9$ U R                  (       a  [3        5       (       a3  [$        R5                  SU R-                  5       U R-                  5       5        U R                  US'   S	U;  a8  [        U R                  [         5      (       a  U R                  R6                  US	'   [        U R8                  [:        5      (       aM  U R8                  R+                  U R-                  5       UU[.        R0                  " U R-                  5       5      US
9$ U R8                  R+                  U R-                  5       UUUS9$ s  snf )zgRun the primitive.

Args:
    pubs: Inputs PUBs to pass to the primitive.

Returns:
    Submitted job.
pubsNtargetcalibration_idzSubmitting job using options %s)
program_idinputsr:   result_decoderr@   zEven though a session/batch context manager is open this job will run in job mode because the %s primitive was initialized outside the context manager. Move the %s initialization inside the context manager to run in a session/batch.r,   instance)rA   r:   rB   rC   r@   )rA   r:   rB   r@   )r   r:   _validate_optionsr3   _get_program_inputsupdate_get_runtime_optionsr   circuitr'   r   r   getattrr   r?   r%   r   check_faultyr(   infor6   _run_program_idr   getr   r)   	_instancer7   r   )r9   r>   primitive_inputsoptions_dictprimitive_optionsruntime_optionspubr@   s           r-   rM   BasePrimitiveV2._run~   s    #D>dll+|, //CCLQ 12--BB<P,T-JTckkT-JDLLY==..!$'4==(D99,t}}B]B])3;;-9M9MNdmmZ88MM..s{{;  %T]]4DdKN57HI ::::??++-''/33D4D4D4FG- #   ==g $$&$$& *.OI&0Zz5Z5Z.2mm.E.E
+dmm%9::==%%++-''/33D4D4D4FG- &   }}!!'')##)	 " 
 	
_ .Ks   ;Mc                    U R                   $ )zReturn the execution mode used by this primitive.

Returns:
    Mode used by this primitive, or ``None`` if an execution mode is not used.
)r6   r9   s    r-   r+   BasePrimitiveV2.mode   s     zzr/   c                    U R                   $ )zReturn options)_optionsrX   s    r-   r:   BasePrimitiveV2.options   s     }}r/   c                    U R                   $ )z6Return the backend the primitive query will be run on.)r'   rX   s    r-   r,   BasePrimitiveV2.backend   s    }}r/   c                F   Uc  U R                  5       U l        g[        U[        5      (       a1  U R                  5       nU R                   " S0 [	        X!5      D6U l        g[        XR                   5      (       a  [        U5      U l        g[        SU R                    35      e)zSet options.Nz7Invalid 'options' type. It can only be a dictionary of  )r3   r[   r%   dictr   r   	TypeError)r9   r:   default_optionss      r-   r8   BasePrimitiveV2._set_options   s    ? //1DM&&"113O //]2B?2\]DM!4!455#G,DMI$J]J]I^_ r/   c                    [        5       e)z{Validate that program inputs (options) are valid

Raises:
    ValueError: if resilience_level is out of the allowed range.
NotImplementedError)r9   r:   s     r-   rE   !BasePrimitiveV2._validate_options   s     "##r/   c                    [        5       e)zReturn the program ID.rf   )clss    r-   rN   BasePrimitiveV2._program_id   s     "##r/   )r'   r6   r[   r7   )NN)r+   z/Optional[Union[BackendV2, Session, Batch, str]]r:   Optional[Union[Dict, OptionsT]])r>   z+Union[list[EstimatorPub], list[SamplerPub]]returnr   )rm   zOptional[Session | Batch])rm   r"   )rm   r   N)r:   rl   rm   None)r:   ra   rm   ro   )rm   str)__name__
__module____qualname____firstlineno____doc__r   r3   __annotations__versionr;   rM   propertyr+   r:   r,   r8   r   rE   classmethodrN   __static_attributes__r`   r/   r-   r1   r1   `   s    3%.NN.G AE37#=# 1#0D
L     $ $ $  $r/   r1   rn   )r+   z*Optional[Union[BackendV2, Session, Batch]]rm   zxtuple[Union[Session, Batch, None], Union[QiskitRuntimeService, QiskitRuntimeLocalService, None], Union[BackendV2, None]])8ru   
__future__r   abcr   r   typingr   r   r	   r
   r   r   loggingdataclassesr   r   *qiskit.primitives.containers.estimator_pubr   (qiskit.primitives.containers.sampler_pubr   qiskit.providers.backendr   options.optionsr   r   options.utilsr   runtime_job_v2r   ibm_backendr   utilsr   r   r   utils.default_sessionr   utils.utilsr   	constantsr   qiskit_runtime_servicer   fake_provider.local_servicer   sessionr    batchr!   	getLoggerrq   r(   r"   r.   r1   r`   r/   r-   <module>r      s    0 " # @ @  ' C ? . 3 + ( # 
 2 % ' 8 B  			8	$:[1,D^R$c78, R$r/   