
    {	i-v                       S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	r
SSKJrJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJrJrJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"J#r#  SSK$J%r%J&r&J'r'J(r(J)r)  SSK*J+r+  SSK,J-r-J.r.  SSK/J0r0  S%S jr1S&S jr2 " S S\5      r3S'S jr4 " S S5      r5S(S jr6S)S jr7S*S  jr8S+S! jr9S,S" jr: " S# S$5      r;g)-z
Estimator class.
    )annotations)defaultdict)Sequence)warnN)ParameterExpressionQuantumCircuit)	transpile)BaseEstimatorV1EstimatorResult)PrimitiveJob)Options)Pauli	PauliListSparsePauliOp)BaseOperator)	BasePauli)ExperimentResult)CouplingMapPassManager)ApplyLayoutEnlargeWithAncillaFullAncillaAllocationOptimize1qGatesDecomposition	SetLayout)deprecate_func   )AerErrorAerSimulator   )_circuit_keyc                    [        U [        5      (       a  U $ [        U [        5      (       a,  [        U [        5      (       d  [	        S[        U 5       35      e[        U [        5      (       a  [	        S[        U 5       35      e[        U 5      $ )a&  Initialize observable by converting the input to a :class:`~qiskit.quantum_info.SparsePauliOp`.

Args:
    observable: The observable.

Returns:
    The observable as :class:`~qiskit.quantum_info.SparsePauliOp`.

Raises:
    AerError: when observable type cannot be converted to SparsePauliOp.
zobservable type not supported: )
isinstancer   r   r   r   typer   
observables    Y/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_aer/primitives/estimator.pyinit_observabler'   /   sz     *m,,	J	-	-jY6W6W8j9I8JKLLj),,<T*=M<NOPPZ((    c                
   U R                   R                  R                  5       U R                   R                  R                  5       U R                   R                  R                  5       U R
                  R                  5       4$ )zqPrivate key function for SparsePauliOp.
Args:
    observable: Input operator.

Returns:
    Key for observables.
)paulisztobytesxphasecoeffsr$   s    r&   _observable_keyr0   F   sh     	##%##%'')!!#	 r(   c                  `  ^  \ rS rSrSrSSSSSSS.           SU 4S jjjr\\" SS	SS
9S 5       5       r\R                  \" SS	SS
9S 5       5       r        SS jr
        SS jrS rS r\S 5       rSS jr\SS j5       r\S S j5       r  S!S jrS rS rS rS rSrU =r$ )"	EstimatorV   a  
Aer implementation of Estimator.

:Run Options:
    - **shots** (None or int) --
      The number of shots. If None and approximation is True, it calculates the exact
      expectation values. Otherwise, it calculates expectation values with sampling.

    - **seed** (int) --
      Set a fixed seed for the sampling.

.. note::
    Precedence of seeding for ``seed_simulator`` is as follows:

    1. ``seed_simulator`` in runtime (i.e. in :meth:`run`)
    2. ``seed`` in runtime (i.e. in :meth:`run`)
    3. ``seed_simulator`` of ``backend_options``.
    4. default.

    ``seed`` is also used for sampling from a normal distribution when approximation is True.

    When combined with the approximation option, we get the expectation values as follows:

    * shots is None and approximation=False: Return an expectation value with sampling-noise w/
      warning.
    * shots is int and approximation=False: Return an expectation value with sampling-noise.
    * shots is None and approximation=True: Return an exact expectation value.
    * shots is int and approximation=True: Return expectation value with sampling-noise using a
      normal distribution approximation.
NFT)backend_optionstranspile_optionsrun_optionsapproximationskip_transpilationabelian_groupingc                 > [        S[        SS9  [        TU ]  US9  / U l        / U l        / U l        Uc  0 OUnU(       a  SU;   a  SOSn[        US	9U l        U R                  R                  " S0 UD6  [        5       U l        Ub  U R                  R                  " S0 UD6  U(       d  [        S
[        SS9  X@l        XPl        0 U l        0 U l        0 U l        0 U l        0 U l        X`l        g)a  
Args:
    backend_options: Options passed to AerSimulator.
    transpile_options: Options passed to transpile.
    run_options: Options passed to run.
    approximation: If True, it calculates expectation values with normal distribution
        approximation. Note that this appproximation ignores readout errors.
    skip_transpilation: If True, transpilation is skipped.
    abelian_grouping: Whether the observable should be grouped into commuting.
        If approximation is True, this parameter is ignored and assumed to be False.
zMEstimator has been deprecated as of Aer 0.15, please use EstimatorV2 instead.   
stacklevel)optionsNnoise_modeldensity_matrix	automatic)methodOption approximation=False is deprecated as of qiskit-aer 0.13. It will be removed no earlier than 3 months after the release date. Instead, use BackendEstimator from qiskit.primitives. )r   DeprecationWarningsuper__init__	_circuits_parameters_observablesr   _backendset_optionsr   _transpile_optionsupdate_options_approximation_skip_transpilation_cache_transpiled_circuits_layouts_circuit_ids_observable_ids_abelian_grouping)	selfr4   r5   r6   r7   r8   r9   rB   	__class__s	           r&   rG   Estimator.__init__v   s    * 	[	

 	-  / 7"_ --?2RXc 	 %F3!!4O4"))(##22G5FGH # ,#5 TV?A!.0.013!1r(   z0.13z
qiskit-aer)sincepackage_nameis_propertyc                    U R                   $ )zThe approximation property)rO   rW   s    r&   r7   Estimator.approximation   s     """r(   c                <    U(       d  [        S[        SS9  Xl        g)zSetter for approximationrC   r;   r<   N)r   rE   rO   )rW   r7   s     r&   r7   r_      s%     H # ,r(   c                    UR                  SS 5      nUb  UR                  SU5        U R                  (       a  U R                  XX4U5      $ U R	                  XX45      $ )Nseedseed_simulator)pop
setdefaultrO   _compute_with_approximation_compute)rW   circuitsobservablesparameter_valuesr6   rb   s         r&   _callEstimator._call   sc     vt,""#3T:33'7d  ==8HVVr(   c                   / nU H  nU R                   R                  [        U5      5      nUb  UR                  U5        M=  UR                  [	        U R
                  5      5        [	        U R
                  5      U R                   [        U5      '   U R
                  R                  U5        U R                  R                  UR                  5        M     / nU H  n	[        U	5      n	U R                  R                  [        U	5      5      nUb  UR                  U5        MH  UR                  [	        U R                  5      5        [	        U R                  5      U R                  [        U	5      '   U R                  R                  U	5        M     [        U R                  UUU40 UD6n
[        U
S5      (       a  U
R                  OU
R                   " 5         U
$ )Nsubmit)rT   getr    appendlenrH   rI   
parametersr'   rU   r0   rJ   r   rk   hasattrrn   _submit)rW   rh   ri   rj   r6   circuit_indicescircuitindexobservable_indicesr%   jobs              r&   _runEstimator._run   s    !#G%%)),w*?@E &&u-&&s4>>':;;>t~~;N!!,w"78%%g.  ''(:(:;   $&%J(4J((,,_Z-HIE "))%0"))#d.?.?*@ADGHYHYDZ$$_Z%@A!!((4 & JJ	

 
 sH--3;;	>A
r(   c                Z  ^ ^ SU;   a8  US   c2  [        ST R                  R                  R                   S3[        5        [        U5      [        U5      T R                  4nUT R                  ;   aK  T R                  U   u  pgT R                  XX75      nT R                  Xh5      u  pT R                  XX7U5      nGOPT R                  U5        [        [        5      n[        X5       H  u  pX   R                  U5        M     0 n0 nUR!                  5        GH  u  p[#        U 4S jU 5       5      R%                  5       nT R&                  (       a  UR)                  SS9nOU Vs/ s H  n[+        U5      PM     nn[        [        5      nU HU  nT R,                  U   R.                   H5  n[1        U5       H#  u  nnUU;   d  M  UU   R                  U5          M3     M7     MW     UX}'   U Vs/ s H  n[3        U5      PM     nn[5        U5      S:X  aF  US   R6                  R9                  5       (       d$  US   R:                  R9                  5       (       d    OjU Vs/ s H  nT R=                  UU5      PM     nnT R>                  (       a  T R@                  U   OT RB                  U   nT RE                  UU5      Xm'   GM     Xg4T R                  U'   T R                  XX75      nT R                  Xh5      u  pT R                  XX7U5      nU	(       aJ  T R                  RF                  " U	4S	[9        U
5      (       a  U
OS 0UD6RI                  5       RJ                  mO/ m[        U4S
 jU 5       6 u  nn[M        [N        RP                  " U5      [        U5      5      $ s  snf s  snf s  snf )NshotsztIf `shots` is None and `approximation` is False, the number of shots is automatically set to backend options' shots=.c              3  V   >#    U  H  nTR                   U   R                  v   M      g 7fN)rJ   r*   ).0obs_indrW   s     r&   	<genexpr>%Estimator._compute.<locals>.<genexpr>#  s%      !EP'D%%g.55[s   &)T)
qubit_wiser   r   parameter_bindsc              3  D   >#    U  H  oR                  T5      v   M     g 7fr   )run)r   post_processingresultss     r&   r   r   X  s     SBR!!'**BRs    ))r   rK   r>   r}   RuntimeWarningtuplerO   rQ   _pre_process_params_flatten_create_post_processing_transpile_circuitsr   listziprp   itemssumuniquerV   group_commutingr   rJ   r*   	enumerate_paulis2basisrq   r-   anyr+   _create_meas_circuitrP   rH   rR   _combine_circsr   resultr   r   npreal_if_close)rW   rh   ri   rj   r6   keyexperiments_dictobs_mapsexp_mapexperimentsr   post_processingscirc_obs_mapcirc_indr   obs_indices
pauli_listpauli_listspauliobs_map	basis_indbasesbasismeas_circuitsrv   expectation_valuesmetadatar   s   `                          @r&   rg   Estimator._compute  s   k!k'&:&B..445Q8 	 Xk 2D4G4GH $++)-S)9&..xFVaG+/==9I+S(K#;;'77  $$X.&t,L%(%?!&--g6 &@!H)5););)=%  !EP! &(  ))","<"<"<"MKAK"L9U#3K"L%d+*G!%!2!27!;!B!B5>{5K1Iz$
2 ' 0 7 7	 B % 6L "C  + &-"EPQ[zz2[Qu:?58::>>+;+;E!HJJNNDTDTY^ _Y^PU!:!:5(!KY^ _ // NN8,228< 
 .2-@-@--X *3 *>4  09DKK..xFVaG ,0==9I+S(K  $;;'77 
 !!7:?7K7KOQU "
   G (+SBRS(
$H r//0BCT(^TTc #M R !`s   &N/N#N(c                X   [        [        5      n[        XU5       H  u  pgnU R                  X5        U R                  U   n	XF   U    HY  n
Xe;   aH  XU   ;   a@  [        U R                  U   5      S:  a$  XV   U
   S   nX;  a  UR                  U5        MN  MP  X/4XV   U
'   M[     M     U$ )Nr   r   )r   dictr   _validate_parameter_lengthrI   rq   rp   )rW   rh   ri   rj   r   r   r   r   	param_val	parameterr   
param_valss               r&   r   Estimator._pre_process_params\  s    d#,/GW,X(Hy++I@((2I%/8	'!X%66D,,X67!;!(!29!=a!@J 2")))4 3 5>{3KG%i0 9 -Y r(   c                &   / n/ nU  Hy  nUR                  X   5        X   R                  5        HM  u  nu  pgUR                  [        U5       VV	V
s0 s H  u  pX V
s/ s H  oU   PM	     sn
_M     sn
n	n/5        MO     M{     X#4$ s  sn
f s  sn
n	nf r   )extendr   r   )r   r   experiments_listr   r   _r   r   iparamr   s              r&   r   Estimator._flatteno  s    (H##$4$>?.5.?.E.E.G**I&& -6i,@,@ "*#M*YaL*#MM,@ /H )  00 $Ns   BB+BBc                   [         R                  " UR                  5      UR                  UR                  -     n[        UR                  [        U5      5      n[        U5       H`  u  pVUR                  U   (       a6  UR                  U   (       a  UR                  U5        UR                  U5        UR                  Xe5        Mb     SU0Ul        U R                  (       a  U$ U R                  U   n[        [        U5      /5      n[!        U R"                  R$                  S9n	UR'                  U	5        [)        U R"                  R*                  [,        5      (       aI  U R"                  R*                  n
UR'                  [/        U
5      5        UR'                  [1        5       5        UR'                  [3        5       5        UR5                  U5      $ )Nr   )target)r   arange
num_qubitsr+   r-   r   rq   r   sdghmeasurer   rP   rS   r   r   r   rK   r   rp   r"   coupling_mapr   r   r   r   r   )rW   r   circuit_indexqargsmeas_circuitclbitqarglayoutpassmanageropt1qr   s              r&   r   Estimator._create_meas_circuit  sX   		%**+EGGegg,=>%e&6&6E
C$U+KEwwt}774= $$T*t$  - , ")% 0##}-!9V#4"56,DMM4H4HI5!dmm00+>>==55L4\BC134;=)|,,r(   c                    / nU Hm  nU R                  5       nUR                   H  nUR                  U5        M     UR                  USS9  [	        XCR
                  5        UR                  U5        Mo     U$ )NT)inplace)copycregsadd_registercompose_update_metadatar   rp   )rv   r   circsr   new_circcregs         r&   r   Estimator._combine_circs  sn    )L||~H$**%%d+ +\48X'<'<=LL" * r(   c                   X@   U   U   nSnUR                  5        H^  u  p[        U	R                  5       5       H<  u  n
u  nu  pX:X  a  Xj:X  a  X|R                  U5      -  nUs  s  $ U[        U5      -  nM>     M`     [	        S5      e)Nr   zJBug. Please report from issue: https://github.com/Qiskit/qiskit-aer/issues)r   r   rw   rq   r   )r   r   term_indr   r   r   r   result_index	_circ_ind	basis_map
_basis_indr   r   s                r&   _calculate_result_index!Estimator._calculate_result_index  s    &w/9	$+MMO I4=ioo>O4P0
0Q(Y-D $4$4Y$??L''J/	 5Q %4 cddr(   c           
        / n[        XU5       GHv  u  pxn	/ n
/ n/ nU R                  U   n[        [        UR                  UR                  5      5       GH  u  nu  nnUR
                  R                  5       (       d^  UR                  R                  5       (       d?  U
R                  S 5        UR                  [        U5      5        UR                  U/5        M  U R                  XxXXE5      nUU
;   a4  U
R                  U5      nUU==   U-  ss'   UU   R                  U5        M  U
R                  U5        UR                  [        U5      5        UR                  U/5        GM     UR                  [        XU5      5        GMy     U$ r   )r   rJ   r   r*   r/   r-   r   r+   rp   r   r   rw   _PostProcessing)rW   rh   ri   rj   r   r   r   r   r   r   result_indicesr*   r/   r%   r   r   coeffr   r   s                      r&   r   !Estimator._create_post_processing  sW    ,/GW,X(Hy/1NFF**73J,5c*:K:KZM^M^6_,`(.5%ww{{}}UWW[[]]"))$/MM)E"23MM5'*#;;xH   >1&,,\:A1I&I1I$$U+")),7MM)E"23MM5'*% -a& ##ONF$ST1 -Y2  r(   c           
     v	   [        U5      [        U5      U R                  4nUR                  SS 5      nX`R                  ;   a  [	        [
        5      n[        XU5       Hf  u  pnU R                  X5        [        U R                  U	   U5       H2  u  pXX4   ;   a  XU
4   U   R                  U5        M(  U/XU
4   U'   M4     Mh     U R                  U   n[        UR                  5       5      Ul        GOU R                  U5        [        5       n[        XU5       GHJ  u  pnU R                  X5        X4UR                  ;   a,  UR                  R!                  X45      nUR"                  U   nOU R$                  (       a  U R&                  U	   R)                  5       OU R*                  U	   R)                  5       nU R,                  U
   nUc   UR/                  UU R0                  U	   5        OF[3        UR4                  5       H-  u  nnUR/                  UU R0                  U	   [7        U5      S9  M/     UR                  X4[        [        U R                  U	   U5      5      US9  GMM     XR                  U'   U R8                  R:                  " UR"                  4SUR                  0UD6R=                  5       nUce  UR>                   V	s/ s H  n	URA                  U	5      S   PM     nn	UR>                   V	s/ s H  n	SURB                  U	   RD                  0PM      nn	GOm/ n[F        RH                  RK                  U5      n/ nUR>                  n[M        [O        U5      5       GH%  n	SnSnUU	   nURQ                  U	5      n[F        RR                  " U R,                  U   RT                  5      nURA                  U5      RW                  5        H/  u  nnSUS	-  -
  nU[Y        U5         n UUU -  -  nUUU S	-  -  -  nM1     [F        RZ                  " UU-  5      n!UR                  UR]                  UU!5      5        UR                  [F        RR                  " U5      R_                  5       UURB                  U   RD                  S
.5        GM(     [a        [F        RR                  " U5      U5      $ s  sn	f s  sn	f )Nr}   )label)r   parameter_bindexperiment_circuitr   expectation_valuesimulator_metadata        r   r   )variancer}   r   )1r   rO   rd   rQ   r   r   r   r   rI   rp   r   valuesr   r   _ExperimentManagerkeysrw   experiment_circuitsrP   rH   r   rR   rJ   save_expectation_valuerS   r   r*   strrK   r   r   experiment_indicesdatar   r   r   randomdefault_rngrangerq   get_observable_keyr   r/   r   intsqrtnormalitemr   )"rW   rh   ri   rj   r6   rb   r   r}   r   r   jvaluekvexperiment_manager	key_indexrv   r%   r   r   r   r   r   rngr   combined_expvalcombined_varr   observable_keyr/   expvalvarr   standard_errors"                                     r&   rf   %Estimator._compute_with_approximation  s    Xk 2D4G4GH. ++)$/O"8:JKe//9 0 0 3U;DAQF33'A/299!<67SA/2	 <  L "&S!115o6L6L6N1O.$$X.!3!5"8:JKe//96/444 2 7 7 = =qf EI0DDYOG  33 q)..0!66q9>>@ 
 "&!2!21!5J}66z4==QRCST/89J9J/KOHe#:: %t}}Q'7s8} ;  0L #))#'D,<,<Q,?(G#H'. * '  L2  2KK""22
.>>
 
 &(	 	 ==O=b=b"=bA23=b  "
 ,>>>A &v~~a'8'A'AB>  H
 "$))''-CH!3!F!F3123"%"1!4!3!F!Fq!I))$*;*;N*K*R*RS(.L(A(G(G(I$Hffai-C"3x=1E#v~5O C%(N2L	 )J "$)=!>"))#**_n*UV$&$4$4\$B$G$G$I!&.4nn\.J.S.S 4, r//0BCXNNE"s   R1;%R6c           	         [        U5      [        U R                  U   5      :w  a1  [        S[        U5       S[        U R                  U   5       S35      eg )NzThe number of values (z+) does not match the number of parameters (z).)rq   rI   
ValueError)rW   r   r   s      r&   r   $Estimator._validate_parameter_length-  sa    y>S!1!1-!@AA(Y(8 9--01A1A-1P-Q,RRTV  Br(   c                |    U R                   (       a  U$ [        XR                  40 U R                  R                  D6$ r   )rP   r	   rK   rM   __dict__)rW   rh   s     r&   
_transpileEstimator._transpile4  s0    ##O==UD4K4K4T4TUUr(   c                   U R                   (       aM  [        U5       H=  nU R                  U   R                  n[	        [        U5      5      U R                  U'   M?     g [        U5       H  nX R                  ;  d  M  U R                  U   R                  5       nUR                  5         UR                  nU R                  R                  U5        U R                  U5      n[        UR                  5       VVs0 s H  u  pVXe_M	     nnnXC* S   VV	s/ s H  u  poU	S      PM     n
nn	UR                  5         X@R                  U'   XR                  U'   M     g s  snnf s  sn	nf Nr   )rP   setrH   r   r   r   rS   rR   r   measure_allrK   set_max_qubitsr  r   qubitsremove_final_measurements)rW   rh   r   r   rv   rw   bitbit_mapr   qrr   s              r&   r   Estimator._transpile_circuits9  s+   ##]!^^A.99
#'j(9#:a  # XA111..+002##%$//
,,Z8//'28A'..8QR8Q*%3:8QR9@9NO9NXQA"Q%.9NO113/6))!,#)a   SOs   ;EE")rV   rO   rK   rQ   rT   rH   rS   rU   rJ   rI   rP   rM   rR   )r4   dict | Noner5   r"  r6   r"  r7   boolr8   r#  r9   r#  )rh   Sequence[int]ri   r$  rj   Sequence[Sequence[float]]returnr   )rh   zSequence[QuantumCircuit]ri   zSequence[BaseOperator]rj   r%  r&  r   )r   r   r   r   )rv   r   r   zlist[QuantumCircuit])r&  r   )r&  zlist[_PostProcessing])__name__
__module____qualname____firstlineno____doc__rG   propertyr   r7   setterrk   rz   rg   r   staticmethodr   r   r   r   r   rf   r   r  r   __static_attributes____classcell__)rX   s   @r&   r2   r2   V   s   D (,)-#'##(!%92 %92 '	92
 !92 92 !92 92 92v !
# # !

, 
,WW #W 4	W 
W$$*$ ,$ 4	$ 
$LUUn& 1 1 -2 	 	 
e 
e 	 >ZOxV
* *r(   r2   c                    SnSnU R                  5        H7  u  p4[        US5      nX-  nX$S[        U5      R                  S5      -  -  -  nM9     X!-  nSUS-  -
  nX&4$ )Nr   r      1r   r   )r   r   bincount)countsdenomr  bin_outcomefreqoutcomer   s          r&   _expval_with_variancer<  M  sr    EF#\\^k2&"W!3!3C!8888 ,
 OF619}Hr(   c                  4    \ rS rSr      SS jrSS jrSrg)r   i[  c                ~    Xl         X l        U Vs/ s H  n[        R                  " U5      PM     snU l        g s  snf r   )_result_indices_paulisr   array_coeffs)rW   r   r*   r/   cs        r&   rG   _PostProcessing.__init__\  s0      .-34VV44s    :c                   SnSn/ n[        U R                  U R                  U R                  5       GHT  u  pVnUc6  [        R
                  " S/[        S9[        R
                  " S/[        S9pSn
OX   nUR                  R                  n[        UR                  5       5      n
 UR                  R                  S   n[        R                  " UR                  UR                   -  5      S   n["        R$                  " UR                  SS2U4   UR                   SS2U4   S5      n['        X5      u  pUR)                  UR                  5        U[        R*                  " X5      -  nU[        R*                  " XS-  5      -  nGMW     W
[        R,                  " U5      R/                  5       US	.nUU4$ ! [         a    UR                  S   S   n GNf = f)
zCoumpute expectation value.

Args:
    results: list of ExperimentResult.

Returns:
    tuple of an expectation value and metadata.
r   Nr   dtyper   r   r   r   )r}   r   r   )r   r?  r@  rB  r   rA  complexr   r7  r   r   headerr   AttributeErrorwherer+   r-   r   from_symplectic_pauli_expval_with_variancerp   dotr   r  )rW   r   r	  r
  r   c_ir*   r/   expvals	variancesr}   r   r6  r   indicesmeasured_paulisr   s                    r&   r   _PostProcessing.runf  s    #&t';';T\\4<<#XC{%'XXqc%A288QCW^C_ **ELLN+?"MM227;E ((577UWW#45a8"+";";HHQZ(&((1g:*># &A%X""))&//:rvvg66OBFF9ai88L- $Y0 ((6;;="4

 (( & ?"MM*5g>E?s   &F77GG)rB  r@  r?  N)r   	list[int]r*   zlist[PauliList]r/   zlist[list[float]])r   zlist[ExperimentResult]r&  ztuple[float, dict])r'  r(  r)  r*  rG   r   r/  rD   r(   r&   r   r   [  s(    5!5  5 "	5()r(   r   c                n    U R                   (       a  U R                   R                  U5        U $ Xl         U $ r   )r   update)rv   r   s     r&   r   r     s3    ) N $Nr(   c                :   [        U5      n[        U5      n[        R                  " U[        S9nSnU R                  5        HH  u  pg[        US5      nXW-  n[        U5       H$  n	S[        X9   U-  5      -  n
XI==   Xz-  -  ss'   M&     MJ     XE-  nSUS-  -
  nXK4$ )NrF  r   r2  r3  r   r   )	rq   _paulis2indsr   zerosfloatr   r   r   _parity)r7  r*   size	diag_indsrP  r8  hex_outcomer:  r;  r  r   rQ  s               r&   rM  rM    s    v;DV$Ihht5)GE#\\^k2&tAGIL7$:;;EJ$,&J  , GGQJIr(   c                   U R                   U R                  -  n[        R                  " USSS9R	                  [
        5      nSS[        R                  " UR                  S   [
        S9-  -  nX#-  nUR                  5       $ )Nr   little)axisbitorder   rF  )	r+   r-   r   packbitsastypeobjectr   shapetolist)r*   nonidpacked_valspower_uint8indss        r&   rY  rY    so    HHvxxE++e!h?FFK BIIk&7&7&:&IIJK$D;;=r(   c                <    [        U 5      R                  S5      S-  $ )zReturn the parity of an integerr4  r   )r5  r6  )integers    r&   r\  r\    s    w<c"Q&&r(   c                    [        [        R                  R                  U R                  5      [        R                  R                  U R
                  5      45      $ r   )r   r   
logical_orreducer+   r-   )r*   s    r&   r   r     s@    MM  *MM  *	
 r(   c                  L    \ rS rSrS rS r\S 5       r      S	S jrS r	Sr
g)
r   i  c                J    / U l         / U l        / U l        / U l        SU l        g r  )r   r   r   _input_indices_num_experimentr^   s    r&   rG   _ExperimentManager.__init__  s)    +-	9; MO/1$%r(   c                    U R                   $ r   )rv  r^   s    r&   __len___ExperimentManager.__len__  s    ###r(   c                r    [         R                  " [        U R                  / 5      5      R	                  5       $ )zindices of experiments)r   argsortr   ru  ri  r^   s    r&   r   %_ExperimentManager.experiment_indices  s)     zz#d11267>>@@r(   c                   XR                   ;   a  U(       a}  U R                   R                  U5      nU R                  U   R                  5        H  u  pVUR	                  X%   5        M     U R
                  U   R	                  U R                  5        OU R                  R	                  U5        U R                   R	                  U5        U R                  R	                  UR                  5        VVs0 s H  u  pWXW/_M
     snn5        U R
                  R	                  U R                  /5        U =R                  S-  sl        gs  snnf )zappend experimentsr   N)r   rw   r   r   rp   ru  rv  r   )rW   r   r   r   r  r  vsr  s           r&   rp   _ExperimentManager.append  s     ))		,I--i8>>@		.+, A	*11$2F2FG$$++,>?IIS!  ''N<P<P<R(S<RDAC<R(ST&&(<(<'=>! )Ts   2E
c                    [        U R                  5       H  u  p#X;   d  M  U R                  U   S   s  $    [        S5      e)zreturn key of observablesr   zUnexpected behavior.)r   ru  r   r   )rW   rw   r   inputss       r&   r   %_ExperimentManager.get_observable_key  s>    "4#6#67IAyy|A& 8 -..r(   )ru  rv  r   r   r   N)r   ztuple[int, int]r   z dict[ParameterExpression, float]r   r   )r'  r(  r)  r*  rG   ry  r,  r   rp   r   r/  rD   r(   r&   r   r     sH    &$ A A"" 9" +	"(/r(   r   )r%   zBaseOperator | strr&  r   )r%   r   r&  r   )r&  ztuple[float, float])rv   r   r   r   r&  r   )r7  r   r*   r   r&  ztuple[np.ndarray, np.ndarray])r*   r   r&  rU  )ro  r   r&  r   )r*   r   r&  r   )<r+  
__future__r   collectionsr   collections.abcr   warningsr   numpyr   qiskit.circuitr   r   qiskit.compilerr	   qiskit.primitivesr
   r   qiskit.primitives.primitive_jobr   qiskit.providersr   qiskit.quantum_infor   r   r   +qiskit.quantum_info.operators.base_operatorr   3qiskit.quantum_info.operators.symplectic.base_paulir   qiskit.result.modelsr   qiskit.transpilerr   r   qiskit.transpiler.passesr   r   r   r   r   qiskit.utilsr    r   r   samplerr    r'   r0   r2   r<  r   r   rM  rY  r\  r   r   rD   r(   r&   <module>r     s    # # $   > % > 8 $ ? ? D I 1 6  ( % !). t* t*n3) 3)l*'
)/ )/r(   