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

Turn Waveform into a bare array #774

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/qibolab/instruments/qblox/cluster_qcm_bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def process_pulse_sequence(
sequencer.waveforms_buffer.unique_waveforms
):
sequencer.waveforms[waveform.serial] = {
"data": waveform.data.tolist(),
"data": waveform.tolist(),
"index": index,
}

Expand Down
2 changes: 1 addition & 1 deletion src/qibolab/instruments/qblox/cluster_qcm_rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def process_pulse_sequence(
sequencer.waveforms_buffer.unique_waveforms
):
sequencer.waveforms[waveform.serial] = {
"data": waveform.data.tolist(),
"data": waveform.tolist(),
"index": index,
}

Expand Down
2 changes: 1 addition & 1 deletion src/qibolab/instruments/qblox/cluster_qrm_rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def process_pulse_sequence(
sequencer.waveforms_buffer.unique_waveforms
):
sequencer.waveforms[waveform.serial] = {
"data": waveform.data.tolist(),
"data": waveform.tolist(),
"index": index,
}

Expand Down
6 changes: 3 additions & 3 deletions src/qibolab/instruments/qblox/sequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def bake_pulse_waveforms(
padded_duration = int(np.ceil(duration / 4)) * 4
memory_needed = padded_duration
padding = np.zeros(padded_duration - duration)
waveform.data = np.append(waveform.data, padding)
waveform = np.append(waveform, padding)

if self.available_memory >= memory_needed:
self.unique_waveforms.append(waveform)
Expand All @@ -168,8 +168,8 @@ def bake_pulse_waveforms(
padded_duration = int(np.ceil(duration / 4)) * 4
memory_needed = padded_duration * 2
padding = np.zeros(padded_duration - duration)
waveform_i.data = np.append(waveform_i.data, padding)
waveform_q.data = np.append(waveform_q.data, padding)
waveform_i = np.append(waveform_i, padding)
waveform_q = np.append(waveform_q, padding)

if self.available_memory >= memory_needed:
self.unique_waveforms.append(waveform_i)
Expand Down
4 changes: 2 additions & 2 deletions src/qibolab/instruments/qm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ def register_waveform(self, pulse, mode="i"):
self.waveforms[serial] = {"type": "constant", "sample": pulse.amplitude}
else:
waveform = getattr(pulse, f"envelope_waveform_{mode}")(SAMPLING_RATE)
serial = hash(waveform)
serial = hash(waveform.tobytes())
if serial not in self.waveforms:
self.waveforms[serial] = {
"type": "arbitrary",
"samples": waveform.data.tolist(),
"samples": waveform.tolist(),
}
return serial

Expand Down
12 changes: 3 additions & 9 deletions src/qibolab/instruments/qm/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,11 @@ def bake(self, config: QMConfig, durations: DurationsType):
for t in durations:
with baking(config.__dict__, padding_method="right") as segment:
if self.pulse.type is PulseType.FLUX:
waveform = self.pulse.envelope_waveform_i(
SAMPLING_RATE
).data.tolist()
waveform = self.pulse.envelope_waveform_i(SAMPLING_RATE).tolist()
waveform = self.calculate_waveform(waveform, t)
else:
waveform_i = self.pulse.envelope_waveform_i(
SAMPLING_RATE
).data.tolist()
waveform_q = self.pulse.envelope_waveform_q(
SAMPLING_RATE
).data.tolist()
waveform_i = self.pulse.envelope_waveform_i(SAMPLING_RATE).tolist()
waveform_q = self.pulse.envelope_waveform_q(SAMPLING_RATE).tolist()
waveform = [
self.calculate_waveform(waveform_i, t),
self.calculate_waveform(waveform_q, t),
Expand Down
8 changes: 4 additions & 4 deletions src/qibolab/instruments/zhinst.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ def select_pulse(pulse, pulse_type):
zero_boundaries=False,
)

if np.all(pulse.envelope_waveform_q(SAMPLING_RATE).data == 0):
if np.all(pulse.envelope_waveform_q(SAMPLING_RATE) == 0):
return sampled_pulse_real(
uid=(f"{pulse_type}_{pulse.qubit}_"),
samples=pulse.envelope_waveform_i(SAMPLING_RATE).data,
samples=pulse.envelope_waveform_i(SAMPLING_RATE),
can_compress=True,
)
else:
# Test this when we have pulses that use it
return sampled_pulse_complex(
uid=(f"{pulse_type}_{pulse.qubit}_"),
samples=pulse.envelope_waveform_i(SAMPLING_RATE).data
+ (1j * pulse.envelope_waveform_q(SAMPLING_RATE).data),
samples=pulse.envelope_waveform_i(SAMPLING_RATE)
+ (1j * pulse.envelope_waveform_q(SAMPLING_RATE)),
can_compress=True,
)

Expand Down
2 changes: 1 addition & 1 deletion src/qibolab/pulses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
PulseShape,
Rectangular,
ShapeInitError,
Waveform,
eCap,
)
from .waveform import Waveform
31 changes: 15 additions & 16 deletions src/qibolab/pulses/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from .pulse import Pulse
from .sequence import PulseSequence
from .shape import SAMPLING_RATE
from .waveform import Waveform
from .shape import SAMPLING_RATE, Waveform


def waveform(wf: Waveform, filename=None):
Expand All @@ -15,7 +14,7 @@ def waveform(wf: Waveform, filename=None):
filename (str): a file path. If provided the plot is save to a file.
"""
plt.figure(figsize=(14, 5), dpi=200)
plt.plot(wf.data, c="C0", linestyle="dashed")
plt.plot(wf, c="C0", linestyle="dashed")
plt.xlabel("Sample Number")
plt.ylabel("Amplitude")
plt.grid(visible=True, which="both", axis="both", color="#888888", linestyle="-")
Expand Down Expand Up @@ -45,31 +44,31 @@ def pulse(pulse_: Pulse, filename=None, sampling_rate=SAMPLING_RATE):
ax1 = plt.subplot(gs[0])
ax1.plot(
time,
waveform_i.data,
waveform_i,
label="envelope i",
c="C0",
linestyle="dashed",
)
ax1.plot(
time,
waveform_q.data,
waveform_q,
label="envelope q",
c="C1",
linestyle="dashed",
)
ax1.plot(
time,
pulse_.shape.modulated_waveform_i(sampling_rate).data,
pulse_.shape.modulated_waveform_i(sampling_rate),
label="modulated i",
c="C0",
)
ax1.plot(
time,
pulse_.shape.modulated_waveform_q(sampling_rate).data,
pulse_.shape.modulated_waveform_q(sampling_rate),
label="modulated q",
c="C1",
)
ax1.plot(time, -waveform_i.data, c="silver", linestyle="dashed")
ax1.plot(time, -waveform_i, c="silver", linestyle="dashed")
ax1.set_xlabel("Time [ns]")
ax1.set_ylabel("Amplitude")

Expand All @@ -79,8 +78,8 @@ def pulse(pulse_: Pulse, filename=None, sampling_rate=SAMPLING_RATE):
ax1.axis((start, finish, -1.0, 1.0))
ax1.legend()

modulated_i = pulse_.shape.modulated_waveform_i(sampling_rate).data
modulated_q = pulse_.shape.modulated_waveform_q(sampling_rate).data
modulated_i = pulse_.shape.modulated_waveform_i(sampling_rate)
modulated_q = pulse_.shape.modulated_waveform_q(sampling_rate)
ax2 = plt.subplot(gs[1])
ax2.plot(
modulated_i,
Expand All @@ -89,8 +88,8 @@ def pulse(pulse_: Pulse, filename=None, sampling_rate=SAMPLING_RATE):
c="C3",
)
ax2.plot(
waveform_i.data,
waveform_q.data,
waveform_i,
waveform_q,
label="envelope",
c="C2",
)
Expand Down Expand Up @@ -159,22 +158,22 @@ def sequence(ps: PulseSequence, filename=None, sampling_rate=SAMPLING_RATE):
time = pulse.start + np.arange(num_samples) / sampling_rate
ax.plot(
time,
pulse.shape.modulated_waveform_q(sampling_rate).data,
pulse.shape.modulated_waveform_q(sampling_rate),
c="lightgrey",
)
ax.plot(
time,
pulse.shape.modulated_waveform_i(sampling_rate).data,
pulse.shape.modulated_waveform_i(sampling_rate),
c=f"C{str(n)}",
)
ax.plot(
time,
pulse.shape.envelope_waveform_i(sampling_rate).data,
pulse.shape.envelope_waveform_i(sampling_rate),
c=f"C{str(n)}",
)
ax.plot(
time,
-pulse.shape.envelope_waveform_i(sampling_rate).data,
-pulse.shape.envelope_waveform_i(sampling_rate),
c=f"C{str(n)}",
)
# TODO: if they overlap use different shades
Expand Down
9 changes: 3 additions & 6 deletions src/qibolab/pulses/pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import numpy as np

from .shape import SAMPLING_RATE, PulseShape
from .waveform import Waveform
from .shape import SAMPLING_RATE, PulseShape, Waveform


class PulseType(Enum):
Expand Down Expand Up @@ -121,9 +120,7 @@ def envelope_waveform_q(self, sampling_rate=SAMPLING_RATE) -> Waveform:

return self.shape.envelope_waveform_q(sampling_rate)

def envelope_waveforms(
self, sampling_rate=SAMPLING_RATE
): # -> tuple[Waveform, Waveform]:
def envelope_waveforms(self, sampling_rate=SAMPLING_RATE):
"""A tuple with the i and q envelope waveforms of the pulse."""

return (
Expand All @@ -143,7 +140,7 @@ def modulated_waveform_q(self, sampling_rate=SAMPLING_RATE) -> Waveform:

return self.shape.modulated_waveform_q(sampling_rate)

def modulated_waveforms(self, sampling_rate): # -> tuple[Waveform, Waveform]:
def modulated_waveforms(self, sampling_rate):
"""A tuple with the i and q waveforms of the pulse, modulated with its
frequency."""

Expand Down
Loading