qcodes.instrument.group_parameter

This module implements a Group intended to hold multiple parameters that are to be gotten and set by the same command. The parameters should be of type GroupParameter

class qcodes.instrument.group_parameter.Group(parameters: Sequence[qcodes.instrument.group_parameter.GroupParameter], set_cmd: Optional[str] = None, get_cmd: Optional[str] = None, get_parser: Optional[Callable[[str], Mapping[str, Any]]] = None, separator: str = ',', single_instrument: bool = True)[source]

Bases: object

The group combines GroupParameter s that are to be gotten or set via the same command. The command has to be a string, for example, a VISA command.

The Group’s methods are used within GroupParameter in order to properly implement setting and getting of a single parameter in the situation where one command sets or gets more than one parameter.

The command used for setting values of parameters has to be a format string which contains the names of the parameters the group has been initialized with. For example, if a command has syntax CMD a_value, b_value, where a_value and b_value are values of two parameters with names a and b, then the command string has to be CMD {a}, {b}, and the group has to be initialized with two GroupParameter s a_param and b_param, where a_param.name=="a" and b_param.name=="b".

Note that by default, it is assumed that the command used for getting values returns a comma-separated list of values of parameters, and their order corresponds to the order of GroupParameter s in the list that is passed to the Group’s constructor. Through keyword arguments of the Group’s constructor, it is possible to change the separator, and even the parser of the output of the get command.

The get and set commands are called via the instrument that the first parameter belongs to. It is assumed that all the parameters within the group belong to the same instrument.

Example

class InstrumentWithGroupParameters(VisaInstrument):
    def __init__(self, name, address, **kwargs):
        super().__init__(name, address, **kwargs)

        ...

        # Here is how group of group parameters is defined for
        # a simple case of an example "SGP" command that sets and gets
        # values of "enabled" and "gain" parameters (it is assumed that
        # "SGP?" returns the parameter values as comma-separated list
        # "enabled_value,gain_value")
        self.add_parameter('enabled',
                           label='Enabled',
                           val_mapping={True: 1, False: 0},
                           parameter_class=GroupParameter)
        self.add_parameter('gain',
                           label='Some gain value',
                           get_parser=float,
                           parameter_class=GroupParameter)
        self.output_group = Group([self.enabled, self.gain],
                                  set_cmd='SGP {enabled}, {gain}',
                                  get_cmd='SGP?')

        ...
Parameters
  • parameters – a list of GroupParameter instances which have to be gotten and set via the same command; the order of parameters in the list should correspond to the order of the values returned by the get_cmd.

  • set_cmd – Format string of the command that is used for setting the values of the parameters; for example, CMD {a}, {b}.

  • get_cmd – String of the command that is used for getting the values of the parameters; for example, CMD?.

  • separator – A separator that is used when parsing the output of the get_cmd in order to obtain the values of the parameters; it is ignored in case a custom get_parser is used.

  • get_parser – A callable with a single string argument that is used to parse the output of the get_cmd; the callable has to return a dictionary where parameter names are keys, and the values are the values (as directly obtained from the output of the get command; note that parsers within the parameters will take care of individual parsing of their values).

  • single_instrument – A flag to indicate that all parameters belong to a

  • instrument (single) –

  • True. (which in turn does additional checks. Defaults to) –

set_parameters(parameters_dict: Mapping[str, Any]) None[source]

Sets the value of one or more parameters within a group to the given values by calling the set_cmd while updating rest.

Parameters
  • parameters_dict – The dictionary of one or more parameters within

  • set. (the group with the corresponding values to be) –

update() None[source]

Update the values of all the parameters within the group by calling the get_cmd.

property parameters: OrderedDict[str, GroupParameter]

All parameters in this group as a dict from parameter name to Parameter

property instrument: Optional[qcodes.instrument.base.InstrumentBase]

The root_instrument that this parameter belongs to.

class qcodes.instrument.group_parameter.GroupParameter(name: str, instrument: Optional[qcodes.instrument.base.InstrumentBase] = None, initial_value: Optional[Union[float, int, str]] = None, **kwargs: Any)[source]

Bases: qcodes.instrument.parameter.Parameter

Group parameter is a Parameter, whose value can be set or get only with other group parameters. This happens when an instrument has commands which set and get more than one parameter per call.

The set_raw method of a group parameter forwards the call to the group, and the group then makes sure that the values of other parameters within the group are left unchanged. The get_raw method of a group parameter also forwards the call to the group, and the group makes sure that the command output is parsed correctly, and the value of the parameter of interest is returned.

After initialization, the group parameters need to be added to a group. See Group for more information.

Parameters
  • name – Name of the parameter.

  • instrument – Instrument that this parameter belongs to; this instrument is used by the group to call its get and set commands.

  • initial_value – Initial value of the parameter. Note that either none or all of the parameters in a Group should have an initial value.

  • **kwargs – All kwargs used by the Parameter class, except set_cmd and get_cmd.

property group: Optional[qcodes.instrument.group_parameter.Group]

The group that this parameter belongs to.

get_raw() Any[source]

get_raw is called to perform the actual data acquisition from the instrument. This method should either be overwritten to perform the desired operation or alternatively for Parameter a suitable method is automatically generated if get_cmd is supplied to the parameter constructor. The method is automatically wrapped to provide a get method on the parameter instance.

set_raw(value: Any) None[source]

set_raw is called to perform the actual setting of a parameter on the instrument. This method should either be overwritten to perform the desired operation or alternatively for Parameter a suitable method is automatically generated if set_cmd is supplied to the parameter constructor. The method is automatically wrapped to provide a set method on the parameter instance.

__getitem__(keys: Any) qcodes.instrument.sweep_values.SweepFixedValues

Slice a Parameter to get a SweepValues object to iterate over during a sweep

__str__() str

Include the instrument name with the Parameter name if possible.

property abstract: Optional[bool]
property full_name: str

Name of the parameter including the name of the instrument and submodule that the parameter may be bound to. The names are separated by underscores, like this: instrument_submodule_parameter.

get_ramp_values(value: Union[float, Sized], step: Optional[float] = None) Sequence[Union[float, Sized]]

Return values to sweep from current value to target value. This method can be overridden to have a custom sweep behaviour. It can even be overridden by a generator.

Parameters
  • value – target value

  • step – maximum step size

Returns

List of stepped values, including target value.

property gettable: bool

Is it allowed to call get on this parameter?

increment(value: Any) None

Increment the parameter with a value

Parameters

value – Value to be added to the parameter.

property instrument: Optional[InstrumentBase]

Return the first instrument that this parameter is bound to. E.g if this is bound to a channel it will return the channel and not the instrument that the channel is bound too. Use root_instrument() to get the real instrument.

property inter_delay: float

Delay time between consecutive set operations. The actual time will not be shorter than this, but may be longer if the underlying set call takes longer.

Typically used in conjunction with step to create an effective ramp rate, but can also be used without a step to enforce a delay between sets.

Getter

Returns the current inter_delay.

Setter

Sets the value of the inter_delay.

Raises
load_metadata(metadata: Dict[Any, Any]) None

Load metadata into this classes metadata dictionary.

Parameters

metadata – Metadata to load.

property name: str

Name of the parameter. This is identical to short_name().

property name_parts: List[str]

List of the parts that make up the full name of this parameter

property post_delay: float

Delay time after start of set operation, for each set. The actual time will not be shorter than this, but may be longer if the underlying set call takes longer.

Typically used in conjunction with step to create an effective ramp rate, but can also be used without a step to enforce a delay after every set. One might think of post_delay as how long a set operation is supposed to take. For example, there might be an instrument that needs extra time after setting a parameter although the command for setting the parameter returns quickly.

Getter

Returns the current post_delay.

Setter

Sets the value of the post_delay.

Raises
property raw_value: Any

Note that this property will be deprecated soon. Use cache.raw_value instead.

Represents the cached raw value of the parameter.

Getter

Returns the cached raw value of the parameter.

restore_at_exit(allow_changes: bool = True) qcodes.instrument.parameter._SetParamContext

Use a context manager to restore the value of a parameter after a with block.

By default, the parameter value may be changed inside the block, but this can be prevented with allow_changes=False. This can be useful, for example, for debugging a complex measurement that unintentionally modifies a parameter.

Example

>>> p = Parameter("p", set_cmd=None, get_cmd=None)
>>> p.set(2)
>>> with p.restore_at_exit():
...     p.set(3)
...     print(f"value inside with block: {p.get()}")  # prints 3
>>> print(f"value after with block: {p.get()}")  # prints 2
>>> with p.restore_at_exit(allow_changes=False):
...     p.set(5)  # raises an exception
property root_instrument: Optional[InstrumentBase]

Return the fundamental instrument that this parameter belongs too. E.g if the parameter is bound to a channel this will return the fundamental instrument that that channel belongs to. Use instrument() to get the channel.

set_to(value: Any, allow_changes: bool = False) qcodes.instrument.parameter._SetParamContext

Use a context manager to temporarily set a parameter to a value. By default, the parameter value cannot be changed inside the context. This may be overridden with allow_changes=True.

Examples

>>> from qcodes import Parameter
>>> p = Parameter("p", set_cmd=None, get_cmd=None)
>>> p.set(2)
>>> with p.set_to(3):
...     print(f"p value in with block {p.get()}")  # prints 3
...     p.set(5)  # raises an exception
>>> print(f"p value outside with block {p.get()}")  # prints 2
>>> with p.set_to(3, allow_changes=True):
...     p.set(5)  # now this works
>>> print(f"value after second block: {p.get()}")  # still prints 2
property settable: bool

Is it allowed to call set on this parameter?

property short_name: str

Short name of the parameter. This is without the name of the instrument or submodule that the parameter may be bound to. For full name refer to full_name().

snapshot(update: Optional[bool] = False) Dict[Any, Any]

Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override snapshot_base().

Parameters

update – Passed to snapshot_base.

Returns

Base snapshot.

snapshot_base(update: Optional[bool] = True, params_to_skip_update: Optional[Sequence[str]] = None) Dict[Any, Any]

State of the parameter as a JSON-compatible dict (everything that the custom JSON encoder class qcodes.utils.helpers.NumpyJSONEncoder supports).

If the parameter has been initiated with snapshot_value=False, the snapshot will NOT include the value and raw_value of the parameter.

Parameters
  • update – If True, update the state by calling parameter.get() unless snapshot_get of the parameter is False. If update is None, use the current value from the cache unless the cache is invalid. If False, never call parameter.get().

  • params_to_skip_update – No effect but may be passed from superclass

Returns

base snapshot

property snapshot_value: bool

If True the value of the parameter will be included in the snapshot.

property step: Optional[float]

Stepsize that this Parameter uses during set operation. Stepsize must be a positive number or None. If step is a positive number, this is the maximum value change allowed in one hardware call, so a single set can result in many calls to the hardware if the starting value is far from the target. All but the final change will attempt to change by +/- step exactly. If step is None stepping will not be used.

Getter

Returns the current stepsize.

Setter

Sets the value of the step.

Raises
  • TypeError – if step is set to not numeric or None

  • ValueError – if step is set to negative

  • TypeError – if step is set to not integer or None for an integer parameter

  • TypeError – if step is set to not a number on None

sweep(start: float, stop: float, step: Optional[float] = None, num: Optional[int] = None) qcodes.instrument.sweep_values.SweepFixedValues

Create a collection of parameter values to be iterated over. Requires start and stop and (step or num) The sign of step is not relevant.

Parameters
  • start – The starting value of the sequence.

  • stop – The end value of the sequence.

  • step – Spacing between values.

  • num – Number of values to generate.

Returns

Collection of parameter values to be iterated over.

Return type

SweepFixedValues

Examples

>>> sweep(0, 10, num=5)
 [0.0, 2.5, 5.0, 7.5, 10.0]
>>> sweep(5, 10, step=1)
[5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
>>> sweep(15, 10.5, step=1.5)
>[15.0, 13.5, 12.0, 10.5]
property underlying_instrument: Optional[InstrumentBase]

Returns an instance of the underlying hardware instrument that this parameter communicates with, per this parameter’s implementation.

This is useful in the case where a parameter does not belongs to an instrument instance that represents a real hardware instrument but actually uses a real hardware instrument in its implementation (e.g. via calls to one or more parameters of that real hardware instrument). This is also useful when a parameter does belong to an instrument instance but that instance does not represent the real hardware instrument that the parameter interacts with: hence root_instrument of the parameter cannot be the hardware_instrument, however underlying_instrument can be implemented to return the hardware_instrument.

By default it returns the root_instrument of the parameter.

validate(value: Any) None

Validate the value supplied.

Parameters

value – value to validate

Raises
  • TypeError – If the value is of the wrong type.

  • ValueError – If the value is outside the bounds specified by the validator.

label: str = ()

Label of the data used for plots etc.

unit = ()

The unit of measure. Use '' for unitless.