Source code for qcodes.parameters.specialized_parameters
"""Module for specialized parameters. The :mod:`qcodes.instrument.parameter`module provides generic parameters for different generic cases. This moduleprovides useful/convenient specializations of such generic parameters."""from__future__importannotationsfromtimeimportperf_counterfromtypingimportTYPE_CHECKING,Any,Literalfromqcodes.validatorsimportStrings,Validatorfrom.parameterimportParameterifTYPE_CHECKING:fromcollections.abcimportCallablefromqcodes.instrumentimportInstrumentBase
[docs]classElapsedTimeParameter(Parameter):""" Parameter to measure elapsed time. Measures wall clock time since the last reset of the instance's clock. The clock is reset upon creation of the instance. The constructor passes kwargs along to the Parameter constructor. Args: name: The local name of the parameter. See the documentation of :class:`qcodes.parameters.Parameter` for more details. """def__init__(self,name:str,label:str="Elapsed time",**kwargs:Any):hardcoded_kwargs=["unit","get_cmd","set_cmd"]forhckinhardcoded_kwargs:ifhckinkwargs:raiseValueError(f'Can not set "{hck}" for an ElapsedTimeParameter.')super().__init__(name=name,label=label,unit="s",set_cmd=False,**kwargs)self._t0:float=perf_counter()
[docs]classInstrumentRefParameter(Parameter):""" An instrument reference parameter. This parameter is useful when one needs a reference to another instrument from within an instrument, e.g., when creating a meta instrument that sets parameters on instruments it contains. Args: name: The name of the parameter that one wants to add. instrument: The "parent" instrument this parameter is attached to, if any. initial_value: Starting value, may be None even if None does not pass the validator. None is only allowed as an initial value and cannot be set after initiation. **kwargs: Passed to InstrumentRefParameter parent class """def__init__(self,name:str,instrument:InstrumentBase|None=None,label:str|None=None,unit:str|None=None,get_cmd:str|Callable[...,Any]|Literal[False]|None=None,set_cmd:str|Callable[...,Any]|Literal[False]|None=None,initial_value:float|str|None=None,max_val_age:float|None=None,vals:Validator[Any]|None=None,docstring:str|None=None,**kwargs:Any,)->None:ifvalsisNone:vals=Strings()ifset_cmdisnotNone:raiseRuntimeError("InstrumentRefParameter does not support set_cmd.")super().__init__(name,instrument=instrument,label=label,unit=unit,get_cmd=get_cmd,set_cmd=set_cmd,initial_value=initial_value,max_val_age=max_val_age,vals=vals,docstring=docstring,**kwargs,)# TODO(nulinspiratie) check class works now it's subclassed from Parameter
[docs]defget_instr(self)->InstrumentBase:""" Returns the instance of the instrument with the name equal to the value of this parameter. """ref_instrument_name=self.get()# note that _instrument refers to the instrument this parameter belongs# to, while the ref_instrument_name is the instrument that is the value# of this parameter.ifself._instrumentisNone:raiseRuntimeError("InstrumentRefParameter is not bound to an instrument.")returnself._instrument.find_instrument(ref_instrument_name)