
    iEZ                        S r SSKrSSKJr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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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'J(r(  SSK)J*r*  \" \5      RV                  S:  a	  SSK,J-r-J.r.  OSSK/J-r-J.r.  \R`                  " \15      r2Sr3Sr4 " S S\5      r5 " S S\55      r6g)z3Module for interfacing with an IBM Quantum Backend.    N)OptionalAnyListUniondatetime)deepcopy)Version)QuantumCircuit__version__)	BackendV2Options)Target   )BackendStatusBackendProperties
GateConfigQasmBackendConfiguration)qiskit_runtime_service)RuntimeClient)IBMBackendApiProtocolErrorIBMBackendError)convert_to_target)properties_from_server_dataconfiguration_from_server_data)local_to_utc   )	MeasLevelMeasReturnTypezcircuit-runnerzqasm3-runnerc                     ^  \ rS rSrSrSr  S'S\SSS\S	\\	   S
\\	   SS4U 4S jjjr
S\	S\4U 4S jjrS(S\SS4S jjr\S\4S j5       r\S\\	S4   4S j5       r\S)S j5       r\S\4S j5       r\S*S j5       r\S\\\      4S j5       r\S\4S j5       rS+S\\   S\4S jjrS*S jr  S,S\S\\   S\\!   4S jjr"S\#4S jr$S\4S jr%S\	4S jr&S-S jr'S \(SS4S! jr)S+S"\*SS 4S# jjr+S*S$ jr,S\	4S% jr-S&r.U =r/$ ).
IBMBackend<   u  Backend class interfacing with an IBM Quantum backend.

Note:

    * You should not instantiate the ``IBMBackend`` class directly. Instead, use
      the methods provided by an :class:`QiskitRuntimeService` instance to retrieve and handle
      backends.

This class represents an IBM Quantum backend. Its attributes and methods provide
information about the backend. For example, the :meth:`status()` method
returns a :class:`BackendStatus<~.providers.models.BackendStatus>` instance.
The instance contains the ``operational`` and ``pending_jobs`` attributes, which state whether
the backend is operational and also the number of jobs in the server queue for the backend,
respectively::

    status = backend.status()
    is_operational = status.operational
    jobs_in_queue = status.pending_jobs

Here is list of attributes available on the ``IBMBackend`` class:

    * name: backend name.
    * backend_version: backend version in the form X.Y.Z.
    * num_qubits: number of qubits.
    * target: A :class:`qiskit.transpiler.Target` object for the backend.
    * basis_gates: list of basis gates names on the backend.
    * gates: list of basis gates on the backend.
    * local: backend is local or remote.
    * simulator: backend is a simulator.
    * conditional: backend supports conditional operations.
    * open_pulse: backend supports open pulse.
    * memory: backend supports memory.
    * coupling_map (list): The coupling map for the device
    * supported_instructions (List[str]): Instructions supported by the backend.
    * dynamic_reprate_enabled (bool): whether delay between primitives can be set dynamically
      (ie via ``rep_delay``). Defaults to False.
    * rep_delay_range (List[float]): 2d list defining supported range of repetition
      delays for backend in μs. First entry is lower end of the range, second entry is
      higher end of the range. Optional, but will be specified when
      ``dynamic_reprate_enabled=True``.
    * default_rep_delay (float): Value of ``rep_delay`` if not specified by user and
      ``dynamic_reprate_enabled=True``.
    * n_uchannels: Number of u-channels.
    * u_channel_lo: U-channel relationship on device los.
    * meas_levels: Supported measurement levels.
    * qubit_lo_range: Qubit lo ranges for each qubit with form (min, max) in GHz.
    * meas_lo_range: Measurement lo ranges for each qubit with form (min, max) in GHz.
    * dt: Qubit drive channel timestep in nanoseconds.
    * dtm: Measurement drive channel timestep in nanoseconds.
    * rep_times: Supported repetition times (program execution time) for backend in μs.
    * meas_kernels: Supported measurement kernels.
    * discriminators: Supported discriminators.
    * hamiltonian: An optional dictionary with fields characterizing the system hamiltonian.
    * channel_bandwidth (list): Bandwidth of all channels
      (qubit, measurement, and U)
    * acquisition_latency (list): Array of dimension
      n_qubits x n_registers. Latency (in units of dt) to write a
      measurement result from qubit n into register slot m.
    * conditional_latency (list): Array of dimension n_channels
      [d->u->m] x n_registers. Latency (in units of dt) to do a
      conditional operation on channel n from register slot m
    * meas_map (list): Grouping of measurement which are multiplexed
    * sample_name (str): Sample name for the backend
    * n_registers (int): Number of register slots available for feedback
      (if conditional is True)
    * register_map (list): An array of dimension n_qubits X
      n_registers that specifies whether a qubit can store a
      measurement in a certain register slot.
    * configurable (bool): True if the backend is configurable, if the
      backend is a simulator
    * credits_required (bool): True if backend requires credits to run a
      job.
    * online_date (datetime): The date that the device went online
    * display_name (str): Alternate name field for the backend
    * description (str): A description for the backend
    * tags (list): A list of string tags to describe the backend
    * version: version of ``Backend`` class (Ex: 1, 2)
    * channels: An optional dictionary containing information of each channel -- their
      purpose, type, and qubits operated on.
    * parametric_pulses (list): A list of pulse shapes which are supported on the backend.
      For example: ``['gaussian', 'constant']``
    * processor_type (dict): Processor type for this backend. A dictionary of the
      form ``{"family": <str>, "revision": <str>, segment: <str>}`` such as
      ``{"family": "Canary", "revision": "1.0", segment: "A"}``.

        * family: Processor family of this backend.
        * revision: Revision version of this processor.
        * segment: Segment this processor belongs to within a larger chip.
FNconfigurationservice+qiskit_runtime_service.QiskitRuntimeService
api_clientinstancecalibration_idreturnc                   > [         TU ]  UR                  UR                  UR                  S9  XPl        X@l        X l        X0l        [        U5      U l
        SU l        SU l        U R                  R                  (       d  [        U R                  S5      (       ae  [        U R                  S5      (       aJ  U R                  R!                  S[#        S5      5        U R                  R!                  S[#        S5      5        [        US5      (       a9  U R                  R!                  SUR$                  S   UR$                  S   45        gg)	zIBMBackend constructor.

Args:
    configuration: Backend configuration.
    service: Instance of QiskitRuntimeService.
    api_client: IBM client used to communicate with the server.
    calibration_id: An optional calibration id to use for this backend
)nameonline_datebackend_versionNnoise_modelseed_simulatorrep_delay_range	rep_delayr   r   )super__init__backend_namer-   r.   _calibration_id	_instance_service_api_clientr	   _configuration_properties_target	simulatorhasattroptionsset_validatortyper1   )selfr$   r%   r'   r(   r)   	__class__s         X/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/ibm_backend.pyr4   IBMBackend.__init__   s     	++%11)99 	 	

  .!%&}5 $ ##--m44&677LL&&}d4jALL&&'7dD="344LL&&..q1=3P3PQR3ST 5    r,   c                   > US;   a/  [        SR                  U R                  R                  U5      5      eU R	                  5         U R                  5          [        TU ]  U5      $ ! [          a     Of = f U R                  R                  U5      $ ! [          a0    [        SR                  U R                  R                  U5      5      ef = f)zGets attribute from self or configuration

This magic method executes when user accesses an attribute that
does not yet exist on IBMBackend class.
)r;   r<   r:   z!'{}' object has no attribute '{}')	AttributeErrorformatrC   __name__
properties_convert_to_targetr3   __getattribute__r:   )rB   r,   rC   s     rD   __getattr__IBMBackend.__getattr__   s     ?? 3::4>>;R;RTXY 
 	!	7+D11 			&&77== 	 3::4>>;R;RTXY 	s   A' '
A43A48B :Crefreshc                 |    U(       d  U R                   (       d$  [        U R                  U R                  S9U l         gg)z>Converts backend configuration and properties to Target objectr$   rK   N)r<   r   r:   r;   )rB   rP   s     rD   rL   IBMBackend._convert_to_target   s.    $,,,"11++DL 'rF   c                 d    [        SS[        R                  [        R                  SSSSSSSSSS9$ )Default runtime options.  FNd   T)shotsmemory
meas_levelmeas_returnmemory_slotsmemory_slot_sizerep_timer2   init_qubitsuse_measure_espuse_fractional_gatesr/   r0   )r   r   
CLASSIFIEDr    AVERAGEclss    rD   _default_optionsIBMBackend._default_options   sD      ++&..  !&
 	
rF   c                     U R                   $ )z)The calibration id used for this backend.)r6   rB   s    rD   r)   IBMBackend.calibration_id   s     ###rF   c                     U R                   $ )zVReturn the ``service`` object

Returns:
    service: instance of QiskitRuntimeService
)r8   ri   s    rD   r%   IBMBackend.service   s     }}rF   c                 .    U R                   R                  $ )znReturn the system time resolution of output signals

Returns:
    dtm: The output signal timestep in seconds.
)r:   dtmri   s    rD   rn   IBMBackend.dtm	  s     ""&&&rF   c                     g)zThis property used to return the `max_experiments` value from the
backend configuration but this value is no longer an accurate representation
of backend circuit limits. New fields will be added to indicate new limits.
N ri   s    rD   max_circuitsIBMBackend.max_circuits  s     rF   c                 .    U R                   R                  $ )zReturn the grouping of measurements which are multiplexed

This is required to be implemented if the backend supports Pulse
scheduling.

Returns:
    meas_map: The grouping of measurements which are multiplexed
)r:   meas_mapri   s    rD   ru   IBMBackend.meas_map  s     ""+++rF   c                 Z    U R                  5         U R                  5         U R                  $ )zQA :class:`qiskit.transpiler.Target` object for the backend.

Returns:
    Target
)rK   rL   r<   ri   s    rD   targetIBMBackend.target'  s$     	!||rF   r   c                 D    [        U R                  U R                  US9S9$ )zuA :class:`qiskit.transpiler.Target` object for the backend.

Returns:
    Target with properties found on `datetime`
r   rR   )r   r:   rK   )rB   r   s     rD   target_historyIBMBackend.target_history2  s(     !--9
 	
rF   c                 8   [        U R                  R                  U R                  5      R	                  U R
                  SU R                  S9U R                  U R                  R                  S9=n(       a  Xl	        U R                  SS9  U R                  SS9  g)zQRetrieve the newest backend configuration and refresh the current backend target.T)rP   r)   )
raw_configr(   ra   )rP   N)r   r8   _get_api_clientr7   backend_configurationr,   r)   r?   ra   r:   rK   rL   )rB   configs     rD   rP   IBMBackend.refresh>  s    3}}44T^^DZZ		48K8K [  ^^!%!B!B
 
6 
 #)%-rF   c                 $   U R                   R                  (       a  g[        U[        5      (       d$  [	        SR                  U[        U5      5      5      eU(       a+  [        U[        5      (       d  [	        S5      e[        U5      nU(       d  U(       d  U R                  cc  U R                  R                  U R                  X R                  S9nU(       d  g[        UU R                  R                   S9nU(       a  U$ X@l	        U R                  $ )a  Return the backend properties, subject to optional filtering.

This data describes qubits properties (such as T1 and T2),
gates properties (such as gate length and error), and other general
properties of the backend.

The schema for backend properties can be found in
`Qiskit/ibm-quantum-schemas/backend_properties
<https://github.com/Qiskit/ibm-quantum-schemas/blob/main/schemas/backend_properties_schema.json>`_.

Args:
    refresh: If ``True``, re-query the server for the backend properties.
        Otherwise, return a cached version.
    datetime: By specifying `datetime`, this function returns an instance
        of the :class:`BackendProperties<~.providers.models.BackendProperties>`
        whose timestamp is closest to, but older than, the specified `datetime`.

Returns:
    The backend properties or ``None`` if the backend properties are not
    currently available.

Raises:
    TypeError: If an input argument is not of the correct type.
    NotImplementedError: If `datetime` is specified when cloud runtime is used.
Nz>The 'refresh' argument needs to be a boolean. {} is of type {}z'{}' is not of type 'datetime'.)r   r)   )ra   )r:   r=   
isinstancebool	TypeErrorrI   rA   python_datetimer   r;   r9   backend_propertiesr,   r)   r   r?   ra   )rB   rP   r   api_propertiesr   s        rD   rK   IBMBackend.propertiesK  s    : (('4((##)6'4=#A  h88 ABB#H-Hw$"2"2":!--@@		H=P=P A N "!<%)\\%F%F" ))1rF   c                     U R                   R                  U R                  5      n [        R                  " U5      $ ! [
         a)  n[        SR                  [        U5      5      5      UeSnAff = f)as  Return the backend status.

Note:
    If the returned :class:`~.providers.models.BackendStatus`
    instance has ``operational=True`` but ``status_msg="internal"``,
    then the backend is accepting jobs but not processing them.

Returns:
    The status of the backend.

Raises:
    IBMBackendApiProtocolError: If the status for the backend cannot be formatted properly.
zPUnexpected return value received from the server when getting backend status: {}N)	r9   backend_statusr,   r   	from_dictr   r   rI   str)rB   
api_statusexs      rD   statusIBMBackend.status  sh     %%44TYY?
	 **:66 	,--3VCG_ 	s   = 
A0$A++A0c                     U R                   $ )a  Return the backend configuration.

Backend configuration contains fixed information about the backend, such
as its name, number of qubits, basis gates, coupling map, quantum volume, etc.

The schema for backend configuration can be found in
`Qiskit/ibm-quantum-schemas/backend_configuration
<https://github.com/Qiskit/ibm-quantum-schemas/blob/main/schemas/backend_configuration_schema.json>`_.

More details about backend configuration properties can be found here `QasmBackendConfiguration
<https://quantum.cloud.ibm.com/docs/api/qiskit/1.4/qiskit.providers.models.QasmBackendConfiguration>`_.

IBM backends may also include the following properties:
    * ``supported_features``: a list of strings of supported features like "qasm3" for dynamic
        circuits support.
    * ``parallel_compilation``: a boolean of whether or not the backend can process multiple
        jobs at once. Parts of the classical computation will be parallelized.

Returns:
    The configuration for the backend.
)r:   ri   s    rD   r$   IBMBackend.configuration  s    0 """rF   c                 b    SR                  U R                  R                  U R                  5      $ )Nz
<{}('{}')>)rI   rC   rJ   r,   ri   s    rD   __repr__IBMBackend.__repr__  s#    ""4>>#:#:DIIFFrF   c                     U $ Nrq   ri   s    rD   __call__IBMBackend.__call__  s    rF   circuitc                   ^ U R                  5       (       d  gU R                  5       R                  5       nU R                  5       R                  5       nU Vs/ s H3  n[        UR                  5      S:  d  M  [        UR                  5      PM5     nnTR                   H  nUR                  R                  S:X  a  M  [        U4S jUR                   5       5      nU H'  nX;   d  M
  [        STR                   SU SU S35      e   [        U5      S	:X  d  M|  Xu;   d  M  [        STR                   SU S
U 35      e   gs  snf )zCheck if the input circuit uses faulty qubits or edges.

Args:
    circuit: Circuit to check.

Raises:
    ValueError: If an instruction operating on a faulty qubit or edge is found.
Nr   barrierc              3   Z   >#    U  H   nTR                  U5      R                  v   M"     g 7fr   )find_bitindex).0xr   s     rD   	<genexpr>*IBMBackend.check_faulty.<locals>.<genexpr>  s"     !R\'"2"21"5";";\s   (+zCircuit z contains instruction z operating on a faulty qubit .r   z operating on a faulty edge )
rK   faulty_qubitsfaulty_gateslenqubitstupledata	operationr,   
ValueError)	rB   r   r   r   gatefaulty_edgesinstrqubit_indices
circ_qubits	    `       rD   check_faultyIBMBackend.check_faulty  s-      )779(5577C\|ts4;;GWZ[G[*dkk*|\\\E##y0!!RU\\!RRM+
.$"7<<.0F '!>zl!M  , =!Q&=+H w||n,Bg9-J  " ]s   E9E_memoc                    [        [        U R                  5       5      U R                  [        U R                  5      U R
                  S9nU R                  Ul        U R                  Ul        U R                  Ul        U R                  Ul	        U R                  Ul
        [        U R                  U5      Ul        [        U R                  U5      Ul        U$ )N)r$   r%   r'   r(   )r"   r	   r$   r8   r9   r7   r,   descriptionr-   r.   _coupling_mapr<   _options)rB   r   cpys      rD   __deepcopy__IBMBackend.__deepcopy__  s    "4#5#5#78MM 0 01^^	
 99****"22 ..t||U3u5
rF   c                     [        S5      e)zH
Raises:
    IBMBackendError: The run() method is no longer supported.

zSupport for backend.run() has been removed. Please see our migration guide https://quantum.cloud.ibm.com/docs/migration-guides/qiskit-runtime for instructions on how to migrate to the primitives interface.)r   )rB   argskwargss      rD   runIBMBackend.run  s     =
 	
rF   c                 <    U R                   R                  (       d  gg)zBReturn the default translation stage plugin name for IBM backends.ibm_dynamic_circuitsibm_dynamic_and_fractional)r?   ra   ri   s    rD   get_translation_stage_plugin'IBMBackend.get_translation_stage_plugin  s    ||00)+rF   )r9   r6   r:   r7   r;   r8   r<   )NN)F)r*   r&   )r*   Nr   FN)r*   r"   )0rJ   
__module____qualname____firstlineno____doc__id_warning_issuedr   r   r   r   r4   r   rN   r   rL   classmethodr   rf   propertyr   r)   r%   floatrn   rr   r   intru   r   rx   r   r{   rP   r   rK   r   r   r$   r   r   r   r   dictr   r   r   __static_attributes____classcell__rC   s   @rD   r"   r"   <   s   Xt  #'(,'/' ?' "	'
 3-' !' 
' 'R  :$ 4  
 
 
& $c4i 0 $ $   'U ' '   	,$tCy/ 	, 	,   

x'@ 

F 

. LP6 6 /7/H6 	#	$6 p 0#	!#4G# G N  t  D$ ,  

,c , ,rF   r"   c            	          ^  \ rS rSrSr SS\SSS\\   SS4U 4S	 jjjr\	S\
4S
 j5       rSS\S\\   SS4S jjrS\4S jr\	 SS\S\\   SS 4S jj5       rSrU =r$ )IBMRetiredBackendi  zIBackend class interfacing with an IBM Quantum device no longer available.Nr$   r%   r&   r'   r*   c                    > [         TU ]  XU5        [        U R                  U R	                  5       R
                  SSSS9U l        g)zIBMRetiredBackend constructor.

Args:
    configuration: Backend configuration.
    service: Instance of QiskitRuntimeService.
    api_client: IBM Quantum client used to communicate with the server.
Fr   z$This backend is no longer available.)r5   r.   operationalpending_jobs
status_msgN)r3   r4   r   r,   r$   r.   _status)rB   r$   r%   r'   rC   s       rD   r4   IBMRetiredBackend.__init__  sB     	<$ ..0@@=
rF   c                     [        SS9$ )rU   rV   )rX   r   rd   s    rD   rf   "IBMRetiredBackend._default_options  s     T""rF   rP   r   c                     g)zReturn the backend properties.Nrq   )rB   rP   r   s      rD   rK   IBMRetiredBackend.properties  s    rF   c                     U R                   $ )zReturn the backend status.r   ri   s    rD   r   IBMRetiredBackend.status#  s    ||rF   r5   apic                 T    [        USSS/ SSSSS[        S/ SS9/SS//S9nU " X25      $ )	z'Return a retired backend from its name.z0.0.0z2019-10-16T04:00:00Zr   FTODO)r,   
parametersqasm_defr   )r5   r.   r-   n_qubitsbasis_gatesr=   localconditional
open_pulserY   gatescoupling_map)r   r   )re   r5   r   r$   s       rD   	from_nameIBMRetiredBackend.from_name'  sQ     1%#.6b6JKa&
 =&&rF   r   r   r   )rJ   r   r   r   r   r   r   r   r4   r   r   rf   r   r   rK   r   r   r   r   r   r   r   s   @rD   r   r     s    S /3	
/
 ?
 ]+	

 

 
, # # #$ (?:S _c    (,'' m$' 
	' 'rF   r   )7r   loggingtypingr   r   r   r   r   r   copyr	   packaging.versionr
   qiskitr   r   qiskit_versionqiskit.providers.backendr   Backendqiskit.providers.optionsr   qiskit.transpiler.targetr   modelsr   r   r   r    r   api.clientsr   
exceptionsr   r   utils.backend_converterr   utils.backend_decoderr   r   utilsr   majorqiskit.resultr   r    qiskit.qobj.utils	getLoggerrJ   loggerQOBJRUNNERPROGRAMIDQASM3RUNNERPROGRAMIDr"   r   rq   rF   rD   <module>r     s    :  - - 0  % @ 9 , +  % & 7  
>  A%77; 
		8	$& % B, B,J;'
 ;'rF   