
    i(                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJr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K#J$r$  \RJ                  " \&5      r' " S S5      r(g)zQiskit runtime service.    )annotationsN)asdict)CallableDictListLiteralOptionalUnion)BackendEstimatorV2BackendSamplerV2)PrimitiveJob)	BackendV2)QiskitBackendNotFoundError)filter_backends   )FakeBackendV2)FakeProviderForBackendV2)LocalRuntimeJob   )
IBMBackend)RuntimeOptionsc                      \ rS rSrSrSS jr S     SS jjr    S         SS jjr  S     SS jjr          SS jr	          SS	 jr
S
rg)QiskitRuntimeLocalService*   zClass for local testing mode.c                    g)z\QiskitRuntimeLocalService constructor.


Returns:
    An instance of QiskitRuntimeService.

N )selfs    h/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/fake_provider/local_service.py__init__"QiskitRuntimeLocalService.__init__-   s        Nc                &    U R                  US9S   $ )zReturn a single fake backend matching the specified filters.

Args:
    name: The name of the backend.

Returns:
    Backend: A backend matching the filtering.
)namer   backends)r   r#   instances      r   backend!QiskitRuntimeLocalService.backend6   s     }}$}'**r!   c                   [        5       R                  U5      n[        S5      nU(       a5  US:X  a  SSKJn  U" 5       /nO U H  nUR
                  U:X  d  M  U/n  O   UeU(       a#  U Vs/ s H  oR                  U:  d  M  UPM     nnUb'  U Vs/ s H  oR                  5       U:X  d  M  UPM     nn[        XTS9nU(       d  UeU$ s  snf s  snf )a  Return all the available fake backends, subject to optional filtering.

Args:
    name: Backend name to filter by.
    min_num_qubits: Minimum number of qubits the fake backend has to have.
    dynamic_circuits: Filter by whether the fake backend supports dynamic circuits.
    filters: More complex filters, such as lambda functions.
        For example::

            from qiskit_ibm_runtime.fake_provider.local_service import QiskitRuntimeLocalService

            QiskitRuntimeService.backends(
                filters=lambda backend: (backend.online_date.year == 2021)
            )
            QiskitRuntimeLocalService.backends(
                filters=lambda backend: (backend.num_qubits > 30 and backend.num_qubits < 100)
            )

Returns:
    The list of available fake backends that match the filters.

Raises:
    QiskitBackendNotFoundError: If none of the available fake backends matches the given
        filters.
z No backend matches the criteria.aer_simulatorr   )AerSimulator)filters)	r   r%   r   
qiskit_aerr+   r#   
num_qubits_supports_dynamic_circuitsr   )	r   r#   min_num_qubitsdynamic_circuitsr,   r%   errr+   bs	            r   r%   "QiskitRuntimeLocalService.backendsC   s    @ ,-66t<()KL&3(N+!Avv~$%3 "
 I#+N8a||~/M8HN'#+b8a/K/K/MQa/a8Hb"8=I O cs   ,C	C	C-Cc                &    U R                  XS9S   $ )aT  Mimics the :meth:`QiskitRuntimeService.least_busy` method by returning a randomly-chosen
fake backend.

Args:
    min_num_qubits: Minimum number of qubits the fake backend has to have.
    filters: More complex filters, such as lambda functions, that can be defined as for the
        :meth:`backends` method.

Returns:
    A fake backend.
)r0   r,   r   r$   )r   r0   r,   s      r   
least_busy$QiskitRuntimeLocalService.least_busy   s      }}N}LQOOr!   c                   [        U[        5      (       a  [        R                  " U5      nO[	        U5      nUR                  SS5      nUS;  a  [        S5      e[        U[        5      (       a  [        S5      e[        U[        5      (       a  [        S5      eSU;   a  [        R                  " S5        [        R                  " U5      nUb  XBS	'   S
UR                  S
5      0nU R                  UUUR                  S0 5      US9$ )a  Execute the runtime program.

Args:
    program_id: Program ID.
    inputs: Program input parameters. These input values are passed
        to the runtime program.
    options: Runtime options that control the execution environment.
    calibration_id: The calibration id to use with the program execution

Returns:
    A job representing the execution.

Raises:
    ValueError: If input is invalid.
    NotImplementedError: If using V2 primitives.
r'   N)sampler	estimatorz?Only sampler and estimator are supported in local testing mode.zGLocal testing mode is not supported when a cloud-based backend is used.z^Passing a backend name is not supported in local testing mode. Please pass a backend instance.resilience_levelz@The resilience_level option has no effect in local testing mode.calibration_idpubsoptions)r'   	primitiver>   inputs)
isinstancer   copydeepcopyr   pop
ValueErrorr   strwarningswarn_run_backend_primitive_v2get)r   
program_idr@   r>   r<   qrt_optionsr'   primitive_inputss           r   _runQiskitRuntimeLocalService._run   s   . gt$$--0K /K//)T255^__gz**Y  gs##2  'MM\]v&%'5#$"FJJv$67-- JJy"-#	 . 
 	
r!   c                :   [         R                  " U5      n0 nUR                  S0 5      nUR                  SS5      =n(       a  XS'   US:X  Ga  [	        US9n	[        U	R                  S5      n
0 nU
(       a  SU;   a  UR                  S5      nU
(       a  SU;   a  UR                  S5      US'   UR                  SS5      =n(       a  XS'   U
(       ak  UR                  S	0 5      R                  S
S5      =n(       aB  US:X  a  SUS'   O)US:X  a  SUS'   SUS'   OUS:X  a  SUS'   SUS'   OXS	   S
'   US	   (       d  US		 U(       a  XS'   [	        XS9nO[UR                  SS5      =n(       a  S[        R                  " U5      -  US'   UR                  SS5      =n(       a  XS'   [        XS9nU(       d  UR                  SS5        U(       a  [        R                  " SU S35        UR                  " S0 UD6n[        UR                  UR                  UUUS9nU$ )zRun V2 backend primitive.

Args:
    backend: The backend to run the primitive on.
    primitive: Name of the primitive.
    options: Primitive options to use.
    inputs: Primitive inputs.

Returns:
    The job object of the result of the primitive.
	simulatorseed_simulatorNr9   )r'   run_optionsnoise_modeldefault_shots	execution	meas_type
classifiedr   
meas_levelkerneledr   singlemeas_returnavg_kerneledavg)r'   r>   	precisiondefault_precisionzOptions z& have no effect in local testing mode.)functionfuturer'   r?   r@   r   )rB   rC   rJ   rD   r   hasattrr>   mathsqrtr   rG   rH   runr   	_function_future)r   r'   r?   r>   r@   options_copyprim_optionssim_optionsrR   
dummy_primuse_run_optionsrS   rU   rW   primitive_instr`   primitive_joblocal_runtime_jobs                     r   rI   3QiskitRuntimeLocalService._run_backend_primitive_v2   s;   $ }}W-"&&{B7(__-=tDD>D-;)*	!)':J%j&8&8-HOK=L#@*..}==K#?-8__]-KM* , 0 0$ GG}G0=_-)--k2>BB;PTUU	U,01K-*,01K-19K..001K-16K. >G-k:#K0$[1.9]+-gTN , 0 0$ GG}G&'$))M*B&B{#$0$4$45H$$OO O4E01/VN[$/MMH\N2XYZ&**4V4+",, ((
 ! r!   r   )returnNone)NN)r#   rF   r&   rF   rr   r   )NNNN)
r#   Optional[str]r0   Optional[int]r1   zOptional[bool]r,   )Optional[Callable[[FakeBackendV2], bool]]rr   zList[FakeBackendV2])r0   ru   r,   rv   rr   r   )
rK   Literal['sampler', 'estimator']r@   r   r>   zUnion[RuntimeOptions, Dict]r<   rt   rr   r   )
r'   r   r?   rw   r>   dictr@   rx   rr   r   )__name__
__module____qualname____firstlineno____doc__r   r'   r%   r6   rN   rI   __static_attributes__r   r!   r   r   r   *   s   ' 15++*-+	+ #(,+/=A<< &< )	<
 ;< 
<@ )-=AP%P ;P 
	P$6
36
 6
 -	6

 &6
 
6
pR!R! 3R! 	R!
 R! 
R!r!   r   ))r}   
__future__r   rd   rB   loggingrG   dataclassesr   typingr   r   r   r   r	   r
   qiskit.primitivesr   r   qiskit.primitives.primitive_jobr   qiskit.providers.backendr   qiskit.providers.exceptionsr   qiskit.providers.providerutilsr   fake_backendr   fake_providerr   rp   r   ibm_backendr   runtime_optionsr   	getLoggerry   loggerr   r   r!   r   <module>r      s`     "      A A 9 . B : ' 3 . $ ,			8	$s! s!r!   