From 772b6921577c058b5ee3fec800e93c3be357c980 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Thu, 18 Jan 2024 17:47:34 +0100 Subject: [PATCH] Remove intermediate frequency from pulse Following @PiergiorgioButtarini removal of last usage in Qblox, in #729 --- src/qibolab/pulses.py | 17 ++++++----------- tests/test_pulses.py | 13 ++++++++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/qibolab/pulses.py b/src/qibolab/pulses.py index f1928fcb52..aab9a32ec5 100644 --- a/src/qibolab/pulses.py +++ b/src/qibolab/pulses.py @@ -140,36 +140,32 @@ def envelope_waveforms( self.envelope_waveform_q(sampling_rate), ) - def modulated_waveform_i(self, sampling_rate=SAMPLING_RATE) -> Waveform: + def modulated_waveform_i(self, _if: int, sampling_rate=SAMPLING_RATE) -> Waveform: """The waveform of the i component of the pulse, modulated with its frequency.""" return self.modulated_waveforms(sampling_rate)[0] - def modulated_waveform_q(self, sampling_rate=SAMPLING_RATE) -> Waveform: + def modulated_waveform_q(self, _if: int, sampling_rate=SAMPLING_RATE) -> Waveform: """The waveform of the q component of the pulse, modulated with its frequency.""" return self.modulated_waveforms(sampling_rate)[1] - def modulated_waveforms(self, sampling_rate=SAMPLING_RATE): + def modulated_waveforms(self, _if: int, sampling_rate=SAMPLING_RATE): """A tuple with the i and q waveforms of the pulse, modulated with its frequency.""" pulse = self.pulse - if abs(pulse._if) * 2 > sampling_rate: + if abs(_if) * 2 > sampling_rate: log.info( f"WARNING: The frequency of pulse {pulse.id} is higher than the nyqusit frequency ({int(sampling_rate // 2)}) for the device sampling rate: {int(sampling_rate)}" ) num_samples = int(np.rint(pulse.duration * sampling_rate)) time = np.arange(num_samples) / sampling_rate global_phase = pulse.global_phase - cosalpha = np.cos( - 2 * np.pi * pulse._if * time + global_phase + pulse.relative_phase - ) - sinalpha = np.sin( - 2 * np.pi * pulse._if * time + global_phase + pulse.relative_phase - ) + cosalpha = np.cos(2 * np.pi * _if * time + global_phase + pulse.relative_phase) + sinalpha = np.sin(2 * np.pi * _if * time + global_phase + pulse.relative_phase) mod_matrix = np.array([[cosalpha, -sinalpha], [sinalpha, cosalpha]]) / np.sqrt( 2 @@ -753,7 +749,6 @@ class Pulse: """Pulse type, as an element of PulseType enumeration.""" qubit: int = 0 """Qubit or coupler addressed by the pulse.""" - _if: int = 0 def __post_init__(self): if isinstance(self.type, str): diff --git a/tests/test_pulses.py b/tests/test_pulses.py index d20a444a73..a4be3e6102 100644 --- a/tests/test_pulses.py +++ b/tests/test_pulses.py @@ -605,6 +605,7 @@ def test_pulseshape_rectangular(): channel=1, qubit=0, ) + _if = 0 assert pulse.duration == 50 assert isinstance(pulse.shape, Rectangular) @@ -622,10 +623,10 @@ def test_pulseshape_rectangular(): pulse.amplitude * np.zeros(num_samples), ) global_phase = ( - 2 * np.pi * pulse._if * pulse.start / 1e9 + 2 * np.pi * _if * pulse.start / 1e9 ) # pulse start, duration and finish are in ns mod_i, mod_q = modulate( - i, q, num_samples, pulse._if, global_phase + pulse.relative_phase, sampling_rate + i, q, num_samples, _if, global_phase + pulse.relative_phase, sampling_rate ) np.testing.assert_allclose(pulse.shape.envelope_waveform_i(sampling_rate).data, i) @@ -649,6 +650,7 @@ def test_pulseshape_gaussian(): channel=1, qubit=0, ) + _if = 0 assert pulse.duration == 50 assert isinstance(pulse.shape, Gaussian) @@ -675,7 +677,7 @@ def test_pulseshape_gaussian(): 2 * np.pi * pulse.frequency * pulse.start / 1e9 ) # pulse start, duration and finish are in ns mod_i, mod_q = modulate( - i, q, num_samples, pulse._if, global_phase + pulse.relative_phase, sampling_rate + i, q, num_samples, _if, global_phase + pulse.relative_phase, sampling_rate ) np.testing.assert_allclose(pulse.shape.envelope_waveform_i(sampling_rate).data, i) @@ -699,6 +701,7 @@ def test_pulseshape_drag(): channel=1, qubit=0, ) + _if = 0 assert pulse.duration == 50 assert isinstance(pulse.shape, Drag) @@ -728,10 +731,10 @@ def test_pulseshape_drag(): * sampling_rate ) global_phase = ( - 2 * np.pi * pulse._if * pulse.start / 1e9 + 2 * np.pi * _if * pulse.start / 1e9 ) # pulse start, duration and finish are in ns mod_i, mod_q = modulate( - i, q, num_samples, pulse._if, global_phase + pulse.relative_phase, sampling_rate + i, q, num_samples, _if, global_phase + pulse.relative_phase, sampling_rate ) np.testing.assert_allclose(pulse.shape.envelope_waveform_i(sampling_rate).data, i)