§
    ²Ûg½>  ã                   ó  — d Z ddlZddlmZ ddlmZmZmZ ddlm	Z
 ddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ  ej        e¦  «        Zdd„Z	 	 	 	 	 	 	 	 dd„Zd„ Z	 dd„Z dd„Z!d„ Z"d„ Z#d„ Z$dS )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                 ó¨  — g }|€“| €t          d¦  «        ‚t          t          | ¦  «        ¦  «        D ]d\  }}|�]t          |ddg¦  «        sKd|d         z
  |d         g|d         d|d         z
  gg}|                     |gt          |¦  «        f¦  «         Œenºt          |j        ¦  «        D ]¥}|                     dd¦  «        }|€Œ|                     |fd¦  «        }|€Œ5t          |d¦  «        rt          |d¦  «        r|j
        |j        }
}	n|j        |j        }
}	d|	z
  |	g|
d|
z
  gg}|                     |gt          |¦  «        f¦  «         Œ¦|S )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              úT/granary/edev/quantum/lib/python3.11/site-packages/qiskit_aer/noise/device/models.pyÚbasic_device_readout_errorsr+   %   s”  € ð" €FØ€~ØÐÝÐLÑMÔMÐMå%Õ&:¸:Ñ&FÔ&FÑGÔGð 	Fð 	F‰LˆE�5ØÐ ­°%¸!¸Q¸Ñ)@Ô)@Ð Ø"# e¨A¤h¡,°°a´Ð!9¸EÀ!¼HÀaÈ%ÐPQÌ(ÁlÐ;SÐ T�Ø—’ ˜w­°]Ñ(CÔ(CÐDÑEÔEÐEøð	Fõ �vÔ(Ñ)Ô)ð 	>ð 	>ˆAØŸš I¨tÑ4Ô4ˆJØÐ!ØØ—>’> 1 $¨Ñ-Ô-ˆDØˆ|ØÝ�tÐ/Ñ0Ô0ð 4µW¸TÐCUÑ5VÔ5Vð 4Ø!Ô2°DÔ4I�d��à!œZ¨¬�d�Ø $™h¨Ð-°°a¸$±hÐ/?Ð@ˆMØ�MŠM˜A˜3¥¨]Ñ ;Ô ;Ð<Ñ=Ô=Ð=Ð=à€Mó    TÚnsc                 óÔ  ‡— | €|€t          d¦  «        ‚|�t          dt          d¬¦  «         nd}|�;|st          dt          ¦  «         |rt          d¦  «        ‚t	          ||||¬	¦  «        S i }g }	|r`t          | ¦  «        }	d
„ |	D ¦   «         }	|rC|D ]@\  }
Š}|t          |         z  }|
|v r||
                              ‰|f¦  «         Œ8‰|fg||
<   ŒAt          | ¦  «        }g }|D ]€\  }
Š}}d}d}|}|
|v rˆfd„||
         D ¦   «         }|r|d         }|rt          ‰||	|¦  «        }|rt          ‰||¦  «        }t          ||¦  «        }|r|                     |
‰|f¦  «         Œ�|S )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.z‚When `target` is supplied, `gate_lengths` option is not allowed.Use `duration` property in target's InstructionProperties instead.)r    Ú
gate_errorÚthermal_relaxationÚtemperaturec                 ó&   — g | ]\  }}}|||d z  f‘ŒS )g    eÍÍA© )Ú.0Út1Út2Úfreqs       r*   ú
<listcomp>z,basic_device_gate_errors.<locals>.<listcomp>¶   s)   € ÐNÐNÐN±°°R¸˜˜R ¨¡Ð,ÐNÐNÐNr,   c                 ó*   •— g | ]\  }}|�|‰k    ¯|‘ŒS ©Nr4   )r5   r%   ÚvalÚqubitss      €r*   r9   z,basic_device_gate_errors.<locals>.<listcomp>Î   s'   ø€ ÐYÐYÐY¡  3ÀÀ	ÈQÐRXÊ[È[˜È[È[È[r,   r   )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   r0   r1   Úgate_lengthsÚgate_length_unitsr2   Úwarningsr    Úcustom_timesÚrelax_paramsÚnamer#   ÚtimeÚdevice_gate_paramsr!   Úgate_lengthÚerror_paramÚdepol_errorÚrelax_errorÚ
relax_timeÚfilteredÚcombined_errorr=   s                         @r*   Úbasic_device_gate_errorsrS   R   sU  ø€ ðp Ð˜f˜nÝÐHÑIÔIÐIàÐÝðJõ Øð	
ñ 	
ô 	
ð 	
ð 	
ð ˆàÐØð 	Ýð4åñô ð ð ð 	ÝðUñô ð õ
 0ØØ!Ø1Ø#ð	
ñ 
ô 
ð 	
ð €LØ€LØð :õ 1°Ñ<Ô<ˆàNÐNÀÐNÑNÔNˆð ð 	:Ø'3ð :ð :Ñ#��f˜eàÕ0Ð1BÔCÑC�Ø˜<Ð'Ð'Ø  Ô&×-Ò-¨v°t¨nÑ=Ô=Ð=Ð=à+1°4¨.Ð)9�L Ñ&Ð&å*¨:Ñ6Ô6Ðð €FØ2Dð :ð :Ñ.ˆˆf�k ;àˆØˆà ˆ
à�<ÐÐØYÐYÐYÐY¨,°tÔ*<ÐYÑYÔYˆHØð )à% aœ[�
àð 	Ý:Ø˜
 L°+ñô ˆKð
 ð 	WÝ4°V¸[È+ÑVÔVˆKõ 8¸À[ÑQÔQˆØð 	:Ø�MŠM˜4 ¨Ð8Ñ9Ô9Ð9øà€Mr,   c                 óH   — | r|r|                       |¦  «        S | r| S |r|S d S r;   )Úcompose)rN   rO   s     r*   rC   rC   ä   sF   € Øð 0�{ð 0Ø×"Ò" ;Ñ/Ô/Ð/Øð ØÐØð ØÐØˆ4r,   c                 óú  ‡ — g }‰                       ¦   «         D ]â\  }}‰                      |¦  «        }t          |t          ¦  «        rŒ0|€Œ3|                      ¦   «         D ]š\  }}	|	€Œd}
d}|r-|	j        r&ˆ fd„|D ¦   «         }t          ||	j        ||¬¦  «        }|r3|	j        r,t          |t          ¦  «        rt          ||	j        |¬¦  «        }
t          |
|¦  «        }|r| 
                    |||f¦  «         Œ›Œã|S )a~  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]
    Nc                 ó|   •— i | ]8}|‰j         |         j        ‰j         |         j        ‰j         |         j        f“Œ9S r4   )Úqubit_propertiesr6   r7   Ú	frequency)r5   r%   r    s     €r*   ú
<dictcomp>z4_basic_device_target_gate_errors.<locals>.<dictcomp>  sZ   ø€ ð  ð  ð  ð ð ØÔ/°Ô2Ô5ØÔ/°Ô2Ô5ØÔ/°Ô2Ô<ðð ð  ð  r,   )r=   Ú	gate_timerH   r2   )r=   rM   rO   )ÚitemsÚoperation_from_nameÚ
isinstancer   ÚdurationrA   r   r   rB   rC   r   )r    r0   r1   r2   r!   Úop_nameÚinst_prop_dicÚ	operationr=   Ú	inst_proprN   rO   rH   rR   s   `             r*   r@   r@   î   st  ø€ ð €FØ"(§,¢,¡.¤.ð %Að %AÑˆ�Ø×.Ò.¨wÑ7Ô7ˆ	Ý�i¥Ñ)Ô)ð 	ØØÐ ØØ!.×!4Ò!4Ñ!6Ô!6ð 	Að 	AÑˆF�IØÐ ØØˆKØˆKà!ð  iÔ&8ð ð ð  ð  ð  ð $ð ñ  ô  �õ ?Ø!Ø'Ô0Ø!-Ø +ð	ñ ô �ð ð ˜iœoð µ*¸YÍÑ2MÔ2Mð Ý8Ø!Ø )¤Ø +ðñ ô �õ <¸KÈÑUÔUˆNØð AØ—’˜w¨°Ð?Ñ@Ô@Ð@øð?	AðB €Mr,   c                 ó`  — |�t          j        |¦  «        }d|z
  }nd}d}|�‹||k    r…t          | ¦  «        }d|z  }||dz   z  }t          ||¦  «        }t          | ¦  «        }d|z  }|||z
  z  ||z  dz
  z  }d|z  d|z  dz
  z  }	||	k    rt          ||	¦  «        }t	          ||¦  «        S dS )zŠConstruct 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   )
r=   rM   rO   Ú	relax_fidÚrelax_infidr   ÚdimÚ	error_maxÚdepol_paramÚ	max_params
             r*   rB   rB   #  sè   € ð* ÐÝÔ,¨[Ñ9Ô9ˆ	Ø˜)‘mˆˆàˆ	ØˆØÐ ;°Ò#<Ð#<Ý˜‘[”[ˆ
Ø�‰mˆØ˜3 ™7‘Oˆ	õ ˜+ yÑ1Ô1ˆå˜‘[”[ˆ
Ø�‰mˆØ˜[¨;Ñ6Ñ7¸3À¹?ÈQÑ;NÑOˆØ�z‘M Q¨
¡]°QÑ%6Ñ7ˆ	Ø˜Ò"Ð"Ý˜k¨9Ñ5Ô5ˆKÝ! +¨zÑ:Ô:Ð:Øˆ4r,   c                 ó$  — |�|dk    rdS d}d}| D ]~}||         \  }}}	t          ||¦  «        }|€t          }|€t          }t          |	|¦  «        }
|rt          ||||
¦  «        }d}ŒWt          ||||
¦  «        }|                     |¦  «        }Œ|S )zÍConstruct 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)r=   r[   rH   r2   Úfirstr   r"   r6   r7   r8   Ú
populationÚsingles               r*   rA   rA   Q  sÁ   € ð Ð˜I¨šN˜NØˆtð €EØ€EØð )ð )ˆØ# EÔ*‰ˆˆB�Ý  BÑ'Ô'ˆØˆ:ÝˆBØˆ:ÝˆBÝ(¨¨{Ñ;Ô;ˆ
Øð 	)Ý,¨R°°YÀ
ÑKÔKˆEØˆEˆEå-¨b°"°iÀÑLÔLˆFØ—L’L Ñ(Ô(ˆEˆEØ€Lr,   c                 ó>   — | €|S |€d| z  S t          |d| z  ¦  «        S )z5Return t2 value truncated to 2 * t1 (for t2 > 2 * t1)Nr   )ri   )r6   r7   s     r*   rq   rq   p  s,   € à	€zØˆ	Ø	ˆØ�2‰vˆÝˆr�1�r‘6‰?Œ?Ðr,   c                 ó¢   — | �|€dS d}| t           k    r;|dk    r5t          d| z  t          |¦  «        z  ¦  «        }dd|z   z  }|dk     rd|z
  }|S )zDReturn excited state population from freq [Hz] and temperature [mK].Nr   gu­ºƒÄi>r	   )r   r   Úabs)r8   r2   ru   Ú	exp_params       r*   rr   rr   y  sp   € à€|�{Ð*ØˆqØ€JØ�s‚{€{�{ aÒ'Ð'õ ˜¨4Ñ/µ3°{Ñ3CÔ3CÑCÑDÔDˆ	Ø˜!˜i™-Ñ(ˆ
Ø˜Š?ˆ?à˜Z™ˆJØÐr,   )NN)NTTNr-   r   NN)TTr   r;   )%Ú__doc__ÚloggingrF   r   Únumpyr   r   r   Úqiskit.quantum_infoÚquantum_inforf   Úqiskit.circuitr   r   Ú
parametersr
   r   r   r   Úerrors.readout_errorr   Úerrors.standard_errorsr   r   Ú
noiseerrorr   Ú	getLoggerÚ__name__Úloggerr+   rS   rC   r@   rB   rA   rq   rr   r4   r,   r*   ú<module>rˆ      sÕ  ððð ð €€€Ø Ð Ð Ð Ð Ð à $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $à  Ð  Ð  Ð  Ð  Ð  Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø )Ð )Ð )Ð )Ð )Ð )Ø )Ð )Ð )Ð )Ð )Ð )Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø /Ð /Ð /Ð /Ð /Ð /Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø =Ð =Ð =Ð =Ð =Ð =Ø #Ð #Ð #Ð #Ð #Ð #à	ˆÔ	˜8Ñ	$Ô	$€ð*ð *ð *ð *ð\ ØØØØØØØðOð Oð Oð Oðdð ð ð CDð2ð 2ð 2ð 2ðj+ð +ð +ð +ð\ð ð ð>ð ð ðð ð ð ð r,   