
    {	i2                        S r SSKrSSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSKJr  SS	KJrJrJrJrJr  SS
KJr  \R*                  " 5       R,                  S-  r\" \" \S-  S-  5      5      r\R4                  R7                  \5      r\" \5        SSSSSSSSSS.	r\" / SQ5      \" / SQ5      \" / SQ5      \" / SQ5      \" / SQ5      \" / SQ5      \" / SQ5      \" / SQ5      S.r \" \!" \ S    5      RE                  \ S!   5      RE                  \ S"   5      RE                  \ S#   5      RE                  \ S$   5      RE                  \ S%   5      RE                  \ S&   5      5      =\ S'   \ S''   S( r#S) r$S* r%S+ r&S, r'S- r(S. r) " S/ S0\5      r*g)1z
Aer simulator backend utils
    N)log2)SimpleNamespace)QuantumCircuit)ProbDistribution)Clifford   )StatevectorDensityMatrixStabilizerStateOperatorSuperOp)aer_initialize_librariesi   @   )statevectorCPU)r   GPU)r   Thrust)density_matrixr   )r   r   )r   r   )unitaryr   )r   r   )r   r   )	statevector_cpustatevector_gpustatevector_thrustdensity_matrix_cpudensity_matrix_gpudensity_matrix_thrustunitary_cpuunitary_gpuunitary_thrust)>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cpcucu1cu2cu3rxxryyrzzrzxccxcczcrxcrycrzcswapmcxmcymczmcsxmcpmcphasemcumcu1mcu2mcu3mcrxmcrymcrzmcrmcswapr   diagonalmultiplexerpaulimcx_grayecrstore)#r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r8   r:   r=   r>   r?   r@   rA   r   rV   rX   rZ   )&r   r    r!   r"   r#   r8   r4   r5   r6   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   rA   r   roerrorrX   r$   r%   r&   r'   r=   r>   r?   r@   r7   rF   rV   rZ   r[   )r(   r)   r*   r+   r,   r-   r.   r/   r0   r4   r5   r6   r3   rX   rZ   r'   r[   )r4   r6   r(   r)   r*   r+   r,   r-   r.   r/   r0   r3   u0r1   r2   r   r#   rA   rB   rX   rZ   r'   r[   )=r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rF   rC   rD   rE   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   r   rV   rW   rX   rZ   r[   )#r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r8   r:   r=   r>   r?   r@   rA   r   rV   rX   r[   )>r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rF   rC   rD   rE   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   r   rV   rW   rX   rY   rZ   r[   )r   r   matrix_product_state
stabilizerextended_stabilizerr   superoptensor_networkr   r_   r   r^   r   ra   rb   	automaticc                 l    [         Ul        U(       a  UR                  SS9O0 nU R                  XU5      $ )z.Execute aer circuits on C++ controller wrapperT)serializable)LIBRARY_DIRlibrary_dirto_dictexecute)
controlleraer_circuitsnoise_modelconfigs       [/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_aer/backends/backend_utils.pycpp_execute_circuitsro     s6    
 %F<G+%%4%8RKl@@    c                     / nU  H5  nUS:X  a  SU;   a  UR                  U5        M"  M$  UR                  U5        M7     [        U5      $ )z"Check available simulation methodsrb   r   )appendtuple)methodsdevicesvalid_methodsmethods       rn   available_methodsrx     sT     M%%$$V,     (  rp   c                 8    U R                  5       n[        U5      $ )z#return available simulation devices)available_devicesrs   )rj   devs     rn   rz   rz     s    

&
&
(C:rp   c                     U  H8  nUR                   nUR                  [        [        U5      5      SU 3SU5        M:     U $ )z5Add final save state op to all experiments in a qobj.save_single)
num_qubits
save_statelistrange)rk   stateaer_circuitr   s       rn   add_final_save_opr     sF     $ ++
tE*$56%wSXY $ rp   c                 ^    U R                   nU[        ;   a  [        U   u  U l         U l        U $ )zBMap legacy method names of qasm simulator to aer simulator options)rw   LEGACY_METHOD_MAPdevice)rm   rw   s     rn   map_legacy_method_configr     s,    ]]F""'8'@$v}Mrp   c                   ^^ [         [        [        [        S [        R
                  [        S.mTT;  a  U $ US;   a  UU4S jnOTT   nUSS S:X  a+  U R                  5        VVs0 s H  u  pEXC" U5      _M     snn$ U" U 5      $ s  snnf )z4Format raw simulator result data based on save type.c                 @    [        [        R                  " U 5      5      $ N)r   r   	from_dict)datas    rn   <lambda>"format_save_type.<locals>.<lambda>  s    9K9KD9Q)Rrp   )save_statevectorsave_density_matrixsave_unitarysave_superopsave_stabilizersave_cliffordsave_probabilities_dict)r   c_listc                 H   > TT   nU  Vs/ s H
  o!" U5      PM     sn$ s  snf r    )r   init_fniinit_fns	save_types      rn   funcformat_save_type.<locals>.func  s)    y)G(,-1GAJ---s   N   c_)r	   r
   r   r   r   r   r   items)r   r   save_subtyper   keyvalr   s    `    @rn   format_save_typer     s     (, R!++#3H  ))	.
 	" BQ4/3zz|<|83T#Y|<<: =s   'Bc                    [        U [        5      (       d
  [        5       $ [        5       nU R                   H5  nUR	                  [        UR                  5      R                  5       5        M7     UR                  [        5        U$ )z@Return set of all operation types and parent types in a circuit.)

isinstancer   setr   updatetype	operationmrodiscardobject)circuitoptypesinstructions      rn   circuit_optypesr     s\    g~..ueG||tK1126689 $OOFNrp   c                   :    \ rS rSrSrS rS r\S 5       rS r	Sr
g)	CircuitHeaderi  zAA class used to represent a dictionary header in circuit objects.c                 :    U R                   R                  U5        g)zInstantiate a new circuit dict field object.

Args:
    kwargs: arbitrary keyword arguments that can be accessed as
        attributes of the object.
N)__dict__r   )selfkwargss     rn   __init__CircuitHeader.__init__  s     	V$rp   c                     U R                   $ )zxReturn a dictionary format representation of the circuit.

Returns:
    dict: The dictionary form of the CircuitHeader.
)r   )r   s    rn   rh   CircuitHeader.to_dict  s     }}rp   c                     U " S0 UD6$ )a  Create a new header object from a dictionary.

Args:
    data (dict): A dictionary representing the header to create. It
        will be in the same format as output by :func:`to_dict`.

Returns:
    CircuitHeader: The CircuitHeader from the input dictionary.
r   r   )clsr   s     rn   r   CircuitHeader.from_dict%  s     {T{rp   c                 n    [        XR                  5      (       a  U R                  UR                  :X  a  gg)NTF)r   	__class__r   )r   others     rn   __eq__CircuitHeader.__eq__3  s'    e^^,,}}.rp   r   N)__name__
__module____qualname____firstlineno____doc__r   rh   classmethodr   r   __static_attributes__r   rp   rn   r   r     s(    K%  rp   r   )+r   osmathr   typesr   psutilqiskit.circuitr   qiskit.resultr   qiskit.quantum_infor   compatibilityr	   r
   r   r   r   controller_wrappersr   virtual_memorytotalSYSTEM_MEMORY_GBintMAX_QUBITS_STATEVECTORpathdirname__file__rf   r   sortedBASIS_GATESr   unionro   rx   rz   r   r   r   r   r   r   rp   rn   <module>r      s   
  !  ) * ( Y Y : ((*00G<  T"2g">"CDE  ggooh'  % .-3339%%+
  ?	
AD $	
&N #'	
)T 	
* "	
6 >	
@B $	
&N ?	
AY	nd 06M"#
U;|$%
U;'()
U;-./
U;y!"
U;y!"
U;'()0 D K,	A
 @&O &rp   