Skip to content

Commit

Permalink
Merge pull request #483 from qiboteam/pydocstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Jun 12, 2023
2 parents b8b24ea + 4ebb6c4 commit 754b938
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ repos:
rev: 1.13.0
hooks:
- id: blacken-docs
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args:
- --select=D103,D200,D206,D300,D301
files: ^src/
4 changes: 1 addition & 3 deletions src/qibolab/instruments/erasynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def power(self, x):
self._set_device_parameter("power", x)

def connect(self):
"""
Connects to the instrument using the IP address set in the runcard.
"""
"""Connects to the instrument using the IP address set in the runcard."""
if not self.is_connected:
for attempt in range(3):
try:
Expand Down
8 changes: 2 additions & 6 deletions src/qibolab/instruments/icarusq.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ def connect(self):
self.is_connected = True

def setup(self, frequency: float, **kwargs):
"""
Sets the frequency in Hz
"""
"""Sets the frequency in Hz."""
if self.is_connected:
self.device.write("0601")
self.frequency(frequency)
Expand Down Expand Up @@ -254,9 +252,7 @@ def connect(self):
self.is_connected = True

def setup(self, trigger_volts, **kwargs):
"""
Sets the frequency in Hz
"""
"""Sets the frequency in Hz."""
if self.is_connected:
input_range_volts = 2.5
trigger_level_code = int(128 + 127 * trigger_volts / input_range_volts)
Expand Down
25 changes: 16 additions & 9 deletions src/qibolab/instruments/qutech.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Class to interface with the SPI Rack Qutech Delft
"""
"""Class to interface with the SPI Rack Qutech Delft."""
from qblox_instruments import SpiRack
from qibo.config import log, raise_error

Expand All @@ -9,7 +7,8 @@

class SPI(Instrument):
property_wrapper = lambda parent, device, *parameter: property(
lambda self: device.get(parameter[0]), lambda self, x: parent._set_device_parameter(device, *parameter, value=x)
lambda self: device.get(parameter[0]),
lambda self, x: parent._set_device_parameter(device, *parameter, value=x),
)

def __init__(self, name, address):
Expand All @@ -21,9 +20,7 @@ def __init__(self, name, address):
self.device_parameters = {}

def connect(self):
"""
Connects to the instrument using the IP address set in the runcard.
"""
"""Connects to the instrument using the IP address set in the runcard."""
if not self.is_connected:
for attempt in range(3):
try:
Expand Down Expand Up @@ -78,7 +75,12 @@ def setup(self, **kwargs):
self.device.add_spi_module(settings[0], "S4g", module_name)
device = self.device.instrument_modules[module_name].instrument_modules["dac" + str(port_number - 1)]
self.dacs[channel] = type(
"S4g_dac", (), {"current": self.property_wrapper(device, "current"), "device": device}
"S4g_dac",
(),
{
"current": self.property_wrapper(device, "current"),
"device": device,
},
)()
self.dacs[channel].device.span("range_min_bi")
# self.dacs[channel].current = current
Expand All @@ -92,7 +94,12 @@ def setup(self, **kwargs):
self.device.add_spi_module(settings[0], "D5a", module_name)
device = self.device.instrument_modules[module_name].instrument_modules["dac" + str(port_number - 1)]
self.dacs[channel] = type(
"D5a_dac", (), {"voltage": self.property_wrapper(device, "voltage"), "device": device}
"D5a_dac",
(),
{
"voltage": self.property_wrapper(device, "voltage"),
"device": device,
},
)()
self.dacs[channel].device.span("range_min_bi")
# self.dacs[channel].voltage = voltage
Expand Down
4 changes: 1 addition & 3 deletions src/qibolab/instruments/rohde_schwarz.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def ref_osc_source(self, x):
self.device.ref_osc_source = x

def connect(self):
"""
Connects to the instrument using the IP address set in the runcard.
"""
"""Connects to the instrument using the IP address set in the runcard."""
if not self.is_connected:
for attempt in range(3):
try:
Expand Down
151 changes: 124 additions & 27 deletions src/qibolab/pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def modulated_waveforms(self):

(envelope_waveform_i, envelope_waveform_q) = self.envelope_waveforms
result = []
for n, t, ii, qq in zip(np.arange(num_samples), time, envelope_waveform_i.data, envelope_waveform_q.data):
for n, t, ii, qq in zip(
np.arange(num_samples),
time,
envelope_waveform_i.data,
envelope_waveform_q.data,
):
result.append(mod_matrix[:, :, n] @ np.array([ii, qq]))
mod_signals = np.array(result)

Expand All @@ -182,10 +187,7 @@ def __eq__(self, item) -> bool:


class Rectangular(PulseShape):
"""
Rectangular pulse shape.
"""
"""Rectangular pulse shape."""

def __init__(self):
self.name = "Rectangular"
Expand Down Expand Up @@ -218,8 +220,7 @@ def __repr__(self):


class Gaussian(PulseShape):
"""
Gaussian pulse shape.
r"""Gaussian pulse shape.
Args:
rel_sigma (float): relative sigma so that the pulse standard deviation (sigma) = duration / rel_sigma
Expand Down Expand Up @@ -336,10 +337,7 @@ def __repr__(self):


class IIR(PulseShape):
"""
IIR Filter using scipy.signal lfilter.
"""
"""IIR Filter using scipy.signal lfilter."""

# https://arxiv.org/pdf/1907.04818.pdf (page 11 - filter formula S22)
# p = [A, tau_iir]
Expand Down Expand Up @@ -475,7 +473,7 @@ def __repr__(self):


class eCap(PulseShape):
"""eCap pulse shape.
r"""eCap pulse shape.
Args:
alpha (float):
Expand Down Expand Up @@ -576,7 +574,16 @@ class Pulse:
count: int = 0

def __init__(
self, start, duration, amplitude, frequency, relative_phase, shape, channel, type=PulseType.DRIVE, qubit=0
self,
start,
duration,
amplitude,
frequency,
relative_phase,
shape,
channel,
type=PulseType.DRIVE,
qubit=0,
):
# def __init__(self, start:int | se_int, duration:int | se_int, amplitude:float, frequency:int, relative_phase:float, shape: PulseShape | str,
# channel: int | str, type: PulseType | str = PulseType.DRIVE, qubit: int | str = 0):
Expand Down Expand Up @@ -1043,8 +1050,20 @@ def plot(self, savefig_filename=None):
fig = plt.figure(figsize=(14, 5), dpi=200)
gs = gridspec.GridSpec(ncols=2, nrows=1, width_ratios=[2, 1])
ax1 = plt.subplot(gs[0])
ax1.plot(time, self.shape.envelope_waveform_i.data, label="envelope i", c="C0", linestyle="dashed")
ax1.plot(time, self.shape.envelope_waveform_q.data, label="envelope q", c="C1", linestyle="dashed")
ax1.plot(
time,
self.shape.envelope_waveform_i.data,
label="envelope i",
c="C0",
linestyle="dashed",
)
ax1.plot(
time,
self.shape.envelope_waveform_q.data,
label="envelope q",
c="C1",
linestyle="dashed",
)
ax1.plot(time, self.shape.modulated_waveform_i.data, label="modulated i", c="C0")
ax1.plot(time, self.shape.modulated_waveform_q.data, label="modulated q", c="C1")
ax1.plot(time, -self.shape.envelope_waveform_i.data, c="silver", linestyle="dashed")
Expand All @@ -1056,8 +1075,18 @@ def plot(self, savefig_filename=None):
ax1.legend()

ax2 = plt.subplot(gs[1])
ax2.plot(self.shape.modulated_waveform_i.data, self.shape.modulated_waveform_q.data, label="modulated", c="C3")
ax2.plot(self.shape.envelope_waveform_i.data, self.shape.envelope_waveform_q.data, label="envelope", c="C2")
ax2.plot(
self.shape.modulated_waveform_i.data,
self.shape.modulated_waveform_q.data,
label="modulated",
c="C3",
)
ax2.plot(
self.shape.envelope_waveform_i.data,
self.shape.envelope_waveform_q.data,
label="envelope",
c="C2",
)
ax2.plot(
self.shape.modulated_waveform_i.data[0],
self.shape.modulated_waveform_q.data[0],
Expand Down Expand Up @@ -1100,11 +1129,29 @@ class ReadoutPulse(Pulse):
See :class:`qibolab.pulses.Pulse` for argument desciption.
"""

def __init__(self, start, duration, amplitude, frequency, relative_phase, shape, channel, qubit=0):
def __init__(
self,
start,
duration,
amplitude,
frequency,
relative_phase,
shape,
channel,
qubit=0,
):
# def __init__(self, start:int | se_int, duration:int | se_int, amplitude:float, frequency:int, relative_phase:float, shape: PulseShape | str,
# channel: int | str, qubit: int | str = 0):
super().__init__(
start, duration, amplitude, frequency, relative_phase, shape, channel, type=PulseType.READOUT, qubit=qubit
start,
duration,
amplitude,
frequency,
relative_phase,
shape,
channel,
type=PulseType.READOUT,
qubit=qubit,
)

@property
Expand Down Expand Up @@ -1139,11 +1186,29 @@ class DrivePulse(Pulse):
See :class:`qibolab.pulses.Pulse` for argument desciption.
"""

def __init__(self, start, duration, amplitude, frequency, relative_phase, shape, channel, qubit=0):
def __init__(
self,
start,
duration,
amplitude,
frequency,
relative_phase,
shape,
channel,
qubit=0,
):
# def __init__(self, start:int | se_int, duration:int | se_int, amplitude:float, frequency:int, relative_phase:float, shape: PulseShape | str,
# channel: int | str, qubit: int | str = 0):
super().__init__(
start, duration, amplitude, frequency, relative_phase, shape, channel, type=PulseType.DRIVE, qubit=qubit
start,
duration,
amplitude,
frequency,
relative_phase,
shape,
channel,
type=PulseType.DRIVE,
qubit=qubit,
)

@property
Expand All @@ -1161,7 +1226,17 @@ class FluxPulse(Pulse):
def __init__(self, start, duration, amplitude, shape, channel, qubit=0):
# def __init__(self, start:int | se_int, duration:int | se_int, amplitude:float, frequency:int, relative_phase:float, shape: PulseShape | str,
# channel: int | str, qubit: int | str = 0):
super().__init__(start, duration, amplitude, 0, 0, shape, channel, type=PulseType.FLUX, qubit=qubit)
super().__init__(
start,
duration,
amplitude,
0,
0,
shape,
channel,
type=PulseType.FLUX,
qubit=qubit,
)

@property
def envelope_waveform_i(self) -> Waveform:
Expand Down Expand Up @@ -1769,17 +1844,39 @@ def plot(self, savefig_filename=None):
else:
num_samples = int(pulse.duration / 1e9 * PulseShape.SAMPLING_RATE)
time = pulse.start + np.arange(num_samples) / PulseShape.SAMPLING_RATE * 1e9
ax.plot(time, pulse.shape.modulated_waveform_q.data, c="lightgrey")
ax.plot(time, pulse.shape.modulated_waveform_i.data, c=f"C{str(n)}")
ax.plot(time, pulse.shape.envelope_waveform_i.data, c=f"C{str(n)}")
ax.plot(time, -pulse.shape.envelope_waveform_i.data, c=f"C{str(n)}")
ax.plot(
time,
pulse.shape.modulated_waveform_q.data,
c="lightgrey",
)
ax.plot(
time,
pulse.shape.modulated_waveform_i.data,
c=f"C{str(n)}",
)
ax.plot(
time,
pulse.shape.envelope_waveform_i.data,
c=f"C{str(n)}",
)
ax.plot(
time,
-pulse.shape.envelope_waveform_i.data,
c=f"C{str(n)}",
)
# TODO: if they overlap use different shades
ax.axhline(0, c="dimgrey")
ax.set_ylabel(f"qubit {qubit} \n channel {channel}")
for vl in vertical_lines:
ax.axvline(vl, c="slategrey", linestyle="--")
ax.axis([0, self.finish, -1, 1])
ax.grid(visible=True, which="both", axis="both", color="#CCCCCC", linestyle="-")
ax.grid(
visible=True,
which="both",
axis="both",
color="#CCCCCC",
linestyle="-",
)
if savefig_filename:
plt.savefig(savefig_filename)
else:
Expand Down

0 comments on commit 754b938

Please sign in to comment.