Skip to content

Commit

Permalink
Remove intermediate frequency from pulse
Browse files Browse the repository at this point in the history
Following @PiergiorgioButtarini removal of last usage in Qblox, in #729
  • Loading branch information
alecandido committed Jan 23, 2024
1 parent 847d471 commit 7dd7883
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
17 changes: 6 additions & 11 deletions src/qibolab/pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 8 additions & 5 deletions tests/test_pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ def test_pulseshape_rectangular():
channel=1,
qubit=0,
)
_if = 0

assert pulse.duration == 50
assert isinstance(pulse.shape, Rectangular)
Expand All @@ -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)
Expand All @@ -649,6 +650,7 @@ def test_pulseshape_gaussian():
channel=1,
qubit=0,
)
_if = 0

assert pulse.duration == 50
assert isinstance(pulse.shape, Gaussian)
Expand All @@ -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)
Expand All @@ -699,6 +701,7 @@ def test_pulseshape_drag():
channel=1,
qubit=0,
)
_if = 0

assert pulse.duration == 50
assert isinstance(pulse.shape, Drag)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7dd7883

Please sign in to comment.