-
Notifications
You must be signed in to change notification settings - Fork 3k
add gaussian square echo pulse #9370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
cd37e22
859c451
760aa7c
fca8fd6
2895969
755d16e
6f73a4c
e1c731e
b083550
0c1ba46
d94fcc7
3d310c7
a1df97f
a331c36
0d695dc
bfd2c5d
7d79645
7ff1871
f1f5a90
75427a9
310b727
f3c1e50
b18df11
877b285
16f2b33
bba03a0
bbeba66
4ead034
d012580
41af294
061aac4
d0d04ce
050c001
fab388b
cb0749e
170370e
92c4b29
17944ca
ecc70c6
5259ff5
686f342
a0575d3
bff8bab
b4851fc
a55abd7
257fd43
75183f2
97a1e5f
bb744bd
8be636a
769b145
88f045f
be39a8f
efb3b07
41647e1
4328ce2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,7 @@ | |
| Gaussian, | ||
| GaussianSquare, | ||
| GaussianSquareDrag, | ||
| GaussianSquareEcho, | ||
| Drag, | ||
| Constant, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1063,6 +1063,158 @@ def GaussianSquareDrag( | |
| return instance | ||
|
|
||
|
|
||
| def GaussianSquareEcho( | ||
| duration: Union[int, ParameterExpression], | ||
| amp: Union[float, ParameterExpression], | ||
| sigma: Union[float, ParameterExpression], | ||
| width: Optional[Union[float, ParameterExpression]] = None, | ||
| angle: Optional[Union[float, ParameterExpression]] = 0.0, | ||
| active_amp: Optional[Union[float, ParameterExpression]] = 0, | ||
| active_angle: Optional[Union[float, ParameterExpression]] = 0, | ||
|
miamico marked this conversation as resolved.
Outdated
|
||
| risefall_sigma_ratio: Optional[Union[float, ParameterExpression]] = None, | ||
| name: Optional[str] = None, | ||
| limit_amplitude: Optional[bool] = None, | ||
| ) -> SymbolicPulse: | ||
| """An echoed Gaussian square pulse with an active tone overlaid on it. | ||
| Exactly one of the ``risefall_sigma_ratio`` and ``width`` parameters has to be specified. | ||
| If ``risefall_sigma_ratio`` is not ``None`` and ``width`` is ``None``: | ||
| .. math:: | ||
| \\text{risefall} &= \\text{risefall_sigma_ratio} \\times \\text{sigma}\\\\ | ||
| \\text{width} &= \\text{duration} - 2 \\times \\text{risefall} | ||
| If ``width`` is not None and ``risefall_sigma_ratio`` is None: | ||
| .. math:: \\text{risefall} = \\frac{\\text{duration} - \\text{width}}{2} | ||
| Gaussian :math:`g(x, c, σ)` and lifted gaussian :math:`g'(x, c, σ)` curves | ||
| can be written as: | ||
| .. math:: | ||
| g(x, c, σ) &= \\exp\\Bigl(-\\frac12 \\frac{(x - c)^2}{σ^2}\\Bigr)\\\\ | ||
| g'(x, c, σ) &= \\frac{g(x, c, σ)-g(-1, c, σ)}{1-g(-1, c, σ)} | ||
|
|
||
|
miamico marked this conversation as resolved.
Outdated
|
||
| Args: | ||
| duration: Pulse length in terms of the sampling period `dt`. | ||
| amp: The amplitude of the rise and fall and of the square pulse. | ||
| sigma: A measure of how wide or narrow the risefall is; see the class | ||
| docstring for more details. | ||
| width: The duration of the embedded square pulse. | ||
|
miamico marked this conversation as resolved.
|
||
| angle: The angle in radians of the complex phase factor uniformly | ||
| scaling the pulse. Default value 0. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to be clarified that this angle affects only the echoed part of the pulse, not the entire pulse. I would change to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tried to be more specific in the docstring on what refers to what. I'd like to avoid changing variable names as |
||
| active_amp: The amplitude of the active cancellation tone. | ||
|
miamico marked this conversation as resolved.
Outdated
|
||
| active_angle: The angle in radian of the complex phase factor uniformly | ||
| scaling the active pulse. Default value 0. | ||
| risefall_sigma_ratio: The ratio of each risefall duration to sigma. | ||
| name: Display name for this pulse envelope. | ||
| limit_amplitude: If ``True``, then limit the amplitude of the | ||
| waveform to 1. The default is ``True`` and the amplitude is constrained to 1. | ||
| Returns: | ||
| ScalableSymbolicPulse instance. | ||
| Raises: | ||
| PulseError: When width and risefall_sigma_ratio are both empty or both non-empty. | ||
| """ | ||
| # Convert risefall_sigma_ratio into width which is defined in OpenPulse spec | ||
| if width is None and risefall_sigma_ratio is None: | ||
| raise PulseError( | ||
| "Either the pulse width or the risefall_sigma_ratio parameter must be specified." | ||
| ) | ||
| if width is not None and risefall_sigma_ratio is not None: | ||
| raise PulseError( | ||
| "Either the pulse width or the risefall_sigma_ratio parameter can be specified" | ||
| " but not both." | ||
| ) | ||
|
|
||
| if width is not None and risefall_sigma_ratio is None: | ||
| total_risefall = duration - width | ||
| echo_risefall = 2*total_risefall | ||
| width_echo = (duration - echo_risefall)/2 | ||
|
|
||
| if width is None and risefall_sigma_ratio is not None: | ||
| width = duration - 2.0 * risefall_sigma_ratio * sigma | ||
| width_echo = (duration - 4.0 * risefall_sigma_ratio * sigma)/2 | ||
|
|
||
|
|
||
|
|
||
| parameters = {"amp": amp, "angle": angle, "sigma": sigma, "width": width, "width_echo": width_echo, | ||
|
miamico marked this conversation as resolved.
Outdated
|
||
| "active_amp": active_amp, "active_angle": active_angle} | ||
|
|
||
| # Prepare symbolic expressions | ||
| _t, _duration, _amp, _sigma, _active_amp, _width, _width_echo, _angle, _active_angle = sym.symbols( | ||
| "t, duration, amp, sigma, active_amp, width, width_echo, angle, active_angle" | ||
| ) | ||
|
|
||
| # gaussian square echo for rotary tone | ||
| _center = _duration / 4 | ||
|
|
||
| _sq_t0 = _center - _width_echo / 2 | ||
| _sq_t1 = _center + _width_echo / 2 | ||
|
|
||
| _gaussian_ledge = _lifted_gaussian(_t, _sq_t0, -1, _sigma) | ||
| _gaussian_redge = _lifted_gaussian(_t, _sq_t1, _duration/2 + 1, _sigma) | ||
|
|
||
| envelope_expr_p = ( | ||
| _amp | ||
| * sym.exp(sym.I * _angle) | ||
| * sym.Piecewise( | ||
| (_gaussian_ledge, _t <= _sq_t0), | ||
| (_gaussian_redge, _t >= _sq_t1), | ||
| (1, True), | ||
| ) | ||
| ) | ||
|
|
||
| _center_echo = _duration/2 + _duration / 4 | ||
|
|
||
| _sq_t0_echo = _center_echo - _width_echo / 2 | ||
| _sq_t1_echo = _center_echo + _width_echo / 2 | ||
|
|
||
| _gaussian_ledge_echo = _lifted_gaussian(_t, _sq_t0_echo, _duration/2-1, _sigma) | ||
| _gaussian_redge_echo = _lifted_gaussian(_t, _sq_t1_echo, _duration + 1, _sigma) | ||
|
|
||
| envelope_expr_echo = ( | ||
| -1*_amp | ||
| * sym.exp(sym.I * _angle) | ||
| * sym.Piecewise( | ||
| (_gaussian_ledge_echo, _t <= _sq_t0_echo), | ||
| (_gaussian_redge_echo, _t >= _sq_t1_echo), | ||
| (1, True), | ||
| ) | ||
| ) | ||
|
|
||
| envelope_expr = sym.Piecewise( (envelope_expr_p, _t <= _duration/2), (envelope_expr_echo, _t >= _duration/2), (0, True) ) | ||
|
|
||
| # gaussian square for active cancellation tone | ||
| _center_xy = _duration/2 | ||
|
miamico marked this conversation as resolved.
Outdated
|
||
|
|
||
| _sq_t0_xy = _center_xy - _width / 2 | ||
| _sq_t1_xy = _center_xy + _width / 2 | ||
|
|
||
| _gaussian_ledge_xy = _lifted_gaussian(_t, _sq_t0_xy, -1, _sigma) | ||
| _gaussian_redge_xy = _lifted_gaussian(_t, _sq_t1_xy, _duration + 1, _sigma) | ||
|
|
||
| envelope_expr_xy = _active_amp * sym.exp(sym.I * _active_angle) * sym.Piecewise( | ||
| (_gaussian_ledge_xy, _t <= _sq_t0_xy), (_gaussian_redge_xy, _t >= _sq_t1_xy), (1, True) | ||
| ) | ||
|
|
||
| envelop_expr_total = envelope_expr + envelope_expr_xy | ||
|
miamico marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| consts_expr = sym.And(_sigma > 0, _width >= 0, _duration >= _width, _duration/2 >= _width_echo) | ||
|
|
||
| # Check validity of amplitudes | ||
| valid_amp_conditions_expr = sym.And(sym.Abs(_amp) <= 1.0) | ||
|
miamico marked this conversation as resolved.
Outdated
|
||
| valid_amp_conditions_expr = sym.And(sym.Abs(_active_amp) <= 1.0) | ||
|
miamico marked this conversation as resolved.
Outdated
|
||
|
|
||
| instance = SymbolicPulse( | ||
| pulse_type="GaussianSquareEcho", | ||
| duration=duration, | ||
| parameters=parameters, | ||
| name=name, | ||
| limit_amplitude=limit_amplitude, | ||
| envelope=envelop_expr_total, | ||
| constraints=consts_expr, | ||
| valid_amp_conditions=valid_amp_conditions_expr, | ||
| ) | ||
| instance.validate_parameters() | ||
|
|
||
| return instance | ||
|
|
||
|
|
||
| class Drag(metaclass=_PulseType): | ||
| """The Derivative Removal by Adiabatic Gate (DRAG) pulse is a standard Gaussian pulse | ||
| with an additional Gaussian derivative component and lifting applied. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.