§
    ²Ûg‡ª  ã                   óÊ   — d Z ddlZddl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mZmZmZmZ ddlmZ  ej        e¦  «        Z G d„ de
¦  «        ZdS )z
Aer qasm simulator backend.
é    N©ÚOptions)Ú	BackendV2é   )Ú__version__é   )Ú
AerBackendÚAerError)ÚAerBackendConfiguration)Útarget_to_backend_properties)Úcpp_execute_circuitsÚavailable_methodsÚavailable_devicesÚMAX_QUBITS_STATEVECTORÚBASIS_GATES)Úaer_controller_executec                   ó,  ‡ — e Zd ZdZeZ eg d¢¦  «         eg d¢¦  «         eg d¢¦  «         eg d¢¦  «         eg d¢¦  «         eg d¢¦  «         eg d¢¦  «         eg d	¢¦  «        d
œZ e eed         ¦  «         	                    ed         ¦  «         	                    ed         ¦  «         	                    ed         ¦  «         	                    ed         ¦  «         	                    ed         ¦  «         	                    ed         ¦  «        ¦  «        xed<   ed<   de
eddddd ed¦  «        dded         ed         g dœZg d¢ZdZdZdZ	 d(ˆ fd„	Zed„ ¦   «         Zˆ fd„Zed„ ¦   «         Zd „ Zd!„ Zd"„ Zd#„ Zˆ fd$„Zd%„ Zd)d&„Zd'„ Zˆ xZS )*ÚAerSimulatoraÒZ  
    Noisy quantum circuit simulator backend.

    **Configurable Options**

    The `AerSimulator` supports multiple simulation methods and
    configurable options for each simulation method. These may be set using the
    appropriate kwargs during initialization. They can also be set of updated
    using the :meth:`set_options` method.

    Run-time options may also be specified as kwargs using the :meth:`run` method.
    These will not be stored in the backend and will only apply to that execution.
    They will also override any previously set options.

    For example, to configure a density matrix simulator with a custom noise
    model to use for every execution

    .. code-block:: python

        noise_model = NoiseModel.from_backend(backend)
        backend = AerSimulator(method='density_matrix',
                                noise_model=noise_model)

    **Simulating an IBM Quantum Backend**

    The simulator can be automatically configured to mimic an IBM Quantum backend using
    the :meth:`from_backend` method. This will configure the simulator to use the
    basic device :class:`NoiseModel` for that backend, and the same basis gates
    and coupling map.

    .. code-block:: python

        backend = AerSimulator.from_backend(backend)

    **Returning the Final State**

    The final state of the simulator can be saved to the returned
    ``Result`` object by appending the
    :func:`~qiskit_aer.library.save_state` instruction to a
    quantum circuit. The format of the final state will depend on the
    simulation method used. Additional simulation data may also be saved
    using the other save instructions in :mod:`qiskit.provider.aer.library`.

    **Simulation Method Option**

    The simulation method is set using the ``method`` kwarg. A list supported
    simulation methods can be returned using :meth:`available_methods`, these
    are

    * ``"automatic"``: Default simulation method. Select the simulation
      method automatically based on the circuit and noise model.

    * ``"statevector"``: A dense statevector simulation that can sample
      measurement outcomes from *ideal* circuits with all measurements at
      end of the circuit. For noisy simulations each shot samples a
      randomly sampled noisy circuit from the noise model.

    * ``"density_matrix"``: A dense density matrix simulation that may
      sample measurement outcomes from *noisy* circuits with all
      measurements at end of the circuit.

    * ``"stabilizer"``: An efficient Clifford stabilizer state simulator
      that can simulate noisy Clifford circuits if all errors in the noise
      model are also Clifford errors.

    * ``"extended_stabilizer"``: An approximate simulated for Clifford + T
      circuits based on a state decomposition into ranked-stabilizer state.
      The number of terms grows with the number of non-Clifford (T) gates.

    * ``"matrix_product_state"``: A tensor-network statevector simulator that
      uses a Matrix Product State (MPS) representation for the state. This
      can be done either with or without truncation of the MPS bond dimensions
      depending on the simulator options. The default behaviour is no
      truncation.

    * ``"unitary"``: A dense unitary matrix simulation of an ideal circuit.
      This simulates the unitary matrix of the circuit itself rather than
      the evolution of an initial quantum state. This method can only
      simulate gates, it does not support measurement, reset, or noise.

    * ``"superop"``: A dense superoperator matrix simulation of an ideal or
      noisy circuit. This simulates the superoperator matrix of the circuit
      itself rather than the evolution of an initial quantum state. This method
      can simulate ideal and noisy gates, and reset, but does not support
      measurement.

    * ``"tensor_network"``: A tensor-network based simulation that supports
      both statevector and density matrix. Currently there is only available
      for GPU and accelerated by using cuTensorNet APIs of cuQuantum.

    **GPU Simulation**

    By default all simulation methods run on the CPU, however select methods
    also support running on a GPU if qiskit-aer was installed with GPU support
    on a compatible NVidia GPU and CUDA version.

    +--------------------------+---------------+
    | Method                   | GPU Supported |
    +==========================+===============+
    | ``automatic``            | Sometimes     |
    +--------------------------+---------------+
    | ``statevector``          | Yes           |
    +--------------------------+---------------+
    | ``density_matrix``       | Yes           |
    +--------------------------+---------------+
    | ``stabilizer``           | No            |
    +--------------------------+---------------+
    | ``matrix_product_state`` | No            |
    +--------------------------+---------------+
    | ``extended_stabilizer``  | No            |
    +--------------------------+---------------+
    | ``unitary``              | Yes           |
    +--------------------------+---------------+
    | ``superop``              | No            |
    +--------------------------+---------------+
    | ``tensor_network``       | Yes(GPU only) |
    +--------------------------+---------------+

    Running a GPU simulation is done using ``device="GPU"`` kwarg during
    initialization or with :meth:`set_options`. The list of supported devices
    for the current system can be returned using :meth:`available_devices`.

    For multiple shots simulation, OpenMP threads should be exploited for
    multi-GPUs. Number of GPUs used for multi-shots is reported in
    metadata ``gpu_parallel_shots_`` or is batched execution is done reported
    in metadata ``batched_shots_optimization_parallel_gpus``.
    For large qubits circuits with multiple GPUs, number of GPUs is reported
    in metadata ``chunk_parallel_gpus`` in ``cacheblocking``.

    If AerSimulator is built with cuStateVec support, cuStateVec APIs are enabled
    by setting ``cuStateVec_enable=True``.

    * ``target_gpus`` (list): List of GPU's IDs starting from 0 sets
      the target GPUs used for the simulation.
      If this option is not specified, all the available GPUs are used for
      chunks/shots distribution.

    **Additional Backend Options**

    The following simulator specific backend options are supported

    * ``method`` (str): Set the simulation method (Default: ``"automatic"``).
      Use :meth:`available_methods` to return a list of all availabe methods.

    * ``device`` (str): Set the simulation device (Default: ``"CPU"``).
      Use :meth:`available_devices` to return a list of devices supported
      on the current system.

    * ``precision`` (str): Set the floating point precision for
      certain simulation methods to either ``"single"`` or ``"double"``
      precision (default: ``"double"``).

    * ``executor`` (futures.Executor or None): Set a custom executor for
      asynchronous running of simulation jobs (Default: None).

    * ``max_job_size`` (int or None): If the number of run circuits
      exceeds this value simulation will be run as a set of of sub-jobs
      on the executor. If ``None`` simulation of all circuits are submitted
      to the executor as a single job (Default: None).

    * ``max_shot_size`` (int or None): If the number of shots of a noisy
      circuit exceeds this value simulation will be split into multi
      circuits for execution and the results accumulated. If ``None``
      circuits will not be split based on shots. When splitting circuits
      use the ``max_job_size`` option to control how these split circuits
      should be submitted to the executor (Default: None).

      a noise model exceeds this value simulation will be splitted into
      sub-circuits. If ``None``  simulator does noting (Default: None).

    * ``enable_truncation`` (bool): If set to True this removes unnecessary
      qubits which do not affect the simulation outcome from the simulated
      circuits (Default: True).

    * ``zero_threshold`` (double): Sets the threshold for truncating
      small values to zero in the result data (Default: 1e-10).

    * ``validation_threshold`` (double): Sets the threshold for checking
      if initial states are valid (Default: 1e-8).

    * ``max_parallel_threads`` (int): Sets the maximum number of CPU
      cores used by OpenMP for parallelization. If set to 0 the
      maximum will be set to the number of CPU cores (Default: 0).

    * ``max_parallel_experiments`` (int): Sets the maximum number of
      experiments that may be executed in parallel up to the
      max_parallel_threads value. If set to 1 parallel circuit
      execution will be disabled. If set to 0 the maximum will be
      automatically set to max_parallel_threads (Default: 1).

    * ``max_parallel_shots`` (int): Sets the maximum number of
      shots that may be executed in parallel during each experiment
      execution, up to the max_parallel_threads value. If set to 1
      parallel shot execution will be disabled. If set to 0 the
      maximum will be automatically set to max_parallel_threads.
      Note that this cannot be enabled at the same time as parallel
      experiment execution (Default: 0).

    * ``max_memory_mb`` (int): Sets the maximum size of memory
      to store quantum states. If quantum states need more, an error
      is thrown unless -1 is set. In general, a state vector of n-qubits
      uses 2^n complex values (16 Bytes).
      If set to 0, the maximum will be automatically set to
      the system memory size (Default: 0).

    * ``cuStateVec_enable`` (bool): This option enables accelerating by
      cuStateVec library of cuQuantum from NVIDIA, that has highly optimized
      kernels for GPUs (Default: False). This option will be ignored
      if AerSimulator is not built with cuStateVec support.

    * ``blocking_enable`` (bool): This option enables parallelization with
      multiple GPUs or multiple processes with MPI (CPU/GPU). This option
      is only available for ``"statevector"``, ``"density_matrix"`` and
      ``"unitary"`` (Default: False).

    * ``blocking_qubits`` (int): Sets the number of qubits of chunk size
      used for parallelizing with multiple GPUs or multiple processes with
      MPI (CPU/GPU). 16*2^blocking_qubits should be less than 1/4 of the GPU
      memory in double precision. This option is only available for
      ``"statevector"``, ``"density_matrix"`` and ``"unitary"``.
      This option should be set when using option ``blocking_enable=True``
      (Default: 0).
      If multiple GPUs are used for parallelization number of GPUs is
      reported to ``chunk_parallel_gpus`` in ``cacheblocking`` metadata.

    * ``chunk_swap_buffer_qubits`` (int): Sets the number of qubits of
      maximum buffer size (=2^chunk_swap_buffer_qubits) used for multiple
      chunk-swaps over MPI processes. This parameter should be smaller than
      ``blocking_qubits`` otherwise multiple chunk-swaps is disabled.
      ``blocking_qubits`` - ``chunk_swap_buffer_qubits`` swaps are applied
      at single all-to-all communication. (Default: 15).

    * ``batched_shots_gpu`` (bool): This option enables batched execution
      of multiple shot simulations on GPU devices for GPU enabled simulation
      methods. This optimization is intended for statevector simulations with
      noise models, or statevecor and density matrix simulations with
      intermediate measurements and can greatly accelerate simulation time
      on GPUs. If there are multiple GPUs on the system, shots are distributed
      automatically across available GPUs. Also this option distributes multiple
      shots to parallel processes of MPI (Default: False).
      If multiple GPUs are used for batched exectuion number of GPUs is
      reported to ``batched_shots_optimization_parallel_gpus`` metadata.
      ``cuStateVec_enable`` is not supported for this option.

    * ``batched_shots_gpu_max_qubits`` (int): This option sets the maximum
      number of qubits for enabling the ``batched_shots_gpu`` option. If the
      number of active circuit qubits is greater than this value batching of
      simulation shots will not be used. (Default: 16).

    * ``num_threads_per_device`` (int): This option sets the number of
      threads per device. For GPU simulation, this value sets number of
      threads per GPU. This parameter is used to optimize Pauli noise
      simulation with multiple-GPUs (Default: 1).

    * ``shot_branching_enable`` (bool): This option enables/disables
      applying shot-branching technique to speed up multi-shots of dynamic
      circutis simulations or circuits simulations with noise models.
      (Default: False).
      Starting from single state shared with multiple shots and
      state will be branched dynamically at runtime.
      This option can decrease runs of shots if there will be less branches
      than number of total shots.
      This option is available for ``"statevector"``, ``"density_matrix"``
      and ``"tensor_network"``.
      WARNING: `shot_branching` option is unstable on MacOS currently

    * ``shot_branching_sampling_enable`` (bool): This option enables/disables
      applying sampling measure if the input circuit has all the measure
      operations at the end of the circuit. (Default: False).
      Because measure operation branches state into 2 states, it is not
      efficient to apply branching for measure.
      Sampling measure improves speed to get counts for multiple-shots
      sharing the same state.
      Note that the counts obtained by sampling measure may not be as same as
      the counts calculated by multiple measure operations,
      becuase sampling measure takes only one randome number per shot.
      This option is available for ``"statevector"``, ``"density_matrix"``
      and ``"tensor_network"``.

    * ``accept_distributed_results`` (bool): This option enables storing
      results independently in each process (Default: None).

    * ``runtime_parameter_bind_enable`` (bool): If this option is True
      parameters are bound at runtime by using multi-shots without constructing
      circuits for each parameters. For GPU this option can be used with
      ``batched_shots_gpu`` to run with multiple parameters in a batch.
      (Default: False).

    These backend options only apply when using the ``"statevector"``
    simulation method:

    * ``statevector_parallel_threshold`` (int): Sets the threshold that
      the number of qubits must be greater than to enable OpenMP
      parallelization for matrix multiplication during execution of
      an experiment. If parallel circuit or shot execution is enabled
      this will only use unallocated CPU cores up to
      max_parallel_threads. Note that setting this too low can reduce
      performance (Default: 14).

    * ``statevector_sample_measure_opt`` (int): Sets the threshold that
      the number of qubits must be greater than to enable a large
      qubit optimized implementation of measurement sampling. Note
      that setting this two low can reduce performance (Default: 10)

    These backend options only apply when using the ``"stabilizer"``
    simulation method:

    * ``stabilizer_max_snapshot_probabilities`` (int): set the maximum
      qubit number for the :class:`~qiskit_aer.library.SaveProbabilities` instruction (Default: 32).

    These backend options only apply when using the ``"extended_stabilizer"``
    simulation method:

    * ``extended_stabilizer_sampling_method`` (string): Choose how to simulate
      measurements on qubits. The performance of the simulator depends
      significantly on this choice. In the following, let n be the number of
      qubits in the circuit, m the number of qubits measured, and S be the
      number of shots (Default: resampled_metropolis).

      - ``"metropolis"``: Use a Monte-Carlo method to sample many output
        strings from the simulator at once. To be accurate, this method
        requires that all the possible output strings have a non-zero
        probability. It will give inaccurate results on cases where
        the circuit has many zero-probability outcomes.
        This method has an overall runtime that scales as n^{2} + (S-1)n.

      - ``"resampled_metropolis"``: A variant of the metropolis method,
        where the Monte-Carlo method is reinitialised for every shot. This
        gives better results for circuits where some outcomes have zero
        probability, but will still fail if the output distribution
        is sparse. The overall runtime scales as Sn^{2}.

      - ``"norm_estimation"``: An alternative sampling method using
        random state inner products to estimate outcome probabilites. This
        method requires twice as much memory, and significantly longer
        runtimes, but gives accurate results on circuits with sparse
        output distributions. The overall runtime scales as Sn^{3}m^{3}.

    * ``extended_stabilizer_metropolis_mixing_time`` (int): Set how long the
      monte-carlo method runs before performing measurements. If the
      output distribution is strongly peaked, this can be decreased
      alongside setting extended_stabilizer_disable_measurement_opt
      to True (Default: 5000).

    * ``extended_stabilizer_approximation_error`` (double): Set the error
      in the approximation for the extended_stabilizer method. A
      smaller error needs more memory and computational time
      (Default: 0.05).

    * ``extended_stabilizer_norm_estimation_samples`` (int): The default number
      of samples for the norm estimation sampler. The method will use the
      default, or 4m^{2} samples where m is the number of qubits to be
      measured, whichever is larger (Default: 100).

    * ``extended_stabilizer_norm_estimation_repetitions`` (int): The number
      of times to repeat the norm estimation. The median of these reptitions
      is used to estimate and sample output strings (Default: 3).

    * ``extended_stabilizer_parallel_threshold`` (int): Set the minimum
      size of the extended stabilizer decomposition before we enable
      OpenMP parallelization. If parallel circuit or shot execution
      is enabled this will only use unallocated CPU cores up to
      max_parallel_threads (Default: 100).

    * ``extended_stabilizer_probabilities_snapshot_samples`` (int): If using
      the metropolis or resampled_metropolis sampling method, set the number of
      samples used to estimate probabilities in a probabilities snapshot
      (Default: 3000).

    These backend options only apply when using the ``matrix_product_state``
    simulation method:

    * ``matrix_product_state_max_bond_dimension`` (int): Sets a limit
      on the number of Schmidt coefficients retained at the end of
      the svd algorithm. Coefficients beyond this limit will be discarded.
      (Default: None, i.e., no limit on the bond dimension).

    * ``matrix_product_state_truncation_threshold`` (double):
      Discard the smallest coefficients for which the sum of
      their squares is smaller than this threshold.
      (Default: 1e-16).

    * ``mps_sample_measure_algorithm`` (str): Choose which algorithm to use for
      ``"sample_measure"`` (Default: "mps_apply_measure").

      - ``mps_probabilities``: This method first constructs the probability
        vector and then generates a sample per shot. It is more efficient for
        a large number of shots and a small number of qubits, with complexity
        O(2^n * n * D^2) to create the vector and O(1) per shot, where n is
        the number of qubits and D is the bond dimension.

      - ``mps_apply_measure``: This method creates a copy of the mps structure
        and measures directly on it. It is more efficient for a small number of
        shots, and a large number of qubits, with complexity around
        O(n * D^2) per shot.

    * ``mps_log_data`` (bool): if True, output logging data of the MPS
      structure: bond dimensions and values discarded during approximation.
      (Default: False)

    * ``mps_swap_direction`` (str): Determine the direction of swapping the
      qubits when internal swaps are inserted for a 2-qubit gate.
      Possible values are "mps_swap_right" and "mps_swap_left".
      (Default: "mps_swap_left")

    * ``chop_threshold`` (float): This option sets a threshold for
      truncating snapshots (Default: 1e-8).

    * ``mps_parallel_threshold`` (int): This option sets OMP number threshold (Default: 14).

    * ``mps_omp_threads`` (int): This option sets the number of OMP threads (Default: 1).

    * ``mps_lapack`` (bool): This option indicates to compute the SVD function
      using OpenBLAS/Lapack interface (Default: False).

    These backend options only apply when using the ``tensor_network``
    simulation method:

    * ``tensor_network_num_sampling_qubits`` (int): is used to set number
      of qubits to be sampled in single tensor network contraction when
      using sampling measure. (Default: 10)

    * ``use_cuTensorNet_autotuning`` (bool): enables auto tuning of plan
      in cuTensorNet API. It takes some time for tuning, so enable if the
      circuit is very large. (Default: False)

    These backend options apply in circuit optimization passes:

    * ``fusion_enable`` (bool): Enable fusion optimization in circuit
      optimization passes [Default: True]
    * ``fusion_verbose`` (bool): Output gates generated in fusion optimization
      into metadata [Default: False]
    * ``fusion_max_qubit`` (int): Maximum number of qubits for a operation generated
      in a fusion optimization. A default value (``None``) automatically sets a value
      depending on the simulation method: [Default: None]
    * ``fusion_threshold`` (int): Threshold that number of qubits must be greater
      than or equal to enable fusion optimization. A default value automatically sets
      a value depending on the simulation method [Default: None]

    ``fusion_enable`` and ``fusion_threshold`` are set as follows if their default
    values (``None``) are configured:

    +--------------------------+----------------------+----------------------+
    | Method                   | ``fusion_max_qubit`` | ``fusion_threshold`` |
    +==========================+======================+======================+
    | ``statevector``          | 5                    | 14                   |
    +--------------------------+----------------------+----------------------+
    | ``density_matrix``       | 2                    | 7                    |
    +--------------------------+----------------------+----------------------+
    | ``unitary``              | 5                    | 7                    |
    +--------------------------+----------------------+----------------------+
    | ``superop``              | 2                    | 7                    |
    +--------------------------+----------------------+----------------------+
    | other methods            | 5                    | 14                   |
    +--------------------------+----------------------+----------------------+

    )Úquantum_channelÚ
qerror_locÚroerrorÚkrausÚsave_expvalÚsave_expval_varÚsave_probabilitiesÚsave_probabilities_dictÚsave_amplitudesÚsave_amplitudes_sqÚsave_density_matrixÚ
save_stateÚsave_statevectorÚsave_statevector_dictÚset_statevectorÚif_elseÚfor_loopÚ
while_loopÚ
break_loopÚcontinue_loopÚ
initializeÚresetÚswitch_caseÚdelay)r   r   r   r   Úsuperopr    r   r   r   r   r   r   Úset_density_matrixr$   r%   r&   r'   r(   r*   r+   r,   )r   r   r   r   r   r   r   r   r    Úsave_matrix_product_stater!   r   r   r   Úset_matrix_product_stater$   r%   r&   r'   r(   r)   r*   r+   r,   )r   r   r   r   r   r   r   r   r    Úsave_cliffordÚsave_stabilizerÚset_stabilizerr$   r%   r&   r'   r(   r*   r+   r,   )r   r   r   r!   r*   r,   )r    Úsave_unitaryÚset_unitaryr*   r,   )	r   r   r   r-   r    Úsave_superopÚset_superopr*   r,   )r   r   r   r   r-   r    r   r   r   r   r   r   r   r!   r"   r#   r.   r)   r*   r+   r,   )ÚstatevectorÚdensity_matrixÚmatrix_product_stateÚ
stabilizerÚextended_stabilizerÚunitaryr-   Útensor_networkr8   r;   r9   r:   r=   r-   r>   NÚ	automaticÚaer_simulatorz$https://github.com/Qiskit/qiskit-aerTç    €„.AzA C++ Qasm simulator with noise)Úbackend_nameÚbackend_versionÚn_qubitsÚurlÚ	simulatorÚlocalÚconditionalÚmemoryÚ	max_shotsÚdescriptionÚcoupling_mapÚbasis_gatesÚcustom_instructionsÚgates)	r?   r8   r9   r;   r:   r<   r=   r-   r>   )ÚCPUÚGPUÚThrustc                 óú  •— t          ¦   «         | _        t          j        €t	          | j        ¦  «        t          _        t          j        €.t          t          j        t          j        ¦  «        t          _        |€t          j	        t          j
        ¦  «        }d|j        vrnd}d}|                     ¦   «         D ]\  }}	|dk    r|	}|dk    r|	}Œ|dvr|xj        d|› �z  c_        |dvr%|xj        d|› �                     ¦   «         z  c_        | j        d         | _        t!          ¦   «                              |||||¬	¦  «         d
|                     ¦   «         v r|                      |d
         ¦  «         d S d S )NÚfromr?   rP   ÚmethodÚdevice)Nr?   Ú_)NrP   )Ú
propertiesÚproviderÚtargetÚbackend_optionsrM   )r   Ú_controllerr   Ú_AVAILABLE_DEVICESr   Ú_AVAILABLE_METHODSr   Ú_SIMULATION_METHODSr   Ú	from_dictÚ_DEFAULT_CONFIGURATIONrB   ÚitemsÚlowerÚ_BASIS_GATESÚ_cached_basis_gatesÚsuperÚ__init__Ú_check_basis_gates)ÚselfÚconfigurationrX   rY   rZ   r[   rU   rV   ÚkeyÚvalueÚ	__class__s             €úW/granary/edev/quantum/lib/python3.11/site-packages/qiskit_aer/backends/aer_simulator.pyrg   zAerSimulator.__init__È  s¡  ø€ õ 2Ñ3Ô3ˆÔõ Ô*Ð2Ý.?ÀÔ@PÑ.QÔ.Q�LÔ+ÝÔ*Ð2Ý.?ÝÔ0µ,Ô2Qñ/ô /�LÔ+ð
 Ð Ý3Ô=½lÔ>aÑbÔbˆMð ˜Ô3Ð3Ð3Ø ˆFØˆFØ-×3Ò3Ñ5Ô5ð #ð #‘
��UØ˜(’?�?Ø"�FØ˜(’?�?Ø"�FøØÐ0Ð0Ð0ØÐ*Ô*¨l°&¨l¨lÑ:Ð*Ô*Ø˜]Ð*Ð*ØÐ*Ô*¨l°&¨l¨l×.@Ò.@Ñ.BÔ.BÑBÐ*Ô*ð $(Ô#4°[Ô#AˆÔ å‰Œ×ÒØØ!ØØØ+ð 	ñ 	
ô 	
ð 	
ð ˜O×1Ò1Ñ3Ô3Ð3Ð3Ø×#Ò# O°MÔ$BÑCÔCÐCÐCÐCð 4Ð3ó    c                 óT  — t          dLi dd“dd“dd“dd“d	d “d
d “dd “dd“dd“dd “dd “dd “dd “dd “dd“dd“dd “dd “dd “dd “dd “dd “dd“dd “d d“d!d “d"d“d#d$“d%d&“d'd“d(d“d)d*“d+d,“d-d.“d/d0“d1d2“d3d4“d5d6“d7d8“d9d6“d:d;“d<d=“d>d “d?d@“dAd“dBdC“dDdE“dFd*“dGd&“dHd“dId,“dJd“dKd“ŽS )MNÚshotsi   rU   r?   rV   rP   Ú	precisionÚdoubleÚexecutorÚmax_job_sizeÚmax_shot_sizeÚenable_truncationTÚzero_thresholdg»½×Ùß|Û=Úvalidation_thresholdÚmax_parallel_threadsÚmax_parallel_experimentsÚmax_parallel_shotsÚmax_memory_mbÚfusion_enableÚfusion_verboseFÚfusion_max_qubitÚfusion_thresholdÚaccept_distributed_resultsrI   Únoise_modelÚseed_simulatorÚcuStateVec_enableÚblocking_qubitsÚblocking_enableÚchunk_swap_buffer_qubitsÚbatched_shots_gpuÚbatched_shots_gpu_max_qubitsé   Únum_threads_per_devicer   Úshot_branching_enableÚshot_branching_sampling_enableÚstatevector_parallel_thresholdé   Ústatevector_sample_measure_opté
   Ú%stabilizer_max_snapshot_probabilitiesé    Ú#extended_stabilizer_sampling_methodÚresampled_metropolisÚ*extended_stabilizer_metropolis_mixing_timeiˆ  Ú'extended_stabilizer_approximation_errorgš™™™™™©?Ú+extended_stabilizer_norm_estimation_sampleséd   Ú/extended_stabilizer_norm_estimation_repetitionsé   Ú&extended_stabilizer_parallel_thresholdÚ2extended_stabilizer_probabilities_snapshot_samplesi¸  Ú)matrix_product_state_truncation_thresholdg¼‰Ø—²Òœ<Ú'matrix_product_state_max_bond_dimensionÚmps_sample_measure_algorithmÚmps_heuristicÚmps_log_dataÚmps_swap_directionÚmps_swap_leftÚchop_thresholdg:Œ0âŽyE>Úmps_parallel_thresholdÚmps_omp_threadsÚ
mps_lapackÚ"tensor_network_num_sampling_qubitsÚuse_cuTensorNet_autotuningÚruntime_parameter_bind_enable© r   )Úclss    rn   Ú_default_optionszAerSimulator._default_optionsö  s  € åð A
ð A
ð A
à�$ðA
ð �;ðA
ð �5ð	A
ð
 �hðA
ð �TðA
ð ˜ðA
ð ˜$ðA
ð #˜dðA
ð !˜5ðA
ð "& ðA
ð "& ðA
ð &* TðA
ð  $˜tðA
ð ˜$ðA
ð  ˜$ð!A
ð" !˜5ð#A
ð$ "˜Tð%A
ð& "˜Tð'A
ð( (, tð)A
ð* �4ð+A
ð, ˜ð-A
ð.  ˜4ð/A
ð2 $˜eð3A
ð6 !˜Dð7A
ð8 "˜Eð9A
ð: &* Tð;A
ð> $˜eð?A
ð@ *,¨ðAA
ðB $% 1ðCA
ðF #( %ðGA
ðH ,1¨5ðIA
ðL ,.¨2ðMA
ðN ,.¨2ðOA
ðR 35°"ðSA
ðV 1GÐ0FðWA
ðX 8<°tðYA
ðZ 59°Dð[A
ð\ 9<¸ð]A
ð^ =>¸Að_A
ð` 47°3ðaA
ðb @D¸tðcA
ðf 7<°eðgA
ðh 59°DðiA
ðj *9¨ðkA
ðl ˜ðmA
ðn  /˜ðoA
ðp  ˜4ðqA
ðr $& 2ðsA
ðt ˜AðuA
ðv �uðwA
ðz 02¨rð{A
ð| (- uð}A
ð@ +0¨%ðAA
ð A	
ro   c                 ó  •— t          ¦   «                              ¦   «         }t          | j        dd¦  «        }|�|                     ¦   «         r|S dt          | j        j        ¦  «        dz   z  }|dd…         › d|› dt          |¦  «        › d�S )	z)String representation of an AerSimulator.rƒ   Nú r   éÿÿÿÿú
znoise_model=ú))	rf   Ú__repr__ÚgetattrÚoptionsÚis_idealÚlenrm   Ú__name__Úrepr)ri   Údisplayrƒ   Úpadrm   s       €rn   rµ   zAerSimulator.__repr__;  s’   ø€ å‘'”'×"Ò"Ñ$Ô$ˆÝ˜dœl¨M¸4Ñ@Ô@ˆØÐ +×"6Ò"6Ñ"8Ô"8ÐØˆNØ•S˜œÔ0Ñ1Ô1°AÑ5Ñ6ˆØ˜#˜2˜#”,ÐGÐG #ÐGÐGµ4¸Ñ3DÔ3DÐGÐGÐGÐGro   c                 ó  — t          |t          ¦  «        r“|j        €d}n|j        }t          d|j        › d�|j        |j        |j        g t          d¦  «        t          |j
                             ¦   «         ¦  «        |j        |¬¦	  «	        }t          |j        ¦  «        }|j        }n t          dt!          |¦  «        › d�¦  «        ‚d	|vr4d
dlm} |                     |¦  «        }|                     ¦   «         s||d	<    | d|||dœ|¤Ž}	|	S )z"Initialize simulator from backend.Nz$created by AerSimulator.from_backendzaer_simulator_from(r´   rA   )	rB   rC   rD   rM   rO   rJ   rL   Úmax_experimentsrK   z8The backend argument requires a BackendV2 object, not a z objectrƒ   r   )Ú
NoiseModel)rj   rX   rZ   r­   )Ú
isinstancer   rK   r   ÚnamerC   Ú
num_qubitsÚoperation_namesÚintÚlistrL   Ú	get_edgesÚmax_circuitsr   rZ   Ú	TypeErrorÚtypeÚnoise.noise_modelrÀ   Úfrom_backendr¸   )
r®   Úbackendr·   rK   rj   rX   rZ   rÀ   rƒ   Úsims
             rn   rÌ   zAerSimulator.from_backendD  sL  € õ �g�yÑ)Ô)ð 	ØÔ"Ð*ØD��à%Ô1�å3ØB°7´<ÐBÐBÐBØ 'Ô 7Ø Ô+Ø#Ô3ØÝ˜c™(œ(Ý! 'Ô"6×"@Ò"@Ñ"BÔ"BÑCÔCØ 'Ô 4Ø'ð
ñ 
ô 
ˆMõ 6°g´nÑEÔEˆJØ”^ˆFˆFåØdÍdÐSZÉmÌmÐdÐdÐdñô ð ð  Ð'Ð'ð 7Ð6Ð6Ð6Ð6Ð6à$×1Ò1°'Ñ:Ô:ˆKØ×'Ò'Ñ)Ô)ð 5Ø)4�˜Ñ&ð ˆcÐ_ ¸*ÈVÐ_Ð_ÐW^Ð_Ð_ˆØˆ
ro   c                 ó4   — t          j         | j        ¦  «        S )ú(Return the available simulation methods.)Úcopyr^   ©ri   s    rn   r   zAerSimulator.available_methodsl  s   € åŒy˜Ô0Ñ1Ô1Ð1ro   c                 óL   — d| j         v rdgS t          j        | j        ¦  «        S )rÐ   Ú_gpurQ   )rÂ   rÑ   r]   rÒ   s    rn   r   zAerSimulator.available_devicesp  s)   € à�T”YÐÐØ�7ˆNÝŒy˜Ô0Ñ1Ô1Ð1ro   c                 ó  — t          j         | j        ¦  «        }| j                             ¦   «         D ]\  }}t	          |||¦  «         Œt          | j        dd¦  «        }| j        |         |_        | j	        |j        z   |_
        |S )z‹Return the simulator backend configuration.

        Returns:
            BackendConfiguration: the configuration for the backend.
        rU   r?   )rÑ   Ú_configurationÚ_options_configurationrb   Úsetattrr¶   r·   Ú_CUSTOM_INSTRrN   re   rM   )ri   Úconfigrk   ÚvalrU   s        rn   rj   zAerSimulator.configurationv  sŠ   € õ ”˜4Ô.Ñ/Ô/ˆØÔ3×9Ò9Ñ;Ô;ð 	&ð 	&‰HˆC�Ý�F˜C Ñ%Ô%Ð%Ð%å˜œ x°Ñ=Ô=ˆð &*Ô%7¸Ô%?ˆÔ"Ø!Ô5¸Ô8RÑRˆÔØˆro   c                 ó4   — t          | j        |||¦  «        }|S )z Execute circuits on the backend.)r   r\   )ri   Úaer_circuitsrƒ   rÚ   Úrets        rn   Ú_execute_circuitszAerSimulator._execute_circuitsˆ  s   € å" 4Ô#3°\À;ÐPVÑWÔWˆØˆ
ro   c                 óv  •— |dk    r|                       ||¦  «         d S |dk    rT|�=||                      ¦   «         vr't          d|› d|                      ¦   «         › �¦  «        ‚|                      |¦  «         |dk    r|                      |¦  «         t          ¦   «                              ||¦  «         |dv r|                      ¦   «         | _        |dv rÙd| j	        vrÒ|dk    rad	| _	        |d
k    rT| xj	        d|› �z  c_	        t          | j        dd¦  «        }|dk    r%| xj	        d|› �                     ¦   «         z  c_	        |dk    rgt          | j        dd¦  «        }d	| _	        |d
k    rF| xj	        d|› �z  c_	        |dk    r/| xj	        d|› �                     ¦   «         z  c_	        d S d S d S d S d S d S )NrN   rU   zInvalid simulation method z. Available methods are: rM   )rU   rƒ   rM   )rU   rV   rT   r@   r?   rW   rV   rP   Úauto)Ú_set_configuration_optionr   r
   Ú_set_method_configrh   rf   Ú
set_optionÚ_basis_gatesre   rÂ   r¶   r·   rc   )ri   rk   rl   rV   rU   rm   s        €rn   rä   zAerSimulator.set_option�  s  ø€ ØÐ'Ò'Ð'Ø×*Ò*¨3°Ñ6Ô6Ð6ØˆFØ�(Š?ˆ?ØÐ  U°$×2HÒ2HÑ2JÔ2JÐ%JÐ%JÝð8°ð 8ð 8Ø!×3Ò3Ñ5Ô5ð8ð 8ñô ð ð ×#Ò# EÑ*Ô*Ð*Ø�-ÒÐØ×#Ò# EÑ*Ô*Ð*å‰Œ×Ò˜3 Ñ&Ô&Ð&ØÐ:Ð:Ð:Ø'+×'8Ò'8Ñ':Ô':ˆDÔ$ð Ð&Ð&Ð&Ø˜TœYÐ&Ð&Ø˜(’?�?Ø /�D”IØ Ò+Ð+Ø˜	œ	 [¨ [ [Ñ0˜	œ	Ý!(¨¬°xÀÑ!GÔ!G˜Ø! Uš?˜?Ø ˜IœI¨¨V¨¨×);Ò);Ñ)=Ô)=Ñ=˜IœIØ˜(’?�?Ý$ T¤\°8¸VÑDÔD�FØ /�D”IØ Ò,Ð,Ø˜	œ	 \¨ \ \Ñ1˜	œ	Ø  Eš>˜>Ø ˜IœI¨¨U¨¨×):Ò):Ñ)<Ô)<Ñ<˜IœI˜I˜Ið 'Ð&Ø&Ð&ð #�?ð -Ð,à)˜>ro   c                 ó¤  — d| j         v r| j         d         S t          | j        dd¦  «        }| j        |         }| j        j        }|r#t          |¦  «                             |¦  «        }n|}t          | j        dd¦  «        }|r|j        }|                     |¦  «        }nd}|st           
                    d|||¦  «         t          |¦  «        S )zåReturn simualtor basis gates.

        This will be the option value of basis gates if it was set,
        otherwise it will be the intersection of the configuration, noise model
        and method supported basis gates.
        rM   rU   r?   rƒ   Nz�The intersection of configuration basis gates (%s), simulation method basis gates (%s), and noise model basis gates (%s) is empty)r×   r¶   Ú_optionsrd   rÖ   rM   ÚsetÚintersectionr·   ÚloggerÚwarningÚsorted)ri   rU   Úmethod_gatesÚconfig_gatesrM   rƒ   Únoise_gatess          rn   rå   zAerSimulator._basis_gates±  sô   € ð ˜DÔ7Ð7Ð7ØÔ.¨}Ô=Ð=õ ˜œ¨°+Ñ>Ô>ˆØÔ(¨Ô0ˆØÔ*Ô6ˆØð 	'Ý˜lÑ+Ô+×8Ò8¸ÑFÔFˆKˆKà&ˆKõ ˜dœl¨M¸4Ñ@Ô@ˆØð 	Ø%Ô1ˆKØ%×2Ò2°;Ñ?Ô?ˆKˆKàˆKàð 	Ý�NŠNð8ð ØØñô ð õ �kÑ"Ô"Ð"ro   c                 óÊ  — |dk    r
d}t           }n^|dk    rd}t           dz  }nK|dk    rd}t           dz  }n8|dk    rd	}t           d
z  }n%|dk    rd}d}n|dk    rd}d}n|dk    rd}d}nd}d}| j        j        r<t          t	          t          t          | j        j        ¦  «        ¦  «        ¦  «        dz   }|                      d|¦  «         |                      d|¦  «         dS )z.Set non-basis gate options when setting methodr8   z&A C++ statevector simulator with noiser9   z)A C++ density matrix simulator with noiser   r=   zA C++ unitary matrix simulatorr-   z)A C++ superop matrix simulator with noiseé   r:   z/A C++ matrix product state simulator with noiseé?   r;   z.A C++ Clifford stabilizer simulator with noisei'  r<   z9A C++ Clifford+T extended stabilizer simulator with noiseNr   rK   rD   )r   rÖ   rL   ÚmaxrÆ   Úmaprâ   )ri   rU   rK   rD   s       rn   rã   zAerSimulator._set_method_configØ  s.  € ð �]Ò"Ð"ØBˆKÝ-ˆHˆHØÐ'Ò'Ð'ØEˆKÝ-°Ñ2ˆHˆHØ�yÒ Ð Ø:ˆKÝ-°Ñ2ˆHˆHØ�yÒ Ð ØEˆKÝ-°Ñ2ˆHˆHØÐ-Ò-Ð-ØKˆKØˆHˆHØ�|Ò#Ð#ØJˆKØˆHˆHØÐ,Ò,Ð,ØUˆKØˆHˆHð ˆKØˆHàÔÔ+ð 	QÝ�4¥¥C¨Ô)<Ô)IÑ JÔ JÑKÔKÑLÔLÈqÑPˆHà×&Ò& }°kÑBÔBÐBØ×&Ò& z°8Ñ<Ô<Ð<Ð<Ð<ro   c                 ó–   — t          | j        dd¦  «        }|dk    r*|D ])}|| j        |         vrt          d|› d|› d�¦  «        ‚Œ(d S d S )NrU   r?   zInvalid gate z for simulation method ú.)r¶   r·   rd   r
   )ri   rM   rU   Úgates       rn   rh   zAerSimulator._check_basis_gatesû  s€   € Ý˜œ x°Ñ=Ô=ˆà�[Ò Ð Ø#ð [ð [�Ø˜tÔ0°Ô8Ð8Ð8Ý"Ð#Y°4Ð#YÐ#YÐPVÐ#YÐ#YÐ#YÑZÔZÐZð 9ð !Ð ð[ð [ro   )NNNN)N) rº   Ú
__module__Ú__qualname__Ú__doc__r   rd   rì   rÙ   rè   Úunionr   r   rÅ   ra   r_   r^   Ú_SIMULATION_DEVICESr]   rg   Úclassmethodr¯   rµ   rÌ   r   r   rj   rß   rä   rå   rã   rh   Ú__classcell__)rm   s   @rn   r   r   '   so  ø€ € € € € ðHð HðT €Lð �vðð ð ñ
ô 
ð8 !˜&ðð ð ñ
ô 
ð2 !' ðð ð ñ!
ô !
ð8 �fðð ð ñ
ô 
ð0  &˜vðð ð ñ	 
ô 	 
ð �6ðð ð ñ
ô 
ð �6ð
ð 
ð 
ñ
ô 
ð !˜&ðð ð ñ
ô 
ðUcð c€MðN 8>°vØˆˆM˜-Ô(Ñ)Ô)ß	Šˆ}˜\Ô*Ñ	+Ô	+ß	Šˆ}Ð-Ô.Ñ	/Ô	/ß	Šˆ}Ð3Ô4Ñ	5Ô	5ß	Šˆ}˜YÔ'Ñ	(Ô	(ß	Šˆ}˜YÔ'Ñ	(Ô	(ß	Šˆ}Ð-Ô.Ñ	/Ô	/ñ8ô 8ð €M�$Ñ˜-¨Ñ4ð (Ø&Ø*Ø5ØØØØØ�S˜‘X”XØ8ØØ" ;Ô/Ø,¨[Ô9Øðð Ðð"
ð 
ð 
Ðð Ðà2ÐàÐð JNð,Dð ,Dð ,Dð ,Dð ,Dð ,Dð\ ðB
ð B
ñ „[ðB
ðHHð Hð Hð Hð Hð ð%ð %ñ „[ð%ðN2ð 2ð 2ð2ð 2ð 2ðð ð ð$ð ð ð
"=ð "=ð "=ð "=ð "=ðH%#ð %#ð %#ðN!=ð !=ð !=ð !=ðF[ð [ð [ð [ð [ð [ð [ro   r   )rú   rÑ   ÚloggingÚqiskit.providers.optionsr   Úqiskit.providers.backendr   Úversionr   Ú
aerbackendr	   r
   Úbackendconfigurationr   Úbackendpropertiesr   Úbackend_utilsr   r   r   r   r   Úcontroller_wrappersr   Ú	getLoggerrº   rê   r   r­   ro   rn   ú<module>r	     sI  ððð ð €€€Ø €€€Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø .Ð .Ð .Ð .Ð .Ð .à !Ð !Ð !Ð !Ð !Ð !Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 8Ð 7Ð 7Ð 7Ð 7Ð 7à	ˆÔ	˜8Ñ	$Ô	$€ðZ[ð Z[ð Z[ð Z[ð Z[�:ñ Z[ô Z[ð Z[ð Z[ð Z[ro   