
    z	iD=                        S r SSKJr  SSKrSSKrSSKJrJr  SSK	J
r
JrJr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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SSSSSSSSS.
r#SSS.r$SSSSS.r% " S S\5      r&g)z6Generic BackendV2 class that with a simulated ``run``.    )annotationsN)QuantumCircuitInstruction)BoxOpIfElseOpWhileLoopOp	ForLoopOpSwitchCaseOpBreakLoopOpContinueLoopOp)get_standard_gate_name_mapping)QiskitError)CouplingMapTargetInstructionPropertiesQubitProperties)Options)BasicSimulator)	BackendV2)	optionals)-8tu>m2>h㈵>{Gzt?)gi"`>gi"p>g9̗?-C6?)        r   )g\|>gOЮ*>r   r   )NN)
cxecrczidrzsxxmeasuredelayreset)r   r   r   )1-qmulti-qg<=)r   g-C6*?)g    _Ag   p5}A)dtt1t2	frequencyc                     ^  \ rS rSrSr SSSSSSSS.               SU 4S jjjjr\S 5       r\S	 5       r\SS
 j5       r	\SS j5       r
SS jrS r      SS jrS rSS jr\SS j5       rSrU =r$ )GenericBackendV2G   a  Generic :class:`~.BackendV2` implementation with a configurable constructor. This class will
return a :class:`~.BackendV2` instance that runs on a local simulator (in the spirit of fake
backends) and contains all the necessary information to test backend-interfacing components, such
as the transpiler. A :class:`.GenericBackendV2` instance can be constructed from as little as a
specified ``num_qubits``, but users can additionally configure the basis gates, coupling map,
ability to run dynamic circuits (control flow instructions) and dtm.
The remainder of the backend properties are generated by randomly sampling
from default ranges extracted from historical IBM backend data. The seed for this random
generation can be fixed to ensure the reproducibility of the backend output.
This backend only supports gates in the standard library, if you need a more flexible backend,
there is always the option to directly instantiate a :class:`.Target` object to use for
transpilation.
NFT)coupling_mapcontrol_flowdtmr)   seed
noise_infoc                 > [         T
U ]  SSU S3SU S3SS9  SU l        [        R                  R                  US9U l        XPl        X`l        Xl	        X@l
        [        5       U l        Xl        Uc  [        5       R                  U5      U l        Os[#        U[        5      (       a  X0l        O[        U5      U l        XR                   R%                  5       :w  a*  ['        S	U S
U R                   R%                  5        S35      eUb  UO/ SQU l        S H/  n	XR(                  ;  d  M  U R(                  R+                  U	5        M1     U R-                  5         g)a  
Args:
    num_qubits: Number of qubits that will be used to construct the backend's target.
        Note that, while there is no limit in the size of the target that can be
        constructed, this backend runs on local noisy simulators, and these might
        present limitations in the number of qubits that can be simulated.

    basis_gates: List of basis gate names to be supported by
        the target. These must be part of the standard qiskit circuit library.
        The default set of basis gates is ``["id", "rz", "sx", "x", "cx"]``
        The ``"reset"``,  ``"delay"``, and ``"measure"`` instructions are
        always supported by default, even if not specified via ``basis_gates``.

    coupling_map: Optional coupling map
        for the backend. Multiple formats are supported:

        #. :class:`~.CouplingMap` instance
        #. List, must be given as an edge list representing the two qubit interactions
           supported by the backend, for example:
           ``[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]``

        If ``coupling_map`` is specified, it must match the number of qubits
        specified in ``num_qubits``. If ``coupling_map`` is not specified,
        a fully connected coupling map will be generated with ``num_qubits``
        qubits.

    control_flow: Flag to enable control flow directives on the target
        (defaults to False).

    dtm: System time resolution of output signals in nanoseconds.
        None by default.

    dt: System time resolution of input signals in nanoseconds.
        None by default.

    seed: Optional seed for generation of default values.

    noise_info: If true, associates gates and qubits with default noise information.
Ngeneric_backend_qzThis is a device with z qubits and generic settings. )providernamedescriptionbackend_version)r3   zThe number of qubits (got z8) must match the size of the provided coupling map (got z).)r   r    r!   r"   r#   )r&   r%   r$   )super__init___simnprandomdefault_rng_rng_dtm_dt_num_qubits_control_flowr   _supported_gates_noise_infor   	from_full_coupling_map
isinstancesizer   _basis_gatesappend_build_generic_target)self
num_qubitsbasis_gatesr0   r1   r2   r)   r3   r4   r:   	__class__s             k/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/providers/fake_provider/generic_backend_v2.pyr>   GenericBackendV2.__init__V   sW   h 	#J<q10<YZ	 	 	
 	II))t)4		%) > @%!,!8!8!DD,44%1"%0%>"//4466!0 =BBFBTBTBYBYB[A\\^`  '2K8U 	 2D,,,!!((. 2 	""$    c                    U R                   $ N)_targetrQ   s    rU   targetGenericBackendV2.target   s    ||rW   c                    g rY    r[   s    rU   max_circuitsGenericBackendV2.max_circuits   s    rW   c                >    U R                   b  U R                   S-  $ S$ )z3Return the system time resolution of output signalsNg&.>)rD   r[   s    rU   r2   GenericBackendV2.dtm   s!     $(99#8tyy4BdBrW   c                .    U R                   R                  $ rY   )rZ   concurrent_measurementsr[   s    rU   meas_mapGenericBackendV2.meas_map   s    ||333rW   c                X    U[         ;   a	  [         U   $ US:X  a	  [        S   $ [        S   $ )a  Return noise default values/ranges for duration and error of supported
instructions. There are two possible formats:
    - (min_duration, max_duration, min_error, max_error),
      if the defaults are ranges.
    - (duration, error), if the defaults are fixed values.
   r'   r(   )_NOISE_DEFAULTS_NOISE_DEFAULTS_FALLBACK)rQ   r:   rR   s      rU   _get_noise_defaults$GenericBackendV2._get_noise_defaults   s4     ?""4((?+E22'	22rW   c                6   [         nU R                  (       de  [        SU R                   S3U R                  U R                  c  US   OU R                  S[        [        U R                  5      5      /S9U l        GO[        SU R                   S3U R                  U R                  c  US   OU R                  [        U R                  5       Vs/ s H  n[        U R                  R                  US   S   US   S   5      U R                  R                  US	   S   US	   S   5      U R                  R                  US
   S   US
   S   5      S9PM     sn[        [        U R                  5      5      /S9U l        U R                   GH  nX0R                  ;  a  [        SU S35      eU R                  U   nU R                  UR                  :  a  [        SU SU R                   S35      eU R                  (       a.  U R                  X4R                  5      nU R!                  XE5        M  UR                  S:  a  U R"                  O[        U R                  5      nU Vs0 s H  n[%        U[&        5      (       a  U4OUS_M      nnU R                  R)                  XHUS9  GM     U R*                  (       a  U R                  R)                  [,        SS9  U R                  R)                  [.        SS9  U R                  R)                  [0        SS9  U R                  R)                  [2        SS9  U R                  R)                  [4        SS9  U R                  R)                  [6        SS9  U R                  R)                  [8        SS9  ggs  snf s  snf )zbThis method generates a :class:`~.Target` instance with
default qubit and instruction properties.
zGeneric Target with z qubitsNr)   )r;   rR   r)   qubit_propertiesre   r*   r   ri   r+   r,   )r*   r+   r,   zProvided basis gate z> is not an instruction in the standard qiskit circuit library.z needs more qubits than z#, which is the size of the backend.)
propertiesr:   if_else)r:   
while_loopfor_loopswitch_casebreakcontinuebox)_QUBIT_PROPERTIESrI   r   rF   rE   listrangerZ   r   rC   uniformrN   rH   r   rR   rl    _add_noisy_instruction_to_targetrK   rL   intadd_instructionrG   r   r   r	   r
   r   r   r   )	rQ   rp   _r:   gatenoise_paramsqarg_setqargpropss	            rU   rP   &GenericBackendV2._build_generic_target   sL   
 '
!243C3C2DGL++'+xx'7:d#TXX!%)-eD4D4D.E)F(GDL "243C3C2DGL++'+xx'7:d#TXX #4#3#34	" 5 $99,,Z-=a-@*TBRSTBUV99,,Z-=a-@*TBRSTBUV"&))"3"3&{3A6
;8OPQ8R# 5	" *.eD4D4D.E)F(GDL& %%D000!*4& 1> ?  ((.D0!*4&0HHY Z8 9  #77ooN55dI1511D4--%PTP_P_J`V^_V^dJtS$9$9$tTIV^_,,T$,O% &( LL((	(BLL((<(HLL(((DLL((M(JLL((7(CLL((j(ILL((U(; G	"@ `s   BN&%Nc           	     J   UR                   S:  a  U R                  O[        U R                   5      n0 nU H  n [        U5      n[        U5      S:X  a  UO7U R                  R                  " USS 6 U R                  R                  " USS 6 4u  pxUbC  [        U5      S:  a4  [        S   n	[        Xy-  5      U	-  n
[        US   [        XS   5      5      nUR                  U[        Xx5      05        M     U R                  R                  X5        g! [         a    U4n Nf = f)zAdd instruction properties to target for specified instruction.

Args:
    instruction: Instance of instruction to be added to the target
    noise_params: Error and duration noise values/ranges to
        include in instruction properties.
ri      Nr)   r   )rR   rK   rz   tuple	TypeErrorlenrC   r{   rx   roundmaxminupdater   rZ   r~   )rQ   instructionr   r   r   r   qargsdurationerrorr)   rounded_durations              rU   r|   1GenericBackendV2._add_noisy_instruction_to_target  s&    *5)?)?!)C4%%tI_D d
 |$)  II%%|BQ'78II%%|AB'78 H #L(9A(=&t,#(#7"#< |A4DSTo0VWLL%!6x!GHI) , 	$$[8'    s   DD"!D"c                   Un[        U[        5      (       d;  [        U[        5      (       a  [        S U 5       5      (       d  [	        SU S35      e[
        R                  (       d  [        R                  " S[        5        U R                  c  U R                  5         U R                  U R                  l        U R                  R                  " U40 UD6nU$ )a  Run on the backend using a simulator.

This method runs circuit jobs (an individual or a list of :class:`~.QuantumCircuit`
) using :class:`~.BasicSimulator` or Aer simulator and returns a
:class:`~qiskit.providers.Job` object.

If qiskit-aer is installed, jobs will be run using the ``AerSimulator`` with
noise model of the backend. Otherwise, jobs will be run using the
``BasicSimulator`` simulator without noise.

Args:
    run_input (QuantumCircuit or list): An
        individual or a list of :class:`~qiskit.circuit.QuantumCircuit`
        objects to run on the backend.
    options: Any kwarg options to pass to the backend for running the
        config. If a key is also present in the options
        attribute/object, then the expectation is that the value
        specified will be used instead of what's set in the options
        object.

Returns:
    Job: The job object for the run

Raises:
    QiskitError: If input is not :class:`~qiskit.circuit.QuantumCircuit` or a list of
    :class:`~qiskit.circuit.QuantumCircuit` objects.
c              3  B   #    U  H  n[        U[        5      v   M     g 7frY   )rL   r   ).0r#   s     rU   	<genexpr>'GenericBackendV2.run.<locals>.<genexpr>T  s     Ghz!^44hs   zInvalid input object zE, must be either a QuantumCircuit or a list of QuantumCircuit objectsz/Aer not found using BasicSimulator and no noise)rL   r   ry   allr   
_optionalsHAS_AERwarningswarnRuntimeWarningr?   
_setup_sim_optionsrun)rQ   	run_inputoptionscircuitsjobs        rU   r   GenericBackendV2.run5  s    8 (N338T**GhGGG'z 2E E 
 !!MMK^\99OO!]]		iimmH00
rW   c                    [         R                  (       aR  SSKJn  SSKJn  U" 5       U l        UR                  U 5      nU R                  R                  US9  U R                  US9  g [        5       U l        g )Nr   AerSimulator)
NoiseModel)noise_model)
r   r   
qiskit_aerr   qiskit_aer.noiser   r?   from_backendset_optionsr   )rQ   r   r   r   s       rU   r   GenericBackendV2._setup_simc  s\    /3$DI$11$7KII!!k!: 5&(DIrW   c                    [         R                  (       a  SSKJn  UR	                  5       $ [
        R                  " 5       $ )Nr   r   )r   r   r   r   _default_optionsr   )clsr   s     rU   r   !GenericBackendV2._default_optionsq  s,    /0022!2244rW   )rN   rG   rK   rE   rD   rI   rF   rC   r?   rH   rZ   rY   )rR   r}   rS   zlist[str] | Noner0   z$list[list[int]] | CouplingMap | Noner1   boolr2   float | Noner)   r   r3   z
int | Noner4   r   )returnfloat)r   zlist[list[int]])r:   strrR   r}   r   r   )r   r   r   ztuple[float, ...] | Noner   None)r   r   )r   r   )__name__
__module____qualname____firstlineno____doc__r>   propertyr\   r`   r2   rf   rl   rP   r|   r   r   classmethodr   __static_attributes____classcell__)rT   s   @rU   r.   r.   G   s)   " )-Y%
 >B" Y%Y% &Y%
 ;Y% Y% Y% Y% Y% Y% Y%v     C C
 4 43=<~$9 $9 /$9 
	$9L,\) 5 5rW   r.   )'r   
__future__r   r   numpyr@   qiskit.circuitr   r   qiskit.circuit.controlflowr   r   r   r	   r
   r   r   %qiskit.circuit.library.standard_gatesr   qiskit.exceptionsr   qiskit.transpilerr   r   r   r   qiskit.providersr   qiskit.providers.basic_providerr   qiskit.providers.backendr   qiskit.utilsr   r   rj   rk   rx   r.   r_   rW   rU   <module>r      s    = "   6   Q ) Y Y $ : . 0 //
.
,

,	+6 .-  

	 q5y q5rW   