diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f49814fc..90b9cd41 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: check-docstring-first - id: check-yaml @@ -15,21 +15,21 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/asottile/pyupgrade - rev: v3.20.0 + rev: v3.21.2 hooks: - id: pyupgrade args: [--py39-plus] - repo: https://github.com/pycqa/isort - rev: 6.0.1 + rev: 8.0.1 hooks: - id: isort args: ["--profile", "black"] -- repo: https://github.com/psf/black - rev: 25.1.0 +- repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.3.0 hooks: - id: black args: ["--line-length", "120"] - repo: https://github.com/pycqa/flake8 - rev: 7.2.0 + rev: 7.3.0 hooks: - id: flake8 diff --git a/src/qumada/instrument/buffers/dummy_dmm_buffer.py b/src/qumada/instrument/buffers/dummy_dmm_buffer.py index e81c8070..718a0939 100644 --- a/src/qumada/instrument/buffers/dummy_dmm_buffer.py +++ b/src/qumada/instrument/buffers/dummy_dmm_buffer.py @@ -22,6 +22,7 @@ @author: till3 """ + from __future__ import annotations import numpy as np diff --git a/src/qumada/instrument/buffers/mfli_buffer.py b/src/qumada/instrument/buffers/mfli_buffer.py index 2ca9b377..eb94e720 100644 --- a/src/qumada/instrument/buffers/mfli_buffer.py +++ b/src/qumada/instrument/buffers/mfli_buffer.py @@ -136,10 +136,8 @@ def num_points(self) -> int | None: @num_points.setter def num_points(self, num_points) -> None: if num_points > 8_388_608: - raise BufferException( - "Buffer is to small for this measurement. \ - Please reduce the number of data points" - ) + raise BufferException("Buffer is to small for this measurement. \ + Please reduce the number of data points") self._num_points = int(num_points) # TODO: Define setter for other settings (e.g. burst_duration, num_bursts etc) @@ -179,10 +177,8 @@ def _set_num_points(self) -> None: self._num_bursts = int(self.settings["num_bursts"]) self._burst_duration = self.settings["duration"] / self._num_bursts else: - logger.info( - "You have specified neither burst_duration nor num_bursts. \ - Using duration as burst_duration!" - ) + logger.info("You have specified neither burst_duration nor num_bursts. \ + Using duration as burst_duration!") self._burst_duration = self.settings["duration"] if "num_points" in self.settings: diff --git a/src/qumada/instrument/mapping/QDevil/qdac2.py b/src/qumada/instrument/mapping/QDevil/qdac2.py index 1be9cade..a3a323c4 100644 --- a/src/qumada/instrument/mapping/QDevil/qdac2.py +++ b/src/qumada/instrument/mapping/QDevil/qdac2.py @@ -146,10 +146,8 @@ def pulse( assert parameter._short_name == "dc_constant_V" instruments = {parameter.root_instrument for parameter in parameters} if len(instruments) > 1: - raise Exception( - "Parameters are from more than one instrument. \ - This would lead to non synchronized ramps." - ) + raise Exception("Parameters are from more than one instrument. \ + This would lead to non synchronized ramps.") qdac: QDac2 = instruments.pop() assert isinstance(qdac, QDac2) if delay < 1e-6: @@ -177,10 +175,8 @@ def pulse( qdac.free_all_triggers() def setup_trigger_in(): - raise Exception( - "QDac2 does not have a trigger input \ - not yet supported!" - ) + raise Exception("QDac2 does not have a trigger input \ + not yet supported!") def clean_generators(self): for dc_list in self.dc_lists: @@ -192,10 +188,8 @@ def query_instrument(parameters: list[Parameter]): """Check if all parameters are from the same instrument""" instruments = {parameter.root_instrument for parameter in parameters} if len(instruments) > 1: - raise Exception( - "Parameters are from more than one instrument. \ - This would lead to non synchronized ramps." - ) + raise Exception("Parameters are from more than one instrument. \ + This would lead to non synchronized ramps.") qdac: QDac2 = instruments.pop() assert isinstance(qdac, QDac2) return qdac diff --git a/src/qumada/instrument/mapping/base.py b/src/qumada/instrument/mapping/base.py index 1e5cbd37..5b0baac8 100644 --- a/src/qumada/instrument/mapping/base.py +++ b/src/qumada/instrument/mapping/base.py @@ -192,10 +192,8 @@ def add_mapping_to_instrument( helper_mapping = _load_instrument_mapping(mapping) instrument._is_triggerable = False else: - raise ValueError( - "Mapping parameter has to be either of type \ - InstrumentMapping or str" - ) + raise ValueError("Mapping parameter has to be either of type \ + InstrumentMapping or str") mapping = {} mapping["parameter_names"] = { diff --git a/src/qumada/measurement/device_object.py b/src/qumada/measurement/device_object.py index d669f653..97af5822 100644 --- a/src/qumada/measurement/device_object.py +++ b/src/qumada/measurement/device_object.py @@ -66,10 +66,8 @@ def add_terminal(self, terminal_name: str, type: str | None = None, terminal_dat self.namespace[terminal_name.replace(" ", "_")] = self.terminals[terminal_name] logger.warning(f"Added {terminal_name} to global namespace!") else: - raise Terminal_Exists_Exception( - f"Terminal {terminal_name} already exists in global namespace. \ - Please remove it first!" - ) + raise Terminal_Exists_Exception(f"Terminal {terminal_name} already exists in global namespace. \ + Please remove it first!") def remove_terminal(self, terminal_name: str): if terminal_name in self.terminals.keys(): @@ -420,15 +418,11 @@ def sweep_2D( if buffered is True: if "num_points" in temp_buffer_settings.keys(): temp_buffer_settings["num_points"] = fast_num_points - logger.warning( - f"Temporarily changed buffer settings to match the \ - number of points specified {fast_num_points=}" - ) + logger.warning(f"Temporarily changed buffer settings to match the \ + number of points specified {fast_num_points=}") else: - logger.warning( - "Num_points not specified in buffer settings! fast_num_points value is \ - ignored and buffer settings are used to specify measurement!" - ) + logger.warning("Num_points not specified in buffer settings! fast_num_points value is \ + ignored and buffer settings are used to specify measurement!") script = Generic_2D_Sweep_buffered() else: @@ -623,10 +617,8 @@ def pulsed_measurement( if "num_points" in temp_buffer_settings.keys(): temp_buffer_settings["num_points"] = len(setpoints[0]) - logger.warning( - "Temporarily changed buffer settings to match the \ - number of points specified in the setpoints" - ) + logger.warning("Temporarily changed buffer settings to match the \ + number of points specified in the setpoints") else: raise Exception( "For this kind of measurement, you have to specify the number of points in the buffer settings!" @@ -761,10 +753,8 @@ def run_measurement( if "num_points" in temp_buffer_settings.keys(): temp_buffer_settings["num_points"] = len(setpoints[0]) - logger.warning( - "Temporarily changed buffer settings to match the \ - number of points specified in the setpoints" - ) + logger.warning("Temporarily changed buffer settings to match the \ + number of points specified in the setpoints") else: raise Exception( "For this kind of measurement, you have to specify the number of points in the buffer settings!" @@ -992,10 +982,8 @@ def _set_limits(self): raise ValueError(f"Invalid limits provided for {self._parent.name} {self.name}") param = self.instrument_parameter if not isinstance(param, Parameter): - logger.exception( - f"Cannot set limits to {self._parent.name} {self.name} \ - as no valid instrument parameter was assigned to it!" - ) + logger.exception(f"Cannot set limits to {self._parent.name} {self.name} \ + as no valid instrument parameter was assigned to it!") else: try: if self._limit_validator in param.validators: @@ -1108,10 +1096,8 @@ def measured_ramp( f"Temporarily changed buffer settings to match the number of points specified {num_points=}" ) else: - logger.warning( - "Num_points not specified in buffer settings! fast_num_points value is \ - ignored and buffer settings are used to specify measurement!" - ) + logger.warning("Num_points not specified in buffer settings! fast_num_points value is \ + ignored and buffer settings are used to specify measurement!") if backsweep is True: script = Generic_1D_Hysteresis_buffered() else: diff --git a/src/qumada/measurement/doNd_enhanced/doNd_enhanced.py b/src/qumada/measurement/doNd_enhanced/doNd_enhanced.py index 3418b9d2..d7823cbe 100644 --- a/src/qumada/measurement/doNd_enhanced/doNd_enhanced.py +++ b/src/qumada/measurement/doNd_enhanced/doNd_enhanced.py @@ -391,10 +391,8 @@ def do1d_parallel_asym( break else: warnings.warn("Break condition was met.") - print( - "Break condition was met. This meassage pops up alone \ - if there is some issue with warning.warn" - ) + print("Break condition was met. This meassage pops up alone \ + if there is some issue with warning.warn") raise BreakConditionInterrupt("Break condition was met.") param_set[0].post_delay = original_delay diff --git a/src/qumada/measurement/measurement.py b/src/qumada/measurement/measurement.py index 293a4ec6..a134ca80 100644 --- a/src/qumada/measurement/measurement.py +++ b/src/qumada/measurement/measurement.py @@ -126,10 +126,8 @@ def add_gate_parameter(self, parameter_name: str, gate_name: str = None, paramet parameter (Parameter): Custom parameter. Set this, if you want to set a custom parameter. Defaults to None. """ if parameter_name not in MeasurementScript.PARAMETER_NAMES: - raise NameError( - f'parameter_name "{parameter_name}" not in MeasurementScript.PARAMETER_NAMES. \ - Allowed parameters are listed in qumada.instrument.parameter_whitelists' - ) + raise NameError(f'parameter_name "{parameter_name}" not in MeasurementScript.PARAMETER_NAMES. \ + Allowed parameters are listed in qumada.instrument.parameter_whitelists') if not gate_name: self.gate_parameters[parameter_name] = parameter else: @@ -309,10 +307,8 @@ def generate_lists(self) -> None: try: self.compensating_parameters_values.append(self.properties[gate][parameter]["value"]) except KeyError as e: - print( - f"No value assigned for compensating parameter \ - {self.compensating_parameters[-1]}" - ) + print(f"No value assigned for compensating parameter \ + {self.compensating_parameters[-1]}") raise e try: leverarms = self.properties[gate][parameter]["leverarms"] @@ -328,20 +324,16 @@ def generate_lists(self) -> None: comp_list.append({"gate": entry["terminal"], "parameter": entry["parameter"]}) self.compensated_parameters.append(comp_list) except KeyError as e: - print( - f"The terminal to be compensated for with {self.compensating_parameters[-1]} \ + print(f"The terminal to be compensated for with {self.compensating_parameters[-1]} \ is not properly specified! Make sure to define a dictionary with \ - terminal and parameter as keys." - ) + terminal and parameter as keys.") raise e try: limits = self.properties[gate][parameter]["limits"] self.compensating_limits.append(limits) except KeyError as e: - print( - f"No limits assigned to compensating parameter \ - {self.compensating_parameters[-1]}!" - ) + print(f"No limits assigned to compensating parameter \ + {self.compensating_parameters[-1]}!") raise e elif self.properties[gate][parameter]["type"].find("dynamic") >= 0: @@ -352,29 +344,23 @@ def generate_lists(self) -> None: try: assert self.properties[gate][parameter]["num_points"] == self.buffered_num_points except AssertionError: - logger.warning( - f"Number of datapoints from buffer_settings\ + logger.warning(f"Number of datapoints from buffer_settings\ and gate_parameters do not match. Using \ the value from the buffer settings: \ - {self.buffered_num_points}" - ) + {self.buffered_num_points}") elif "setpoints" in self.properties[gate][parameter].keys(): try: assert len(self.properties[gate][parameter]["setpoints"]) == self.buffered_num_points except AssertionError: - logger.warning( - f"Number of datapoints from buffer_settings\ + logger.warning(f"Number of datapoints from buffer_settings\ and gate_parameters do not match. Using \ the value from the buffer settings: \ - {self.buffered_num_points}" - ) + {self.buffered_num_points}") else: - logger.info( - "No num_points or setpoints given for\ + logger.info("No num_points or setpoints given for\ buffered measurement. The value from \ - buffer_settings is used" - ) + buffer_settings is used") try: self.dynamic_sweeps.append( LinSweep( @@ -514,31 +500,25 @@ def initialize(self, dyn_ramp_to_val=False, inactive_dyn_channels: list | None = try: assert self.properties[gate][parameter]["num_points"] == self.buffered_num_points except AssertionError: - logger.warning( - f"Number of datapoints from buffer_settings\ + logger.warning(f"Number of datapoints from buffer_settings\ and gate_parameters do not match. Using \ the value from the buffer settings: \ - {self.buffered_num_points}" - ) + {self.buffered_num_points}") self.properties[gate][parameter]["num_points"] = self.buffered_num_points elif "setpoints" in self.properties[gate][parameter].keys(): try: assert len(self.properties[gate][parameter]["setpoints"]) == self.buffered_num_points except AssertionError: - logger.warning( - f"Number of datapoints from buffer_settings\ + logger.warning(f"Number of datapoints from buffer_settings\ and gate_parameters do not match. Using \ the value from the buffer settings: \ - {self.buffered_num_points}" - ) + {self.buffered_num_points}") else: - logger.info( - "No num_points or setpoints given for\ + logger.info("No num_points or setpoints given for\ buffered measurement. The value from \ - buffer_settings is used" - ) + buffer_settings is used") # try: # self.dynamic_sweeps.append( # LinSweep( @@ -748,10 +728,8 @@ def reset(self) -> None: Resets all static/dynamic parameters to their value/start value. TODO: Remove! Since initialize() does only create lists one, there is no advantage of using reset(). """ - logger.warning( - "The reset() method is deprecated and will be removed in a future release! \ - It is recommended to replace all calls of reset() with initialize()" - ) + logger.warning("The reset() method is deprecated and will be removed in a future release! \ + It is recommended to replace all calls of reset() with initialize()") ramp_rate = self.settings.get("ramp_rate", 0.3) setpoint_intervall = self.settings.get("setpoint_intervall", 0.1) for gate, parameters in self.gate_parameters.items(): diff --git a/src/qumada/measurement/scripts/generic_measurement.py b/src/qumada/measurement/scripts/generic_measurement.py index ecd665c3..15a11a7d 100644 --- a/src/qumada/measurement/scripts/generic_measurement.py +++ b/src/qumada/measurement/scripts/generic_measurement.py @@ -168,12 +168,10 @@ def run(self, **dond_kwargs): class Generic_1D_parallel_asymm_Sweep(MeasurementScript): def run(self): - raise Exception( - "This script was renamed to Generic_1D_parallel_Sweep \ + raise Exception("This script was renamed to Generic_1D_parallel_Sweep \ and is no longer available. \ Please use Generic_1D_parallel_Sweep instead! \ - No measurement was started." - ) + No measurement was started.") class Generic_1D_parallel_Sweep(MeasurementScript): @@ -562,12 +560,10 @@ def run(self): sync_trigger=sync_trigger, ) except AttributeError as ex: - logger.error( - "Exception: This instrument probably does not have a \ + logger.error("Exception: This instrument probably does not have a \ qtools_ramp method. Buffered measurements without \ ramp method are no longer supported. \ - Use the unbuffered script!" - ) + Use the unbuffered script!") raise ex if trigger_type == "manual": @@ -582,12 +578,10 @@ def run(self): elif trigger_type == "software": for buffer in self.buffers: buffer.force_trigger() - logger.warning( - "You are using software trigger, which \ + logger.warning("You are using software trigger, which \ can lead to significant delays between \ measurement instruments! Only recommended\ - for debugging." - ) + for debugging.") while not all(buffer.is_finished() for buffer in list(self.buffers)): sleep(0.1) try: @@ -712,10 +706,8 @@ def run(self): try: parameter_value = self.properties[parameter["gate"]][parameter["parameter"]]["value"] except KeyError: - logger.error( - "An idle dynamic parameter has no value assigned\ - and cannot be logged!" - ) + logger.error("An idle dynamic parameter has no value assigned\ + and cannot be logged!") break static_gettables.append((channel, [parameter_value for _ in range(int(self.buffered_num_points))])) for param in static_gettables: @@ -766,12 +758,10 @@ def run(self): sync_trigger=sync_trigger, ) except AttributeError as ex: - logger.error( - "Exception: This instrument probably does not have a \ + logger.error("Exception: This instrument probably does not have a \ a qumada_ramp method. Buffered measurements without \ ramp method are no longer supported. \ - Use the unbuffered script!" - ) + Use the unbuffered script!") raise ex if trigger_type == "manual": @@ -786,12 +776,10 @@ def run(self): elif trigger_type == "software": for buffer in self.buffers: buffer.force_trigger() - logger.warning( - "You are using software trigger, which \ + logger.warning("You are using software trigger, which \ can lead to significant delays between \ measurement instruments! Only recommended \ - for debugging." - ) + for debugging.") while not all(buffer.is_finished() for buffer in list(self.buffers)): sleep(0.1) try: @@ -915,10 +903,8 @@ def run(self): try: parameter_value = self.properties[parameter["gate"]][parameter["parameter"]]["value"] except KeyError: - logger.error( - "An idle dynamic parameter has no value assigned\ - and cannot be logged!" - ) + logger.error("An idle dynamic parameter has no value assigned\ + and cannot be logged!") break static_gettables.append((channel, [parameter_value for _ in range(int(self.buffered_num_points))])) for param in static_gettables: @@ -961,12 +947,10 @@ def run(self): sync_trigger=sync_trigger, ) except AttributeError as ex: - logger.error( - "Exception: This instrument probably does not have a \ + logger.error("Exception: This instrument probably does not have a \ a qumada_ramp method. Buffered measurements without \ ramp method are no longer supported. \ - Use the unbuffered script!" - ) + Use the unbuffered script!") raise ex if trigger_type == "manual": @@ -981,12 +965,10 @@ def run(self): elif trigger_type == "software": for buffer in self.buffers: buffer.force_trigger() - logger.info( - "You are using software trigger, which \ + logger.info("You are using software trigger, which \ can lead to significant delays between \ measurement instruments! Only recommended\ - for debugging." - ) + for debugging.") while not all(buffer.is_finished() for buffer in list(self.buffers)): sleep(0.1) try: @@ -1217,12 +1199,10 @@ def run(self): sync_trigger=sync_trigger, ) except AttributeError as ex: - logger.error( - "Exception: This instrument probably does not have a \ + logger.error("Exception: This instrument probably does not have a \ a qumada_ramp method. Buffered measurements without \ ramp method are no longer supported. \ - Use the unbuffered script!" - ) + Use the unbuffered script!") raise ex if trigger_type == "manual": @@ -1238,12 +1218,10 @@ def run(self): elif trigger_type == "software": for buffer in self.buffers: buffer.force_trigger() - logger.warning( - "You are using software trigger, which \ + logger.warning("You are using software trigger, which \ can lead to significant delays between \ measurement instruments! Only recommended\ - for debugging." - ) + for debugging.") timer = 0 while not all(buffer.is_finished() for buffer in list(self.buffers)): timer += 0.1 @@ -1253,11 +1231,9 @@ def run(self): try: trigger_reset() except TypeError: - logger.info( - "No method to reset the trigger defined. \ + logger.info("No method to reset the trigger defined. \ As you are doing a 2D Sweep, this can have undesired \ - consequences!" - ) + consequences!") results = self.readout_buffers() datasaver.add_result( @@ -1418,12 +1394,10 @@ def run(self): sync_trigger=sync_trigger, ) except AttributeError as ex: - logger.error( - f"Exception: {instr} probably does not have a \ + logger.error(f"Exception: {instr} probably does not have a \ a qumada_pulse method. Buffered measurements without \ ramp method are no longer supported. \ - Use the unbuffered script!" - ) + Use the unbuffered script!") raise ex if trigger_type == "manual": @@ -1442,12 +1416,10 @@ def run(self): elif trigger_type == "software": for buffer in self.buffers: buffer.force_trigger() - logger.warning( - "You are using software trigger, which \ + logger.warning("You are using software trigger, which \ can lead to significant delays between \ measurement instruments! Only recommended\ - for debugging." - ) + for debugging.") timeout_timer = 0 while not all(buffer.is_finished() for buffer in list(self.buffers)): timeout_timer += 0.1 @@ -1623,12 +1595,10 @@ def run(self): sync_trigger=sync_trigger, ) except AttributeError as ex: - logger.error( - f"Exception: {instr} probably does not have a \ + logger.error(f"Exception: {instr} probably does not have a \ a qumada_pulse method. Buffered measurements without \ ramp method are no longer supported. \ - Use the unbuffered script!" - ) + Use the unbuffered script!") raise ex if trigger_type == "manual": @@ -1647,12 +1617,10 @@ def run(self): elif trigger_type == "software": for buffer in self.buffers: buffer.force_trigger() - logger.warning( - "You are using software trigger, which \ + logger.warning("You are using software trigger, which \ can lead to significant delays between \ measurement instruments! Only recommended\ - for debugging." - ) + for debugging.") while not all(buffer.is_finished() for buffer in list(self.buffers)): sleep(0.1) diff --git a/src/qumada/utils/GUI.py b/src/qumada/utils/GUI.py index be6620b3..89dfaff0 100644 --- a/src/qumada/utils/GUI.py +++ b/src/qumada/utils/GUI.py @@ -49,11 +49,9 @@ def open_web_gui(parameters): elif isinstance(parameters, list): params = parameters else: - print( - "The provided parameters are invalid. Please pass as Station \ + print("The provided parameters are invalid. Please pass as Station \ object, a Measurement Script (after parameter mapping) or a \ - list of parameters" - ) + list of parameters") return False monitor_process = Popen([sys.executable, "-m", "qcodes.monitor.monitor"], shell=True) monitor = Monitor(*params) diff --git a/src/qumada/utils/load_from_sqlite_db.py b/src/qumada/utils/load_from_sqlite_db.py index 92a4787f..367d7017 100644 --- a/src/qumada/utils/load_from_sqlite_db.py +++ b/src/qumada/utils/load_from_sqlite_db.py @@ -22,6 +22,7 @@ """ Loading data from Database """ + from __future__ import annotations from os import path