[BUG] Gaussian and DragCorrection envelopes contain `nan` values when `amplitude` is set to zero.
Closed this issue · 2 comments
Expected behavior
When running:
drag_pair = DragPair(amplitude=0.0, duration=40, num_sigmas=4, drag_coefficient=1.2)
print(drag_pair.I.envelope())
print(drag_pair.Q.envelope())
The envelopes should contain a list of zeros.
Actual behavior
Instead, the following is printed:
[nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan
nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan
nan nan nan nan]
[nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan
nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan
nan nan nan nan]
Additional information
No response
Source code
No response
Tracebacks
No response
Existing GitHub issues
- I have searched existing GitHub issues to make sure the issue does not already exist.
The formula for the envelope of the gaussian is:
def envelope(self, resolution: float = 1):
"""Returns the pulse matrix
Args:
resolution (int, optional): Pulse resolution. Defaults to 1.
Returns:
np.ndarray: pulse matrix
resolution (int, optional): Pulse resolution. Defaults to 1.
"""
x = np.arange(self.duration / resolution) * resolution
gaussian = self.amplitude * np.exp(-0.5 * (x - self.mu) ** 2 / self.sigma**2)
norm = np.amax(np.real(gaussian))
gaussian = gaussian - gaussian[0] # Shift to avoid introducing noise at time 0
corr_norm = np.amax(np.real(gaussian))
return gaussian * norm / corr_norm
If the whole envelope is 0, then division by corr_norm
will return nan
. This is because Gaussian
does not expect the amplitude to be 0, same way as it does not expect sigma
to be 0 (this would also result in an error).
Are there any scenarios in which one might send a pulse with 0 amplitude? If that is the case, there are probably more scenarios (in the old workflow with pulse_shape
), where we operate over envelopes to add distorsions and so on which might give similar errors.
I mean a 0 amplitude pulse doesn't make much sense from base. But surely we should add a Raise with an if statement as Victor did also in the pulseshapes!