§
    ²ÛghÃ  ã                   óˆ  — d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
ZddlmZmZmZ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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- G d„ dej.        ¦  «        Z/ G d„ de¦  «        Z0 G d„ d¦  «        Z1d„ Z2dS )z'
Noise model class for Aer simulators.
é    N)ÚOptional)ÚwarnÚcatch_warningsÚfilterwarnings)ÚQuantumCircuitÚInstructionÚDelayÚReset)Ú	PauliGateÚUnitaryGate)ÚQubitProperties)ÚPassManager)Úapply_prefixé   )Ú_excited_populationÚ_truncate_t2_value)Úbasic_device_gate_errors)Úbasic_device_readout_errors)ÚBaseQuantumError)ÚQuantumError)ÚReadoutError)Ú
NoiseError)ÚRelaxationNoisePassé   )ÚBASIS_GATESc                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚAerJSONEncoderzæ
    JSON encoder for NumPy arrays and complex numbers.

    This functions as the standard JSON Encoder but adds support
    for encoding:
        complex numbers z as lists [z.real, z.imag]
        ndarrays as nested lists.
    c                 ó0  •— t          |t          j        ¦  «        r|                     ¦   «         S t          |t          ¦  «        r|j        |j        gS t          |d¦  «        r|                     ¦   «         S t          ¦   «          
                    |¦  «        S )NÚto_dict)Ú
isinstanceÚnpÚndarrayÚtolistÚcomplexÚrealÚimagÚhasattrr   ÚsuperÚdefault)ÚselfÚoÚ	__class__s     €úR/granary/edev/quantum/lib/python3.11/site-packages/qiskit_aer/noise/noise_model.pyr)   zAerJSONEncoder.default4   s|   ø€ Ý�a�œÑ$Ô$ð 	Ø—8’8‘:”:ÐÝ�a�Ñ!Ô!ð 	$Ø”F˜AœFÐ#Ð#Ý�1�iÑ Ô ð 	Ø—9’9‘;”;ÐÝ‰wŒw�Š˜qÑ!Ô!Ð!ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   Ú__classcell__©r,   s   @r-   r   r   )   sB   ø€ € € € € ðð ð"ð "ð "ð "ð "ð "ð "ð "ð "r.   r   c                   ó&   ‡ — e Zd ZdZdZˆ fd„Zˆ xZS )ÚQuantumErrorLocationz?Instruction for referencing a multi-qubit error in a NoiseModelTc                 óh   •— t          ¦   «                              d|j        dg |j        ¬¦  «         dS )zŽConstruct a new quantum error location instruction.

        Args:
            qerror (QuantumError): the quantum error to reference.
        Ú
qerror_locr   )ÚlabelN)r(   Ú__init__Ú
num_qubitsÚid)r*   Úqerrorr,   s     €r-   r:   zQuantumErrorLocation.__init__C   s3   ø€ õ 	‰Œ×Ò˜ vÔ'8¸!¸RÀvÄyÐÑQÔQÐQÐQÐQr.   )r/   r0   r1   r2   Ú
_directiver:   r3   r4   s   @r-   r6   r6   >   sL   ø€ € € € € ØIÐIà€JðRð Rð Rð Rð Rð Rð Rð Rð Rr.   r6   c                   óÎ  — e Zd ZdZ eg d¢¦  «        Z eg d¢¦  «        Z eddg¦  «        Zd.d„Ze	d„ ¦   «         Z
e	d	„ ¦   «         Ze	d
„ ¦   «         Ze	 	 	 	 	 	 	 d/d„¦   «         Ze	 	 	 	 	 	 	 d/dddededededee         dedee         fd„¦   «         Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd0d„Zd0d „Zd0d!„Zd0d"„Zd1d$„Ze d%„ ¦   «         Z!d&„ Z"d'„ Z#d(„ Z$d)„ Z%d*„ Z&d+„ Z'd,ee(         fd-„Z)dS )2Ú
NoiseModelaœ  Noise model class for Aer simulators.

    This class is used to represent noise model for the
    :class:`~qiskit_aer.QasmSimulator`. It can be used to construct
    custom noise models for simulator, or to automatically generate a basic
    device noise model for an IBMQ backend. See the
    :mod:`~qiskit_aer.noise` module documentation for additional
    information.

    **Example: Basic device noise model**

    An approximate :class:`NoiseModel` can be generated automatically from the
    properties of real device backends from the IBMQ provider using the
    :meth:`~NoiseModel.from_backend` method.

    .. code-block:: python

        from qiskit import IBMQ, Aer
        from qiskit_aer.noise import NoiseModel

        provider = IBMQ.load_account()
        backend = provider.get_backend('ibmq_vigo')
        noise_model = NoiseModel.from_backend(backend)
        print(noise_model)


    **Example: Custom noise model**

    Custom noise models can be used by adding :class:`QuantumError` to circuit
    gate, reset or measure instructions, and :class:`ReadoutError` to measure
    instructions.

    .. code-block:: python

        import qiskit_aer.noise as noise

        # Error probabilities
        prob_1 = 0.001  # 1-qubit gate
        prob_2 = 0.01   # 2-qubit gate

        # Depolarizing quantum errors
        error_1 = noise.depolarizing_error(prob_1, 1)
        error_2 = noise.depolarizing_error(prob_2, 2)

        # Add errors to noise model
        noise_model = noise.NoiseModel()
        noise_model.add_all_qubit_quantum_error(error_1, ['rz', 'sx', 'x'])
        noise_model.add_all_qubit_quantum_error(error_2, ['cx'])
        print(noise_model)

    )Úu1Úu2Úu3ÚuÚpÚrÚrxÚryÚrzr<   ÚxÚyÚzÚhÚsÚsdgÚsxÚsxdgÚtÚtdg)ÚswapÚcxÚcyÚczÚcsxÚcpÚcuÚcu1Úcu2Úcu3ÚrxxÚryyÚrzzÚrzxÚecrÚccxÚcswapNc                 ó,  — |€t          g d¢¦  «        | _        n1t          d„ |                      |¦  «        D ¦   «         ¦  «        | _        t          ¦   «         | _        t          ¦   «         | _        i | _        i | _        d| _        i | _        g | _	        dS )a  Initialize an empty noise model.

        Args:
            basis_gates (list[str] or None): Specify an initial basis_gates
                for the noise model. If None a default value of ['id', 'rz', 'sx', 'cx']
                is used (Default: None).

        Additional Information:
        Errors added to the noise model will have their instruction
        appended to the noise model basis_gates if the instruction is in
        the :class:`~qiskit_aer.QasmSimulator` basis_gates. If
        the instruction is not in the
        :class:`~qiskit_aer.QasmSimulator` basis_gates it is
        assumed to be a label for a standard gate, and that gate should be
        added to the `NoiseModel` basis_gates either using the init method,
        or the :meth:`add_basis_gates` method.
        N)r<   rI   rP   rU   c              3   ó    K  — | ]	\  }}|V — Œ
d S ©N© )Ú.0ÚnameÚ_s      r-   ú	<genexpr>z&NoiseModel.__init__.<locals>.<genexpr>Ç   s&   è è € Ð#dÐ#d©W¨T°1 DÐ#dÐ#dÐ#dÐ#dÐ#dÐ#dr.   )
ÚsetÚ_basis_gatesÚ_instruction_names_labelsÚ_noise_instructionsÚ_noise_qubitsÚ_default_quantum_errorsÚ_local_quantum_errorsÚ_default_readout_errorÚ_local_readout_errorsÚ_custom_noise_passes)r*   Úbasis_gatess     r-   r:   zNoiseModel.__init__¯   s¤   € ð$ Ðõ !$Ð$<Ð$<Ð$<Ñ =Ô =ˆDÔÐå #Ð#dÐ#d¸×8VÒ8VÐWbÑ8cÔ8cÐ#dÑ#dÔ#dÑ dÔ dˆDÔå#&¡5¤5ˆÔ õ !™UœUˆÔð (*ˆÔ$ð
 &(ˆÔ"ð '+ˆÔ#ð &(ˆÔ"à$&ˆÔ!Ð!Ð!r.   c                 ó*   — t          | j        ¦  «        S )z4Return basis_gates for compiling to the noise model.)Úsortedrn   ©r*   s    r-   rw   zNoiseModel.basis_gatesà   s   € õ �dÔ'Ñ(Ô(Ð(r.   c                 ó*   — t          | j        ¦  «        S )z:Return the set of noisy instructions for this noise model.)ry   rp   rz   s    r-   Únoise_instructionszNoiseModel.noise_instructionsæ   s   € õ �dÔ.Ñ/Ô/Ð/r.   c                 ó*   — t          | j        ¦  «        S )z4Return the set of noisy qubits for this noise model.)ry   rq   rz   s    r-   Únoise_qubitszNoiseModel.noise_qubitsë   s   € õ �dÔ(Ñ)Ô)Ð)r.   Tr   Únsc	                 óè  ‡‡— |�t          dt          d¬¦  «         nd}t          |dd¦  «        }	t          |	t          ¦  «        sd}	d}
|	dk    r¯|st          dt
          ¦  «         dŠ|j        }|j        }
|rWt          j	        |
¦  «        }
|D ]@\  }}}|
|         |         }t          ||¦  «        |_        |
                     |||¦  «         ŒA|j        j        }|st          d	|› d
�t
          ¦  «         |j        }n¥|	dk    r�t          dt          d¬¦  «         |                     ¦   «         Š|                     ¦   «         }|j        }ˆfd„t%          |j        ¦  «        D ¦   «         }t          |dd¦  «        }‰st)          d	|› d�¦  «        ‚nt)          |› d�¦  «        ‚t+          |¬¦  «        }|r/t-          ‰|
¬¦  «        D ]\  }}|                     |||¬¦  «         Œt1          ¦   «         5  t3          dt          d¬¦  «         t5          ‰||||‰||
¬¦  «        }ddd¦  «         n# 1 swxY w Y   |D ]\  }}}|                     ||||¬¦  «         Œ |r–|r”	 ˆfd„|D ¦   «         }n# t8          $ r d}Y nw xY w	 d„ |D ¦   «         }d„ |D ¦   «         }t;          d„ |D ¦   «         d„ |D ¦   «         |t<          ||
¬¦  «        }|j                              |¦  «         n# t8          $ r Y nw xY w|S )aŽ  Return a noise model derived from a devices backend properties.

        This function generates a noise model based on:

        * 1 and 2 qubit gate errors consisting of a
          :func:`depolarizing_error` followed
          by a :func:`thermal_relaxation_error`.

        * Single qubit :class:`ReadoutError` on all measurements.

        The error (noise) parameters are tuned for each individual qubit based on
        the :math:`T_1`, :math:`T_2`, frequency and readout error parameters for
        each qubit, and the gate error and gate time parameters for each gate
        obtained from the device backend properties.

        Note that if un-physical parameters are supplied, they are internally truncated to
        the theoretical bound values. For example, if :math:`T_2 > 2 T_1`, :math:`T_2`
        parameter will be truncated to :math:`2 T_1`.

        **Additional Information**

        The noise model includes the following errors:

        * If ``readout_error=True`` include single qubit readout
          errors on measurements.

        * If ``gate_error=True`` and ``thermal_relaxation=True`` include:

            * Single-qubit gate errors consisting of a :func:`depolarizing_error`
              followed by a :func:`thermal_relaxation_error` for the qubit the
              gate acts on.

            * Two-qubit gate errors consisting of a 2-qubit
              :func:`depolarizing_error` followed by single qubit
              :func:`thermal_relaxation_error` on each qubit participating in
              the gate.

        * If ``gate_error=True`` is ``True`` and ``thermal_relaxation=False``:

            * An N-qubit :func:`depolarizing_error` on each N-qubit gate.

        * If ``gate_error=False`` and ``thermal_relaxation=True`` include
          single-qubit :func:`thermal_relaxation_errors` on each qubits
          participating in a multi-qubit gate.

        For best practice in simulating a backend make sure that the
        circuit is compiled using the set of basis gates in the noise
        module by setting ``basis_gates=noise_model.basis_gates``
        and using the device coupling map with
        ``coupling_map=backend.configuration().coupling_map``

        **Specifying custom gate times**

        The ``gate_lengths`` kwarg can be used to specify custom gate times
        to add gate errors using the :math:`T_1` and :math:`T_2` values from
        the backend properties. This should be passed as a list of tuples
        ``gate_lengths=[(name, value), ...]``
        where ``name`` is the gate name string, and ``value`` is the gate time
        in nanoseconds.

        If a custom gate is specified that already exists in
        the backend properties, the ``gate_lengths`` value will override the
        gate time value from the backend properties.
        If non-default values are used gate_lengths should be a list

        Args:
            backend (Backend): backend. For BackendV2, `warnings`
                               options are ignored, and their default values are used.
            gate_error (bool): Include depolarizing gate errors (Default: True).
            readout_error (Bool): Include readout errors in model
                                  (Default: True).
            thermal_relaxation (Bool): Include thermal relaxation errors
                                       (Default: True).
            temperature (double): qubit temperature in milli-Kelvin (mK) for
                                  thermal relaxation errors (Default: 0).
            gate_lengths (list): Custom gate times for thermal relaxation errors.
                                  Used to extend or override the gate times in
                                  the 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').
            warnings (bool): DEPRECATED, Display warnings (Default: None).

        Returns:
            NoiseModel: An approximate noise model for the device backend.

        Raises:
            NoiseError: If the input backend is not valid.
        NzÀ"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   ©Ú
stacklevelTÚversionr   zXWhen a BackendV2 is supplied, `warnings` are ignored, and their default values are used.zQiskit backend ze has no QubitProperties, so the resulting noise model will not include any thermal relaxation errors.r   z¦ from_backend using V1 based backend is deprecated as of Aer 0.15 and will be removed no sooner than 3 months from that release date. Please use backends based on V2.c           	      ó¦   •— g | ]M}t          ‰                     |¦  «        ‰                     |¦  «        ‰                     |¦  «        ¬ ¦  «        ‘ŒNS ))Út1Út2Ú	frequency)r   r…   r†   r‡   )ri   ÚqÚ
propertiess     €r-   ú
<listcomp>z+NoiseModel.from_backend.<locals>.<listcomp>Š  sh   ø€ ð $ð $ð $ð õ  Ø!—}’} QÑ'Ô'¨J¯MªM¸!Ñ,<Ô,<È
×H\ÒH\Ð]^ÑH_ÔH_ðñ ô ð$ð $ð $r.   Údtz" does not have a BackendPropertiesz is not a Qiskit backend©rw   )Útarget©ÚwarningsÚignorezqiskit_aer.noise©ÚcategoryÚmodule)Ú
gate_errorÚthermal_relaxationÚgate_lengthsÚgate_length_unitsÚtemperaturer�   r�   c                 ó<   •— g | ]}t          |j        ‰¬ ¦  «        ‘ŒS ©)Úfreqr˜   ©r   r‡   )ri   rˆ   r˜   s     €r-   rŠ   z+NoiseModel.from_backend.<locals>.<listcomp>°  s8   ø€ ð -ð -ð -àõ (¨Q¬[ÀkÐRÑRÔRð-ð -ð -r.   c                 ó   — g | ]	}|j         ‘Œ
S rh   ©r…   ©ri   Úprops     r-   rŠ   z+NoiseModel.from_backend.<locals>.<listcomp>·  s   € Ð@Ð@Ð@ 4�t”wÐ@Ð@Ð@r.   c                 óB   — g | ]}t          |j        |j        ¦  «        ‘ŒS rh   ©r   r…   r†   rŸ   s     r-   rŠ   z+NoiseModel.from_backend.<locals>.<listcomp>¸  s'   € Ð]Ð]Ð]ÀÕ)¨$¬'°4´7Ñ;Ô;Ð]Ð]Ð]r.   c                 ó.   — g | ]}|€t           j        n|‘ŒS rg   ©r!   Úinf©ri   rJ   s     r-   rŠ   z+NoiseModel.from_backend.<locals>.<listcomp>º  ó"   € ÐAÐAÐA¸ 1 9�œ˜°!ÐAÐAÐAr.   c                 ó.   — g | ]}|€t           j        n|‘ŒS rg   r¤   r¦   s     r-   rŠ   z+NoiseModel.from_backend.<locals>.<listcomp>»  r§   r.   )Út1sÚt2sr‹   Úop_typesÚexcited_state_populationsr�   )!r   ÚDeprecationWarningÚgetattrr    ÚintÚUserWarningÚoperation_namesr�   ÚcopyÚdeepcopyr   ÚdurationÚupdate_instruction_propertiesÚqubit_propertiesr‹   r‰   Úconfigurationrw   Úranger;   r   r@   r   Úadd_readout_errorr   r   r   Úadd_quantum_errorÚ
ValueErrorr   r	   rv   Úappend)ÚclsÚbackendr”   Úreadout_errorr•   r˜   r–   r—   r�   Úbackend_interface_versionr�   rw   Úop_nameÚqubitsÚvaluer    Úall_qubit_propertiesr‹   r·   Únoise_modelÚerrorÚgate_errorsrj   r¬   r©   rª   Ú
delay_passr‰   s        `                     @r-   Úfrom_backendzNoiseModel.from_backendð   s«  øø€ ðJ ÐÝðNõ #Øðñ ô ð ð ð ˆHå$+¨G°YÀÑ$EÔ$EÐ!ÝÐ3µSÑ9Ô9ð 	*Ø()Ð%àˆØ$¨Ò)Ð)Øð ÝðGåñô ð ð
 ˆJØ!Ô1ˆKØ”^ˆFØð Påœ vÑ.Ô.�Ø.:ð Pð PÑ*�G˜V UØ! 'œ?¨6Ô2�DÝ$0°Ð8IÑ$JÔ$J�D”MØ×8Ò8¸À&È$ÑOÔOÐOÐOØ#*¤>Ô#BÐ Ø'ð ÝðS gð Sð Sð Såñô ð ð
 ”ˆBˆBØ&¨!Ò+Ð+åð:õ #Øðñ ô ð ð !×+Ò+Ñ-Ô-ˆJØ#×1Ò1Ñ3Ô3ˆMØ'Ô3ˆKð$ð $ð $ð $õ ˜}Ô7Ñ8Ô8ð	$ñ $ô $Ð õ ˜¨¨aÑ0Ô0ˆBØð `Ý Ð!^°7Ð!^Ð!^Ð!^Ñ_Ô_Ð_ð`õ  ÐAÐAÐAÑBÔBÐBå ¨[Ð9Ñ9Ô9ˆð ð 	PÝ!<¸ZÐPVÐ!WÑ!WÔ!Wð Pð P‘�˜Ø×-Ò-¨e°VÀhÐ-ÑOÔOÐOÐOõ ÑÔð 	ð 	Ý˜8Õ.@ÐI[Ð\Ñ\Ô\Ð\Ý2ØØ%Ø#5Ø)Ø"3Ø'Ø!Øð	ñ 	ô 	ˆKð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð $/ð 	Rð 	RÑˆD�&˜%Ø×)Ò)¨%°°vÈÐ)ÑQÔQÐQÐQàð 	Ð"6ð 	ð1ð-ð -ð -ð -à1ð-ñ -ô -Ð)Ð)øõ ð 1ð 1ð 1Ø,0Ð)Ð)Ð)ð1øøøðØ@Ð@Ð+?Ð@Ñ@Ô@�Ø]Ð]ÐH\Ð]Ñ]Ô]�Ý0ØAÐA¸SÐAÑAÔAØAÐA¸SÐAÑAÔAØÝ"Ø.GØ!ðñ ô �
ð Ô0×7Ò7¸
ÑCÔCÐCÐCøÝð ð ð ð �ðøøøð
 Ðs7   Ç2/H-È-H1È4H1ÉI. É.I=É<I=ÊA K" Ë"
K/Ë.K/Úbackend_propertiesÚBackendPropertiesr”   r¿   r•   r˜   r–   r—   r‹   c	                 ó:  ‡‡— dD ]%}	t          ‰|	¦  «        st          d|	› d�¦  «        ‚Œ&t          ¦   «         }
‰j        D ]}|
                     |j        ¦  «         Œt          |
¦  «        }
t          ‰j        ¦  «        }t          |
¬¦  «        }|r+t          ‰¦  «        D ]\  }}|                     ||¦  «         Œt          ‰||||‰¬¦  «        }|D ]\  }}}|                     |||¦  «         Œ|r§	 ˆˆfd„t          |¦  «        D ¦   «         }n# t          $ r d}Y nw xY w	 t!          ˆfd„t          |¦  «        D ¦   «         ˆfd	„t          |¦  «        D ¦   «         |t"          |¬
¦  «        }|j                             |¦  «         n# t          $ r Y nw xY w|S )aœ
  Return a noise model derived from a backend properties.
        We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`

        This method basically generates a noise model in the same way as
        :meth:`~.NoiseModel.from_backend`. One small difference is that the ``dt`` option is
        required to be set manually if you want to add thermal relaxation noises to delay
        instructions with durations in ``dt`` time unit. Because it is not supplied by a
        :class:`BackendProperties` object unlike a :class:`Backend` object.
        Note that the resulting noise model is the same as described in
        :meth:`~.NoiseModel.from_backend` so please refer to it for the details.

        Args:
            backend_properties (BackendProperties): The property of backend.
                We assume the structure of the class `BackendProperties` in `qiskit-ibm-runtime`
            gate_error (Bool): Include depolarizing gate errors (Default: True).
            readout_error (Bool): Include readout errors in model (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``.
            temperature (double): qubit temperature in milli-Kelvin (mK) for
                                  thermal relaxation errors (Default: 0).
            gate_lengths (Optional[list]): Custom gate times for thermal relaxation errors.
                                  Used to extend or override the gate times in
                                  the 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').
            dt (Optional[float]): Backend sample time (resolution) in seconds (Default: None).
                        Required to convert time unit of durations to seconds
                        if including thermal relaxation errors on delay instructions.

        Returns:
            NoiseModel: An approximate noise model for the device backend.

        Raises:
            NoiseError: If the input backend properties are not valid.
        )ÚgatesrÂ   r‡   r…   r†   z3Backend properties are missing the required field 'ú'rŒ   )r”   r•   r–   r—   r˜   c                 óX   •— g | ]&}t          ‰                     |¦  «        ‰¬ ¦  «        ‘Œ'S rš   rœ   )ri   rˆ   rÊ   r˜   s     €€r-   rŠ   z6NoiseModel.from_backend_properties.<locals>.<listcomp>  sM   ø€ ð -ð -ð -ð õ (Ø/×9Ò9¸!Ñ<Ô<È+ðñ ô ð-ð -ð -r.   Nc                 ó:   •— g | ]}‰                      |¦  «        ‘ŒS rh   rž   ©ri   rˆ   rÊ   s     €r-   rŠ   z6NoiseModel.from_backend_properties.<locals>.<listcomp>'  s(   ø€ ÐMÐMÐM°aÐ+×.Ò.¨qÑ1Ô1ÐMÐMÐMr.   c                 ó|   •— g | ]8}t          ‰                     |¦  «        ‰                     |¦  «        ¦  «        ‘Œ9S rh   r¢   rÑ   s     €r-   rŠ   z6NoiseModel.from_backend_properties.<locals>.<listcomp>(  sR   ø€ ð ð ð àõ +Ð+=×+@Ò+@ÀÑ+CÔ+CÐEW×EZÒEZÐ[\ÑE]ÔE]Ñ^Ô^ðð ð r.   )r©   rª   r‹   r«   r¬   )r'   r   rm   rÍ   ÚaddÚgateÚlistÚlenrÂ   r@   r   r¹   r   rº   r¸   r»   r   r	   rv   r¼   )r½   rÊ   r”   r¿   r•   r˜   r–   r—   r‹   Úrequired_fieldrw   r    r;   rÅ   rÂ   rÆ   rÇ   rj   r¬   rÈ   s    `   `              r-   Úfrom_backend_propertiesz"NoiseModel.from_backend_propertiesÉ  sq  øø€ ðj Kð 	ð 	ˆNÝÐ-¨~Ñ>Ô>ð Ý Ø[È.Ð[Ð[Ð[ñô ð ðõ ‘e”eˆØ&Ô,ð 	'ð 	'ˆDØ�OŠO˜DœIÑ&Ô&Ð&Ð&Ý˜;Ñ'Ô'ˆÝÐ+Ô2Ñ3Ô3ˆ
Ý ¨[Ð9Ñ9Ô9ˆð ð 	=Ý!<Ð=OÑ!PÔ!Pð =ð =‘�˜Ø×-Ò-¨e°VÑ<Ô<Ð<Ð<å.ØØ!Ø1Ø%Ø/Ø#ð
ñ 
ô 
ˆð $/ð 	?ð 	?ÑˆD�&˜%Ø×)Ò)¨%°°vÑ>Ô>Ð>Ð>àð 	ð1ð-ð -ð -ð -ð -õ # :Ñ.Ô.ð	-ñ -ô -Ð)Ð)øõ ð 1ð 1ð 1Ø,0Ð)Ð)Ð)ð1øøøðÝ0ØMÐMÐMÐM½5ÀÑ;LÔ;LÐMÑMÔMðð ð ð å!& zÑ!2Ô!2ðñ ô ð Ý"Ø.Gð	ñ 	ô 	�
ð Ô0×7Ò7¸
ÑCÔCÐCÐCøÝð ð ð ð �ðøøøð
 Ðs%   Ã5D ÄD!Ä D!Ä%A%F Æ
FÆFc                 ó`   — | j         rdS | j        rdS | j        rdS | j        rdS | j        rdS dS )z2Return True if the noise model has no noise terms.FT)rr   rt   rs   ru   rv   rz   s    r-   Úis_idealzNoiseModel.is_ideal8  sY   € ð Ô'ð 	Ø�5ØÔ&ð 	Ø�5ØÔ%ð 	Ø�5ØÔ%ð 	Ø�5ØÔ$ð 	Ø�5Øˆtr.   c                 óP   — d                      t          | j        ¦  «        ¦  «        S )zNoise model reprz<NoiseModel on {}>)ÚformatrÕ   rp   rz   s    r-   Ú__repr__zNoiseModel.__repr__G  s!   € à#×*Ò*­4°Ô0HÑ+IÔ+IÑJÔJÐJr.   c                 ó0  — |                       ¦   «         rdS g }| j        D ]*}|                     d                     |¦  «        ¦  «         Œ+| j        �d|vr|                     d¦  «         g }| j                             ¦   «         D ]3\  }}|                     ¦   «         D ]}|                     ||f¦  «         ŒŒ4| j        D ]}d|f}||vr|                     |¦  «         Œ d}|d                     | j	        ¦  «        z  }| j
        r*|d                     t          | j
        ¦  «        ¦  «        z  }| j        r*|d                     t          | j        ¦  «        ¦  «        z  }|r|d	                     |¦  «        z  }|r|d
                     |¦  «        z  }|S )z!Noise model string representationzNoiseModel: Idealz{}NÚmeasurezNoiseModel:z
  Basis gates: {}z
  Instructions with noise: {}z
  Qubits with noise: {}z
  All-qubits errors: {}z
  Specific qubit errors: {})rÚ   rr   r¼   rÜ   rt   rs   ÚitemsÚkeysru   rw   rp   rÕ   rq   )r*   Údefault_error_opsÚinstÚlocal_error_opsÚdicrÂ   ÚtmpÚoutputs           r-   Ú__str__zNoiseModel.__str__K  sç  € ð �=Š=‰?Œ?ð 	'Ø&Ð&ð ÐØÔ0ð 	8ð 	8ˆDØ×$Ò$ T§[¢[°Ñ%6Ô%6Ñ7Ô7Ð7Ð7ØÔ&Ð2ØÐ 1Ð1Ð1Ø!×(Ò(¨Ñ3Ô3Ð3ð ˆØÔ3×9Ò9Ñ;Ô;ð 	7ð 	7‰IˆD�#ØŸ(š(™*œ*ð 7ð 7�Ø×&Ò&¨¨f ~Ñ6Ô6Ð6Ð6ð7àÔ0ð 	,ð 	,ˆFØ˜fÐ%ˆCØ˜/Ð)Ð)Ø×&Ò& sÑ+Ô+Ð+øàˆØÐ'×.Ò.¨tÔ/?Ñ@Ô@Ñ@ˆØÔ#ð 	_ØÐ7×>Ò>½tÀDÔD\Ñ?]Ô?]Ñ^Ô^Ñ^ˆFØÔð 	SØÐ1×8Ò8½¸dÔ>PÑ9QÔ9QÑRÔRÑRˆFØð 	LØÐ1×8Ò8Ð9JÑKÔKÑKˆFØð 	NØÐ5×<Ò<¸_ÑMÔMÑMˆFØˆr.   c                 ó  — t          |t          ¦  «        r0| j        |j        k    s | j        |j        k    s| j        |j        k    rdS |                      |¦  «        sdS |                      |¦  «        sdS |                      |¦  «        sdS dS )z#Test if two noise models are equal.FT)r    r@   rw   r~   r|   Ú_readout_errors_equalÚ_all_qubit_quantum_errors_equalÚ_local_quantum_errors_equal)r*   Úothers     r-   Ú__eq__zNoiseModel.__eq__p  s¤   € õ ˜5¥*Ñ-Ô-ð	àÔ 5Ô#4Ò4Ð4ØÔ  EÔ$6Ò6Ð6ØÔ&¨%Ô*BÒBÐBà�5à×)Ò)¨%Ñ0Ô0ð 	Ø�5à×3Ò3°EÑ:Ô:ð 	Ø�5Ø×/Ò/°Ñ6Ô6ð 	Ø�5àˆtr.   c                 ó.   — |                       ¦   «          dS )zReset the noise model.N)r:   rz   s    r-   ÚresetzNoiseModel.resetˆ  s   € à�Š‰Œˆˆˆr.   c                 ó–   — |                       |¦  «        D ]2\  }}|t          d         v r|dvr| j                             |¦  «         Œ3dS )a9  Add additional gates to the noise model basis_gates.

        This should be used to add any gates that are identified by a
        custom gate label in the noise model.

        Args:
            instructions (list[str] or
                          list[Instruction]): the instructions error applies to.
        Ú	automatic)rß   rð   Ú
initializeÚkrausÚsuperopÚroerrorN)ro   r   rn   rÓ   )r*   Úinstructionsrj   rk   s       r-   Úadd_basis_gateszNoiseModel.add_basis_gatesŒ  se   € ð ×5Ò5°lÑCÔCð 	0ð 	0‰GˆD�!ð •{ ;Ô/Ð/Ð/ØÐ`Ð`Ð`ØÔ%×)Ò)¨$Ñ/Ô/Ð/øð	0ð 	0r.   c                 óê  — t          |t          ¦  «        s3	 t          |¦  «        }n"# t          $ r}t          d¦  «        |‚d}~ww xY w|                     ¦   «         rdS |                      |¦  «        D ]þ\  }}|                      ||¦  «         || j        v rH| j        |                              |¦  «        }|| j        |<   |rt           
                    d|¦  «         n
|| j        |<   || j        v rP|                      | j        |                              ¦   «         ¦  «        }|rt           
                    d||¦  «         | j                             |¦  «         |                      |¦  «         ŒÿdS )a–  
        Add a quantum error to the noise model that applies to all qubits.

        Args:
            error (QuantumError): the quantum error object.
            instructions (str or list[str] or
                          Instruction or
                          list[Instruction]): the instructions error applies to.
            warnings (bool): Display warning if appending to an instruction that
                             already has an error (Default: True).

        Raises:
            NoiseError: if the input parameters are invalid.

        Additional Information:
            If the error object is ideal it will not be added to the model.
        ú#Input is not a valid quantum error.Nz^WARNING: all-qubit error already exists for instruction "%s", composing with additional error.zlWARNING: all-qubit error for instruction "%s" will not apply to qubits: %s as specific error already exists.)r    r   r   r   Úidealro   Ú_check_number_of_qubitsrr   ÚcomposeÚloggerÚwarningrs   Ú	_keys2strrá   rp   rÓ   rø   )	r*   rÆ   r÷   r�   Úexrj   r9   Ú	new_errorÚlocal_qubitss	            r-   Úadd_all_qubit_quantum_errorz&NoiseModel.add_all_qubit_quantum_error�  s·  € õ& ˜%Õ!1Ñ2Ô2ð 	PðPÝ$ UÑ+Ô+��øÝð Pð Pð PÝ Ð!FÑGÔGÈRÐOøøøøðPøøøð �;Š;‰=Œ=ð 	ØˆFð  ×9Ò9¸,ÑGÔGð 	'ð 	'‰KˆD�%Ø×(Ò(¨°Ñ5Ô5Ð5Ø˜Ô4Ð4Ð4Ø Ô8¸Ô?×GÒGÈÑNÔN�	Ø6?�Ô,¨UÑ3Øð Ý—N’Nð;ð ñ	ô ð øð 7<�Ô,¨UÑ3à˜Ô2Ð2Ð2Ø#Ÿ~š~¨dÔ.HÈÔ.O×.TÒ.TÑ.VÔ.VÑWÔW�Øð Ý—N’Nð?ð Ø$ñô ð ð Ô$×(Ò(¨Ñ/Ô/Ð/Ø× Ò  Ñ&Ô&Ð&Ð&ð5	'ð 	'ó   —' §
A±AÁAc                 ó\  — t          |t          ¦  «        s3	 t          |¦  «        }n"# t          $ r}t          d¦  «        |‚d}~ww xY w	 t	          |¦  «        }n"# t
          $ r}t          d¦  «        |‚d}~ww xY w|                     ¦   «         rdS |D ]}| j                             |¦  «         Œ|  	                    |¦  «        D �]d\  }}|  
                    ||¦  «         t          |t          ¦  «        st          d¦  «        ‚|  
                    ||¦  «         || j        v r| j        |         }	ni }	|j        t          |¦  «        k    r5t          d                     t          |¦  «        |j        ¦  «        ¦  «        ‚||	v r?|	|                              |¦  «        }
|
|	|<   |rt"                               d||¦  «         n||	|<   |	| j        |<   || j        v r|rt"                               d||¦  «         | j                             |¦  «         |                      |¦  «         �ŒfdS )aÄ  
        Add a quantum error to the noise model.

        Args:
            error (QuantumError): the quantum error object.
            instructions (str or list[str] or
                          Instruction or
                          list[Instruction]): the instructions error applies to.
            qubits (Sequence[int]): qubits instruction error applies to.
            warnings (bool): Display warning if appending to an instruction that
                             already has an error (Default: True).

        Raises:
            NoiseError: if the input parameters are invalid.

        Additional Information:
            If the error object is ideal it will not be added to the model.
        rú   Nú1Qubits must be convertible to a tuple of integersz$QuantumCircuit invalid instructions.z9Number of qubits ({}) does not match  the error size ({})zeWARNING: quantum error already exists for instruction "%s" on qubits %s , appending additional error.zxWARNING: Specific error for instruction "%s" on qubits %s overrides previously defined all-qubit error for these qubits.)r    r   r   r   ÚtupleÚ	TypeErrorrû   rq   rÓ   ro   rü   Ústrrs   r;   rÖ   rÜ   rý   rþ   rÿ   rr   rp   rø   )r*   rÆ   r÷   rÂ   r�   r  Úqubitrj   r9   Ú
qubit_dictr  s              r-   rº   zNoiseModel.add_quantum_errorÖ  s©  € õ( ˜%Õ!1Ñ2Ô2ð 	PðPÝ$ UÑ+Ô+��øÝð Pð Pð PÝ Ð!FÑGÔGÈRÐOøøøøðPøøøð	ZÝ˜6‘]”]ˆFˆFøÝð 	Zð 	Zð 	ZÝÐPÑQÔQÐWYÐYøøøøð	Zøøøð �;Š;‰=Œ=ð 	ØˆFàð 	*ð 	*ˆEØÔ×"Ò" 5Ñ)Ô)Ð)Ð)à×9Ò9¸,ÑGÔGð ,	'ñ ,	'‰KˆD�%Ø×(Ò(¨°Ñ5Ô5Ð5Ý˜e¥SÑ)Ô)ð IÝ Ð!GÑHÔHÐHà×(Ò(¨°Ñ5Ô5Ð5Ø˜Ô2Ð2Ð2Ø!Ô7¸Ô>�
�
à�
ð Ô¥3 v¡;¤;Ò.Ð.Ý ð+ß+1ª6µ#°f±+´+¸uÔ?OÑ+PÔ+Pñô ð ð ˜Ð#Ð#Ø& vÔ.×6Ò6°uÑ=Ô=�	Ø%.�
˜6Ñ"Øð Ý—N’Nð8ð Øñô ð øð &+�
˜6Ñ"à0:ˆDÔ& uÑ-ð ˜Ô4Ð4Ð4Øð Ý—N’Nð<ð Øñô ð ð Ô$×(Ò(¨Ñ/Ô/Ð/Ø× Ò  Ñ&Ô&Ð&Ñ&ðY,	'ð ,	'ó,   —' §
A±AÁAÁ
A Á
A9Á$A4Á4A9c                 ó  — t          |t          ¦  «        s3	 t          |¦  «        }n"# t          $ r}t          d¦  «        |‚d}~ww xY w|                     ¦   «         rdS |j        dk    rt          d¦  «        ‚| j        �|rt                               d¦  «         || _        | j        rI|  	                    | j         
                    ¦   «         ¦  «        }|rt                               d|¦  «         | j                             d¦  «         dS )aï  
        Add a single-qubit readout error that applies measure on all qubits.

        Args:
            error (ReadoutError): the quantum error object.
            warnings (bool): Display warning if appending to an instruction that
                             already has an error (Default: True)

        Raises:
            NoiseError: if the input parameters are invalid.

        Additional Information:
            If the error object is ideal it will not be added to the model.
        ú#Input is not a valid readout error.Nr   z=All-qubit readout errors must defined as single-qubit errors.zSWARNING: all-qubit readout error already exists, overriding with new readout error.z}WARNING: The all-qubit readout error will not apply to measure of qubits qubits: %s as specific readout errors already exist.rß   )r    r   r   rû   Únumber_of_qubitsrt   rþ   rÿ   ru   r   rá   rp   rÓ   )r*   rÆ   r�   r  r  s        r-   Úadd_all_qubit_readout_errorz&NoiseModel.add_all_qubit_readout_error(  sA  € õ" ˜%¥Ñ.Ô.ð 	PðPÝ$ UÑ+Ô+��øÝð Pð Pð PÝ Ð!FÑGÔGÈRÐOøøøøðPøøøð �;Š;‰=Œ=ð 	ØˆFð Ô! QÒ&Ð&ÝÐ\Ñ]Ô]Ð]ØÔ&Ð2Øð Ý—’ð9ñô ð ð ',ˆÔ#ð Ô%ð 	ØŸ>š>¨$Ô*D×*IÒ*IÑ*KÔ*KÑLÔLˆLØð Ý—’ð@ð !ñ	ô ð ð 	Ô ×$Ò$ YÑ/Ô/Ð/Ð/Ð/r  c                 óÜ  — t          |t          ¦  «        s3	 t          |¦  «        }n"# t          $ r}t          d¦  «        |‚d}~ww xY w	 t          |¦  «        }n"# t          $ r}t          d¦  «        |‚d}~ww xY w|                     ¦   «         rdS |D ]}| j                             |¦  «         Œ|j        t          |¦  «        k    r5t          d 
                    t          |¦  «        |j        ¦  «        ¦  «        ‚|| j        v r|rt                               d|¦  «         || j        |<   | j        �|rt                               d|¦  «         | j                             d¦  «         dS )a%  
        Add a readout error to the noise model.

        Args:
            error (ReadoutError): the quantum error object.
            qubits (list[int] or tuple[int]): qubits instruction error applies to.
            warnings (bool): Display warning if appending to an instruction that
                             already has an error [Default: True]

        Raises:
            NoiseError: if the input parameters are invalid.

        Additional Information:
            If the error object is ideal it will not be added to the model.
        r  Nr  z@Number of qubits ({}) does not match the readout error size ({})zWWARNING: readout error already exists for qubits %s, overriding with new readout error.zsWARNING: Specific readout error on qubits %s overrides previously defined all-qubit readout error for these qubits.rß   )r    r   r   r  r	  rû   rq   rÓ   r  rÖ   rÜ   ru   rþ   rÿ   rt   rp   )r*   rÆ   rÂ   r�   r  r  s         r-   r¹   zNoiseModel.add_readout_errorZ  sÇ  € õ$ ˜%¥Ñ.Ô.ð 	PðPÝ$ UÑ+Ô+��øÝð Pð Pð PÝ Ð!FÑGÔGÈRÐOøøøøðPøøøð	ZÝ˜6‘]”]ˆFˆFøÝð 	Zð 	Zð 	ZÝÐPÑQÔQÐWYÐYøøøøð	Zøøøð �;Š;‰=Œ=ð 	ØˆFð ð 	*ð 	*ˆEØÔ×"Ò" 5Ñ)Ô)Ð)Ð)ð Ô!¥S¨¡[¤[Ò0Ð0Ýð"ß"(¢&­¨V©¬°eÔ6LÑ"MÔ"Mñô ð ð
 �TÔ/Ð/Ð/Øð Ý—’ð=àñô ð ð
 .3ˆÔ" 6Ñ*ð Ô&Ð2Øð Ý—’ð@ð ñ	ô ð ð 	Ô ×$Ò$ YÑ/Ô/Ð/Ð/Ð/r  Fc                 óî  — g }| j                              ¦   «         D ]4\  }}|                     ¦   «         }|g|d<   |                     |¦  «         Œ5| j                             ¦   «         D ]T\  }}|                     ¦   «         D ]:\  }}|                     ¦   «         }|g|d<   |g|d<   |                     |¦  «         Œ;ŒU| j        �.| j                             ¦   «         }|                     |¦  «         | j                             ¦   «         D ]4\  }}|                     ¦   «         }|g|d<   |                     |¦  «         Œ5d|i}|r-t          j        t          j	        |t          ¬¦  «        ¦  «        }|S )a"  
        Return the noise model as a dictionary.

        Args:
            serializable (bool): if `True`, return a dict containing only types
                that can be serializable by the stdlib `json` module.

        Returns:
            dict: a dictionary for a noise model.
        Ú
operationsÚgate_qubitsNÚerrors)r½   )rr   rà   r   r¼   rs   rt   ru   ÚjsonÚloadsÚdumpsr   )	r*   ÚserializableÚ
error_listrj   rÆ   Ú
error_dictr  rÂ   Úrets	            r-   r   zNoiseModel.to_dict™  sŸ  € ð ˆ
ð  Ô7×=Ò=Ñ?Ô?ð 	*ð 	*‰KˆD�%ØŸš™œˆJØ(, vˆJ�|Ñ$Ø×Ò˜jÑ)Ô)Ð)Ð)ð !%Ô :× @Ò @Ñ BÔ Bð 	.ð 	.ÑˆD�*Ø!+×!1Ò!1Ñ!3Ô!3ð .ð .‘�˜Ø"Ÿ]š]™_œ_�
Ø,0¨6�
˜<Ñ(Ø-3¨H�
˜=Ñ)Ø×!Ò! *Ñ-Ô-Ð-Ð-ð	.ð Ô&Ð2ØÔ4×<Ò<Ñ>Ô>ˆJØ×Ò˜jÑ)Ô)Ð)ð "Ô7×=Ò=Ñ?Ô?ð 	*ð 	*‰MˆF�EØŸš™œˆJØ)/¨ˆJ�}Ñ%Ø×Ò˜jÑ)Ô)Ð)Ð)à˜Ð$ˆØð 	BÝ”*�TœZ¨µÐ@Ñ@Ô@ÑAÔAˆCàˆ
r.   c                 óH  ‡— t          dt          d¬¦  «         d„ Št          ¦   «         }|                      dg ¦  «        }|D �]^}|d         }|dk    rÀˆfd„|d	         D ¦   «         }t	          t          ||d
         ¦  «        ¦  «        }t          |¦  «        }|                     dd¦  «        p|j        |_        |d         }|                     dd¦  «        }	|	�|	D ]}
| 	                    |||
d¬¦  «         ŒŒ¸| 
                    ||d¬¦  «         ŒÑ|dk    rg|d
         }|                     dd¦  «        }	t          |¦  «        }|	�|	D ]}
|                     ||
d¬¦  «         Œ�Œ%|                     |d¬¦  «         �Œ>t          d                     |¦  «        ¦  «        ‚|S )a  
        Load NoiseModel from a dictionary.
        Args:
            noise_dict (dict): A serialized noise model.
        Returns:
            NoiseModel: the noise model.
        Raises:
            NoiseError: if dict cannot be converted to NoiseModel.
        zzfrom_dict has been deprecated as of qiskit-aer 0.15.0 and will be removed no earlier than 3 months from that release date.r   r�   c                 ó’  — t          d„ | D ¦   «         ¦  «        dz   }t          |¦  «        }| D �]—}|d         dk    r*|                     t          ¦   «         |d         ¬¦  «         Œ9|d         dk    rH|                     t	          dt          |d         ¦  «        d|d	         ¬
¦  «        |d         ¬¦  «         Œ�|d         dk    r8|                     t          |d	         d         ¬¦  «        |d         ¬¦  «         ŒÑ|d         dk    r8|                     t          |d	         d         ¦  «        |d         ¬¦  «         �Œt          ¦   «         5  t          dt          d¬¦  «         |                     t          |d         t          |d         ¦  «        ¬¦  «        |d         ¬¦  «         d d d ¦  «         n# 1 swxY w Y   �Œ™|S )Nc              3   ó@   K  — | ]}t          |d          ¦  «        V — ŒdS )rÂ   N)Úmax)ri   rå   s     r-   rl   zINoiseModel.from_dict.<locals>.inst_dic_list_to_circuit.<locals>.<genexpr>Ø  s.   è è € ÐDÐD°C�S  X¤Ñ/Ô/ÐDÐDÐDÐDÐDÐDr.   r   rj   rð   rÂ   )Úqargsrô   r   Úparams)rj   r;   Ú
num_clbitsr#  Úunitary)ÚdataÚpaulir�   z"qiskit_aer.noise.errors.errorutilsr‘   )r9   r&  )r!  r   r¼   r
   r   rÖ   r   r   r   r   r­   Ú_standard_gate_unitary)Údic_listr;   Úcircrå   s       r-   Úinst_dic_list_to_circuitz6NoiseModel.from_dict.<locals>.inst_dic_list_to_circuit×  s,  € ÝÐDÐD¸8ÐDÑDÔDÑDÔDÀqÑHˆJÝ! *Ñ-Ô-ˆDØð ñ �Ø�v”; 'Ò)Ð)Ø—K’K¥¡¤¨s°8¬}�KÑ=Ô=Ð=Ð=Ø˜”[ GÒ+Ð+Ø—K’KÝ#Ø!(Ý'*¨3¨x¬=Ñ'9Ô'9Ø'(Ø#& x¤=ð	ñ ô ð " (œmð  ñ ô ð ð ð ˜”[ IÒ-Ð-Ø—K’K¥°°X´¸qÔ1AÐ BÑ BÔ BÈ#ÈhÌ-�KÑXÔXÐXÐXØ˜”[ GÒ+Ð+Ø—K’K¥	¨#¨h¬-¸Ô*:Ñ ;Ô ;À3ÀxÄ=�KÑQÔQÐQÑQå'Ñ)Ô)ð ð Ý&Ø$Ý%7Ø#Gðñ ô ð ð
 ŸšÝ'Ø&)¨&¤kÕ8NÈsÐSYÌ{Ñ8[Ô8[ðñ ô ð #& h¤-ð	 $ñ ô ð ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ùð ˆKs   ÅAF:Æ:F>	ÇF>	r  Útyper=   c                 ó&   •— g | ]} ‰|¦  «        ‘ŒS rh   rh   )ri   Údicsr+  s     €r-   rŠ   z(NoiseModel.from_dict.<locals>.<listcomp>  s%   ø€ Ð]Ð]Ð]¸tÐ4Ð4°TÑ:Ô:Ð]Ð]Ð]r.   r÷   Úprobabilitiesr<   Nr  r  FrŽ   rö   zInvalid error type: {})r   r­   r@   Úgetr  Úzipr   r<   Ú_idrº   r  r   r¹   r  r   rÜ   )Ú
noise_dictrÅ   r  rÆ   Ú
error_typeÚcircuitsÚ	noise_opsr=   Úinstruction_namesÚall_gate_qubitsr  r/  rö   r+  s                @r-   Ú	from_dictzNoiseModel.from_dictÅ  s(  ø€ õ 	ðTåØð		
ñ 	
ô 	
ð 	
ð!	ð !	ð !	õH !‘l”lˆð —’ ¨"Ñ-Ô-ˆàð %	Nñ %	NˆEØ˜vœˆJð ˜XÒ%Ð%Ø]Ð]Ð]Ð]ÀuÈ^ÔG\Ð]Ñ]Ô]�Ý!¥# h°°oÔ0FÑ"GÔ"GÑHÔH�	Ý% iÑ0Ô0�Ø"ŸYšY t¨TÑ2Ô2Ð?°f´i�”
Ø$)¨,Ô$7Ð!Ø"'§)¢)¨M¸4Ñ"@Ô"@�Ø"Ð.Ø'6ð ð ˜à#×5Ò5Ø"Ð$5°{ÈUð 6ñ ô ð ð ðð  ×;Ò;ØÐ 1¸Eð <ñ ô ð ð ð
 ˜yÒ(Ð(Ø % oÔ 6�Ø"'§)¢)¨M¸4Ñ"@Ô"@�Ý& }Ñ5Ô5�à"Ð.Ø'6ð \ð \˜Ø#×5Ò5°g¸{ÐUZÐ5Ñ[Ô[Ð[Ð[ñ\ð  ×;Ò;¸GÈeÐ;ÑTÔTÐTÑTõ !Ð!9×!@Ò!@ÀÑ!LÔ!LÑMÔMÐMØÐr.   c                 ó‚  — t          |t          t          f¦  «        s|g}g }|D ]š}t          |t          ¦  «        r5|j        }t          |d|j        ¦  «        }|                     ||f¦  «         ŒLt          |t          ¦  «        r|                     ||f¦  «         Œyt          d 	                    |¦  «        ¦  «        ‚|S )z?Return two lists of instruction name strings and label strings.r9   zInvalid instruction type {})
r    rÕ   r  r   rj   r®   r¼   r
  r   rÜ   )r*   r÷   Únames_labelsrã   rj   r9   s         r-   ro   z$NoiseModel._instruction_names_labels(  sÐ   € å˜,­­u¨Ñ6Ô6ð 	*Ø(˜>ˆLØˆØ ð 
	Mð 
	MˆDõ ˜$¥Ñ,Ô,ð MØ”y�Ý  g¨t¬yÑ9Ô9�Ø×#Ò# T¨5 MÑ2Ô2Ð2Ð2Ý˜D¥#Ñ&Ô&ð MØ×#Ò# T¨4 LÑ1Ô1Ð1Ð1å Ð!>×!EÒ!EÀdÑ!KÔ!KÑLÔLÐLØÐr.   c                 ó"  ‡‡— ˆˆfd„}‰| j         v r#‰j        dk    rt           |d¦  «        ¦  «        ‚‰| j        v r#‰j        dk    rt           |d¦  «        ¦  «        ‚‰| j        v r#‰j        dk    rt           |d¦  «        ¦  «        ‚dS dS )aA  
        Check if error is corrected number of qubits for standard instruction.

        Args:
            error (QuantumError): the quantum error object.
            name (str): qobj instruction name to apply error to.

        Raises:
            NoiseError: If instruction and error qubit number do not match.
        c                 ó”   •— d                      ‰j        ¦  «        d                      | ¦  «        z   d                      ‰¦  «        z   }|S )Nz{} qubit QuantumErrorz cannot be applied to {} qubitz instruction "{}".)rÜ   r;   )r  ÚmsgrÆ   rj   s     €€r-   Úerror_messagez9NoiseModel._check_number_of_qubits.<locals>.error_messageF  sP   ø€ à'×.Ò.¨uÔ/?Ñ@Ô@Ø2×9Ò9¸+ÑFÔFñGà&×-Ò-¨dÑ3Ô3ñ4ð ð
 ˆJr.   r   r   é   N)Ú_1qubit_instructionsr;   r   Ú_2qubit_instructionsÚ_3qubit_instructions)r*   rÆ   rj   r?  s    `` r-   rü   z"NoiseModel._check_number_of_qubits:  sË   øø€ ð	ð 	ð 	ð 	ð 	ð 	ð �4Ô,Ð,Ð,°Ô1AÀQÒ1FÐ1FÝ˜]˜]¨1Ñ-Ô-Ñ.Ô.Ð.Ø�4Ô,Ð,Ð,°Ô1AÀQÒ1FÐ1FÝ˜]˜]¨1Ñ-Ô-Ñ.Ô.Ð.Ø�4Ô,Ð,Ð,°Ô1AÀQÒ1FÐ1FÝ˜]˜]¨1Ñ-Ô-Ñ.Ô.Ð.ð -Ð,Ð1FÐ1Fr.   c                 óT   — d                      d„ |D ¦   «         ¦  «        }|dd…         S )z8Convert dicitonary keys to comma seperated print string.Ú c                 ó8   — g | ]}d                       |¦  «        ‘ŒS )z{}, )rÜ   )ri   Úkeys     r-   rŠ   z(NoiseModel._keys2str.<locals>.<listcomp>W  s$   € Ð:Ð:Ð:¨c�v—}’} SÑ)Ô)Ð:Ð:Ð:r.   Néþÿÿÿ)Újoin)r*   rá   ræ   s      r-   r   zNoiseModel._keys2strU  s/   € à�gŠgÐ:Ð:°TÐ:Ñ:Ô:Ñ;Ô;ˆØ�3�B�3Œxˆr.   c                 ó0  — | j         |j         k    rdS t          | j                             ¦   «         ¦  «        t          |j                             ¦   «         ¦  «        k    rdS | j                             ¦   «         D ]\  }}||j        |         k    r dS ŒdS )z0Check two noise models have equal readout errorsFT)rt   ry   ru   rá   rà   ©r*   rí   rG  rÃ   s       r-   rê   z NoiseModel._readout_errors_equalZ  sž   € ð Ô&¨%Ô*FÒFÐFØ�5å�$Ô,×1Ò1Ñ3Ô3Ñ4Ô4½¸uÔ?Z×?_Ò?_Ñ?aÔ?aÑ8bÔ8bÒbÐbØ�5ØÔ4×:Ò:Ñ<Ô<ð 	ð 	‰JˆC�Ø˜Ô3°CÔ8Ò8Ð8Ø�u�uð 9àˆtr.   c                 ó  — t          | j                             ¦   «         ¦  «        t          |j                             ¦   «         ¦  «        k    rdS | j                             ¦   «         D ]\  }}||j        |         k    r dS ŒdS ©z6Check two noise models have equal local quantum errorsFT)ry   rr   rá   rà   rK  s       r-   rë   z*NoiseModel._all_qubit_quantum_errors_equalg  s‘   € å�$Ô.×3Ò3Ñ5Ô5Ñ6Ô6½&ØÔ)×.Ò.Ñ0Ô0ñ;
ô ;
ò 
ð 
ð �5ØÔ6×<Ò<Ñ>Ô>ð 	ð 	‰JˆC�Ø˜Ô5°cÔ:Ò:Ð:Ø�u�uð ;àˆtr.   c                 ó  — t          | j                             ¦   «         ¦  «        t          |j                             ¦   «         ¦  «        k    rdS | j                             ¦   «         D ]—\  }}|j        |         }t          |                     ¦   «         ¦  «        t          |                     ¦   «         ¦  «        k    r dS |                     ¦   «         D ]\  }}|||         k    r  dS Œ||j        |         k    r dS Œ˜dS rM  )ry   rs   rá   rà   )r*   rí   rG  rÃ   Úinner_dict2Ú	inner_keyÚinner_values          r-   rì   z&NoiseModel._local_quantum_errors_equalr  s  € å�$Ô,×1Ò1Ñ3Ô3Ñ4Ô4½¸uÔ?Z×?_Ò?_Ñ?aÔ?aÑ8bÔ8bÒbÐbØ�5ØÔ4×:Ò:Ñ<Ô<ð 	ð 	‰JˆC�ØÔ5°cÔ:ˆKÝ�e—j’j‘l”lÑ#Ô#¥v¨k×.>Ò.>Ñ.@Ô.@Ñ'AÔ'AÒAÐAØ�u�uØ*/¯+ª+©-¬-ð !ð !Ñ&�	˜;Ø +¨iÔ"8Ò8Ð8Ø ˜5˜5˜5ð 9à˜Ô3°CÔ8Ò8Ð8Ø�u�uð 9àˆtr.   Úreturnc                 ó‚   — g }|                      | j        ¦  «         t          |¦  «        dk    rt          |¦  «        S dS )zü
        Return the pass manager that add custom noises defined as noise passes
        (stored in the _custom_noise_passes field). Note that the pass manager
        does not include passes to add other noises (stored in the different field).
        r   N)Úextendrv   rÖ   r   )r*   Úpassess     r-   Ú_pass_managerzNoiseModel._pass_manager�  s@   € ð ˆØ�Š�dÔ/Ñ0Ô0Ð0Ýˆv‰;Œ;˜Š?ˆ?Ý˜vÑ&Ô&Ð&Øˆtr.   rg   )TTTr   Nr   N)T)F)*r/   r0   r1   r2   rm   rA  rB  rC  r:   Úpropertyrw   r|   r~   ÚclassmethodrÉ   ÚboolÚfloatr   rÕ   r
  rØ   rÚ   rÝ   rè   rî   rð   rø   r  rº   r  r¹   r   Ústaticmethodr9  ro   rü   r   rê   rë   rì   r   rV  rh   r.   r-   r@   r@   L   s"  € € € € € ð2ð 2ðj ˜3ð	
ð 	
ð 	
ñô Ðð0 ˜3ð	
ð 	
ð 	
ñô Ðð& ˜3  wÐ/Ñ0Ô0Ðð/'ð /'ð /'ð /'ðb ð)ð )ñ „Xð)ð
 ð0ð 0ñ „Xð0ð ð*ð *ñ „Xð*ð ð ØØØØØØðVð Vð Vñ „[ðVðp ð  Ø"Ø#'ØØ'+Ø!%Ø"ðlð là/ðlð ðlð ð	lð
 !ðlð ðlð ˜t”nðlð ðlð �UŒOðlð lð lñ „[ðlð\ð ð ðKð Kð Kð#ð #ð #ðJð ð ð0ð ð ð0ð 0ð 0ð"7'ð 7'ð 7'ð 7'ðrP'ð P'ð P'ð P'ðd00ð 00ð 00ð 00ðd=0ð =0ð =0ð =0ð~*ð *ð *ð *ðX ð`ð `ñ „\ð`ðDð ð ð$/ð /ð /ð6ð ð ð
ð ð ð	ð 	ð 	ðð ð ð
˜x¨Ô4ð 
ð 
ð 
ð 
ð 
ð 
r.   r@   c                 óæ  ‡ — i dt          j        dt          ¬¦  «        “dt          j        ddgddggt          ¬¦  «        “dt          j        ddgd	dggt          ¬¦  «        “d
t          j        ddgddggt          ¬¦  «        “dt          j        ddgddggt          ¬¦  «        t          j        d¦  «        z  “dt          j        ddgdd	ggt          ¬¦  «        “dt          j        ddgddggt          ¬¦  «        “dt          j        ddgdt          j        d	t           j        z  dz  ¦  «        ggt          ¬¦  «        “dt          j        ddgdt          j        dt           j        z  dz  ¦  «        ggt          ¬¦  «        “dt          j        g d¢g d¢g d¢g d¢gt          ¬¦  «        “dt          j        g d¢g d¢g d¢g d¢gt          ¬¦  «        “dt          j        g d¢g d¢g d¢g d¢gt          ¬¦  «        “dt          j        g d¢g d¢g d¢g d¢gt          ¬¦  «        “dt          j        g d¢g d¢g d¢g d¢g d ¢g d!¢g d"¢g d#¢gt          ¬¦  «        “d$t          j        g d¢g d¢g d¢g d#¢g d ¢g d¢g d"¢g d!¢gt          ¬¦  «        “d%t          j        g d¢g d¢g d¢g d#¢g d ¢g d!¢g d¢g d"¢gt          ¬¦  «        “}t          ˆ fd&„|                     ¦   «         D ¦   «         d ¦  «        S )'N)r<   ÚIr   )Údtype)rJ   ÚXr   r   )rK   ÚYy       €      ð¿y              ð?)rL   ÚZéÿÿÿÿ)rM   ÚH)rN   ÚS)rO   ÚSdg)rR   ÚTé   )rS   ÚTdg)rU   ÚCXÚcx_01)r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )Úcx_10)rW   ÚCZ)r   r   r   rb  )rT   ÚSWAP)rc   ÚCCXÚccx_012Úccx_102)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )Úccx_021Úccx_201)Úccx_120Úccx_210c              3   ó*   •K  — | ]\  }}‰|v ¯	|V — Œd S rg   rh   )ri   rG  rÃ   rj   s      €r-   rl   z)_standard_gate_unitary.<locals>.<genexpr>Ï  s+   øè è € ÐQÐQ™:˜3 ÀTÈSÀ[À[�À[À[À[À[ÐQÐQr.   )	r!   Úeyer$   ÚarrayÚsqrtÚexpÚpiÚnextrà   )rj   Úunitary_matricess   ` r-   r(  r(  Ž  s  ø€ ð=Ø•R”V˜A¥WÐ-Ñ-Ô-ð=à•B”H˜q !˜f q¨! fÐ-µWÐ=Ñ=Ô=ð=ð 	•B”H˜q #˜h¨¨Q¨Ð0½Ð@Ñ@Ô@ð=ð 	•B”H˜q !˜f q¨" gÐ.µgÐ>Ñ>Ô>ð	=ð
 	•B”H˜q !˜f q¨" gÐ.µgÐ>Ñ>Ô>ÅÄÈÁÄÑKð=ð 	•B”H˜q !˜f q¨" gÐ.µgÐ>Ñ>Ô>ð=ð 	�œ 1 a &¨1¨c¨(Ð!3½7ÐCÑCÔCð=ð 	•B”H˜q !˜f q­"¬&°µb´e±¸a±Ñ*@Ô*@Ð&AÐBÍ'ÐRÑRÔRð=ð 	�œ 1 a &¨1­b¬f°S½2¼5±[À1±_Ñ.EÔ.EÐ*FÐ!GÍwÐWÑWÔWð=ð 	�rœxØˆ\ˆ\˜<˜<˜<¨¨¨°|°|°|ÐDÍGð 
ñ  
ô  
ð=ð 	•B”HØˆ\ˆ\˜<˜<˜<¨¨¨°|°|°|ÐDÍGð
ñ 
ô 
ð=ð  	•b”hØˆ\ˆ\˜<˜<˜<¨¨¨°}°}°}ÐEÍWð
ñ 
ô 
ð!=ð& 	�"œ(Øˆ\ˆ\˜<˜<˜<¨¨¨°|°|°|ÐDÍGð
ñ 
ô 
ð'=ð, 	-­b¬hà(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(ð	õ ð/
ñ /
ô /
ð-=ðF 	¥¤à(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(ð	õ ð!
ñ !
ô !
ðG=ð` 	¥¤à(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(Ø(Ð(Ð(ð	õ ð!
ñ !
ô !
ða=Ðõ~ ÐQÐQÐQÐQÐ)9×)?Ò)?Ñ)AÔ)AÐQÑQÔQÐSWÑXÔXÐXr.   )3r2   r²   r  ÚloggingÚtypingr   r�   r   r   r   Únumpyr!   Úqiskit.circuitr   r   r	   r
   Ú(qiskit.circuit.library.generalized_gatesr   r   Úqiskit.providersr   Úqiskit.transpilerr   Úqiskit.utilsr   Údevice.modelsr   r   r   r   Úerrors.base_quantum_errorr   Úerrors.quantum_errorr   Úerrors.readout_errorr   Ú
noiseerrorr   rU  r   Úbackends.backend_utilsr   Ú	getLoggerr/   rþ   ÚJSONEncoderr   r6   r@   r(  rh   r.   r-   ú<module>r�     sG  ððð ð €€€Ø €€€Ø €€€Ø Ð Ð Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9à Ð Ð Ð à DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DØ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø )Ð )Ð )Ð )Ð )Ð )Ø %Ð %Ð %Ð %Ð %Ð %Ø BÐ BÐ BÐ BÐ BÐ BÐ BÐ BØ 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø .Ð .Ð .Ð .Ð .Ð .Ø .Ð .Ð .Ð .Ð .Ð .Ø "Ð "Ð "Ð "Ð "Ð "Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0à	ˆÔ	˜8Ñ	$Ô	$€ð"ð "ð "ð "ð "�TÔ%ñ "ô "ð "ð*Rð Rð Rð Rð R˜;ñ Rô Rð Rðð ð ð ð ñ ô ð ðD"AYð AYð AYð AYð AYr.   