From 50c14e3f015e55319fbcab3ec5ab8bdbea1cc095 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 23 Jan 2020 09:51:01 +0100 Subject: [PATCH 01/23] Improve HMC804x --- .../rohde_schwarz/private/HMC804x.py | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py b/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py index e6da5162143..0762dff2fd3 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py +++ b/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py @@ -1,37 +1,46 @@ -from qcodes import VisaInstrument, validators as vals +from typing import Union + +from qcodes import VisaInstrument, validators as vals, Instrument from qcodes import InstrumentChannel, ChannelList class RohdeSchwarzHMC804xChannel(InstrumentChannel): - def __init__(self, parent, name, channel): + def __init__(self, parent: Instrument, name: str, + channel: Union[str, int]) -> None: super().__init__(parent, name) select_cmd = ":INSTrument:NSELect {};".format(channel) self.add_parameter("set_voltage", label='Target voltage output', - set_cmd="{} :SOURce:VOLTage:LEVel:IMMediate:AMPLitude {}".format( - select_cmd, '{}'), - get_cmd="{} :SOURce:VOLTage:LEVel:IMMediate:AMPLitude?".format( - select_cmd), + set_cmd="{} " + ":SOURce:VOLTage:LEVel:IMMediate:AMPLitude " + "{}".format(select_cmd, '{}'), + get_cmd="{} " + ":SOURce:VOLTage:LEVel:IMMediate:AMPLitude?". + format(select_cmd), get_parser=float, unit='V', vals=vals.Numbers(0, 32.050) ) self.add_parameter("set_current", label='Target current output', - set_cmd="{} :SOURce:CURRent:LEVel:IMMediate:AMPLitude {}".format( - select_cmd, '{}'), - get_cmd="{} :SOURce:CURRent:LEVel:IMMediate:AMPLitude?".format( - select_cmd), + set_cmd="{} " + ":SOURce:CURRent:LEVel:IMMediate:AMPLitude " + "{}".format(select_cmd, '{}'), + get_cmd="{} " + ":SOURce:CURRent:LEVel:IMMediate:AMPLitude?". + format(select_cmd), get_parser=float, unit='A', vals=vals.Numbers(0.5e-3, self._parent.max_current) ) self.add_parameter('state', label='Output enabled', - set_cmd='{} :OUTPut:CHANnel:STATe {}'.format(select_cmd, '{}'), - get_cmd='{} :OUTPut:CHANnel:STATe?'.format(select_cmd), + set_cmd='{} :OUTPut:CHANnel:STATe {}'. + format(select_cmd, '{}'), + get_cmd='{} :OUTPut:CHANnel:STATe?'. + format(select_cmd), val_mapping={'ON': 1, 'OFF': 0}, vals=vals.Enum('ON', 'OFF') ) @@ -60,15 +69,18 @@ def __init__(self, parent, name, channel): class _RohdeSchwarzHMC804x(VisaInstrument): """ - This is the general HMC804x Power Supply driver class that implements shared parameters and functionality - among all similar power supply from Rohde & Schwarz. + This is the general HMC804x Power Supply driver class that implements + shared parameters and functionality among all similar power supply + from Rohde & Schwarz. - This driver was written to be inherited from by a specific driver (e.g. HMC8043). + This driver was written to be inherited from by a specific driver + (e.g. HMC8043). """ _max_currents = {3: 3.0, 2: 5.0, 1: 10.0} - def __init__(self, name, address, num_channels, **kwargs): + def __init__(self, name: str, address: str, + num_channels: int, **kwargs) -> None: super().__init__(name, address, **kwargs) self.max_current = _RohdeSchwarzHMC804x._max_currents[num_channels] @@ -82,7 +94,8 @@ def __init__(self, name, address, num_channels, **kwargs): ) # channel-specific parameters - channels = ChannelList(self, "SupplyChannel", RohdeSchwarzHMC804xChannel, snapshotable=False) + channels = ChannelList(self, "SupplyChannel", + RohdeSchwarzHMC804xChannel, snapshotable=False) for ch_num in range(1, num_channels+1): ch_name = "ch{}".format(ch_num) channel = RohdeSchwarzHMC804xChannel(self, ch_name, ch_num) From c5704b8335faa0d50be7217b5fcdf8a1e763a5f4 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 23 Jan 2020 09:53:32 +0100 Subject: [PATCH 02/23] Improve SGS100A --- qcodes/instrument_drivers/rohde_schwarz/SGS100A.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/SGS100A.py b/qcodes/instrument_drivers/rohde_schwarz/SGS100A.py index 6c80ab83475..da5f3b07570 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/SGS100A.py +++ b/qcodes/instrument_drivers/rohde_schwarz/SGS100A.py @@ -4,7 +4,7 @@ class RohdeSchwarz_SGS100A(VisaInstrument): """ - This is the qcodes driver for the Rohde & Schwarz SGS100A signal generator + This is the QCoDeS driver for the Rohde & Schwarz SGS100A signal generator. Status: beta-version. @@ -27,7 +27,7 @@ class RohdeSchwarz_SGS100A(VisaInstrument): only the ones most commonly used. """ - def __init__(self, name, address, **kwargs): + def __init__(self, name: str, address: str, **kwargs) -> None: super().__init__(name, address, terminator='\n', **kwargs) self.add_parameter(name='frequency', @@ -90,7 +90,8 @@ def __init__(self, name, address, **kwargs): label='REF/LO Output', get_cmd='CONN:REFL:OUTP?', set_cmd='CONN:REFL:OUTP {}', - vals=vals.Enum('REF', 'LO', 'OFF', 'ref', 'lo', 'off', 'Off')) + vals=vals.Enum('REF', 'LO', 'OFF', 'ref', 'lo', + 'off', 'Off')) # Frequency mw_source outputs when used as a reference self.add_parameter('ref_osc_output_freq', label='Reference Oscillator Output Frequency', From 81150b26fca380e5e650c4bc1cb95945f4844a49 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 23 Jan 2020 10:13:50 +0100 Subject: [PATCH 03/23] Improve RTO1000 I --- .../rohde_schwarz/RTO1000.py | 85 ++++++++++--------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index bf89e2ef1c5..77fca6ab5aa 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -62,8 +62,8 @@ def prepare_trace(self) -> None: values_per_sample = hdr_vals[3] # NOTE (WilliamHPNielsen): - # if samples are multi-valued, we need a MultiParameter - # instead of an arrayparameter + # If samples are multi-valued, we need a `MultiParameter` + # instead of an `ArrayParameter`. if values_per_sample > 1: raise NotImplementedError('There are several values per sample ' 'in this trace (are you using envelope' @@ -77,7 +77,7 @@ def prepare_trace(self) -> None: # we must ensure that all this took effect before proceeding self.channel._parent.ask('*OPC?') - def get_raw(self): + def get_raw(self) -> int: """ Returns a trace """ @@ -89,13 +89,13 @@ def get_raw(self): 'prepare_trace().') if instr.run_mode() == 'RUN Nx SINGLE': - N = instr.num_acquisitions() - M = instr.completed_acquisitions() - log.info('Acquiring {} traces.'.format(N)) - while M < N: - log.info('Acquired {}:{} traces.'.format(M, N)) + n = instr.num_acquisitions() + m = instr.completed_acquisitions() + log.info('Acquiring {} traces.'.format(n)) + while m < n: + log.info('Acquired {}:{} traces.'.format(m, n)) time.sleep(0.25) - M = instr.completed_acquisitions() + m = instr.completed_acquisitions() log.info('Acquisition completed. Polling trace from instrument.') vh = instr.visa_handle @@ -129,12 +129,13 @@ def get_raw(self): return output + class ScopeMeasurement(InstrumentChannel): """ - Class to hold a measurement of the scope + Class to hold a measurement of the scope. """ - def __init__(self, parent: Instrument, name: str, meas_nr: int): + def __init__(self, parent: Instrument, name: str, meas_nr: int) -> None: """ Args: parent: The instrument to which the channel is attached @@ -171,41 +172,47 @@ def __init__(self, parent: Instrument, name: str, meas_nr: int): 'Z2V1', 'Z2V2', 'Z2V3', 'Z2V4', 'Z2I1', 'Z2I2', 'Z2I3', 'Z2I4') - self.categories = vals.Enum('AMPTime', 'JITTer', 'EYEJitter', 'SPECtrum', - 'HISTogram', 'PROTocol') + self.categories = vals.Enum('AMPTime', 'JITTer', 'EYEJitter', + 'SPECtrum', 'HISTogram', 'PROTocol') self.meas_type = vals.Enum( # Amplitude/time measurements - 'HIGH', 'LOW', 'AMPLitude', 'MAXimum', - 'MINimum', 'PDELta', 'MEAN', 'RMS', - 'STDDev', 'POVershoot', 'NOVershoot', 'AREA', - 'RTIMe', 'FTIMe', 'PPULse', 'NPULse', - 'PERiod', 'FREQuency', 'PDCYcle', 'NDCYcle', - 'CYCarea', 'CYCMean', 'CYCRms', 'CYCStddev', - 'PULCnt', 'DELay', 'PHASe', 'BWIDth', - 'PSWitching', 'NSWitching', 'PULSetrain', 'EDGecount', - 'SHT', 'SHR', 'DTOTrigger', 'PROBemeter', - 'SLERising', 'SLEFalling' + 'HIGH', 'LOW', 'AMPLitude', + 'MAXimum', 'MINimum', 'PDELta', + 'MEAN', 'RMS', 'STDDev', + 'POVershoot', 'NOVershoot', 'AREA', + 'RTIMe', 'FTIMe', 'PPULse', + 'NPULse', 'PERiod', 'FREQuency', + 'PDCYcle', 'NDCYcle', 'CYCarea', + 'CYCMean', 'CYCRms', 'CYCStddev', + 'PULCnt', 'DELay', 'PHASe', + 'BWIDth', 'PSWitching', 'NSWitching', + 'PULSetrain', 'EDGecount', 'SHT', + 'SHR', 'DTOTrigger', 'PROBemeter', + 'SLERising', 'SLEFalling', # Jitter measurements - 'CCJitter', 'NCJitter', 'CCWidth', 'CCDutycycle', - 'TIE', 'UINTerval', 'DRATe', 'SKWDelay', - 'SKWPhase', + 'CCJitter', 'NCJitter', 'CCWidth', + 'CCDutycycle', 'TIE', 'UINTerval', + 'DRATe', 'SKWDelay', 'SKWPhase', # Eye diagram measurements - 'ERPercent', 'ERDB', 'EHEight', 'EWIDth', - 'ETOP', 'EBASe', 'QFACtor', 'RMSNoise', - 'SNRatio', 'DCDistortion', 'ERTime', 'EFTime', - 'EBRate', 'EAMPlitude', 'PPJitter', 'STDJitter', - 'RMSJitter', + 'ERPercent', 'ERDB', 'EHEight', + 'EWIDth', 'ETOP', 'EBASe', + 'QFACtor', 'RMSNoise', 'SNRatio', + 'DCDistortion', 'ERTime', 'EFTime', + 'EBRate', 'EAMPlitude', 'PPJitter', + 'STDJitter', 'RMSJitter', # Spectrum measurements - 'CPOWer', 'OBWidth', 'SBWidth', 'THD', - 'THDPCT', 'THDA', 'THDU', 'THDR', - 'HAR', 'PLISt', + 'CPOWer', 'OBWidth', 'SBWidth', + 'THD', 'THDPCT', 'THDA', + 'THDU', 'THDR', 'HAR', + 'PLISt', # Histogram measurements - 'WCOunt', 'WSAMples', 'HSAMples', 'HPEak', - 'PEAK', 'UPEakvalue', 'LPEakvalue', 'HMAXimum', - 'HMINimum', 'MEDian', 'MAXMin', 'HMEan', - 'HSTDdev', 'M1STddev', 'M2STddev', 'M3STddev', - 'MKPositive', 'MKNegative' + 'WCOunt', 'WSAMples', 'HSAMples', + 'HPEak', 'PEAK', 'UPEakvalue', + 'LPEakvalue', 'HMAXimum', 'HMINimum', + 'MEDian', 'MAXMin', 'HMEan', + 'HSTDdev', 'M1STddev', 'M2STddev', + 'M3STddev', 'MKPositive', 'MKNegative' ) self.add_parameter('enable', From be537bfa4d3283dc8efe484e23f12d59c61d10c1 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 23 Jan 2020 10:18:34 +0100 Subject: [PATCH 04/23] Improve RTO1000 II --- .../rohde_schwarz/RTO1000.py | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index 77fca6ab5aa..d9437e9796f 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -219,70 +219,76 @@ def __init__(self, parent: Instrument, name: str, meas_nr: int) -> None: label=f'Measurement {meas_nr} enable', set_cmd=f'MEASurement{meas_nr}:ENABle {{}}', vals=vals.Enum('ON', 'OFF'), - docstring='Switches the measurement on or off') + docstring='Switches the measurement on or off.') self.add_parameter('source', label=f'Measurement {meas_nr} source', set_cmd=f'MEASurement{meas_nr}:SOURce {{}}', vals=self.sources, - docstring='Set the source of a measurement if the ' \ - 'measurement only needs one source') + docstring='Set the source of a measurement if the ' + 'measurement only needs one source.') self.add_parameter('source_first', label=f'Measurement {meas_nr} first source', set_cmd=f'MEASurement{meas_nr}:FSRC {{}}', vals=self.sources, - docstring='Set the first source of a measurement if the ' \ - 'measurement only needs mutliple sources') + docstring='Set the first source of a measurement' + ' if the measurement only needs multiple' + ' sources.') self.add_parameter('source_second', label=f'Measurement {meas_nr} second source', set_cmd=f'MEASurement{meas_nr}:SSRC {{}}', vals=self.sources, - docstring='Set the second source of a measurement if the ' \ - 'measurement only needs multiple sources') + docstring='Set the second source of a measurement' + ' if the measurement only needs multiple' + ' sources.') self.add_parameter('category', label=f'Measurement {meas_nr} category', set_cmd=f'MEASurement{meas_nr}:CATegory {{}}', vals=self.categories, - docstring='Set the category of a measurement') + docstring='Set the category of a measurement.') self.add_parameter('main', label=f'Measurement {meas_nr} main', set_cmd=f'MEASurement{meas_nr}:MAIN {{}}', vals=self.meas_type, - docstring='Set the main of a measurement') + docstring='Set the main of a measurement.') self.add_parameter('statistics_enable', label=f'Measurement {meas_nr} enable statistics', - set_cmd=f'MEASurement{meas_nr}:STATistics:ENABle {{}}', + set_cmd=f'MEASurement{meas_nr}:STATistics:ENABle' + f' {{}}', vals=vals.Enum('ON', 'OFF'), - docstring='Switches the measurement on or off') + docstring='Switches the measurement on or off.') self.add_parameter('clear', label=f'Measurement {meas_nr} clear statistics', set_cmd=f'MEASurement{meas_nr}:CLEar', - docstring='Clears/reset measurement') + docstring='Clears/reset measurement.') self.add_parameter('event_count', label=f'Measurement {meas_nr} number of events', get_cmd=f'MEASurement{meas_nr}:RESult:EVTCount?', get_parser=int, - docstring='Number of measurement results in the long-term measurement') + docstring='Number of measurement results in the' + ' long-term measurement.') self.add_parameter('result_avg', label=f'Measurement {meas_nr} averages', get_cmd=f'MEASurement{meas_nr}:RESult:AVG?', get_parser=float, - docstring='Average of the long-term measurement results') + docstring='Average of the long-term measurement' + ' results.') + class ScopeChannel(InstrumentChannel): """ Class to hold an input channel of the scope. Exposes: state, coupling, ground, scale, range, position, offset, - invert, bandwidth, impedance, overload + invert, bandwidth, impedance, overload. """ def __init__(self, parent: Instrument, name: str, channum: int) -> None: @@ -402,24 +408,20 @@ def __init__(self, parent: Instrument, name: str, channum: int) -> None: 'ENVELOPE': 'ENV'} ) - ######################### - # Trace - self.add_parameter('trace', channum=self.channum, parameter_class=ScopeTrace) self._trace_ready = False - ######################### # Specialised/interlinked set/getters - def _set_range(self, value): + def _set_range(self, value: float) -> None: self.scale.cache.set(value/10) self._parent.write('CHANnel{}:RANGe {}'.format(self.channum, value)) - def _set_scale(self, value): + def _set_scale(self, value: float) -> None: self.range.cache.set(value*10) self._parent.write('CHANnel{}:SCALe {}'.format(self.channum, From 8e50ed3adffcf4d01b9b29dfacb30d4714664181 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 23 Jan 2020 10:39:20 +0100 Subject: [PATCH 05/23] Improve RTO1000 III --- .../rohde_schwarz/RTO1000.py | 72 +++++++++---------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index d9437e9796f..4811442e2b8 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -436,9 +436,9 @@ class RTO1000(VisaInstrument): """ def __init__(self, name: str, address: str, - model: str=None, timeout: float=5., - HD: bool=True, - terminator: str='\n', + model: str = None, timeout: float = 5., + HD: bool = True, + terminator: str = '\n', **kwargs) -> None: """ Args: @@ -455,12 +455,10 @@ def __init__(self, name: str, address: str, super().__init__(name=name, address=address, timeout=timeout, terminator=terminator, **kwargs) - - # With firmware versions earlier than 3.65, it seems that the # model number can NOT be queried from the instrument # (at least fails with RTO1024, fw 2.52.1.1), so in that case - # the user must provide the model manually + # the user must provide the model manually. firmware_version = self.get_idn()['firmware'] if LooseVersion(firmware_version) < LooseVersion('3'): @@ -496,7 +494,6 @@ def __init__(self, name: str, address: str, val_mapping={'remote': 0, 'view': 1}) - ######################### # Triggering self.add_parameter('trigger_display', @@ -524,9 +521,10 @@ def __init__(self, name: str, address: str, set_cmd='TRIGger:MODE {}', get_cmd='TRIGger1:SOURce?', vals=vals.Enum('AUTO', 'NORMAL', 'FREERUN'), - docstring='Sets the trigger mode which determines the ' \ - ' behaviour of the instrument if no trigger occurs.\n' \ - 'Options: AUTO, NORMAL, FREERUN.', + docstring='Sets the trigger mode which determines' + ' the behaviour of the instrument if no' + ' trigger occurs.\n' + 'Options: AUTO, NORMAL, FREERUN.', unit='none') self.add_parameter('trigger_type', @@ -563,7 +561,6 @@ def __init__(self, name: str, address: str, get_cmd='TRIGger1:EDGE:SLOPe?', vals=vals.Enum('POS', 'NEG', 'EITH')) - ######################### # Horizontal settings self.add_parameter('timebase_scale', @@ -590,14 +587,13 @@ def __init__(self, name: str, address: str, unit='s', vals=vals.Numbers(-100e24, 100e24)) - ######################### # Acquisition # I couldn't find a way to query the run mode, so we manually keep # track of it. It is very important when getting the trace to make - # sense of completed_acquisitions + # sense of completed_acquisitions. self.add_parameter('run_mode', - label='Run/acqusition mode of the scope', + label='Run/acquisition mode of the scope', get_cmd=None, set_cmd=None) @@ -632,7 +628,6 @@ def __init__(self, name: str, address: str, vals=vals.Numbers(2, 20e12), get_parser=float) - ######################### # Data self.add_parameter('dataformat', @@ -642,7 +637,6 @@ def __init__(self, name: str, address: str, vals=vals.Enum('ASC,0', 'REAL,32', 'INT,8', 'INT,16')) - ######################### # High definition mode (might not be available on all instruments) if HD: @@ -651,11 +645,14 @@ def __init__(self, name: str, address: str, set_cmd=self._set_hd_mode, get_cmd='HDEFinition:STAte?', val_mapping={'ON': 1, 'OFF': 0}, - docstring='Sets the filter bandwidth for the high definition mode.\n' \ - 'ON: high definition mode, up to 16 bit digital resolution\n' \ - 'Options: ON, OFF\n\n' \ - 'Warning/Bug: By opening the HD acquisition menu on the scope, ' \ - 'this value will be set to "ON"') + docstring='Sets the filter bandwidth for the' + ' high definition mode.\n' + 'ON: high definition mode, up to 16' + ' bit digital resolution\n' + 'Options: ON, OFF\n\n' + 'Warning/Bug: By opening the HD ' + 'acquisition menu on the scope, ' + 'this value will be set to "ON".') self.add_parameter('high_definition_bandwidth', label='High definition mode bandwidth', @@ -689,7 +686,9 @@ def __init__(self, name: str, address: str, self.add_function('reset', call_cmd='*RST') self.add_parameter('opc', get_cmd='*OPC?') self.add_parameter('stop_opc', get_cmd='STOP;*OPC?') - self.add_parameter('status_operation', get_cmd='STATus:OPERation:CONDition?', get_parser=int) + self.add_parameter('status_operation', + get_cmd='STATus:OPERation:CONDition?', + get_parser=int) self.add_function('run_continues', call_cmd='RUNContinous') # starts the shutdown of the system self.add_function('system_shutdown', call_cmd='SYSTem:EXIT') @@ -711,27 +710,26 @@ def run_single(self) -> None: self.run_mode.set('RUN Nx SINGLE') def is_triggered(self) -> bool: - waitTriggerMask = 0b01000; + waitTriggerMask = 0b01000 return bool(self.status_operation() & waitTriggerMask) == False def is_running(self) -> bool: - measuringMask = 0b10000; + measuringMask = 0b10000 return bool(self.status_operation() & measuringMask) def is_acquiring(self) -> bool: return self.is_triggered() & self.is_running() - ######################### # Specialised set/get functions - def _set_hd_mode(self, value): + def _set_hd_mode(self, value) -> None: """ Set/unset the high def mode """ self._make_traces_not_ready() self.write('HDEFinition:STAte {}'.format(value)) - def _set_timebase_range(self, value): + def _set_timebase_range(self, value) -> None: """ Set the full range of the timebase """ @@ -740,25 +738,25 @@ def _set_timebase_range(self, value): self.write('TIMebase:RANGe {}'.format(value)) - def _set_timebase_scale(self, value): + def _set_timebase_scale(self, value) -> None: """ - Set the length of one horizontal division + Set the length of one horizontal division. """ self._make_traces_not_ready() self.timebase_range.cache.set(value*self._horisontal_divs) self.write('TIMebase:SCALe {}'.format(value)) - def _set_timebase_position(self, value): + def _set_timebase_position(self, value) -> None: """ - Set the horizontal position + Set the horizontal position. """ self._make_traces_not_ready() self.write('TIMEbase:HORizontal:POSition {}'.format(value)) - def _make_traces_not_ready(self): + def _make_traces_not_ready(self) -> None: """ - Make the scope traces be not ready + Make the scope traces be not ready. """ self.ch1.trace._trace_ready = False self.ch2.trace._trace_ready = False @@ -768,11 +766,11 @@ def _make_traces_not_ready(self): def _set_trigger_level(self, value): """ Set the trigger level on the currently used trigger source - channel + channel. """ trans = {'CH1': 1, 'CH2': 2, 'CH3': 3, 'CH4': 4, 'EXT': 5} - # we use get and not get_latest because we don't trust users to - # not touch the front panel of an oscilloscope + # We use get and not get_latest because we don't trust users to + # not touch the front panel of an oscilloscope. source = trans[self.trigger_source.get()] if source != 5: v_range = self.submodules['ch{}'.format(source)].range() @@ -783,7 +781,7 @@ def _set_trigger_level(self, value): self.write('TRIGger1:LEVel{} {}'.format(source, value)) - def _get_trigger_level(self): + def _get_trigger_level(self) -> float: """ Get the trigger level from the currently used trigger source """ From a26d49c2a5c94095b8c2cdc5be366b091ccc5eed Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 23 Jan 2020 11:07:05 +0100 Subject: [PATCH 06/23] Improve ZNB I --- .../instrument_drivers/rohde_schwarz/ZNB.py | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index bba6e51d46e..630d345ce3f 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -77,14 +77,16 @@ def __init__(self, name, instrument, start, stop, npts, channel): label='{} magnitude'.format( instrument.short_name), setpoint_units=('Hz',), - setpoint_labels=('{} frequency'.format(instrument.short_name),), - setpoint_names=('{}_frequency'.format(instrument.short_name),)) + setpoint_labels=('{} frequency'.format( + instrument.short_name),), + setpoint_names=('{}_frequency'.format( + instrument.short_name),)) self.set_sweep(start, stop, npts) self._channel = channel def set_sweep(self, start, stop, npts): - # needed to update config of the software parameter on sweep change - # freq setpoints tuple as needs to be hashable for look up + # Needed to update config of the software parameter on sweep change + # freq setpoints tuple as needs to be hashable for look up. f = tuple(np.linspace(int(start), int(stop), num=npts)) self.setpoints = (f,) self.shape = (npts,) @@ -120,7 +122,7 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, """ n = channel self._instrument_channel = channel - # additional wait when adjusting instrument timeout to sweep time + # Additional wait when adjusting instrument timeout to sweep time. self._additional_wait = 1 if vna_parameter is None: @@ -133,21 +135,23 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, else: traces = self._parent.ask(f"CONFigure:TRACe:CATalog?") if existing_trace_to_bind_to not in traces: - raise RuntimeError(f"Trying to bind to {existing_trace_to_bind_to} " + raise RuntimeError(f"Trying to bind to" + f" {existing_trace_to_bind_to} " f"which is not in {traces}") self._tracename = existing_trace_to_bind_to # map hardware channel to measurement - # hardware channels are mapped one to one to qcodes channels + # hardware channels are mapped one to one to QCoDeS channels # we are not using sub traces within channels. if existing_trace_to_bind_to is None: - self.write("CALC{}:PAR:SDEF '{}', '{}'".format(self._instrument_channel, - self._tracename, - self._vna_parameter)) - - # source power is dependent on model, but not well documented. - # here we assume -60 dBm for ZNB20, the others are set, - # due to lack of knowledge, to -80 dBm as of before the edit + self.write("CALC{}:PAR:SDEF '{}', '{}'".format( + self._instrument_channel, + self._tracename, + self._vna_parameter)) + + # Source power is dependent on model, but not well documented. + # Here we assume -60 dBm for ZNB20, the others are set, + # due to lack of knowledge, to -80 dBm as of before the edit. full_modelname = self._parent.get_idn()['model'] if full_modelname is not None: model = full_modelname.split('-')[0] @@ -161,8 +165,9 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, self.add_parameter(name='vna_parameter', label='VNA parameter', - get_cmd="CALC{}:PAR:MEAS? '{}'".format(self._instrument_channel, - self._tracename), + get_cmd="CALC{}:PAR:MEAS? '{}'".format( + self._instrument_channel, + self._tracename), get_parser=self._strip) self.add_parameter(name='power', label='Power', @@ -195,22 +200,26 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, get_cmd='SENS{}:FREQ:START?'.format(n), set_cmd=self._set_start, get_parser=float, - vals=vals.Numbers(self._parent._min_freq, self._parent._max_freq - 10)) + vals=vals.Numbers(self._parent._min_freq, + self._parent._max_freq - 10)) self.add_parameter(name='stop', get_cmd='SENS{}:FREQ:STOP?'.format(n), set_cmd=self._set_stop, get_parser=float, - vals=vals.Numbers(self._parent._min_freq + 1, self._parent._max_freq)) + vals=vals.Numbers(self._parent._min_freq + 1, + self._parent._max_freq)) self.add_parameter(name='center', get_cmd='SENS{}:FREQ:CENT?'.format(n), set_cmd=self._set_center, get_parser=float, - vals=vals.Numbers(self._parent._min_freq + 0.5, self._parent._max_freq - 10)) + vals=vals.Numbers(self._parent._min_freq + 0.5, + self._parent._max_freq - 10)) self.add_parameter(name='span', get_cmd='SENS{}:FREQ:SPAN?'.format(n), set_cmd=self._set_span, get_parser=float, - vals=vals.Numbers(1, self._parent._max_freq - self._parent._min_freq)) + vals=vals.Numbers(1, self._parent._max_freq - + self._parent._min_freq)) self.add_parameter(name='npts', get_cmd='SENS{}:SWE:POIN?'.format(n), set_cmd=self._set_npts, @@ -220,7 +229,8 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, set_cmd='CONF:CHAN{}:MEAS {{}}'.format(n), get_parser=int) self.add_parameter(name='format', - get_cmd=partial(self._get_format, tracename=self._tracename), + get_cmd=partial(self._get_format, + tracename=self._tracename), set_cmd=self._set_format, val_mapping={'dB': 'MLOG\n', 'Linear Magnitude': 'MLIN\n', @@ -263,7 +273,8 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, call_cmd='SENS{}:CORR:EDEL:AUTO ONCE'.format(n)) self.add_function('autoscale', - call_cmd='DISPlay:TRACe1:Y:SCALe:AUTO ONCE, "{}"'.format(self._tracename)) + call_cmd='DISPlay:TRACe1:Y:SCALe:AUTO ONCE,' + ' "{}"'.format(self._tracename)) def _get_format(self, tracename): n = self._instrument_channel @@ -313,7 +324,8 @@ def _set_start(self, val): if val >= stop: raise ValueError( "Stop frequency must be larger than start frequency.") - # we get start as the vna may not be able to set it to the exact value provided + # we get start as the vna may not be able to set it to the + # exact value provided. start = self.start() if val != start: log.warning( @@ -327,7 +339,8 @@ def _set_stop(self, val): raise ValueError( "Stop frequency must be larger than start frequency.") self.write('SENS{}:FREQ:STOP {:.7f}'.format(channel, val)) - # we get stop as the vna may not be able to set it to the exact value provided + # We get stop as the vna may not be able to set it to the + # exact value provided. stop = self.stop() if val != stop: log.warning( @@ -365,8 +378,8 @@ def _get_sweep_data(self, force_polar=False): if not self._parent.rf_power(): log.warning("RF output is off when getting sweep data") - # it is possible that the instrument and qcodes disagree about - # which parameter is measured on this channel + # It is possible that the instrument and QCoDeS disagree about + # which parameter is measured on this channel. instrument_parameter = self.vna_parameter() if instrument_parameter != self._vna_parameter: raise RuntimeError("Invalid parameter. Tried to measure " @@ -409,7 +422,7 @@ def _get_sweep_data(self, force_polar=False): class ZNB(VisaInstrument): """ - qcodes driver for the Rohde & Schwarz ZNB8 and ZNB20 + QCoDeS driver for the Rohde & Schwarz ZNB8 and ZNB20 virtual network analyser. It can probably be extended to ZNB4 and 40 without too much work. @@ -447,7 +460,8 @@ def __init__(self, name: str, address: str, init_s_params: bool = True, else: raise RuntimeError("Could not determine ZNB model") # format seems to be ZNB8-4Port - mFrequency = {'ZNB4': (9e3, 4.5e9), 'ZNB8': (9e3, 8.5e9), 'ZNB20': (100e3, 20e9)} + mFrequency = {'ZNB4': (9e3, 4.5e9), 'ZNB8': (9e3, 8.5e9), + 'ZNB20': (100e3, 20e9)} if model not in mFrequency.keys(): raise RuntimeError("Unsupported ZNB model {}".format(model)) self._min_freq: float @@ -471,8 +485,9 @@ def __init__(self, name: str, address: str, init_s_params: bool = True, self.add_function('update_display_once', call_cmd='SYST:DISP:UPD ONCE') self.add_function('update_display_on', call_cmd='SYST:DISP:UPD ON') self.add_function('update_display_off', call_cmd='SYST:DISP:UPD OFF') - self.add_function('display_sij_split', call_cmd='DISP:LAY GRID;:DISP:LAY:GRID {},{}'.format( - num_ports, num_ports)) + self.add_function('display_sij_split', + call_cmd='DISP:LAY GRID;:DISP:LAY:GRID {},{}'.format( + num_ports, num_ports)) self.add_function('display_single_window', call_cmd='DISP:LAY GRID;:DISP:LAY:GRID 1,1') self.add_function('display_dual_window', @@ -501,7 +516,7 @@ def __init__(self, name: str, address: str, init_s_params: bool = True, def display_grid(self, rows: int, cols: int): """ - Display a grid of channels rows by cols + Display a grid of channels rows by columns. """ self.write('DISP:LAY GRID;:DISP:LAY:GRID {},{}'.format(rows, cols)) From 8635bee91449b4580ca90178d0a1ae02cda7d0d6 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 23 Jan 2020 11:51:09 +0100 Subject: [PATCH 07/23] Improve ZNB II --- .../instrument_drivers/rohde_schwarz/ZNB.py | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index 630d345ce3f..6b717e348fa 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -2,7 +2,7 @@ from functools import partial from typing import Optional -from qcodes import VisaInstrument +from qcodes import VisaInstrument, Instrument from qcodes import ChannelList, InstrumentChannel from qcodes.utils import validators as vals import numpy as np @@ -16,7 +16,8 @@ class FrequencySweepMagPhase(MultiParameter): Sweep that return magnitude and phase. """ - def __init__(self, name, instrument, start, stop, npts, channel): + def __init__(self, name: str, instrument: Instrument, + start: float, stop: float, npts: int, channel: int) -> None: super().__init__(name, names=("", ""), shapes=((), ())) self._instrument = instrument self.set_sweep(start, stop, npts) @@ -34,9 +35,9 @@ def __init__(self, name, instrument, start, stop, npts, channel): ('{}_frequency'.format(instrument.short_name),), ('{}_frequency'.format(instrument.short_name),)) - def set_sweep(self, start, stop, npts): - # needed to update config of the software parameter on sweep change - # freq setpoints tuple as needs to be hashable for look up + def set_sweep(self, start: float, stop: float, npts: int): + # Needed to update config of the software parameter on sweep change + # frequency setpoints tuple as needs to be hashable for look up. f = tuple(np.linspace(int(start), int(stop), num=npts)) self.setpoints = ((f,), (f,)) self.shapes = ((npts,), (npts,)) @@ -70,7 +71,8 @@ class FrequencySweep(ArrayParameter): """ - def __init__(self, name, instrument, start, stop, npts, channel): + def __init__(self, name: str, instrument: Instrument, + start: float, stop: float, npts: int, channel: int) -> None: super().__init__(name, shape=(npts,), instrument=instrument, unit='dB', @@ -84,7 +86,7 @@ def __init__(self, name, instrument, start, stop, npts, channel): self.set_sweep(start, stop, npts) self._channel = channel - def set_sweep(self, start, stop, npts): + def set_sweep(self, start: float, stop: float, npts: int): # Needed to update config of the software parameter on sweep change # freq setpoints tuple as needs to be hashable for look up. f = tuple(np.linspace(int(start), int(stop), num=npts)) @@ -276,12 +278,12 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, call_cmd='DISPlay:TRACe1:Y:SCALe:AUTO ONCE,' ' "{}"'.format(self._tracename)) - def _get_format(self, tracename): + def _get_format(self, tracename: str) -> str: n = self._instrument_channel self.write(f"CALC{n}:PAR:SEL '{tracename}'") return self.ask(f"CALC{n}:FORM?") - def _set_format(self, val): + def _set_format(self, val: str) -> None: unit_mapping = {'MLOG\n': 'dB', 'MLIN\n': '', 'PHAS\n': 'rad', @@ -313,11 +315,12 @@ def _set_format(self, val): self.trace.label = "{} {}".format( self.short_name, label_mapping[val]) - def _strip(self, var): - """Strip newline and quotes from instrument reply""" + @staticmethod + def _strip(var: str) -> str: + """Strip newline and quotes from instrument reply.""" return var.rstrip()[1:-1] - def _set_start(self, val): + def _set_start(self, val: float): channel = self._instrument_channel self.write('SENS{}:FREQ:START {:.7f}'.format(channel, val)) stop = self.stop() @@ -332,7 +335,7 @@ def _set_start(self, val): "Could not set start to {} setting it to {}".format(val, start)) self.update_traces() - def _set_stop(self, val): + def _set_stop(self, val: float): channel = self._instrument_channel start = self.start() if val <= start: @@ -347,17 +350,17 @@ def _set_stop(self, val): "Could not set stop to {} setting it to {}".format(val, stop)) self.update_traces() - def _set_npts(self, val): + def _set_npts(self, val: int): channel = self._instrument_channel self.write('SENS{}:SWE:POIN {:.7f}'.format(channel, val)) self.update_traces() - def _set_span(self, val): + def _set_span(self, val: float): channel = self._instrument_channel self.write('SENS{}:FREQ:SPAN {:.7f}'.format(channel, val)) self.update_traces() - def _set_center(self, val): + def _set_center(self, val: float): channel = self._instrument_channel self.write('SENS{}:FREQ:CENT {:.7f}'.format(channel, val)) self.update_traces() @@ -374,7 +377,7 @@ def update_traces(self): except AttributeError: pass - def _get_sweep_data(self, force_polar=False): + def _get_sweep_data(self, force_polar: bool = False): if not self._parent.rf_power(): log.warning("RF output is off when getting sweep data") From 3df9273b384353e1692caed695646c8834bcb7cb Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 30 Jan 2020 10:43:02 +0100 Subject: [PATCH 08/23] Remove spaces --- .../rohde_schwarz/RTO1000.py | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index 4811442e2b8..82aaf967f69 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -150,69 +150,69 @@ def __init__(self, parent: Instrument, name: str, meas_nr: int) -> None: self.meas_nr = meas_nr super().__init__(parent, name) - self.sources = vals.Enum('C1W1', 'C1W2', 'C1W3', - 'C2W1', 'C2W2', 'C2W3', - 'C3W1', 'C3W2', 'C3W3', - 'C4W1', 'C4W2', 'C4W3', - 'M1', 'M2', 'M3', 'M4', - 'R1', 'R2', 'R3', 'R4', - 'SBUS1', 'SBUS2', 'SBUS3', 'SBUS4', - 'D0', 'D1', 'D2', 'D3', - 'D4', 'D5', 'D6', 'D7', - 'D8', 'D9', 'D10', 'D11', - 'D12', 'D13', 'D14', 'D15', - 'TRK1', 'TRK2', 'TRK3', 'TRK4', - 'TRK5', 'TRK6', 'TRK7', 'TRK8', - 'SG1TL1', 'SG1TL2', - 'SG2TL1', 'SG2TL2', - 'SG3TL1', 'SG3TL2', - 'SG4TL1', 'SG4TL2', - 'Z1V1', 'Z1V2', 'Z1V3', 'Z1V4', - 'Z1I1', 'Z1I2', 'Z1I3', 'Z1I4', - 'Z2V1', 'Z2V2', 'Z2V3', 'Z2V4', - 'Z2I1', 'Z2I2', 'Z2I3', 'Z2I4') - - self.categories = vals.Enum('AMPTime', 'JITTer', 'EYEJitter', - 'SPECtrum', 'HISTogram', 'PROTocol') + self.sources = vals.Enum('C1W1', 'C1W2', 'C1W3', + 'C2W1', 'C2W2', 'C2W3', + 'C3W1', 'C3W2', 'C3W3', + 'C4W1', 'C4W2', 'C4W3', + 'M1', 'M2', 'M3', 'M4', + 'R1', 'R2', 'R3', 'R4', + 'SBUS1', 'SBUS2', 'SBUS3', 'SBUS4', + 'D0', 'D1', 'D2', 'D3', + 'D4', 'D5', 'D6', 'D7', + 'D8', 'D9', 'D10', 'D11', + 'D12', 'D13', 'D14', 'D15', + 'TRK1', 'TRK2', 'TRK3', 'TRK4', + 'TRK5', 'TRK6', 'TRK7', 'TRK8', + 'SG1TL1', 'SG1TL2', + 'SG2TL1', 'SG2TL2', + 'SG3TL1', 'SG3TL2', + 'SG4TL1', 'SG4TL2', + 'Z1V1', 'Z1V2', 'Z1V3', 'Z1V4', + 'Z1I1', 'Z1I2', 'Z1I3', 'Z1I4', + 'Z2V1', 'Z2V2', 'Z2V3', 'Z2V4', + 'Z2I1', 'Z2I2', 'Z2I3', 'Z2I4') + + self.categories = vals.Enum('AMPTime', 'JITTer', 'EYEJitter', + 'SPECtrum', 'HISTogram', 'PROTocol') self.meas_type = vals.Enum( # Amplitude/time measurements - 'HIGH', 'LOW', 'AMPLitude', - 'MAXimum', 'MINimum', 'PDELta', - 'MEAN', 'RMS', 'STDDev', - 'POVershoot', 'NOVershoot', 'AREA', - 'RTIMe', 'FTIMe', 'PPULse', - 'NPULse', 'PERiod', 'FREQuency', - 'PDCYcle', 'NDCYcle', 'CYCarea', - 'CYCMean', 'CYCRms', 'CYCStddev', - 'PULCnt', 'DELay', 'PHASe', - 'BWIDth', 'PSWitching', 'NSWitching', - 'PULSetrain', 'EDGecount', 'SHT', - 'SHR', 'DTOTrigger', 'PROBemeter', - 'SLERising', 'SLEFalling', + 'HIGH', 'LOW', 'AMPLitude', + 'MAXimum', 'MINimum', 'PDELta', + 'MEAN', 'RMS', 'STDDev', + 'POVershoot', 'NOVershoot', 'AREA', + 'RTIMe', 'FTIMe', 'PPULse', + 'NPULse', 'PERiod', 'FREQuency', + 'PDCYcle', 'NDCYcle', 'CYCarea', + 'CYCMean', 'CYCRms', 'CYCStddev', + 'PULCnt', 'DELay', 'PHASe', + 'BWIDth', 'PSWitching', 'NSWitching', + 'PULSetrain', 'EDGecount', 'SHT', + 'SHR', 'DTOTrigger', 'PROBemeter', + 'SLERising', 'SLEFalling', # Jitter measurements - 'CCJitter', 'NCJitter', 'CCWidth', - 'CCDutycycle', 'TIE', 'UINTerval', - 'DRATe', 'SKWDelay', 'SKWPhase', + 'CCJitter', 'NCJitter', 'CCWidth', + 'CCDutycycle', 'TIE', 'UINTerval', + 'DRATe', 'SKWDelay', 'SKWPhase', # Eye diagram measurements - 'ERPercent', 'ERDB', 'EHEight', - 'EWIDth', 'ETOP', 'EBASe', - 'QFACtor', 'RMSNoise', 'SNRatio', - 'DCDistortion', 'ERTime', 'EFTime', - 'EBRate', 'EAMPlitude', 'PPJitter', - 'STDJitter', 'RMSJitter', + 'ERPercent', 'ERDB', 'EHEight', + 'EWIDth', 'ETOP', 'EBASe', + 'QFACtor', 'RMSNoise', 'SNRatio', + 'DCDistortion', 'ERTime', 'EFTime', + 'EBRate', 'EAMPlitude', 'PPJitter', + 'STDJitter', 'RMSJitter', # Spectrum measurements - 'CPOWer', 'OBWidth', 'SBWidth', - 'THD', 'THDPCT', 'THDA', - 'THDU', 'THDR', 'HAR', + 'CPOWer', 'OBWidth', 'SBWidth', + 'THD', 'THDPCT', 'THDA', + 'THDU', 'THDR', 'HAR', 'PLISt', # Histogram measurements - 'WCOunt', 'WSAMples', 'HSAMples', - 'HPEak', 'PEAK', 'UPEakvalue', - 'LPEakvalue', 'HMAXimum', 'HMINimum', - 'MEDian', 'MAXMin', 'HMEan', - 'HSTDdev', 'M1STddev', 'M2STddev', - 'M3STddev', 'MKPositive', 'MKNegative' + 'WCOunt', 'WSAMples', 'HSAMples', + 'HPEak', 'PEAK', 'UPEakvalue', + 'LPEakvalue', 'HMAXimum', 'HMINimum', + 'MEDian', 'MAXMin', 'HMEan', + 'HSTDdev', 'M1STddev', 'M2STddev', + 'M3STddev', 'MKPositive', 'MKNegative' ) self.add_parameter('enable', From 75b8d6407e7cbdd99b4730fe5a5ec6dea70007f6 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 30 Jan 2020 10:45:49 +0100 Subject: [PATCH 09/23] Fix namin --- qcodes/instrument_drivers/rohde_schwarz/ZNB.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index 6b717e348fa..fbc5776d12c 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -463,13 +463,13 @@ def __init__(self, name: str, address: str, init_s_params: bool = True, else: raise RuntimeError("Could not determine ZNB model") # format seems to be ZNB8-4Port - mFrequency = {'ZNB4': (9e3, 4.5e9), 'ZNB8': (9e3, 8.5e9), - 'ZNB20': (100e3, 20e9)} - if model not in mFrequency.keys(): + m_frequency = {'ZNB4': (9e3, 4.5e9), 'ZNB8': (9e3, 8.5e9), + 'ZNB20': (100e3, 20e9)} + if model not in m_frequency.keys(): raise RuntimeError("Unsupported ZNB model {}".format(model)) self._min_freq: float self._max_freq: float - self._min_freq, self._max_freq = mFrequency[model] + self._min_freq, self._max_freq = m_frequency[model] self.add_parameter(name='num_ports', get_cmd='INST:PORT:COUN?', From a6c9c5732d3fa1675f4c757912bf4af160954666 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Thu, 30 Jan 2020 11:25:12 +0100 Subject: [PATCH 10/23] Fix naming of variables --- qcodes/instrument_drivers/rohde_schwarz/RTO1000.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index 82aaf967f69..353e78ea88d 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -710,12 +710,12 @@ def run_single(self) -> None: self.run_mode.set('RUN Nx SINGLE') def is_triggered(self) -> bool: - waitTriggerMask = 0b01000 - return bool(self.status_operation() & waitTriggerMask) == False + wait_trigger_mask = 0b01000 + return bool(self.status_operation() & wait_trigger_mask) == False def is_running(self) -> bool: - measuringMask = 0b10000 - return bool(self.status_operation() & measuringMask) + measuring_mask = 0b10000 + return bool(self.status_operation() & measuring_mask) def is_acquiring(self) -> bool: return self.is_triggered() & self.is_running() From 69496e7c867847408101f056db77e2b0abbf78a4 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 13:51:11 +0100 Subject: [PATCH 11/23] Change naming and f-strings in get_raw of RTO --- .../instrument_drivers/rohde_schwarz/RTO1000.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index 353e78ea88d..2d253df1ebb 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -89,17 +89,18 @@ def get_raw(self) -> int: 'prepare_trace().') if instr.run_mode() == 'RUN Nx SINGLE': - n = instr.num_acquisitions() - m = instr.completed_acquisitions() - log.info('Acquiring {} traces.'.format(n)) - while m < n: - log.info('Acquired {}:{} traces.'.format(m, n)) + total_acquisitions = instr.num_acquisitions() + completed_acquisitions = instr.completed_acquisitions() + log.info(f'Acquiring {total_acquisitions} traces.') + while completed_acquisitions < total_acquisitions: + log.info(f'Acquired {completed_acquisitions}:' + f'{total_acquisitions}') time.sleep(0.25) - m = instr.completed_acquisitions() + completed_acquisitions = instr.completed_acquisitions() log.info('Acquisition completed. Polling trace from instrument.') vh = instr.visa_handle - vh.write('CHANnel{}:DATA?'.format(self.channum)) + vh.write(f'CHANnel{self.channum}:DATA?') raw_vals = vh.read_raw() num_length = int(raw_vals[1:2]) From 87f456fa65bd91b2b3886b2e1726141791eb3276 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 14:01:07 +0100 Subject: [PATCH 12/23] Implement create_on_off_val_mapping in RTO --- qcodes/instrument_drivers/rohde_schwarz/RTO1000.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index 2d253df1ebb..2dba097a50a 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -13,6 +13,7 @@ from qcodes.instrument.channel import InstrumentChannel from qcodes.utils import validators as vals from qcodes.instrument.parameter import ArrayParameter +from qcodes.utils.helpers import create_on_off_val_mapping log = logging.getLogger(__name__) @@ -645,7 +646,8 @@ def __init__(self, name: str, address: str, label='High definition (16 bit) state', set_cmd=self._set_hd_mode, get_cmd='HDEFinition:STAte?', - val_mapping={'ON': 1, 'OFF': 0}, + val_mapping=create_on_off_val_mapping(on_val=1, + off_val=0), docstring='Sets the filter bandwidth for the' ' high definition mode.\n' 'ON: high definition mode, up to 16' From d0ccad0567a4cbaf75b74b68f10845848a8d2d51 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 14:05:38 +0100 Subject: [PATCH 13/23] Format write method in ZNB --- qcodes/instrument_drivers/rohde_schwarz/ZNB.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index fbc5776d12c..2ad7b4078ce 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -146,10 +146,8 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, # hardware channels are mapped one to one to QCoDeS channels # we are not using sub traces within channels. if existing_trace_to_bind_to is None: - self.write("CALC{}:PAR:SDEF '{}', '{}'".format( - self._instrument_channel, - self._tracename, - self._vna_parameter)) + self.write(f"CALC{self._instrument_channel}:PAR:SDEF" + f" '{self._tracename}', '{self._vna_parameter}'") # Source power is dependent on model, but not well documented. # Here we assume -60 dBm for ZNB20, the others are set, From 4044374ce6a246fe669aba809987ae8d505575f3 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 14:14:13 +0100 Subject: [PATCH 14/23] Fix format in vna_parameter --- qcodes/instrument_drivers/rohde_schwarz/ZNB.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index 2ad7b4078ce..8910fb95328 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -165,9 +165,8 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, self.add_parameter(name='vna_parameter', label='VNA parameter', - get_cmd="CALC{}:PAR:MEAS? '{}'".format( - self._instrument_channel, - self._tracename), + get_cmd=f"CALC{self._instrument_channel}:" + f"PAR:MEAS? '{self._tracename}'", get_parser=self._strip) self.add_parameter(name='power', label='Power', From 0e58643b6650f0f159997b0ddab7252efd89c7d6 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 14:33:18 +0100 Subject: [PATCH 15/23] Apply suggestions from code review Co-Authored-By: Mikhail Astafev --- qcodes/instrument_drivers/rohde_schwarz/ZNB.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index fbc5776d12c..bd26270760f 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -35,7 +35,7 @@ def __init__(self, name: str, instrument: Instrument, ('{}_frequency'.format(instrument.short_name),), ('{}_frequency'.format(instrument.short_name),)) - def set_sweep(self, start: float, stop: float, npts: int): + def set_sweep(self, start: float, stop: float, npts: int) -> None: # Needed to update config of the software parameter on sweep change # frequency setpoints tuple as needs to be hashable for look up. f = tuple(np.linspace(int(start), int(stop), num=npts)) @@ -86,7 +86,7 @@ def __init__(self, name: str, instrument: Instrument, self.set_sweep(start, stop, npts) self._channel = channel - def set_sweep(self, start: float, stop: float, npts: int): + def set_sweep(self, start: float, stop: float, npts: int) -> None: # Needed to update config of the software parameter on sweep change # freq setpoints tuple as needs to be hashable for look up. f = tuple(np.linspace(int(start), int(stop), num=npts)) From 87fa1fe0943acef2bda632231de02124a389b78b Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 14:50:32 +0100 Subject: [PATCH 16/23] f-string conversion I --- .../rohde_schwarz/RTO1000.py | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index 2dba097a50a..d3dcc54d9b3 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -54,7 +54,7 @@ def prepare_trace(self) -> None: # now get setpoints - hdr = self.channel._parent.ask('CHANnel{}:'.format(self.channum) + + hdr = self.channel._parent.ask(f'CHANnel{self.channum}:' 'DATA:HEADER?') hdr_vals = list(map(float, hdr.split(','))) t_start = hdr_vals[0] @@ -310,25 +310,25 @@ def __init__(self, parent: Instrument, name: str, channum: int) -> None: super().__init__(parent, name) self.add_parameter('state', - label='Channel {} state'.format(channum), - get_cmd='CHANnel{}:STATe?'.format(channum), - set_cmd='CHANnel{}:STATE {{}}'.format(channum), + label=f'Channel {channum} state', + get_cmd=f'CHANnel{channum}:STATe?', + set_cmd=f'CHANnel{channum}:STATE {{}}', vals=vals.Enum('ON', 'OFF'), docstring='Switches the channel on or off') self.add_parameter('coupling', - label='Channel {} coupling'.format(channum), - get_cmd='CHANnel{}:COUPling?'.format(channum), - set_cmd='CHANnel{}:COUPling {{}}'.format(channum), + label=f'Channel {channum} coupling', + get_cmd=f'CHANnel{channum}:COUPling?', + set_cmd=f'CHANnel{channum}:COUPling {{}}', vals=vals.Enum('DC', 'DCLimit', 'AC'), docstring=('Selects the connection of the channel' 'signal. DC: 50 Ohm, DCLimit 1 MOhm, ' 'AC: Con. through DC capacitor')) self.add_parameter('ground', - label='Channel {} ground'.format(channum), - get_cmd='CHANnel{}:GND?'.format(channum), - set_cmd='CHANnel{}:GND {{}}'.format(channum), + label=f'Channel {channum} ground', + get_cmd=f'CHANnel{channum}:GND?', + set_cmd=f'CHANnel{channum}:GND {{}}', vals=vals.Enum('ON', 'OFF'), docstring=('Connects/disconnects the signal to/from' 'the ground.')) @@ -336,17 +336,17 @@ def __init__(self, parent: Instrument, name: str, channum: int) -> None: # NB (WilliamHPNielsen): This parameter depends on other parameters and # should be dynamically updated accordingly. Cf. p 1178 of the manual self.add_parameter('scale', - label='Channel {} Y scale'.format(channum), + label=f'Channel {channum} Y scale', unit='V/div', - get_cmd='CHANnel{}:SCALe?'.format(channum), + get_cmd=f'CHANnel{channum}:SCALe?', set_cmd=self._set_scale, get_parser=float, ) self.add_parameter('range', - label='Channel {} Y range'.format(channum), + label=f'Channel {channum} Y range', unit='V', - get_cmd='CHANnel{}:RANGe?'.format(channum), + get_cmd=f'CHANnel{channum}:RANGe?', set_cmd=self._set_range, get_parser=float ) @@ -354,43 +354,43 @@ def __init__(self, parent: Instrument, name: str, channum: int) -> None: # TODO (WilliamHPNielsen): would it be better to recast this in terms # of Volts? self.add_parameter('position', - label='Channel {} vert. pos.'.format(channum), + label=f'Channel {channum} vert. pos.', unit='div', - get_cmd='CHANnel{}:POSition?'.format(channum), - set_cmd='CHANnel{}:POSition {{}}'.format(channum), + get_cmd=f'CHANnel{channum}:POSition?', + set_cmd=f'CHANnel{channum}:POSition {{}}', get_parser=float, vals=vals.Numbers(-5, 5), docstring=('Positive values move the waveform up,' ' negative values move it down.')) self.add_parameter('offset', - label='Channel {} offset'.format(channum), + label=f'Channel {channum} offset', unit='V', - get_cmd='CHANnel{}:OFFSet?'.format(channum), - set_cmd='CHANnel{}:OFFSet {{}}'.format(channum), + get_cmd=f'CHANnel{channum}:OFFSet?', + set_cmd=f'CHANnel{channum}:OFFSet {{}}', get_parser=float, ) self.add_parameter('invert', - label='Channel {} inverted'.format(channum), - get_cmd='CHANnel{}:INVert?'.format(channum), - set_cmd='CHANnel{}:INVert {{}}'.format(channum), + label=f'Channel {channum} inverted', + get_cmd=f'CHANnel{channum}:INVert?', + set_cmd=f'CHANnel{channum}:INVert {{}}', vals=vals.Enum('ON', 'OFF')) # TODO (WilliamHPNielsen): This parameter should be dynamically # validated since 800 MHz BW is only available for 50 Ohm coupling self.add_parameter('bandwidth', - label='Channel {} bandwidth'.format(channum), - get_cmd='CHANnel{}:BANDwidth?'.format(channum), - set_cmd='CHANnel{}:BANDwidth {{}}'.format(channum), + label=f'Channel {channum} bandwidth', + get_cmd=f'CHANnel{channum}:BANDwidth?', + set_cmd=f'CHANnel{channum}:BANDwidth {{}}', vals=vals.Enum('FULL', 'B800', 'B200', 'B20') ) self.add_parameter('impedance', - label='Channel {} impedance'.format(channum), + label=f'Channel {channum} impedance', unit='Ohm', - get_cmd='CHANnel{}:IMPedance?'.format(channum), - set_cmd='CHANnel{}:IMPedance {{}}'.format(channum), + get_cmd=f'CHANnel{channum}:IMPedance?', + set_cmd=f'CHANnel{channum}:IMPedance {{}}', vals=vals.Ints(1, 100000), docstring=('Sets the impedance of the channel ' 'for power calculations and ' From 6bf094a7adbc4852bd146829cc917d33c7dd9e21 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 14:57:26 +0100 Subject: [PATCH 17/23] f-string conversion II --- .../rohde_schwarz/RTO1000.py | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index d3dcc54d9b3..e1b8fed151b 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -397,14 +397,13 @@ def __init__(self, parent: Instrument, name: str, channum: int) -> None: 'measurements.')) self.add_parameter('overload', - label='Channel {} overload'.format(channum), - get_cmd='CHANnel{}:OVERload?'.format(channum) - ) + label=f'Channel {channum} overload', + get_cmd=f'CHANnel{channum}:OVERload?') self.add_parameter('arithmetics', - label='Channel {} arithmetics'.format(channum), - set_cmd='CHANnel{}:ARIThmetics {{}}'.format(channum), - get_cmd='CHANnel{}:ARIThmetics?'.format(channum), + label=f'Channel {channum} arithmetics', + set_cmd=f'CHANnel{channum}:ARIThmetics {{}}', + get_cmd=f'CHANnel{channum}:ARIThmetics?', val_mapping={'AVERAGE': 'AVER', 'OFF': 'OFF', 'ENVELOPE': 'ENV'} @@ -420,14 +419,12 @@ def __init__(self, parent: Instrument, name: str, channum: int) -> None: def _set_range(self, value: float) -> None: self.scale.cache.set(value/10) - self._parent.write('CHANnel{}:RANGe {}'.format(self.channum, - value)) + self._parent.write(f'CHANnel{self.channum}:RANGe {value}') def _set_scale(self, value: float) -> None: self.range.cache.set(value*10) - self._parent.write('CHANnel{}:SCALe {}'.format(self.channum, - value)) + self._parent.write(f'CHANnel{self.channum}:SCALe {value}') class RTO1000(VisaInstrument): @@ -474,7 +471,7 @@ def __init__(self, name: str, address: str, warnings.warn("The model number provided by the user " "does not match the instrument's response." " I am going to assume that this oscilloscope " - "is a model {}".format(self.model)) + f"is a model {self.model}") else: if model is None: raise ValueError('No model number provided. Please provide ' @@ -730,7 +727,7 @@ def _set_hd_mode(self, value) -> None: Set/unset the high def mode """ self._make_traces_not_ready() - self.write('HDEFinition:STAte {}'.format(value)) + self.write(f'HDEFinition:STAte {value}') def _set_timebase_range(self, value) -> None: """ @@ -739,7 +736,7 @@ def _set_timebase_range(self, value) -> None: self._make_traces_not_ready() self.timebase_scale.cache.set(value/self._horisontal_divs) - self.write('TIMebase:RANGe {}'.format(value)) + self.write(f'TIMebase:RANGe {value}') def _set_timebase_scale(self, value) -> None: """ @@ -748,14 +745,14 @@ def _set_timebase_scale(self, value) -> None: self._make_traces_not_ready() self.timebase_range.cache.set(value*self._horisontal_divs) - self.write('TIMebase:SCALe {}'.format(value)) + self.write(f'TIMebase:SCALe {value}') def _set_timebase_position(self, value) -> None: """ Set the horizontal position. """ self._make_traces_not_ready() - self.write('TIMEbase:HORizontal:POSition {}'.format(value)) + self.write(f'TIMEbase:HORizontal:POSition {value}') def _make_traces_not_ready(self) -> None: """ @@ -776,13 +773,13 @@ def _set_trigger_level(self, value): # not touch the front panel of an oscilloscope. source = trans[self.trigger_source.get()] if source != 5: - v_range = self.submodules['ch{}'.format(source)].range() - offset = self.submodules['ch{}'.format(source)].offset() + v_range = self.submodules[f'ch{source}'].range() + offset = self.submodules[f'ch{source}'].offset() if (value < -v_range/2 + offset) or (value > v_range/2 + offset): raise ValueError('Trigger level outside channel range.') - self.write('TRIGger1:LEVel{} {}'.format(source, value)) + self.write(f'TRIGger1:LEVel{source} {value}') def _get_trigger_level(self) -> float: """ @@ -793,6 +790,6 @@ def _get_trigger_level(self) -> float: # not touch the front panel of an oscilloscope source = trans[self.trigger_source.get()] - val = self.ask('TRIGger1:LEVel{}?'.format(source)) + val = self.ask(f'TRIGger1:LEVel{source}?') return float(val.strip()) From 62a997ee096146c104d2fbe260d0d6cd6412f217 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 15:09:19 +0100 Subject: [PATCH 18/23] f-string conversion III --- .../rohde_schwarz/private/HMC804x.py | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py b/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py index 0762dff2fd3..056e627a80c 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py +++ b/qcodes/instrument_drivers/rohde_schwarz/private/HMC804x.py @@ -9,59 +9,48 @@ def __init__(self, parent: Instrument, name: str, channel: Union[str, int]) -> None: super().__init__(parent, name) - select_cmd = ":INSTrument:NSELect {};".format(channel) + select_cmd = f":INSTrument:NSELect {channel};" + voltage_amp = ":SOURce:VOLTage:LEVel:IMMediate:AMPLitude" + current_amp = ":SOURce:CURRent:LEVel:IMMediate:AMPLitude" self.add_parameter("set_voltage", label='Target voltage output', - set_cmd="{} " - ":SOURce:VOLTage:LEVel:IMMediate:AMPLitude " - "{}".format(select_cmd, '{}'), - get_cmd="{} " - ":SOURce:VOLTage:LEVel:IMMediate:AMPLitude?". - format(select_cmd), + set_cmd=f"{select_cmd} {voltage_amp} {{}}", + get_cmd=f"{select_cmd} {voltage_amp}?", get_parser=float, unit='V', vals=vals.Numbers(0, 32.050) ) self.add_parameter("set_current", label='Target current output', - set_cmd="{} " - ":SOURce:CURRent:LEVel:IMMediate:AMPLitude " - "{}".format(select_cmd, '{}'), - get_cmd="{} " - ":SOURce:CURRent:LEVel:IMMediate:AMPLitude?". - format(select_cmd), + set_cmd=f"{select_cmd} {current_amp} {{}}", + get_cmd=f"{select_cmd} {current_amp}?", get_parser=float, unit='A', vals=vals.Numbers(0.5e-3, self._parent.max_current) ) self.add_parameter('state', label='Output enabled', - set_cmd='{} :OUTPut:CHANnel:STATe {}'. - format(select_cmd, '{}'), - get_cmd='{} :OUTPut:CHANnel:STATe?'. - format(select_cmd), + set_cmd=f'{select_cmd} :OUTPut:CHANnel:STATe {{}}', + get_cmd=f'{select_cmd} :OUTPut:CHANnel:STATe?', val_mapping={'ON': 1, 'OFF': 0}, vals=vals.Enum('ON', 'OFF') ) self.add_parameter("voltage", label='Measured voltage', - get_cmd="{} :MEASure:SCALar:VOLTage:DC?".format( - select_cmd), + get_cmd=f"{select_cmd} :MEASure:SCALar:VOLTage:DC?", get_parser=float, unit='V', ) self.add_parameter("current", label='Measured current', - get_cmd="{} :MEASure:SCALar:CURRent:DC?".format( - select_cmd), + get_cmd=f"{select_cmd} :MEASure:SCALar:CURRent:DC?", get_parser=float, unit='A', ) self.add_parameter("power", label='Measured power', - get_cmd="{} :MEASure:SCALar:POWer?".format( - select_cmd), + get_cmd=f"{select_cmd} :MEASure:SCALar:POWer?", get_parser=float, unit='W', ) @@ -97,7 +86,7 @@ def __init__(self, name: str, address: str, channels = ChannelList(self, "SupplyChannel", RohdeSchwarzHMC804xChannel, snapshotable=False) for ch_num in range(1, num_channels+1): - ch_name = "ch{}".format(ch_num) + ch_name = f"ch{ch_num}" channel = RohdeSchwarzHMC804xChannel(self, ch_name, ch_num) channels.append(channel) self.add_submodule(ch_name, channel) From c17be9de3d2e84042bbf2919284b52ab55605b32 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 15:15:29 +0100 Subject: [PATCH 19/23] f-string conversion IV --- .../instrument_drivers/rohde_schwarz/ZNB.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index c7c15fe79cb..9b34532c361 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -24,16 +24,18 @@ def __init__(self, name: str, instrument: Instrument, self._channel = channel self.names = ('magnitude', 'phase') - self.labels = ('{} magnitude'.format(instrument.short_name), - '{} phase'.format(instrument.short_name)) + self.labels = (f'{instrument.short_name} magnitude', + f'{instrument.short_name} phase') self.units = ('', 'rad') self.setpoint_units = (('Hz',), ('Hz',)) self.setpoint_labels = ( - ('{} frequency'.format(instrument.short_name),), - ('{} frequency'.format(instrument.short_name),)) + (f'{instrument.short_name} frequency',), + (f'{instrument.short_name} frequency',) + ) self.setpoint_names = ( - ('{}_frequency'.format(instrument.short_name),), - ('{}_frequency'.format(instrument.short_name),)) + (f'{instrument.short_name}_frequency',), + (f'{instrument.short_name}_frequency',) + ) def set_sweep(self, start: float, stop: float, npts: int) -> None: # Needed to update config of the software parameter on sweep change @@ -76,13 +78,11 @@ def __init__(self, name: str, instrument: Instrument, super().__init__(name, shape=(npts,), instrument=instrument, unit='dB', - label='{} magnitude'.format( - instrument.short_name), + label=f'{instrument.short_name} magnitude', setpoint_units=('Hz',), - setpoint_labels=('{} frequency'.format( - instrument.short_name),), - setpoint_names=('{}_frequency'.format( - instrument.short_name),)) + setpoint_labels=(f'{instrument.short_name}' + ' frequency',), + setpoint_names=(f'{instrument.short_name}_frequency',)) self.set_sweep(start, stop, npts) self._channel = channel From b3fe73258b05fc8012d468b92e631d22ce2a4e90 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 15:19:18 +0100 Subject: [PATCH 20/23] f-string conversion V --- .../instrument_drivers/rohde_schwarz/ZNB.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index 9b34532c361..be035949ae0 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -133,7 +133,7 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, super().__init__(parent, name) if existing_trace_to_bind_to is None: - self._tracename = "Trc{}".format(channel) + self._tracename = f"Trc{channel}" else: traces = self._parent.ask(f"CONFigure:TRACe:CATalog?") if existing_trace_to_bind_to not in traces: @@ -159,7 +159,7 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, raise RuntimeError("Could not determine ZNB model") mSourcePower = {'ZNB4': -80, 'ZNB8': -80, 'ZNB20': -60} if model not in mSourcePower.keys(): - raise RuntimeError("Unsupported ZNB model: {}".format(model)) + raise RuntimeError(f"Unsupported ZNB model: {model}") self._min_source_power: float self._min_source_power = mSourcePower[model] @@ -171,8 +171,8 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, self.add_parameter(name='power', label='Power', unit='dBm', - get_cmd='SOUR{}:POW?'.format(n), - set_cmd='SOUR{}:POW {{:.4f}}'.format(n), + get_cmd=f'SOUR{n}:POW?', + set_cmd=f'SOUR{n}:POW {{:.4f}}', get_parser=float, vals=vals.Numbers(self._min_source_power, 25)) # there is an 'increased bandwidth option' (p. 4 of manual) that does @@ -180,8 +180,8 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, self.add_parameter(name='bandwidth', label='Bandwidth', unit='Hz', - get_cmd='SENS{}:BAND?'.format(n), - set_cmd='SENS{}:BAND {{:.4f}}'.format(n), + get_cmd=f'SENS{n}:BAND?', + set_cmd=f'SENS{n}:BAND {{:.4f}}', get_parser=int, vals=vals.Enum( *np.append(10 ** 6, @@ -191,41 +191,41 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, self.add_parameter(name='avg', label='Averages', unit='', - get_cmd='SENS{}:AVER:COUN?'.format(n), - set_cmd='SENS{}:AVER:COUN {{:.4f}}'.format(n), + get_cmd=f'SENS{n}:AVER:COUN?', + set_cmd=f'SENS{n}:AVER:COUN {{:.4f}}', get_parser=int, vals=vals.Ints(1, 5000)) self.add_parameter(name='start', - get_cmd='SENS{}:FREQ:START?'.format(n), + get_cmd=f'SENS{n}:FREQ:START?', set_cmd=self._set_start, get_parser=float, vals=vals.Numbers(self._parent._min_freq, self._parent._max_freq - 10)) self.add_parameter(name='stop', - get_cmd='SENS{}:FREQ:STOP?'.format(n), + get_cmd=f'SENS{n}:FREQ:STOP?', set_cmd=self._set_stop, get_parser=float, vals=vals.Numbers(self._parent._min_freq + 1, self._parent._max_freq)) self.add_parameter(name='center', - get_cmd='SENS{}:FREQ:CENT?'.format(n), + get_cmd=f'SENS{n}:FREQ:CENT?', set_cmd=self._set_center, get_parser=float, vals=vals.Numbers(self._parent._min_freq + 0.5, self._parent._max_freq - 10)) self.add_parameter(name='span', - get_cmd='SENS{}:FREQ:SPAN?'.format(n), + get_cmd=f'SENS{n}:FREQ:SPAN?', set_cmd=self._set_span, get_parser=float, vals=vals.Numbers(1, self._parent._max_freq - self._parent._min_freq)) self.add_parameter(name='npts', - get_cmd='SENS{}:SWE:POIN?'.format(n), + get_cmd=f'SENS{n}:SWE:POIN?', set_cmd=self._set_npts, get_parser=int) self.add_parameter(name='status', - get_cmd='CONF:CHAN{}:MEAS?'.format(n), - set_cmd='CONF:CHAN{}:MEAS {{}}'.format(n), + get_cmd=f'CONF:CHAN{n}:MEAS?', + set_cmd=f'CONF:CHAN{n}:MEAS {{}}', get_parser=int) self.add_parameter(name='format', get_cmd=partial(self._get_format, From baeed3bd420cc792302c36a30809b42f8ba93eb7 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Fri, 31 Jan 2020 15:30:09 +0100 Subject: [PATCH 21/23] f-string conversion VI --- .../instrument_drivers/rohde_schwarz/ZNB.py | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py index be035949ae0..5e4a563e378 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/ZNB.py +++ b/qcodes/instrument_drivers/rohde_schwarz/ZNB.py @@ -259,21 +259,21 @@ def __init__(self, parent: 'ZNB', name: str, channel: int, parameter_class=FrequencySweep) self.add_parameter(name='electrical_delay', label='Electrical delay', - get_cmd='SENS{}:CORR:EDEL2:TIME?'.format(n), - set_cmd='SENS{}:CORR:EDEL2:TIME {{}}'.format(n), + get_cmd=f'SENS{n}:CORR:EDEL2:TIME?', + set_cmd=f'SENS{n}:CORR:EDEL2:TIME {{}}', get_parser=float, unit='s') self.add_parameter(name='sweep_time', label='Sweep time', - get_cmd='SENS{}:SWE:TIME?'.format(n), + get_cmd=f'SENS{n}:SWE:TIME?', get_parser=float, unit='s') self.add_function('set_electrical_delay_auto', - call_cmd='SENS{}:CORR:EDEL:AUTO ONCE'.format(n)) + call_cmd=f'SENS{n}:CORR:EDEL:AUTO ONCE') self.add_function('autoscale', - call_cmd='DISPlay:TRACe1:Y:SCALe:AUTO ONCE,' - ' "{}"'.format(self._tracename)) + call_cmd='DISPlay:TRACe1:Y:SCALe:AUTO ONCE, ' + f"{self._tracename}") def _get_format(self, tracename: str) -> str: n = self._instrument_channel @@ -309,8 +309,7 @@ def _set_format(self, val: str) -> None: self.write(f"CALC{channel}:PAR:SEL '{self._tracename}'") self.write(f"CALC{channel}:FORM {val}") self.trace.unit = unit_mapping[val] - self.trace.label = "{} {}".format( - self.short_name, label_mapping[val]) + self.trace.label = f"{self.short_name} {label_mapping[val]}" @staticmethod def _strip(var: str) -> str: @@ -319,7 +318,7 @@ def _strip(var: str) -> str: def _set_start(self, val: float): channel = self._instrument_channel - self.write('SENS{}:FREQ:START {:.7f}'.format(channel, val)) + self.write(f'SENS{channel}:FREQ:START {val:.7f}') stop = self.stop() if val >= stop: raise ValueError( @@ -329,7 +328,7 @@ def _set_start(self, val: float): start = self.start() if val != start: log.warning( - "Could not set start to {} setting it to {}".format(val, start)) + f"Could not set start to {val} setting it to {start}") self.update_traces() def _set_stop(self, val: float): @@ -338,28 +337,28 @@ def _set_stop(self, val: float): if val <= start: raise ValueError( "Stop frequency must be larger than start frequency.") - self.write('SENS{}:FREQ:STOP {:.7f}'.format(channel, val)) + self.write(f'SENS{channel}:FREQ:STOP {val:.7f}') # We get stop as the vna may not be able to set it to the # exact value provided. stop = self.stop() if val != stop: log.warning( - "Could not set stop to {} setting it to {}".format(val, stop)) + f"Could not set stop to {val} setting it to {stop}") self.update_traces() def _set_npts(self, val: int): channel = self._instrument_channel - self.write('SENS{}:SWE:POIN {:.7f}'.format(channel, val)) + self.write(f'SENS{channel}:SWE:POIN {val:.7f}') self.update_traces() def _set_span(self, val: float): channel = self._instrument_channel - self.write('SENS{}:FREQ:SPAN {:.7f}'.format(channel, val)) + self.write(f'SENS{channel}:FREQ:SPAN {val:.7f}') self.update_traces() def _set_center(self, val: float): channel = self._instrument_channel - self.write('SENS{}:FREQ:CENT {:.7f}'.format(channel, val)) + self.write(f'SENS{channel}:FREQ:CENT {val:.7f}') self.update_traces() def update_traces(self): @@ -383,10 +382,10 @@ def _get_sweep_data(self, force_polar: bool = False): instrument_parameter = self.vna_parameter() if instrument_parameter != self._vna_parameter: raise RuntimeError("Invalid parameter. Tried to measure " - "{} got {}".format(self._vna_parameter, - instrument_parameter)) - self.write('SENS{}:AVER:STAT ON'.format(self._instrument_channel)) - self.write('SENS{}:AVER:CLE'.format(self._instrument_channel)) + f"{self._vna_parameter} " + f"got {instrument_parameter}") + self.write(f'SENS{self._instrument_channel}:AVER:STAT ON') + self.write(f'SENS{self._instrument_channel}:AVER:CLE') # preserve original state of the znb with self.status.set_to(1): @@ -404,13 +403,12 @@ def _get_sweep_data(self, force_polar: bool = False): # instrument averages over its last 'avg' number of sweeps # need to ensure averaged result is returned for avgcount in range(self.avg()): - self.write('INIT{}:IMM; *WAI' - .format(self._instrument_channel)) + self.write(f'INIT{self._instrument_channel}:IMM; *WAI') self.write(f"CALC{self._instrument_channel}:PAR:SEL " f"'{self._tracename}'") data_str = self.ask( - 'CALC{}:DATA? {}'.format(self._instrument_channel, - data_format_command)) + f'CALC{self._instrument_channel}:DATA?' + f' {data_format_command}') data = np.array(data_str.rstrip().split(',')).astype('float64') if self.format() in ['Polar', 'Complex', 'Smith', 'Inverse Smith']: @@ -463,7 +461,7 @@ def __init__(self, name: str, address: str, init_s_params: bool = True, m_frequency = {'ZNB4': (9e3, 4.5e9), 'ZNB8': (9e3, 8.5e9), 'ZNB20': (100e3, 20e9)} if model not in m_frequency.keys(): - raise RuntimeError("Unsupported ZNB model {}".format(model)) + raise RuntimeError(f"Unsupported ZNB model {model}") self._min_freq: float self._max_freq: float self._min_freq, self._max_freq = m_frequency[model] @@ -486,8 +484,8 @@ def __init__(self, name: str, address: str, init_s_params: bool = True, self.add_function('update_display_on', call_cmd='SYST:DISP:UPD ON') self.add_function('update_display_off', call_cmd='SYST:DISP:UPD OFF') self.add_function('display_sij_split', - call_cmd='DISP:LAY GRID;:DISP:LAY:GRID {},{}'.format( - num_ports, num_ports)) + call_cmd=f'DISP:LAY GRID;:DISP:LAY:GRID' + f' {num_ports},{num_ports}') self.add_function('display_single_window', call_cmd='DISP:LAY GRID;:DISP:LAY:GRID 1,1') self.add_function('display_dual_window', @@ -518,7 +516,7 @@ def display_grid(self, rows: int, cols: int): """ Display a grid of channels rows by columns. """ - self.write('DISP:LAY GRID;:DISP:LAY:GRID {},{}'.format(rows, cols)) + self.write(f'DISP:LAY GRID;:DISP:LAY:GRID {rows},{cols}') def add_channel(self, channel_name: str, **kwargs): i_channel = len(self.channels) + 1 @@ -531,10 +529,10 @@ def add_channel(self, channel_name: str, **kwargs): # shortcut setattr(self, channel_name, channel) # initialising channel - self.write('SENS{}:SWE:TYPE LIN'.format(i_channel)) - self.write('SENS{}:SWE:TIME:AUTO ON'.format(i_channel)) - self.write('TRIG{}:SEQ:SOUR IMM'.format(i_channel)) - self.write('SENS{}:AVER:STAT ON'.format(i_channel)) + self.write(f'SENS{i_channel}:SWE:TYPE LIN') + self.write(f'SENS{i_channel}:SWE:TIME:AUTO ON') + self.write(f'TRIG{i_channel}:SEQ:SOUR IMM') + self.write(f'SENS{i_channel}:AVER:STAT ON') def clear_channels(self): """ From 3a38d3387c6a0c69ca246db4727d9d8c07041eb3 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Tue, 18 Feb 2020 12:55:31 +0100 Subject: [PATCH 22/23] Update qcodes/instrument_drivers/rohde_schwarz/RTO1000.py Co-Authored-By: Mikhail Astafev --- qcodes/instrument_drivers/rohde_schwarz/RTO1000.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index e1b8fed151b..a9e452f3f96 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -78,7 +78,7 @@ def prepare_trace(self) -> None: # we must ensure that all this took effect before proceeding self.channel._parent.ask('*OPC?') - def get_raw(self) -> int: + def get_raw(self) -> numpy.ndarray: """ Returns a trace """ From a16453b5a715326d1b9c48587d06f125fb1be659 Mon Sep 17 00:00:00 2001 From: AUC Hardal Date: Tue, 18 Feb 2020 13:12:43 +0100 Subject: [PATCH 23/23] Change numpy to np --- qcodes/instrument_drivers/rohde_schwarz/RTO1000.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py index a9e452f3f96..376ef9b4b37 100644 --- a/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py +++ b/qcodes/instrument_drivers/rohde_schwarz/RTO1000.py @@ -78,7 +78,7 @@ def prepare_trace(self) -> None: # we must ensure that all this took effect before proceeding self.channel._parent.ask('*OPC?') - def get_raw(self) -> numpy.ndarray: + def get_raw(self) -> np.ndarray: """ Returns a trace """