§
    º³Ùg´9  ã                  óð   — d Z ddlmZ ddlZddlZddlmZ d.d
„Zd/d„Z	d0d1d„Z
d0d1d„Zd0d1d„Zd0d1d„Zd0d1d„Z	 	 	 d2d3d„Z	 	 	 d2d4d!„Z	 	 	 d5d6d#„Z	 	 	 d2d7d%„Zd&„ Z	 	 	 d2d4d'„Z	 d8d9d)„Z	 d:d;d+„Z	 	 d<d=d-„ZdS )>z.Module for builtin continuous pulse functions.é    )ÚannotationsN)Ú
PulseErrorÚtimesú
np.ndarrayÚampÚcomplexÚreturnc                ó^   — t          j        t          | ¦  «        |t           j        ¬¦  «        S )zzContinuous constant pulse.

    Args:
        times: Times to output pulse for.
        amp: Complex pulse amplitude.
    ©Údtype)ÚnpÚfullÚlenÚ
complex128)r   r   s     úU/granary/edev/quantum/lib/python3.11/site-packages/qiskit/pulse/library/continuous.pyÚconstantr      s#   € õ Œ7•3�u‘:”:˜s­"¬-Ð8Ñ8Ô8Ð8ó    c                ó"   — t          | d¦  «        S )zPContinuous zero pulse.

    Args:
        times: Times to output pulse for.
    r   )r   )r   s    r   Úzeror   "   s   € õ �E˜1ÑÔÐr   ÚfreqÚfloatÚphasec                óÖ   — | |z  |t           j        z  z   }|ddt          j        |¦  «        z  t          j        d|z  ¦  «        z
  z  dz                        t           j        ¦  «        z  S )zÓContinuous square wave.

    Args:
        times: Times to output wave for.
        amp: Pulse amplitude. Wave range is [-amp, amp].
        freq: Pulse frequency. units of 1/dt.
        phase: Pulse phase.
    é   é   ©r   ÚpiÚfloorÚastyper   ©r   r   r   r   Úxs        r   Úsquarer"   +   sZ   € ð 	�‰�u�rœu‘}Ñ$€AØ�!�q�2œ8 A™;œ;‘­¬°!°a±%©¬Ñ8Ñ9¸AÑ=×EÒEÅbÄmÑTÔTÑTÐTr   c                ó¦   — | |z  |t           j        z  z   }|dz  |t          j        d|z   ¦  «        z
                       t           j        ¦  «        z  S )zÕContinuous sawtooth wave.

    Args:
        times: Times to output wave for.
        amp: Pulse amplitude. Wave range is [-amp, amp].
        freq: Pulse frequency. units of 1/dt.
        phase: Pulse phase.
    r   g      à?r   r    s        r   Úsawtoothr$   8   sJ   € ð 	�‰�u�rœu‘}Ñ$€AØ�‰7�a�"œ( 5¨1¡9Ñ-Ô-Ñ-×5Ò5µb´mÑDÔDÑDÐDr   c                ó¾   — |dt          j        t          | d||t           j        dz  z
  dz  ¬¦  «        ¦  «        z  dz                        t           j        ¦  «        z  S )zÕContinuous triangle wave.

    Args:
        times: Times to output wave for.
        amp: Pulse amplitude. Wave range is [-amp, amp].
        freq: Pulse frequency. units of 1/dt.
        phase: Pulse phase.
    éþÿÿÿr   r   )r   )r   Úabsr$   r   r   r   ©r   r   r   r   s       r   Útriangler)   E   s_   € ð �"•r”v�h u¨a°¸eÅbÄeÈaÁiÑ>OÐSTÑ=TÐUÑUÔUÑVÔVÑVÐYZÑZ×bÒbÝ
Œñô ñ ð r   c                ó–   — |t          j        dt           j        z  |z  | z  |z   ¦  «                             t           j        ¦  «        z  S ©z¸Continuous cosine wave.

    Args:
        times: Times to output wave for.
        amp: Pulse amplitude.
        freq: Pulse frequency, units of 1/dt.
        phase: Pulse phase.
    r   )r   Úcosr   r   r   r(   s       r   r,   r,   S   ó>   € ð •”˜�BœE™	 DÑ(¨5Ñ0°5Ñ8Ñ9Ô9×@Ò@ÅÄÑOÔOÑOÐOr   c                ó–   — |t          j        dt           j        z  |z  | z  |z   ¦  «                             t           j        ¦  «        z  S r+   )r   Úsinr   r   r   r(   s       r   r/   r/   _   r-   r   FÚgaussian_samplesÚcenterÚsigmaÚzeroed_widthúfloat | NoneÚrescale_ampÚboolÚret_scale_factorú%np.ndarray | tuple[np.ndarray, float]c                ó¸   — |€d|dz   z  }t          t          j        |dz  g¦  «        |d|¦  «        }| |z  } d}|r||z
  dk    r|||z
  z  nd}| |z  } |r| |fS | S )að  Enforce that the supplied gaussian pulse is zeroed at a specific width.

    This is achieved by subtracting $\Omega_g(center \pm zeroed_width/2)$ from all samples.

    amp: Pulse amplitude at `center`.
    center: Center (mean) of pulse.
    sigma: Standard deviation of pulse.
    zeroed_width: Subtract baseline from gaussian pulses to make sure
        $\Omega_g(center \pm zeroed_width/2)=0$ is satisfied. This is used to avoid
        large discontinuities at the start of a gaussian pulse. If unsupplied,
        defaults to $2*(center + 1)$ such that $\Omega_g(-1)=0$ and $\Omega_g(2*(center + 1))=0$.
    rescale_amp: If True the pulse will be rescaled so that $\Omega_g(center)=amp$.
    ret_scale_factor: Return amplitude scale factor.
    Nr   r   r   ç      ð?)Úgaussianr   Úarray)	r0   r   r1   r2   r3   r5   r7   Úzero_offsetÚamp_scale_factors	            r   Ú_fix_gaussian_widthr?   k   s¡   € ð. ÐØ˜F Q™JÑ'ˆå�2œ8 \°AÑ%5Ð$6Ñ7Ô7¸¸aÀÑGÔG€KØ˜Ñ#ÐØ58ÐØð -Ø8;¸kÑ8IÈQÒ8NÐ8N˜3 #¨Ñ"3Ñ4Ð4ÐTWÐØÐ,Ñ,Ðàð 2ØÐ!1Ð1Ð1ØÐr   Úret_xú*np.ndarray | tuple[np.ndarray, np.ndarray]c                ó  — t          j        | t           j        ¬¦  «        } | |z
  |z  }|t          j        |dz   dz  ¦  «                             t           j        ¦  «        z  }|�t          ||||||¬¦  «        }|r||fS |S )a7  Continuous unnormalized gaussian pulse.

    Integrated area under curve is $\Omega_g(amp, sigma) = amp \times np.sqrt(2\pi \sigma^2)$

    Args:
        times: Times to output pulse for.
        amp: Pulse amplitude at `center`. If `zeroed_width` is set pulse amplitude at center
            will be $amp-\Omega_g(center \pm zeroed_width/2)$ unless `rescale_amp` is set,
            in which case all samples will be rescaled such that the center
            amplitude will be `amp`.
        center: Center (mean) of pulse.
        sigma: Width (standard deviation) of pulse.
        zeroed_width: Subtract baseline from gaussian pulses to make sure
            $\Omega_g(center \pm zeroed_width/2)=0$ is satisfied. This is used to avoid
            large discontinuities at the start of a gaussian pulse.
        rescale_amp: If `zeroed_width` is not `None` and `rescale_amp=True` the pulse will
            be rescaled so that $\Omega_g(center)=amp$.
        ret_x: Return centered and standard deviation normalized pulse location.
               $x=(times-center)/sigma.
    r   r   N©r   r1   r2   r3   r5   )r   Úasarrayr   Úexpr   r?   )	r   r   r1   r2   r3   r5   r@   r!   Úgausss	            r   r;   r;   ‘   sš   € õ: ŒJ�u¥B¤MÐ2Ñ2Ô2€EØ	�‰˜5Ñ €AØ•"”&˜1˜a™4˜ 1™Ñ%Ô%×,Ò,­R¬]Ñ;Ô;Ñ;€EàÐÝ#ØØØØØ%Ø#ð
ñ 
ô 
ˆð ð Ø�aˆxˆØ€Lr   Úret_gaussianc           	     óV   — t          | |||||d¬¦  «        \  }}| |z  |z  }	|r|	|fS |	S )a¢  Continuous unnormalized gaussian derivative pulse.

    Args:
        times: Times to output pulse for.
        amp: Pulse amplitude at `center`.
        center: Center (mean) of pulse.
        sigma: Width (standard deviation) of pulse.
        ret_gaussian: Return gaussian with which derivative was taken with.
        zeroed_width: Subtract baseline of pulse to make sure
            $\Omega_g(center \pm zeroed_width/2)=0$ is satisfied. This is used to avoid
            large discontinuities at the start of a pulse.
        rescale_amp: If `zeroed_width` is not `None` and `rescale_amp=True` the pulse will
            be rescaled so that $\Omega_g(center)=amp$.
    T)r   r1   r2   r3   r5   r@   )r;   )
r   r   r1   r2   rG   r3   r5   rF   r!   Úgauss_derivs
             r   Úgaussian_derivrJ   Á   s\   € õ. ØØØØØ!ØØðñ ô �H€Eˆ1ð �"�u‘*˜uÑ$€KØð "Ø˜EÐ!Ð!ØÐr   Úsech_samplesc                ó¸   — |€d|dz   z  }t          t          j        |dz  g¦  «        |d|¦  «        }| |z  } d}|r||z
  dk    r|||z
  z  nd}| |z  } |r| |fS | S )aä  Enforce that the supplied sech pulse is zeroed at a specific width.

    This is achieved by subtracting $\Omega_g(center \pm zeroed_width/2)$ from all samples.

    amp: Pulse amplitude at `center`.
    center: Center (mean) of pulse.
    sigma: Standard deviation of pulse.
    zeroed_width: Subtract baseline from sech pulses to make sure
        $\Omega_g(center \pm zeroed_width/2)=0$ is satisfied. This is used to avoid
        large discontinuities at the start of a sech pulse. If unsupplied,
        defaults to $2*(center + 1)$ such that $\Omega_g(-1)=0$ and $\Omega_g(2*(center + 1))=0$.
    rescale_amp: If True the pulse will be rescaled so that $\Omega_g(center)=amp$.
    ret_scale_factor: Return amplitude scale factor.
    Nr   r   r   r:   )Úsechr   r<   )	rK   r   r1   r2   r3   r5   r7   r=   r>   s	            r   Ú_fix_sech_widthrN   ç   sŸ   € ð. ÐØ˜F Q™JÑ'ˆå•r”x °Ñ!1Ð 2Ñ3Ô3°S¸!¸UÑCÔC€KØ�KÑ€LØ58ÐØð )Ø8;¸kÑ8IÈQÒ8NÐ8N˜3 #¨Ñ"3Ñ4Ð4ÐTWÐØÐ(Ñ(ˆàð .ØÐ-Ð-Ð-ØÐr   c                ó2   — dt          j        | g|¢R i |¤Žz  S )zHyperbolic secant functionr:   )r   Úcosh)r!   ÚargsÚkwargss      r   Úsech_fnrS     s'   € à•”˜Ð,˜TÐ,Ð,Ð, VÐ,Ð,Ñ,Ð,r   c                óî   — t          j        | t           j        ¬¦  «        } | |z
  |z  }|t          |¦  «                             t           j        ¦  «        z  }|�t          ||||||¬¦  «        }|r||fS |S )aÊ  Continuous unnormalized sech pulse.

    Args:
        times: Times to output pulse for.
        amp: Pulse amplitude at `center`.
        center: Center (mean) of pulse.
        sigma: Width (standard deviation) of pulse.
        zeroed_width: Subtract baseline from pulse to make sure
            $\Omega_g(center \pm zeroed_width/2)=0$ is satisfied. This is used to avoid
            large discontinuities at the start and end of the pulse.
        rescale_amp: If `zeroed_width` is not `None` and `rescale_amp=True` the pulse will
            be rescaled so that $\Omega_g(center)=amp$.
        ret_x: Return centered and standard deviation normalized pulse location.
            $x=(times-center)/sigma$.
    r   NrC   )r   rD   r   rS   r   rN   )	r   r   r1   r2   r3   r5   r@   r!   Úsech_outs	            r   rM   rM     s�   € õ0 ŒJ�u¥B¤MÐ2Ñ2Ô2€EØ	�‰˜5Ñ €AØ•W˜Q‘Z”Z×&Ò&¥r¤}Ñ5Ô5Ñ5€HàÐÝ"ØØØØØ%Ø#ð
ñ 
ô 
ˆð ð Ø˜ˆ{ÐØ€Or   Úret_sechc                óv   — t          | |||d¬¦  «        \  }}| t          j        |¦  «        z  |z  }|r||fS |S )a2  Continuous unnormalized sech derivative pulse.

    Args:
        times: Times to output pulse for.
        amp: Pulse amplitude at `center`.
        center: Center (mean) of pulse.
        sigma: Width (standard deviation) of pulse.
        ret_sech: Return sech with which derivative was taken with.
    T)r   r1   r2   r@   )rM   r   Útanh)r   r   r1   r2   rV   rU   r!   Úsech_out_derivs           r   Ú
sech_derivrZ   =  sR   € õ �u #¨f¸EÈÐNÑNÔN�K€HˆaØ�Y¥¤¨¡¤Ñ+¨eÑ3€NØð (Ø˜xÐ'Ð'ØÐr   Úsquare_widthc           	     óŽ  — ||dz  z
  }||dz  z   }|r||k     rt          d¦  «        ‚||z
  }nd}t          j        t          ||||d¬¦  «        t          j        t          ||||d¬¦  «        t          j        t          |¬¦  «        g}	| |k    | |k    g}
t          j        |                      t
          j        ¦  «        |
|	¦  «        S )a  Continuous gaussian square pulse.

    Args:
        times: Times to output pulse for.
        amp: Pulse amplitude.
        center: Center of the square pulse component.
        square_width: Width of the square pulse component.
        sigma: Standard deviation of Gaussian rise/fall portion of the pulse.
        zeroed_width: Subtract baseline of gaussian square pulse
            to enforce $\OmegaSquare(center \pm zeroed_width/2)=0$.

    Raises:
        PulseError: if zeroed_width is not compatible with square_width.
    r   z1zeroed_width cannot be smaller than square_width.NTrC   )r   )	r   Ú	functoolsÚpartialr;   r   r   Ú	piecewiser   r   )r   r   r1   r[   r2   r3   Úsquare_startÚsquare_stopÚgaussian_zeroed_widthÚfunclistÚcondlists              r   Úgaussian_squarere   P  sþ   € ð, ˜L¨1Ñ,Ñ,€LØ˜<¨!Ñ+Ñ+€KØð %Ø˜,Ò&Ð&ÝÐPÑQÔQÐQØ ,¨|Ñ ;ÐÐà $Ðõ 	ÔÝØØØØ.Øð	
ñ 	
ô 	
õ 	ÔÝØØØØ.Øð	
ñ 	
ô 	
õ 	Ô�(¨Ð,Ñ,Ô,ð#€Hð& ˜Ò% u°Ò';Ð<€HÝŒ<˜Ÿš¥R¤]Ñ3Ô3°X¸xÑHÔHÐHr   Úbetac           	     óJ   — t          | |||d||¬¦  «        \  }}|d|z  |z  z   S )a€  Continuous Y-only correction DRAG pulse for standard nonlinear oscillator (SNO) [1].

    [1] Gambetta, J. M., Motzoi, F., Merkel, S. T. & Wilhelm, F. K.
        Analytic control methods for high-fidelity unitary operations
        in a weakly nonlinear oscillator. Phys. Rev. A 83, 012308 (2011).

    Args:
        times: Times to output pulse for.
        amp: Pulse amplitude at `center`.
        center: Center (mean) of pulse.
        sigma: Width (standard deviation) of pulse.
        beta: Y correction amplitude. For the SNO this is $\beta=-\frac{\lambda_1^2}{4\Delta_2}$.
            Where $\lambds_1$ is the relative coupling strength between the first excited and second
            excited states and $\Delta_2$ is the detuning between the respective excited states.
        zeroed_width: Subtract baseline of drag pulse to make sure
            $\Omega_g(center \pm zeroed_width/2)=0$ is satisfied. This is used to avoid
            large discontinuities at the start of a drag pulse.
        rescale_amp: If `zeroed_width` is not `None` and `rescale_amp=True` the pulse will
            be rescaled so that $\Omega_g(center)=amp$.

    T)r   r1   r2   rG   r3   r5   y              ð?)rJ   )	r   r   r1   r2   rf   r3   r5   rI   rF   s	            r   Údragrh   †  sH   € õ< (ØØØØØØ!Øðñ ô Ñ€K�ð �2˜‘9˜{Ñ*Ñ*Ð*r   )r   r   r   r   r	   r   )r   r   r	   r   )r   )
r   r   r   r   r   r   r   r   r	   r   )NFF)r0   r   r   r   r1   r   r2   r   r3   r4   r5   r6   r7   r6   r	   r8   )r   r   r   r   r1   r   r2   r   r3   r4   r5   r6   r@   r6   r	   rA   )FNF)r   r   r   r   r1   r   r2   r   rG   r6   r3   r4   r5   r6   r	   rA   )rK   r   r   r   r1   r   r2   r   r3   r4   r5   r6   r7   r6   r	   r8   )F)r   r   r   r   r1   r   r2   r   rV   r6   r	   rA   )N)r   r   r   r   r1   r   r[   r   r2   r   r3   r4   r	   r   )NF)r   r   r   r   r1   r   r2   r   rf   r   r3   r4   r5   r6   r	   r   )Ú__doc__Ú
__future__r   r]   Únumpyr   Úqiskit.pulse.exceptionsr   r   r   r"   r$   r)   r,   r/   r?   r;   rJ   rN   rS   rM   rZ   re   rh   © r   r   ú<module>rn      s9  ðð 5Ð 4Ø "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð à Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .ð9ð 9ð 9ð 9ðð ð ð ð
Uð 
Uð 
Uð 
Uð 
Uð
Eð 
Eð 
Eð 
Eð 
Eðð ð ð ð ð	Pð 	Pð 	Pð 	Pð 	Pð	Pð 	Pð 	Pð 	Pð 	Pð" "&ØØ"ð#ð #ð #ð #ð #ðV "&ØØð-ð -ð -ð -ð -ðj Ø!%Øð#ð #ð #ð #ð #ðV "&ØØ"ð#ð #ð #ð #ð #ðL-ð -ð -ð "&ØØð(ð (ð (ð (ð (ðX TYðð ð ð ð ð2 "&ð3Ið 3Ið 3Ið 3Ið 3Iðx "&Øð(+ð (+ð (+ð (+ð (+ð (+ð (+r   