Skip to content
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

Update GaussianPulse for consistent parameter validation results whether validation occurs during or after construction. #8151

Merged
15 changes: 10 additions & 5 deletions qiskit/pulse/library/parametric_pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,23 @@ def __init__(
limit_amplitude: If ``True``, then limit the amplitude of the
waveform to 1. The default is ``True`` and the
amplitude is constrained to 1.

Raises:
PulseError: If the parameters passed are not valid.
"""
if not _is_parameterized(amp):
amp = complex(amp)
self._amp = amp
self._sigma = sigma
self._risefall_sigma_ratio = risefall_sigma_ratio
self._width = width

if self.width is not None and self.risefall_sigma_ratio is not None:
raise PulseError(
"Either the pulse width or the risefall_sigma_ratio parameter can be specified"
" but not both."
)

super().__init__(duration=duration, name=name, limit_amplitude=limit_amplitude)

@property
Expand Down Expand Up @@ -284,11 +294,6 @@ def validate_parameters(self) -> None:
)
if not _is_parameterized(self.sigma) and self.sigma <= 0:
raise PulseError("Sigma must be greater than 0.")
if self.width is not None and self.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 self.width is None and self.risefall_sigma_ratio is None:
raise PulseError(
"Either the pulse width or the risefall_sigma_ratio parameter must be specified."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Parameter validation for :class:`~.pulse.library.GaussianSquare` is now
consistent before and after construction.
Refer to `#7882 <https://github.com/Qiskit/qiskit-terra/issues/7882>`__ for more details.
5 changes: 5 additions & 0 deletions test/python/pulse/test_pulse_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def test_gauss_square_extremes(self):
gaus_square.get_waveform().samples[2:-2], const.get_waveform().samples[2:-2]
)

def test_gauss_square_passes_validation_after_construction(self):
"""Test that parameter validation is consistent before and after construction."""
jakelishman marked this conversation as resolved.
Show resolved Hide resolved
pulse = GaussianSquare(duration=125, sigma=4, amp=0.5j, width=100)
pulse.validate_parameters()

def test_drag_pulse(self):
"""Test that the Drag sample pulse matches the pulse library."""
drag = Drag(duration=25, sigma=4, amp=0.5j, beta=1)
Expand Down