§
    ²Û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
 dd	lmZ dd
lmZmZmZmZmZmZ ddlmZ ddlmZ  ej        e¦  «        Z G d„ de¦  «        ZdS )z 
Aer Unitary Simulator Backend.
é    N)Úwarn©ÚOptionsé   )ÚAerError)Ú__version__é   )Ú
AerBackend)Úcpp_execute_circuitsÚavailable_devicesÚMAX_QUBITS_STATEVECTORÚLEGACY_METHOD_MAPÚadd_final_save_opÚmap_legacy_method_config)ÚAerBackendConfiguration)Úaer_controller_executec                   óÆ   ‡ — e Zd ZdZdeedz  dddddd ed¦  «        dd	 eg d
¢¦  «         eg d¢¦  «        g dœZdZ	d	Z
dˆ fd„	Zed„ ¦   «         Zˆ fd„Zd„ Zd„ Zd„ Zˆ xZS )ÚUnitarySimulatora•  Ideal quantum circuit unitary simulator.

    **Configurable Options**

    The `UnitarySimulator` supports CPU and GPU simulation methods and
    additional configurable options. 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 a single-precision simulator

    .. code-block:: python

        backend = UnitarySimulator(precision='single')

    **Backend Options**

    The following configurable backend options are supported

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

    * ``method`` (str): [DEPRECATED] Set the simulation method supported
      methods are ``"unitary"`` for CPU simulation, and
      ``"unitary_gpu"`` for GPU simulation. This option has been
      deprecated, use the ``device`` option to set "CPU" or "GPU"
      simulation instead.

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

    * ``executor`` (futures.Executor): Set a custom executor for
      asynchronous running of simulation jobs (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).

    * ``max_shot_size`` (int or None): If the number of shots with
      a noise model exceeds this value, simulation will split the experiments into
      sub experiments. If ``None``  simulator does nothing (Default: None).

    * ``"initial_unitary"`` (matrix_like): Sets a custom initial unitary
      matrix for the simulation instead of identity (Default: None).

    * ``"validation_threshold"`` (double): Sets the threshold for checking
      if initial unitary and target unitary are unitary matrices.
      (Default: 1e-8).

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

    * ``"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_memory_mb"`` (int): Sets the maximum size of memory
      to store a state vector. If a state vector needs more, an error
      is thrown. 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).

    * ``"statevector_parallel_threshold"`` (int): Sets the threshold that
      2 * "n_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).

    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 [Default: 5]
    * ``fusion_threshold`` (int): Threshold that number of qubits must be greater
      than or equal to enable fusion optimization [Default: 7]
    Úunitary_simulatorr   z$https://github.com/Qiskit/qiskit-aerTFg    €„.AzA C++ unitary circuit simulatorN)9Úu1Úu2Úu3ÚuÚpÚrÚrxÚryÚrzÚidÚxÚyÚzÚhÚsÚsdgÚsxÚsxdgÚtÚtdgÚswapÚcxÚcyÚczÚcsxÚcuÚcpÚcu1Úcu2Úcu3ÚrxxÚryyÚrzzÚrzxÚccxÚcczÚcswapÚmcxÚmcyÚmczÚmcsxÚmcuÚmcpÚmcphaseÚmcu1Úmcu2Úmcu3ÚmcrxÚmcryÚmcrzÚmcrÚmcswapÚunitaryÚdiagonalÚmultiplexerÚdelayÚpauli)Úsave_unitaryÚ
save_stateÚset_unitaryÚreset)Úbackend_nameÚbackend_versionÚn_qubitsÚurlÚ	simulatorÚlocalÚconditionalÚ
open_pulseÚmemoryÚ	max_shotsÚdescriptionÚcoupling_mapÚbasis_gatesÚcustom_instructionsÚgates)ÚCPUÚGPUÚThrustc                 óF  •— t          dt          ¦  «         t          ¦   «         | _        t          j        €t          | j        ¦  «        t          _        |€t          j        t          j	        ¦  «        }nd|_
        t          ¦   «                              ||||¬¦  «         d S )Na  The `UnitarySimulator` backend will be deprecated in the future. It has been superseded by the `AerSimulator` backend. To obtain legacy functionality initialize with `AerSimulator(method="unitary")` and append run circuits with the `save_state` instruction.F)Ú
propertiesÚproviderÚbackend_options)r   ÚPendingDeprecationWarningr   Ú_controllerr   Ú_AVAILABLE_DEVICESr   r   Ú	from_dictÚ_DEFAULT_CONFIGURATIONrZ   ÚsuperÚ__init__)ÚselfÚconfigurationrf   rg   rh   Ú	__class__s        €ú[/granary/edev/quantum/lib/python3.11/site-packages/qiskit_aer/backends/unitary_simulator.pyro   zUnitarySimulator.__init__ã   s«   ø€ Ýð2õ
 &ñ	
ô 	
ð 	
õ 2Ñ3Ô3ˆÔåÔ.Ð6Ý2CÀDÔDTÑ2UÔ2UÕÔ/àÐ Ý3Ô=Ý Ô7ñô ˆMˆMð (-ˆMÔ$å‰Œ×ÒØ j¸8ÐUdð 	ñ 	
ô 	
ð 	
ð 	
ð 	
ó    c                 óŽ   — t          di 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“ŽS )NÚshotsr	   Údevicerb   Ú	precisionÚdoubleÚexecutorÚmax_job_sizeÚmax_shot_sizeÚzero_thresholdg»½×Ùß|Û=Úseed_simulatorÚvalidation_thresholdÚmax_parallel_threadsÚmax_parallel_experimentsÚmax_parallel_shotsÚmax_memory_mbÚfusion_enableTÚfusion_verboseFÚfusion_max_qubité   Úfusion_thresholdé   Úblocking_qubitsÚblocking_enableÚstatevector_parallel_threshold© r   )Úclss    rs   Ú_default_optionsz!UnitarySimulator._default_optionsý   s  € åð 
ð 
ð 
à�!ð
ð �5ð
ð �hð	
ð
 �Tð
ð ˜ð
ð ˜$ð
ð !˜5ð
ð  ˜4ð
ð "& ð
ð "& ð
ð &* Tð
ð  $˜tð
ð ˜$ð
ð ˜$ð
ð  !˜5ð!
ð" ˜Qð#
ð$  ˜Rð%
ð& !˜Dð'
ð( "˜Eð)
ð, ,.¨2ð-
ð 	
rt   c                 ó  •— |dk    r[t          dt          ¦  «         |t          v r&t          |         \  }}|                      d|¦  «         |dk    rt	          d¦  «        ‚d S t          ¦   «                              ||¦  «         d S )NÚmethodz¡The method option of the `UnitarySimulator` has been deprecated as of qiskit-aer 0.9.0. To run a GPU statevector simulation use the option `device='GPU'` insteadrw   rJ   z?only the 'unitary' method is supported for the UnitarySimulator)r   ÚDeprecationWarningr   Ú
set_optionr   rn   )rp   ÚkeyÚvaluerw   rr   s       €rs   r“   zUnitarySimulator.set_option  s˜   ø€ Ø�(Š?ˆ?åðDõ #ñ	ô ð ð Õ)Ð)Ð)Ý 1°%Ô 8‘��vØ—’ ¨&Ñ1Ô1Ð1Ø˜	Ò!Ð!ÝÐ`ÑaÔaÐaØˆFÝ‰Œ×Ò˜3 Ñ&Ô&Ð&Ð&Ð&rt   c                 ó0   — t          dt          ¦  «         dS )ú(Return the available simulation methods.zàThe `available_methods` method of the UnitarySimulator is deprecated as of qiskit-aer 0.9.0 as this simulator only supports a single method. To check if GPU simulation is available use the `available_devices` method instead.)rJ   )r   r’   ©rp   s    rs   Úavailable_methodsz"UnitarySimulator.available_methods)  s%   € åð;õ ñ	
ô 	
ð 	
ð ˆ|rt   c                 ó4   — t          j         | j        ¦  «        S )r—   )Úcopyrk   r˜   s    rs   r   z"UnitarySimulator.available_devices4  s   € åŒy˜Ô0Ñ1Ô1Ð1rt   c                 ón   — t          |¦  «        }t          |d¦  «        }t          | j        |||¦  «        S )z Execute circuits on the backend.rJ   )r   r   r   rj   )rp   Úaer_circuitsÚnoise_modelÚconfigs       rs   Ú_execute_circuitsz"UnitarySimulator._execute_circuits8  s6   € å)¨&Ñ1Ô1ˆÝ(¨°yÑAÔAˆÝ# DÔ$4°lÀKÐQWÑXÔXÐXrt   )NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚintÚsortedrm   Ú_SIMULATION_DEVICESrk   ro   Úclassmethodr�   r“   r™   r   r    Ú__classcell__)rr   s   @rs   r   r   +   s>  ø€ € € € € ð_ð _ðD ,Ø&Ø*¨aÑ/Ø5ØØØØØØ�S˜‘X”Xð
 9ØØ�vð:ð :ð :ñ<
ô <
ðz  &˜vÐ&\Ð&\Ð&\Ñ]Ô]Øð_Pð PÐðd 3ÐàÐð
ð 
ð 
ð 
ð 
ð 
ð4 ð
ð 
ñ „[ð
ð4'ð 'ð 'ð 'ð 'ð"	ð 	ð 	ð2ð 2ð 2ðYð Yð Yð Yð Yð Yð Yrt   r   )r¤   r›   ÚloggingÚwarningsr   Úqiskit.providers.optionsr   Úaererrorr   Úversionr   Ú
aerbackendr
   Úbackend_utilsr   r   r   r   r   r   Úbackendconfigurationr   Úcontroller_wrappersr   Ú	getLoggerr¡   Úloggerr   r�   rt   rs   ú<module>rµ      sQ  ððð ð €€€Ø €€€Ø Ð Ð Ð Ð Ð à ,Ð ,Ð ,Ð ,Ð ,Ð ,à Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø "Ð "Ð "Ð "Ð "Ð "ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð :Ð 9Ð 9Ð 9Ð 9Ð 9ð 8Ð 7Ð 7Ð 7Ð 7Ð 7ð 
ˆÔ	˜8Ñ	$Ô	$€ðQYð QYð QYð QYð QY�zñ QYô QYð QYð QYð QYrt   