
    {	i>                     "   S r SSK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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  \R4                  " \5      rSS jr        SS jrS r SS jr SS jr!S r"S r#S r$g)z/
Simplified noise models for devices backends.
    N)warn)infexpallclose)GateMeasure   )_NANOSECOND_UNITS)gate_param_values)readout_error_values)thermal_relaxation_values   )ReadoutError)depolarizing_error)thermal_relaxation_error)
NoiseErrorc                    / nUc~  U c  [        S5      e[        [        U 5      5       HV  u  p4Uc  M
  [        USS/5      (       a  M  SUS   -
  US   /US   SUS   -
  //nUR	                  U/[        U5      45        MX     U$ [        UR                  5       H  nUR                  SS5      nUc  M  UR                  U4S5      nUc  M2  [        US5      (       a)  [        US5      (       a  UR                  UR                  pOUR                  UR                  pSU	-
  U	/U
SU
-
  //nUR	                  U/[        U5      45        M     U$ )a  
Return readout error parameters from either of device Target or BackendProperties.

If ``target`` is supplied, ``properties`` will be ignored.

Args:
    properties (BackendProperties): device backend properties
    target (Target): device backend target

Returns:
    list: A list of pairs ``(qubits, ReadoutError)`` for qubits with
    non-zero readout error values.

Raises:
    NoiseError: if neither properties nor target is supplied.
N-Either properties or target must be supplied.r   r	   measureprob_meas1_prep0prob_meas0_prep1)r   	enumerater   r   appendr   range
num_qubitsgethasattrr   r   error)
propertiestargeterrorsqubitvalueprobabilitiesq
meas_propspropp0m1p1m0s              X/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_aer/noise/device/models.pybasic_device_readout_errorsr+   %   s\   " F~LMM%&::&FGLE %!Q)@)@"#eAh,a!9E!Ha%PQ(l;S Tw](CDE H( M v(()AIt4J!>>1$-D|t/00WTCU5V5V!22D4I4Id!ZZd$h-a$h/?@MMMA3] ;<= * M    c           	         U c  Uc  [        S5      eUb  [        S[        SS9  OSnUb5  U(       d  [        S[        5        U(       a  [        S5      e[	        UUUUS	9$ 0 n/ n	U(       aj  [        U 5      n	U	 V
VVs/ s H  u  poXS
-  4PM     n	nn
nU(       a;  U H5  u  pnU[        U   -  nX;   a  X   R                  UU45        M.  UU4/X'   M7     [        U 5      n/ nU H  u  pnnSnSnUnX;   a0  X    VVs/ s H  u  nnUb  UU:X  d  M  UPM     nnnU(       a  US   nU(       a  [        UUX5      nU(       a  [        UUU5      n[        UU5      nU(       d  M  UR                  XU45        M     U$ s  snnn
f s  snnf )a
  
Return QuantumErrors derived from either of a devices BackendProperties or Target.

If non-default values are used gate_lengths should be a list
of tuples ``(name, qubits, value)`` where ``name`` is the gate
name string, ``qubits`` is either a list of qubits or ``None``
to apply gate time to this gate one any set of qubits,
and ``value`` is the gate time in nanoseconds.

The resulting errors may contains two types of errors: gate errors and relaxation errors.
The gate errors are generated only for ``Gate`` objects while the relaxation errors are
generated for all ``Instruction`` objects. Exceptionally, no ``QuantumError`` s are
generated for ``Measure`` since ``ReadoutError`` s are generated separately instead.

Args:
    properties (BackendProperties): device backend properties.
    gate_error (bool): Include depolarizing gate errors (Default: True).
    thermal_relaxation (Bool): Include thermal relaxation errors (Default: True).
            If no ``t1`` and ``t2`` values are provided (i.e. None) in ``target`` for a qubit,
            an identity ``QuantumError` (i.e. effectively no thermal relaxation error)
            will be added to the qubit even if this flag is set to True.
            If no ``frequency`` is not defined (i.e. None) in ``target`` for a qubit,
            no excitation is considered in the thermal relaxation error on the qubit
            even with non-zero ``temperature``.
    gate_lengths (list): Override device gate times with custom
                         values. If None use gate times from
                         backend properties. (Default: None).
    gate_length_units (str): Time units for gate length values in ``gate_lengths``.
                             Can be 'ns', 'ms', 'us', or 's' (Default: 'ns').
    temperature (double): qubit temperature in milli-Kelvin (mK)
                          (Default: 0).
    warnings (bool): DEPRECATED, Display warnings (Default: None).
    target (Target): device backend target (Default: None). When this is supplied,
                     several options are disabled:
                     ``properties``, ``gate_lengths`` and ``gate_length_units`` are not used
                     during the construction of gate errors.
                     Default values are always used for ``warnings``.

Returns:
    list: A list of tuples ``(label, qubits, QuantumError)``, for gates
    with non-zero quantum error terms, where `label` is the label of the
    noisy gate, `qubits` is the list of qubits for the gate.

Raises:
    NoiseError: If invalid arguments are supplied.
Nr   z"warnings" argument has been deprecated as of qiskit-aer 0.12.0 and will be removed no earlier than 3 months from that release date. Use the warnings filter in Python standard library instead.r   )
stacklevelTzSWhen `target` is supplied, `warnings` are ignored, and they are always set to true.zWhen `target` is supplied, `gate_lengths` option is not allowed.Use `duration` property in target's InstructionProperties instead.)r    
gate_errorthermal_relaxationtemperatureg    eAr   )r   r   DeprecationWarningUserWarning _basic_device_target_gate_errorsr   r
   r   r    _device_thermal_relaxation_error_device_depolarizing_error_combine_depol_and_relax_error)r   r/   r0   gate_lengthsgate_length_unitsr1   warningsr    custom_timesrelax_paramst1t2freqnamequbitsr#   timedevice_gate_paramsr!   gate_lengtherror_paramdepol_errorrelax_error
relax_timer%   valfilteredcombined_errors                               r*   basic_device_gate_errorsrL   R   s   p fnHIIJ 	
 4 U 
 0!1#	
 	
 LL 1<AMNR,N '3#e01BCC' &--vtn=+14.)9L& (4 +:6 F2D.k; 
*6*<Y*<3	QRX[*<HY%a[
:
LK
 4V[+VK 8[Q>MM4893 3E6 MW O0 Zs   ;E;<FFc                 f    U (       a  U(       a  U R                  U5      $ U (       a  U $ U(       a  U$ g N)compose)rF   rG   s     r*   r7   r7      s-    {"";//r,   c           
         / nU R                  5        GHI  u  pVU R                  U5      n[        U[        5      (       a  M.  Uc  M3  UR                  5        GH  u  pU	c  M  Sn
SnU(       a  U	R                  (       aq  U Vs0 s HN  nUU R
                  U   R                  U R
                  U   R                  U R
                  U   R                  4_MP     nn[        UU	R                  UUS9nU(       a;  U	R                  (       a*  [        U[        5      (       a  [        UU	R                  US9n
[        X5      nU(       d  M  UR                  XXU45        GM     GML     U$ s  snf )aj  Return QuantumErrors derived from a devices Target.
Note that, in the resulting error list, non-Gate instructions (e.g. Reset) will have
no gate errors while they may have thermal relaxation errors. Exceptionally,
Measure instruction will have no errors, neither gate errors nor relaxation errors.

Note: Units in use: Time [s], Frequency [Hz], Temperature [mK]
N)rA   	gate_timer<   r1   )rA   rE   rG   )itemsoperation_from_name
isinstancer   durationqubit_propertiesr=   r>   	frequencyr5   r   r   r6   r7   r   )r    r/   r0   r1   r!   op_nameinst_prop_dic	operationrA   	inst_proprF   rG   r%   r<   rK   s                  r*   r4   r4      s`    F"(,,...w7	i)) !.!4!4!6F KK!i&8&8 $  $ //255//255//2<< 
 $    ?!'00!- +	 ioo*Y2M2M8! ) + <KUN~w?@? "7 #1N M5 s   AE#c                 .   Ub  [         R                  " U5      nSU-
  nOSnSnUbo  X:  aj  [        U 5      nSU-  nXfS-   -  n[        X5      n[        U 5      nSU-  nXaU-
  -  Xc-  S-
  -  nSU-  SU-  S-
  -  n	X:  a  [        X5      n[	        X5      $ g)zConstruct a depolarizing_error for device.
If un-physical parameters are supplied, they are truncated to the theoretical bound values.Nr	   r   r      )qiaverage_gate_fidelitylenminr   )
rA   rE   rG   	relax_fidrelax_infidr   dim	error_maxdepol_param	max_params
             r*   r6   r6   #  s    * ,,[9	)m	;#<[
m7O	 +1[
m;673?Q;NOzMQ
]Q%67	"k5K!+::r,   c                     Ub  US:X  a  gSnSnU  Hf  nX&   u  pxn	[        Xx5      nUc  [        nUc  [        n[        X5      n
U(       a  [        XxX5      nSnMI  [        XxX5      nUR	                  U5      nMh     U$ )zConstruct a thermal_relaxation_error for device.

Expected units: frequency in relax_params [Hz], temperature [mK].
Note that gate_time and T1/T2 in relax_params must be in the same time unit.
Nr   TF)_truncate_t2_valuer   _excited_populationr   expand)rA   rQ   r<   r1   firstr   r"   r=   r>   r?   
populationsingles               r*   r5   r5   Q  s     IN EE#*':B:B(;
,RYKEE-biLFLL(E  Lr,   c                 :    U c  U$ Uc  SU -  $ [        USU -  5      $ )z5Return t2 value truncated to 2 * t1 (for t2 > 2 * t1)r   )ra   )r=   r>   s     r*   ri   ri   p  s*    	z		2vr1r6?r,   c                     U b  Uc  gSnU [         :w  a3  US:w  a-  [        SU -  [        U5      -  5      nSSU-   -  nUS:  a  SU-
  nU$ )zDReturn excited state population from freq [Hz] and temperature [mK].r   gui>r	   )r   r   abs)r?   r1   rm   	exp_params       r*   rj   rj   y  sa    |{*Js{{a' 4/3{3CCD	!i-(
?ZJr,   )NN)NTTNnsr   NN)TTr   rN   )%__doc__loggingr:   r   numpyr   r   r   qiskit.quantum_infoquantum_infor^   qiskit.circuitr   r   
parametersr
   r   r   r   errors.readout_errorr   errors.standard_errorsr   r   
noiseerrorr   	getLogger__name__loggerr+   rL   r7   r4   r6   r5   ri   rj    r,   r*   <module>r      s      $ $   ( ) ) , 1 / 7 = #			8	$*\ Od CD2j+\>r,   