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

Add flake8 to pre-commit #13

Merged
merged 19 commits into from
Dec 6, 2023
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
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ repos:
hooks:
- id: black
args: ["--line-length", "120"]
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pre-commit
pyupgrade
black

pylint
flake8
mypy

pytest
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[pylint.master]
[flake8]
max-line-length = 120
ignore = FZJ_Decadac.py,Example_measurements.py,SET_testing.py
extension-pkg-whitelist = PyQt5
extend-ignore = E203

[mypy]
show_error_codes = True
Expand Down
5 changes: 5 additions & 0 deletions src/examples/buffered_dummy_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
# - Daniel Grothe
# - Till Huckeman

# Ignore flake8 and mypy, as these file is going to be redone either way.
# TODO: Remove these comments then
# flake8: noqa
# type: ignore

# %% Experiment Setup
# As we have only dummy instruments that are not connected, we have to use a global
# trigger event for triggering.
Expand Down
4 changes: 4 additions & 0 deletions src/examples/buffered_example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
# - Till Huckemann
# - Daniel Grothe

# Ignore flake8 and mypy, as these file is going to be redone either way.
# TODO: Remove these comments then
# flake8: noqa
# type: ignore

import qtools_metadata.db as db
import yaml
Expand Down
10 changes: 6 additions & 4 deletions src/qumada/instrument/buffers/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@

Args:
components (Mapping[Any, Metadatable]): Instruments/Components in QCoDeS
gate_parameters (Mapping[Any, Union[Mapping[Any, Parameter], Parameter]]): Gates, as defined in the measurement script
gate_parameters (Mapping[Any, Union[Mapping[Any, Parameter], Parameter]]):
Gates, as defined in the measurement script
"""
# subscribe to gettable parameters with buffer
for gate, parameters in gate_parameters.items():
Expand All @@ -87,7 +88,7 @@
if overwrite_trigger is not None:
try:
chosen = int(overwrite_trigger)
except:
except Exception:

Check warning on line 91 in src/qumada/instrument/buffers/buffer.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/buffers/buffer.py#L91

Added line #L91 was not covered by tests
chosen = int(input(f"Choose the trigger input for {instrument.name}: "))
else:
chosen = int(input(f"Choose the trigger input for {instrument.name}: "))
Expand All @@ -111,7 +112,8 @@

Args:
components (Mapping[Any, Metadatable]): Instruments/Components in QCoDeS
gate_parameters (Mapping[Any, Union[Mapping[Any, Parameter], Parameter]]): Gates, as defined in the measurement script
gate_parameters (Mapping[Any, Union[Mapping[Any, Parameter], Parameter]]):
Gates, as defined in the measurement script
"""
triggered_instruments = filter(is_triggerable, components.values())
for instrument in triggered_instruments:
Expand All @@ -126,7 +128,7 @@
if overwrite_trigger is not None:
try:
chosen = int(overwrite_trigger)
except:
except Exception:

Check warning on line 131 in src/qumada/instrument/buffers/buffer.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/buffers/buffer.py#L131

Added line #L131 was not covered by tests
chosen = int(input(f"Choose the trigger input for {instrument.name}: "))
else:
chosen = int(input(f"Choose the trigger input for {instrument.name}: "))
Expand Down
9 changes: 5 additions & 4 deletions src/qumada/instrument/buffers/dummy_dmm_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from jsonschema import validate
from qcodes.parameters import Parameter

from qumada.instrument.buffers.buffer import Buffer
from qumada.instrument.buffers.buffer import Buffer, BufferException
from qumada.instrument.custom_drivers.Dummies.dummy_dmm import DummyDmm


Expand Down Expand Up @@ -72,7 +72,8 @@
def num_points(self, num_points) -> None:
if num_points > 16383:
raise BufferException(
"Dummy Dacs Buffer is to small for this measurement. Please reduce the number of data points or the delay"
"Dummy Dacs Buffer is to small for this measurement. "
"Please reduce the number of data points or the delay"
)
self._num_points = int(num_points)

Expand Down Expand Up @@ -123,13 +124,13 @@
return self.read_raw()

def subscribe(self, parameters: list[Parameter]) -> None:
assert type(parameters) == list
assert isinstance(parameters, list)

Check warning on line 127 in src/qumada/instrument/buffers/dummy_dmm_buffer.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/buffers/dummy_dmm_buffer.py#L127

Added line #L127 was not covered by tests
for parameter in parameters:
self._device.buffer.subscribe(parameter)
self._subscribed_parameters.add(parameter)

def unsubscribe(self, parameters: list[Parameter]) -> None:
assert type(parameters) == list
assert isinstance(parameters, list)

Check warning on line 133 in src/qumada/instrument/buffers/dummy_dmm_buffer.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/buffers/dummy_dmm_buffer.py#L133

Added line #L133 was not covered by tests
for parameter in parameters:
if parameter in self._device.buffer.subscribed_params:
self._device.buffer.subscribed_params.remove(parameter)
Expand Down
3 changes: 2 additions & 1 deletion src/qumada/instrument/buffers/sr830_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def trigger(self, trigger: str | None) -> None:
self._device.buffer_trig_mode("ON")
else:
raise BufferException(
"SR830 does not support setting custom trigger inputs. Use 'external' and the input on the back of the unit."
"SR830 does not support setting custom trigger inputs. "
"Use 'external' and the input on the back of the unit."
)
self._trigger = trigger

Expand Down
2 changes: 1 addition & 1 deletion src/qumada/instrument/custom_drivers/Dummies/dummy_dac.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
self.thread.start()

def _run_triggered_ramp(self, start, stop, duration, stepsize=0.01):
_is_triggered = self._is_triggered.wait()
_ = self._is_triggered.wait()

Check warning on line 61 in src/qumada/instrument/custom_drivers/Dummies/dummy_dac.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/custom_drivers/Dummies/dummy_dac.py#L61

Added line #L61 was not covered by tests
num_points = int((stop - start) / stepsize)
for setpoint in np.linspace(start, stop, num_points):
self.voltage(setpoint)
Expand Down
6 changes: 3 additions & 3 deletions src/qumada/instrument/custom_drivers/Dummies/dummy_dmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@
self.thread.start()

def _run(self):
_is_triggered = self._is_triggered.wait()
_ = self._is_triggered.wait()

Check warning on line 81 in src/qumada/instrument/custom_drivers/Dummies/dummy_dmm.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/custom_drivers/Dummies/dummy_dmm.py#L81

Added line #L81 was not covered by tests
for i in range(0, self.buffer_length):
for j in range(len(self.subscribed_params)):
datapoint = self.subscribed_params[j]()
if type(datapoint) == float:
if isinstance(datapoint, float):

Check warning on line 85 in src/qumada/instrument/custom_drivers/Dummies/dummy_dmm.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/custom_drivers/Dummies/dummy_dmm.py#L85

Added line #L85 was not covered by tests
self.buffer_data[j].append(self.subscribed_params[j]())
elif type(datapoint) == list:
elif isinstance(datapoint, list):

Check warning on line 87 in src/qumada/instrument/custom_drivers/Dummies/dummy_dmm.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/custom_drivers/Dummies/dummy_dmm.py#L87

Added line #L87 was not covered by tests
self.buffer_data[j].append(self.subscribed_params[j]()[i])
sleep(1 / self.SR)
self.is_finished = True
Expand Down
48 changes: 23 additions & 25 deletions src/qumada/instrument/custom_drivers/Harvard/Decadac.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


from functools import partial
from math import ceil
from time import sleep, time
from typing import Union, cast

Expand Down Expand Up @@ -54,7 +53,8 @@
"""
if volt < self.min_val or volt >= self.max_val:
raise ValueError(
f"Cannot convert voltage {volt} V to a voltage code, value out of range ({self.min_val} V - {self.max_val} V)"
f"Cannot convert voltage {volt} V to a voltage code, "
f"value out of range ({self.min_val} V - {self.max_val} V)"
)

frac = (volt - self.min_val) / (self.max_val - self.min_val)
Expand Down Expand Up @@ -82,9 +82,7 @@
"""
resp = self.ask_raw(f"B{self._slot};")
if int(self._dac_parse(resp)) != self._slot:
raise DACException(
"Unexpected return from DAC when setting slot: " f"{resp}. DAC slot may not have been set."
)
raise DACException(f"Unexpected return from DAC when setting slot: {resp}. DAC slot may not have been set.")

Check warning on line 85 in src/qumada/instrument/custom_drivers/Harvard/Decadac.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/custom_drivers/Harvard/Decadac.py#L85

Added line #L85 was not covered by tests

def _script_set_slot(self):
"""
Expand Down Expand Up @@ -370,27 +368,27 @@
timestep (bool): Should the call block until the ramp is complete?
"""
_control_str = ""
trigger_mapping = {
"continous": 0,
"edge": 12,
}
# trigger_mapping = {
# "continous": 0,
# "edge": 12,
# }
# trigger = 'after_trig1_rising'
trigger_dict = {
"always": 0,
"trig1_low": 2,
"trig2_low": 3,
"until_trig1_rising": 4,
"until_trig2_rising": 5,
"until_trig1_falling": 6,
"until_trig2_falling": 7,
"never": 8,
"trig1_high": 10,
"trig2_high": 11,
"after_trig1_rising": 12,
"after_trig2_rising": 13,
"after_trig1_falling": 14,
"after_trig2_falling": 15,
}
# trigger_dict = {
# "always": 0,
# "trig1_low": 2,
# "trig2_low": 3,
# "until_trig1_rising": 4,
# "until_trig2_rising": 5,
# "until_trig1_falling": 6,
# "until_trig2_falling": 7,
# "never": 8,
# "trig1_high": 10,
# "trig2_high": 11,
# "after_trig1_rising": 12,
# "after_trig2_rising": 13,
# "after_trig1_falling": 14,
# "after_trig2_falling": 15,
# }

# _control_str = f'G{trigger_mapping[trigger]};'
_control_str = f"G{trigger};"
Expand Down
2 changes: 1 addition & 1 deletion src/qumada/instrument/custom_drivers/ZI/MFLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
self, name: str, device: str, serverhost: str = "localhost", existing_session: Session = None, **kwargs
):
super().__init__(name, **kwargs)
if type(existing_session) == Session:
if isinstance(existing_session, Session):

Check warning on line 48 in src/qumada/instrument/custom_drivers/ZI/MFLI.py

View check run for this annotation

Codecov / codecov/patch

src/qumada/instrument/custom_drivers/ZI/MFLI.py#L48

Added line #L48 was not covered by tests
session = existing_session
else:
self.session = session = Session(serverhost)
Expand Down
57 changes: 27 additions & 30 deletions src/qumada/instrument/mapping/Harvard/Decadac.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
# - Till Huckeman


import time

import numpy as np
from qcodes.instrument.parameter import Parameter

from qumada.instrument.custom_drivers.Harvard.Decadac import Decadac
Expand Down Expand Up @@ -65,7 +62,7 @@ def ramp(

if not start_values:
start_values = [param.get() for param in parameters]
ramp_rates = np.abs((np.array(end_values) - np.array(start_values)) / np.array(ramp_time))
# ramp_rates = np.abs((np.array(end_values) - np.array(start_values)) / np.array(ramp_time))
# if sync_trigger:
# if sync_trigger in parameters:
# raise Exception("Synchronized trigger cannot be part of parameters")
Expand All @@ -86,33 +83,33 @@ def trigger(self, parameter, level=1) -> None:
parameter.volt.set(level)

def setup_trigger_in(self, trigger_settings: dict):
trigger_dict = {
"always": 0,
"trig1_low": 2,
"trig2_low": 3,
"until_trig1_rising": 4,
"until_trig2_rising": 5,
"until_trig1_falling": 6,
"until_trig2_falling": 7,
"never": 8,
"trig1_high": 10,
"trig2_high": 11,
"after_trig1_rising": 12,
"after_trig2_rising": 13,
"after_trig1_falling": 14,
"after_trig2_falling": 15,
}
TRIGGER_MODE_MAPPING: dict = {
"continuous": 0,
"edge": 1,
"pulse": 3,
"tracking_edge": 4,
"tracking_pulse": 7,
"digital": 6,
}
# trigger_dict = {
# "always": 0,
# "trig1_low": 2,
# "trig2_low": 3,
# "until_trig1_rising": 4,
# "until_trig2_rising": 5,
# "until_trig1_falling": 6,
# "until_trig2_falling": 7,
# "never": 8,
# "trig1_high": 10,
# "trig2_high": 11,
# "after_trig1_rising": 12,
# "after_trig2_rising": 13,
# "after_trig1_falling": 14,
# "after_trig2_falling": 15,
# }
# TRIGGER_MODE_MAPPING: dict = {
# "continuous": 0,
# "edge": 1,
# "pulse": 3,
# "tracking_edge": 4,
# "tracking_pulse": 7,
# "digital": 6,
# }
print(
"Warning: The Decadacs trigger level is fixed at roughly 1.69 V and cannot be changed. \
Please make sure that your triggers are setup accordingly"
"Warning: The Decadacs trigger level is fixed at roughly 1.69 V and cannot be changed. "
"Please make sure that your triggers are setup accordingly"
)
trigger_mode = trigger_settings.get("trigger_mode", "continuous")
polarity = trigger_settings.get("trigger_mode_polarity", "positive")
Expand Down
5 changes: 3 additions & 2 deletions src/qumada/instrument/mapping/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def add_mapping_to_instrument(
instrument._qumada_mapping = mapping
try:
instrument._qumada_trigger = mapping.trigger
except:
except Exception:
pass
# TODO: Better name??
elif path is not None and mapping is None:
Expand All @@ -194,7 +194,8 @@ def add_mapping_to_instrument(

def _generate_mapping_stub(instrument: Instrument, path: str) -> None:
"""
Generates JSON stub of instrument parametes and saves it under the provided path. Overwrites existing files by default.
Generates JSON stub of instrument parametes and saves it under the provided path.
Overwrites existing files by default.

The saved JSON-structure is as follows:

Expand Down
Loading