qcodes.instrument

Classes:

ChannelList(parent, name, chan_type[, ...])

Mutable Container for channelized parameters that allows for sweeps over all channels, as well as addressing of individual channels.

ChannelTuple(parent, name, chan_type[, ...])

Container for channelized parameters that allows for sweeps over all channels, as well as addressing of individual channels.

IPInstrument(name[, address, port, timeout, ...])

Bare socket ethernet instrument implementation.

Instrument(name, **kwargs)

Base class for all QCodes instruments.

InstrumentBase(name[, metadata, label])

Base class for all QCodes instruments and instrument channels

InstrumentBaseKWArgs

This TypedDict defines the type of the kwargs that can be passed to the InstrumentBase class.

InstrumentChannel(parent, name, **kwargs)

InstrumentModule(parent, name, **kwargs)

Base class for a module in an instrument.

VisaInstrument(name, address[, timeout, ...])

Base class for all instruments using visa connections.

VisaInstrumentKWArgs

This TypedDict defines the type of the kwargs that can be passed to the VisaInstrument class.

Functions:

find_or_create_instrument(instrument_class, ...)

Find an instrument with the given name of a given class, or create one if it is not found.

class qcodes.instrument.ChannelList(parent: InstrumentBase, name: str, chan_type: type[InstrumentModuleType], chan_list: Sequence[InstrumentModuleType] | None = None, snapshotable: bool = True, multichan_paramclass: type[MultiChannelInstrumentParameter] | None = None)[source]

Bases: ChannelTuple, MutableSequence[InstrumentModuleType]

Mutable Container for channelized parameters that allows for sweeps over all channels, as well as addressing of individual channels.

This behaves like a python list i.e. it implements the collections.abc.MutableSequence interface.

Note it may be useful to use the mutable ChannelList while constructing it. E.g. adding channels as they are created, but in most use cases it is recommended to convert this to a ChannelTuple before adding it to an instrument. This can be done using the to_channel_tuple() method.

Parameters:
  • parent – The instrument to which this ChannelList should be attached.

  • name – The name of the ChannelList.

  • chan_type – The type of channel contained within this list.

  • chan_list – An optional iterable of channels of type chan_type. This will create a list and immediately lock the ChannelList.

  • snapshotable – Optionally disables taking of snapshots for a given ChannelList. This is used when objects stored inside a ChannelList are accessible in multiple ways and should not be repeated in an instrument snapshot.

  • multichan_paramclass – The class of the object to be returned by the __getattr__() method of ChannelList. Should be a subclass of MultiChannelInstrumentParameter. Defaults to MultiChannelInstrumentParameter if None.

Raises:

Methods:

append(obj)

Append a Channel to this list.

clear()

Clear all items from the ChannelList.

remove(obj)

Removes obj from ChannelList if not locked.

extend(objects)

Insert an iterable of objects into the list of channels.

insert(index, obj)

Insert an object into the ChannelList at a specific index.

get_validator()

Returns a validator that checks that the returned object is a channel in this ChannelList.

lock()

Lock the channel list.

to_channel_tuple()

Returns a ChannelTuple build from this ChannelList containing the same channels but without the ability to be modified.

__add__(other)

Return a new ChannelTuple containing the channels from both ChannelTuple self and r.

__getattr__(name)

Look up an attribute by name.

__getitem__(i)

Return either a single channel, or a new ChannelTuple containing only the specified channels

count(obj)

Returns number of instances of the given object in the list

get_channel_by_name(*names)

Get a channel by name, or a ChannelTuple if multiple names are given.

index(obj[, start, stop])

Return the index of the given object

invalidate_cache()

Invalidate the cache of all parameters on the ChannelTuple.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

pop([index])

Raise IndexError if list is empty or index is out of range.

print_readable_snapshot([update, max_chars])

reverse()

S.reverse() -- reverse IN PLACE

snapshot([update])

Decorate a snapshot dictionary with metadata.

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Attributes:

full_name

Name including name of any parent that this object is bound to separated by '_'.

name_parts

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

short_name

Name excluding name of any parent that this object is bound to.

append(obj: InstrumentModuleType) None[source]

Append a Channel to this list. Requires that the ChannelList is not locked and that the channel is of the same type as the ones in the list.

Parameters:

obj – New channel to add to the list.

clear() None[source]

Clear all items from the ChannelList.

remove(obj: InstrumentModuleType) None[source]

Removes obj from ChannelList if not locked.

Parameters:

obj – Channel to remove from the list.

extend(objects: Iterable[InstrumentModuleType]) None[source]

Insert an iterable of objects into the list of channels.

Parameters:

objects – A list of objects to add into the ChannelList.

insert(index: int, obj: InstrumentModuleType) None[source]

Insert an object into the ChannelList at a specific index.

Parameters:
  • index – Index to insert object.

  • obj – Object of type chan_type to insert.

get_validator() ChannelTupleValidator[source]

Returns a validator that checks that the returned object is a channel in this ChannelList.

Raises:

AttributeError – If the ChannelList is not locked.

lock() None[source]

Lock the channel list. Once this is done, the ChannelList is locked and any future changes to the list are prevented. Note this is not recommended and may be deprecated in the future. Use to_channel_tuple to convert this into a tuple instead.

to_channel_tuple() ChannelTuple[source]

Returns a ChannelTuple build from this ChannelList containing the same channels but without the ability to be modified.

__add__(other: ChannelTuple) T

Return a new ChannelTuple containing the channels from both ChannelTuple self and r.

Both ChannelTuple must hold the same type and have the same parent.

Parameters:

other – Right argument to add.

__getattr__(name: str) MultiChannelInstrumentParameter | Callable[[...], None] | InstrumentModuleType

Look up an attribute by name. If this is the name of a parameter or a function on the channel type contained in this container return a multi-channel function or parameter that can be used to get or set all items in a channel list simultaneously. If this is the name of a channel, return that channel.

Parameters:

name – The name of the parameter, function or channel that we want to operate on.

__getitem__(i: int | slice | tuple[int, ...]) InstrumentModuleType | T

Return either a single channel, or a new ChannelTuple containing only the specified channels

Parameters:

i – Either a single channel index or a slice of channels to get

count(obj: InstrumentModuleType) int

Returns number of instances of the given object in the list

Parameters:

obj – The object to find in the ChannelTuple.

property full_name: str

Name including name of any parent that this object is bound to separated by ‘_’.

get_channel_by_name(*names: str) InstrumentModuleType | T

Get a channel by name, or a ChannelTuple if multiple names are given.

Parameters:

*names – channel names

index(obj: InstrumentModuleType, start: int = 0, stop: int = 9223372036854775807) int

Return the index of the given object

Parameters:
  • obj – The object to find in the channel list.

  • start – Index to start searching from.

  • stop – Index to stop searching at.

invalidate_cache() None

Invalidate the cache of all parameters on the ChannelTuple.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

property name_parts: list[str]

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

pop([index]) item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

print_readable_snapshot(update: bool = False, max_chars: int = 80) None
reverse()

S.reverse() – reverse IN PLACE

property short_name: str

Name excluding name of any parent that this object is bound to.

snapshot(update: bool | None = False) dict[str, 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: bool | None = True, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None only update if the state is known to be invalid. If False, just use the latest values in memory and never update.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters instead.

Returns:

base snapshot

Return type:

dict

class qcodes.instrument.ChannelTuple(parent: InstrumentBase, name: str, chan_type: type[InstrumentModuleType], chan_list: Sequence[InstrumentModuleType] | None = None, snapshotable: bool = True, multichan_paramclass: type[MultiChannelInstrumentParameter] | None = None)[source]

Bases: MetadatableWithName, Sequence[InstrumentModuleType]

Container for channelized parameters that allows for sweeps over all channels, as well as addressing of individual channels.

This behaves like a python tuple i.e. it implements the collections.abc.Sequence interface.

Parameters:
  • parent – The instrument to which this ChannelTuple should be attached.

  • name – The name of the ChannelTuple.

  • chan_type – The type of channel contained within this tuple.

  • chan_list – An optional iterable of channels of type chan_type.

  • snapshotable – Optionally disables taking of snapshots for a given ChannelTuple. This is used when objects stored inside a ChannelTuple are accessible in multiple ways and should not be repeated in an instrument snapshot.

  • multichan_paramclass – The class of the object to be returned by the __getattr__() method of ChannelTuple. Should be a subclass of MultiChannelInstrumentParameter. Defaults to MultiChannelInstrumentParameter if None.

Raises:

Methods:

__getitem__()

Return either a single channel, or a new ChannelTuple containing only the specified channels

__add__(other)

Return a new ChannelTuple containing the channels from both ChannelTuple self and r.

index(obj[, start, stop])

Return the index of the given object

count(obj)

Returns number of instances of the given object in the list

get_channel_by_name(*names)

Get a channel by name, or a ChannelTuple if multiple names are given.

get_validator()

Returns a validator that checks that the returned object is a channel in this ChannelTuple

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

__getattr__(name)

Look up an attribute by name.

print_readable_snapshot([update, max_chars])

invalidate_cache()

Invalidate the cache of all parameters on the ChannelTuple.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

snapshot([update])

Decorate a snapshot dictionary with metadata.

Attributes:

short_name

Name excluding name of any parent that this object is bound to.

full_name

Name including name of any parent that this object is bound to separated by '_'.

name_parts

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

__getitem__(i: int) InstrumentModuleType[source]
__getitem__(i: slice | tuple[int, ...]) T

Return either a single channel, or a new ChannelTuple containing only the specified channels

Parameters:

i – Either a single channel index or a slice of channels to get

__add__(other: ChannelTuple) T[source]

Return a new ChannelTuple containing the channels from both ChannelTuple self and r.

Both ChannelTuple must hold the same type and have the same parent.

Parameters:

other – Right argument to add.

property short_name: str

Name excluding name of any parent that this object is bound to.

property full_name: str

Name including name of any parent that this object is bound to separated by ‘_’.

property name_parts: list[str]

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

index(obj: InstrumentModuleType, start: int = 0, stop: int = 9223372036854775807) int[source]

Return the index of the given object

Parameters:
  • obj – The object to find in the channel list.

  • start – Index to start searching from.

  • stop – Index to stop searching at.

count(obj: InstrumentModuleType) int[source]

Returns number of instances of the given object in the list

Parameters:

obj – The object to find in the ChannelTuple.

get_channel_by_name(*names: str) InstrumentModuleType | T[source]

Get a channel by name, or a ChannelTuple if multiple names are given.

Parameters:

*names – channel names

get_validator() ChannelTupleValidator[source]

Returns a validator that checks that the returned object is a channel in this ChannelTuple

snapshot_base(update: bool | None = True, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any][source]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None only update if the state is known to be invalid. If False, just use the latest values in memory and never update.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters instead.

Returns:

base snapshot

Return type:

dict

__getattr__(name: str) MultiChannelInstrumentParameter | Callable[[...], None] | InstrumentModuleType[source]

Look up an attribute by name. If this is the name of a parameter or a function on the channel type contained in this container return a multi-channel function or parameter that can be used to get or set all items in a channel list simultaneously. If this is the name of a channel, return that channel.

Parameters:

name – The name of the parameter, function or channel that we want to operate on.

print_readable_snapshot(update: bool = False, max_chars: int = 80) None[source]
invalidate_cache() None[source]

Invalidate the cache of all parameters on the ChannelTuple.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

snapshot(update: bool | None = False) dict[str, 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.

class qcodes.instrument.IPInstrument(name: str, address: str | None = None, port: int | None = None, timeout: float = 5, terminator: str = '\n', persistent: bool = True, write_confirmation: bool = True, **kwargs: Unpack[InstrumentBaseKWArgs])[source]

Bases: Instrument

Bare socket ethernet instrument implementation. Use of VisaInstrument is promoted instead of this.

Parameters:
  • name – What this instrument is called locally.

  • address – The IP address or name. If not given on construction, must be provided before any communication.

  • port – The IP port. If not given on construction, must be provided before any communication.

  • timeout – Seconds to allow for responses. Default 5.

  • terminator – Character(s) to terminate each send. Default ‘n’.

  • persistent – Whether to leave the socket open between calls. Default True.

  • write_confirmation – Whether the instrument acknowledges writes with some response we should read. Default True.

  • **kwargs – Forwarded to the base class.

See help for qcodes.Instrument for additional information on writing instrument subclasses.

Methods:

set_address([address, port])

Change the IP address and/or port of this instrument.

set_persistent(persistent)

Change whether this instrument keeps its socket open between calls.

flush_connection()

set_timeout(timeout)

Change the read timeout for the socket.

set_terminator(terminator)

Change the write terminator to use.

close()

Disconnect and irreversibly tear down the instrument.

write_raw(cmd)

Low-level interface to send a command that gets no response.

ask_raw(cmd)

Low-level interface to send a command an read a response.

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

__del__()

Close the instrument and remove its instance record.

__getitem__(key)

Delegate instrument['name'] to parameter or function 'name'.

__getstate__()

Prevent pickling instruments, and give a nice error message.

__repr__()

Simplified repr giving just the class and name.

add_function(name, **kwargs)

Bind one Function to this instrument.

add_parameter(name[, parameter_class])

Bind one Parameter to this instrument.

add_submodule(name, submodule)

Bind one submodule to this instrument.

ask(cmd)

Write a command string to the hardware and return a response.

call(func_name, *args)

Shortcut for calling a function from its name.

close_all()

Try to close all instruments registered in _all_instruments This is handy for use with atexit to ensure that all instruments are closed when a python session is closed.

connect_message([idn_param, begin_time])

Print a standard message on initial connection to an instrument.

exist(name[, instrument_class])

Check if an instrument with a given names exists (i.e. is already instantiated).

find_instrument(name[, instrument_class])

Find an existing instrument by name.

get(param_name)

Shortcut for getting a parameter from its name.

get_component(full_name)

Recursively get a component of the instrument by full_name.

get_idn()

Parse a standard VISA *IDN? response into an ID dict.

instances()

Get all currently defined instances of this instrument class.

invalidate_cache()

Invalidate the cache of all parameters on the instrument.

is_valid(instr_instance)

Check if a given instance of an instrument is valid: if an instrument has been closed, its instance is not longer a "valid" instrument.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

print_readable_snapshot([update, max_chars])

Prints a readable version of the snapshot.

record_instance(instance)

Record (a weak ref to) an instance in a class's instance list.

remove_instance(instance)

Remove a particular instance from the record.

remove_parameter(name)

Remove a Parameter from this instrument.

set(param_name, value)

Shortcut for setting a parameter from its name and new value.

snapshot([update])

Decorate a snapshot dictionary with metadata.

validate_status([verbose])

Validate the values of all gettable parameters

write(cmd)

Write a command string with NO response to the hardware.

Attributes:

ancestors

Ancestors in the form of a list of InstrumentBase

delegate_attr_dicts

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

full_name

Full name of the instrument.

label

Nicely formatted label of the instrument.

name

Full name of the instrument

name_parts

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs

A list of attribute names (strings) to not delegate to any other dictionary or object.

parent

The parent instrument.

root_instrument

The topmost parent of this module.

short_name

Short name of the instrument.

parameters

All the parameters supported by this instrument.

functions

All the functions supported by this instrument.

submodules

All the submodules of this instrument such as channel lists or logical groupings of parameters.

instrument_modules

All the InstrumentModule of this instrument Usually populated via add_submodule().

set_address(address: str | None = None, port: int | None = None) None[source]

Change the IP address and/or port of this instrument.

Parameters:
  • address – The IP address or name.

  • port – The IP port.

set_persistent(persistent: bool) None[source]

Change whether this instrument keeps its socket open between calls.

Parameters:

persistent – Set True to keep the socket open all the time.

flush_connection() None[source]
set_timeout(timeout: float) None[source]

Change the read timeout for the socket.

Parameters:

timeout – Seconds to allow for responses.

set_terminator(terminator: str) None[source]

Change the write terminator to use.

Parameters:

terminator – Character(s) to terminate each send. Default ‘n’.

close() None[source]

Disconnect and irreversibly tear down the instrument.

write_raw(cmd: str) None[source]

Low-level interface to send a command that gets no response.

Parameters:

cmd – The command to send to the instrument.

ask_raw(cmd: str) str[source]

Low-level interface to send a command an read a response.

Parameters:

cmd – The command to send to the instrument.

Returns:

The instrument’s string response.

snapshot_base(update: bool | None = False, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any][source]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None only update if the state is known to be invalid. If False, just use the latest values in memory and never update.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters: instead.

Returns:

base snapshot

Return type:

dict

__del__() None

Close the instrument and remove its instance record.

__getitem__(key: str) Callable[[...], Any] | Parameter

Delegate instrument[‘name’] to parameter or function ‘name’.

__getstate__() None

Prevent pickling instruments, and give a nice error message.

__repr__() str

Simplified repr giving just the class and name.

add_function(name: str, **kwargs: Any) None

Bind one Function to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real function of the instrument.

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only.

Note

We do not recommend the usage of Function for any new driver. Function does not add any significant features over a method defined on the class.

Parameters:
  • name – How the Function will be stored within instrument.Functions and also how you address it using the shortcut methods: instrument.call(func_name, *args) etc.

  • **kwargs – constructor kwargs for Function

Raises:

KeyError – If this instrument already has a function with this name.

add_parameter(name: str, parameter_class: type[TParameter] | None = None, **kwargs: Any) TParameter

Bind one Parameter to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real parameter of the instrument.

In this sense, parameters are the state variables of the instrument, anything the user can set and/or get.

Parameters:
  • name – How the parameter will be stored within parameters and also how you address it using the shortcut methods: instrument.set(param_name, value) etc.

  • parameter_class – You can construct the parameter out of any class. Default parameters.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

Raises:
  • KeyError – If this instrument already has a parameter with this name and the parameter being replaced is not an abstract parameter.

  • ValueError – If there is an existing abstract parameter and the unit of the new parameter is inconsistent with the existing one.

add_submodule(name: str, submodule: InstrumentModule | ChannelTuple) None

Bind one submodule to this instrument.

Instrument subclasses can call this repeatedly in their __init__ method for every submodule of the instrument.

Submodules can effectively be considered as instruments within the main instrument, and should at minimum be snapshottable. For example, they can be used to either store logical groupings of parameters, which may or may not be repeated, or channel lists. They should either be an instance of an InstrumentModule or a ChannelTuple.

Parameters:
  • name – How the submodule will be stored within instrument.submodules and also how it can be addressed.

  • submodule – The submodule to be stored.

Raises:
  • KeyError – If this instrument already contains a submodule with this name.

  • TypeError – If the submodule that we are trying to add is not an instance of an Metadatable object.

property ancestors: tuple[InstrumentBase, ...]

Ancestors in the form of a list of InstrumentBase

The list starts with the current module then the parent and the parents parent until the root instrument is reached.

ask(cmd: str) str

Write a command string to the hardware and return a response.

Subclasses that transform cmd should override this method, and in it call super().ask(new_cmd). Subclasses that define a new hardware communication should instead override ask_raw.

Parameters:

cmd – The string to send to the instrument.

Returns:

response

Raises:

Exception – Wraps any underlying exception with extra context, including the command and the instrument.

call(func_name: str, *args: Any) Any

Shortcut for calling a function from its name.

Parameters:
  • func_name – The name of a function of this instrument.

  • *args – any arguments to the function.

Returns:

The return value of the function.

classmethod close_all() None

Try to close all instruments registered in _all_instruments This is handy for use with atexit to ensure that all instruments are closed when a python session is closed.

Examples

>>> atexit.register(qc.Instrument.close_all())
connect_message(idn_param: str = 'IDN', begin_time: float | None = None) None

Print a standard message on initial connection to an instrument.

Parameters:
  • idn_param – Name of parameter that returns ID dict. Default IDN.

  • begin_timetime.time() when init started. Default is self._t0, set at start of Instrument.__init__.

delegate_attr_dicts: ClassVar[list[str]] = ['parameters', 'functions', 'submodules']

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects: ClassVar[list[str]] = []

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

static exist(name: str, instrument_class: type[Instrument] | None = None) bool

Check if an instrument with a given names exists (i.e. is already instantiated).

Parameters:
  • name – Name of the instrument.

  • instrument_class – The type of instrument you are looking for.

classmethod find_instrument(name: str, instrument_class: type[T] | None = None) T | Instrument

Find an existing instrument by name.

Parameters:
  • name – Name of the instrument.

  • instrument_class – The type of instrument you are looking for.

Returns:

The instrument found.

Raises:
  • KeyError – If no instrument of that name was found, or if its reference is invalid (dead).

  • TypeError – If a specific class was requested but a different type was found.

property full_name: str

Full name of the instrument.

For an InstrumentModule this includes all parents separated by _

get(param_name: str) Any

Shortcut for getting a parameter from its name.

Parameters:

param_name – The name of a parameter of this instrument.

Returns:

The current value of the parameter.

get_component(full_name: str) MetadatableWithName

Recursively get a component of the instrument by full_name.

Parameters:

full_name – The name of the component to get.

Returns:

The component with the given name.

Raises:

KeyError – If the component does not exist.

get_idn() dict[str, str | None]

Parse a standard VISA *IDN? response into an ID dict.

Even though this is the VISA standard, it applies to various other types as well, such as IPInstruments, so it is included here in the Instrument base class.

Override this if your instrument does not support *IDN? or returns a nonstandard IDN string. This string is supposed to be a comma-separated list of vendor, model, serial, and firmware, but semicolon and colon are also common separators so we accept them here as well.

Returns:

A dict containing vendor, model, serial, and firmware.

classmethod instances() list[T]

Get all currently defined instances of this instrument class.

You can use this to get the objects back if you lose track of them, and it’s also used by the test system to find objects to test against.

Returns:

A list of instances.

invalidate_cache() None

Invalidate the cache of all parameters on the instrument. Calling this method will recursively mark the cache of all parameters on the instrument and any parameter on instrument modules as invalid.

This is useful if you have performed manual operations (e.g. using the frontpanel) which changes the state of the instrument outside QCoDeS.

This in turn means that the next snapshot of the instrument will trigger a (potentially slow) reread of all parameters of the instrument if you pass update=None to snapshot.

static is_valid(instr_instance: Instrument) bool

Check if a given instance of an instrument is valid: if an instrument has been closed, its instance is not longer a “valid” instrument.

Parameters:

instr_instance – Instance of an Instrument class or its subclass.

property label: str

Nicely formatted label of the instrument.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

property name: str

Full name of the instrument

This is equivalent to full_name() for backwards compatibility.

property name_parts: list[str]

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs: ClassVar[list[str]] = []

A list of attribute names (strings) to not delegate to any other dictionary or object.

property parent: InstrumentBase | None

The parent instrument. By default, this is None. Any SubInstrument should subclass this to return the parent instrument.

print_readable_snapshot(update: bool = False, max_chars: int = 80) None

Prints a readable version of the snapshot. The readable snapshot includes the name, value and unit of each parameter. A convenience function to quickly get an overview of the status of an instrument.

Parameters:
  • update – If True, update the state by querying the instrument. If False, just use the latest values in memory. This argument gets passed to the snapshot function.

  • max_chars – the maximum number of characters per line. The readable snapshot will be cropped if this value is exceeded. Defaults to 80 to be consistent with default terminal width.

classmethod record_instance(instance: Instrument) None

Record (a weak ref to) an instance in a class’s instance list.

Also records the instance in list of all instruments, and verifies that there are no other instruments with the same name.

This method is called after initialization of the instrument is completed.

Parameters:

instance – Instance to record.

Raises:

KeyError – If another instance with the same name is already present.

classmethod remove_instance(instance: Instrument) None

Remove a particular instance from the record.

Parameters:

instance – The instance to remove

remove_parameter(name: str) None

Remove a Parameter from this instrument.

Unlike modifying the parameters dict directly, this method will make sure that the parameter is properly unbound from the instrument if the parameter is added as a real attribute to the instrument. If a property of the same name exists it will not be modified. If name is an attribute but not a parameter, it will not be modified.

Parameters:

name – The name of the parameter to remove.

Raises:

KeyError – If the parameter does not exist on the instrument.

property root_instrument: InstrumentBase

The topmost parent of this module.

For the root_instrument this is self.

set(param_name: str, value: Any) None

Shortcut for setting a parameter from its name and new value.

Parameters:
  • param_name – The name of a parameter of this instrument.

  • value – The new value to set.

property short_name: str

Short name of the instrument.

For an InstrumentModule this does not include any parent names.

snapshot(update: bool | None = False) dict[str, 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.

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

The validation is done for all parameters that have both a get and set method.

Parameters:

verbose – If True, then information about the parameters that are being check is printed.

write(cmd: str) None

Write a command string with NO response to the hardware.

Subclasses that transform cmd should override this method, and in it call super().write(new_cmd). Subclasses that define a new hardware communication should instead override write_raw.

Parameters:

cmd – The string to send to the instrument.

Raises:

Exception – Wraps any underlying exception with extra context, including the command and the instrument.

parameters: dict[str, ParameterBase] = {}

All the parameters supported by this instrument. Usually populated via add_parameter().

functions: dict[str, Function] = {}

All the functions supported by this instrument. Usually populated via add_function().

submodules: dict[str, InstrumentModule | ChannelTuple] = {}

All the submodules of this instrument such as channel lists or logical groupings of parameters. Usually populated via add_submodule().

instrument_modules: dict[str, InstrumentModule] = {}

All the InstrumentModule of this instrument Usually populated via add_submodule().

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
metadata: dict[str, Any] = {}
class qcodes.instrument.Instrument(name: str, **kwargs: Unpack[InstrumentBaseKWArgs])[source]

Bases: InstrumentBase

Base class for all QCodes instruments.

Parameters:
  • name – an identifier for this instrument, particularly for attaching it to a Station.

  • metadata – additional static metadata to add to this instrument’s JSON snapshot.

  • label – nicely formatted name of the instrument; if None, the name is used.

Methods:

get_idn()

Parse a standard VISA *IDN? response into an ID dict.

connect_message([idn_param, begin_time])

Print a standard message on initial connection to an instrument.

__repr__()

Simplified repr giving just the class and name.

__del__()

Close the instrument and remove its instance record.

close()

Irreversibly stop this instrument and free its resources.

close_all()

Try to close all instruments registered in _all_instruments This is handy for use with atexit to ensure that all instruments are closed when a python session is closed.

record_instance(instance)

Record (a weak ref to) an instance in a class's instance list.

instances()

Get all currently defined instances of this instrument class.

remove_instance(instance)

Remove a particular instance from the record.

find_instrument()

Find an existing instrument by name.

exist(name[, instrument_class])

Check if an instrument with a given names exists (i.e. is already instantiated).

is_valid(instr_instance)

Check if a given instance of an instrument is valid: if an instrument has been closed, its instance is not longer a "valid" instrument.

write(cmd)

Write a command string with NO response to the hardware.

write_raw(cmd)

Low level method to write a command string to the hardware.

__getitem__(key)

Delegate instrument['name'] to parameter or function 'name'.

__getstate__()

Prevent pickling instruments, and give a nice error message.

add_function(name, **kwargs)

Bind one Function to this instrument.

add_parameter(name[, parameter_class])

Bind one Parameter to this instrument.

add_submodule(name, submodule)

Bind one submodule to this instrument.

ask(cmd)

Write a command string to the hardware and return a response.

call(func_name, *args)

Shortcut for calling a function from its name.

get(param_name)

Shortcut for getting a parameter from its name.

get_component(full_name)

Recursively get a component of the instrument by full_name.

invalidate_cache()

Invalidate the cache of all parameters on the instrument.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

print_readable_snapshot([update, max_chars])

Prints a readable version of the snapshot.

remove_parameter(name)

Remove a Parameter from this instrument.

set(param_name, value)

Shortcut for setting a parameter from its name and new value.

snapshot([update])

Decorate a snapshot dictionary with metadata.

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

validate_status([verbose])

Validate the values of all gettable parameters

ask_raw(cmd)

Low level method to write to the hardware and return a response.

Attributes:

ancestors

Ancestors in the form of a list of InstrumentBase

delegate_attr_dicts

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

full_name

Full name of the instrument.

label

Nicely formatted label of the instrument.

name

Full name of the instrument

name_parts

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs

A list of attribute names (strings) to not delegate to any other dictionary or object.

parent

The parent instrument.

root_instrument

The topmost parent of this module.

short_name

Short name of the instrument.

parameters

All the parameters supported by this instrument.

functions

All the functions supported by this instrument.

submodules

All the submodules of this instrument such as channel lists or logical groupings of parameters.

instrument_modules

All the InstrumentModule of this instrument Usually populated via add_submodule().

get_idn() dict[str, str | None][source]

Parse a standard VISA *IDN? response into an ID dict.

Even though this is the VISA standard, it applies to various other types as well, such as IPInstruments, so it is included here in the Instrument base class.

Override this if your instrument does not support *IDN? or returns a nonstandard IDN string. This string is supposed to be a comma-separated list of vendor, model, serial, and firmware, but semicolon and colon are also common separators so we accept them here as well.

Returns:

A dict containing vendor, model, serial, and firmware.

connect_message(idn_param: str = 'IDN', begin_time: float | None = None) None[source]

Print a standard message on initial connection to an instrument.

Parameters:
  • idn_param – Name of parameter that returns ID dict. Default IDN.

  • begin_timetime.time() when init started. Default is self._t0, set at start of Instrument.__init__.

__repr__() str[source]

Simplified repr giving just the class and name.

__del__() None[source]

Close the instrument and remove its instance record.

close() None[source]

Irreversibly stop this instrument and free its resources.

Subclasses should override this if they have other specific resources to close.

classmethod close_all() None[source]

Try to close all instruments registered in _all_instruments This is handy for use with atexit to ensure that all instruments are closed when a python session is closed.

Examples

>>> atexit.register(qc.Instrument.close_all())
classmethod record_instance(instance: Instrument) None[source]

Record (a weak ref to) an instance in a class’s instance list.

Also records the instance in list of all instruments, and verifies that there are no other instruments with the same name.

This method is called after initialization of the instrument is completed.

Parameters:

instance – Instance to record.

Raises:

KeyError – If another instance with the same name is already present.

classmethod instances() list[T][source]

Get all currently defined instances of this instrument class.

You can use this to get the objects back if you lose track of them, and it’s also used by the test system to find objects to test against.

Returns:

A list of instances.

classmethod remove_instance(instance: Instrument) None[source]

Remove a particular instance from the record.

Parameters:

instance – The instance to remove

classmethod find_instrument(name: str, instrument_class: None = None) Instrument[source]
classmethod find_instrument(name: str, instrument_class: type[T]) T

Find an existing instrument by name.

Parameters:
  • name – Name of the instrument.

  • instrument_class – The type of instrument you are looking for.

Returns:

The instrument found.

Raises:
  • KeyError – If no instrument of that name was found, or if its reference is invalid (dead).

  • TypeError – If a specific class was requested but a different type was found.

static exist(name: str, instrument_class: type[Instrument] | None = None) bool[source]

Check if an instrument with a given names exists (i.e. is already instantiated).

Parameters:
  • name – Name of the instrument.

  • instrument_class – The type of instrument you are looking for.

static is_valid(instr_instance: Instrument) bool[source]

Check if a given instance of an instrument is valid: if an instrument has been closed, its instance is not longer a “valid” instrument.

Parameters:

instr_instance – Instance of an Instrument class or its subclass.

write(cmd: str) None[source]

Write a command string with NO response to the hardware.

Subclasses that transform cmd should override this method, and in it call super().write(new_cmd). Subclasses that define a new hardware communication should instead override write_raw.

Parameters:

cmd – The string to send to the instrument.

Raises:

Exception – Wraps any underlying exception with extra context, including the command and the instrument.

write_raw(cmd: str) None[source]

Low level method to write a command string to the hardware.

Subclasses that define a new hardware communication should override this method. Subclasses that transform cmd should instead override write.

Parameters:

cmd – The string to send to the instrument.

__getitem__(key: str) Callable[[...], Any] | Parameter

Delegate instrument[‘name’] to parameter or function ‘name’.

__getstate__() None

Prevent pickling instruments, and give a nice error message.

add_function(name: str, **kwargs: Any) None

Bind one Function to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real function of the instrument.

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only.

Note

We do not recommend the usage of Function for any new driver. Function does not add any significant features over a method defined on the class.

Parameters:
  • name – How the Function will be stored within instrument.Functions and also how you address it using the shortcut methods: instrument.call(func_name, *args) etc.

  • **kwargs – constructor kwargs for Function

Raises:

KeyError – If this instrument already has a function with this name.

add_parameter(name: str, parameter_class: type[TParameter] | None = None, **kwargs: Any) TParameter

Bind one Parameter to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real parameter of the instrument.

In this sense, parameters are the state variables of the instrument, anything the user can set and/or get.

Parameters:
  • name – How the parameter will be stored within parameters and also how you address it using the shortcut methods: instrument.set(param_name, value) etc.

  • parameter_class – You can construct the parameter out of any class. Default parameters.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

Raises:
  • KeyError – If this instrument already has a parameter with this name and the parameter being replaced is not an abstract parameter.

  • ValueError – If there is an existing abstract parameter and the unit of the new parameter is inconsistent with the existing one.

add_submodule(name: str, submodule: InstrumentModule | ChannelTuple) None

Bind one submodule to this instrument.

Instrument subclasses can call this repeatedly in their __init__ method for every submodule of the instrument.

Submodules can effectively be considered as instruments within the main instrument, and should at minimum be snapshottable. For example, they can be used to either store logical groupings of parameters, which may or may not be repeated, or channel lists. They should either be an instance of an InstrumentModule or a ChannelTuple.

Parameters:
  • name – How the submodule will be stored within instrument.submodules and also how it can be addressed.

  • submodule – The submodule to be stored.

Raises:
  • KeyError – If this instrument already contains a submodule with this name.

  • TypeError – If the submodule that we are trying to add is not an instance of an Metadatable object.

property ancestors: tuple[InstrumentBase, ...]

Ancestors in the form of a list of InstrumentBase

The list starts with the current module then the parent and the parents parent until the root instrument is reached.

ask(cmd: str) str[source]

Write a command string to the hardware and return a response.

Subclasses that transform cmd should override this method, and in it call super().ask(new_cmd). Subclasses that define a new hardware communication should instead override ask_raw.

Parameters:

cmd – The string to send to the instrument.

Returns:

response

Raises:

Exception – Wraps any underlying exception with extra context, including the command and the instrument.

call(func_name: str, *args: Any) Any

Shortcut for calling a function from its name.

Parameters:
  • func_name – The name of a function of this instrument.

  • *args – any arguments to the function.

Returns:

The return value of the function.

delegate_attr_dicts: ClassVar[list[str]] = ['parameters', 'functions', 'submodules']

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects: ClassVar[list[str]] = []

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

property full_name: str

Full name of the instrument.

For an InstrumentModule this includes all parents separated by _

get(param_name: str) Any

Shortcut for getting a parameter from its name.

Parameters:

param_name – The name of a parameter of this instrument.

Returns:

The current value of the parameter.

get_component(full_name: str) MetadatableWithName

Recursively get a component of the instrument by full_name.

Parameters:

full_name – The name of the component to get.

Returns:

The component with the given name.

Raises:

KeyError – If the component does not exist.

invalidate_cache() None

Invalidate the cache of all parameters on the instrument. Calling this method will recursively mark the cache of all parameters on the instrument and any parameter on instrument modules as invalid.

This is useful if you have performed manual operations (e.g. using the frontpanel) which changes the state of the instrument outside QCoDeS.

This in turn means that the next snapshot of the instrument will trigger a (potentially slow) reread of all parameters of the instrument if you pass update=None to snapshot.

property label: str

Nicely formatted label of the instrument.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

property name: str

Full name of the instrument

This is equivalent to full_name() for backwards compatibility.

property name_parts: list[str]

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs: ClassVar[list[str]] = []

A list of attribute names (strings) to not delegate to any other dictionary or object.

property parent: InstrumentBase | None

The parent instrument. By default, this is None. Any SubInstrument should subclass this to return the parent instrument.

print_readable_snapshot(update: bool = False, max_chars: int = 80) None

Prints a readable version of the snapshot. The readable snapshot includes the name, value and unit of each parameter. A convenience function to quickly get an overview of the status of an instrument.

Parameters:
  • update – If True, update the state by querying the instrument. If False, just use the latest values in memory. This argument gets passed to the snapshot function.

  • max_chars – the maximum number of characters per line. The readable snapshot will be cropped if this value is exceeded. Defaults to 80 to be consistent with default terminal width.

remove_parameter(name: str) None

Remove a Parameter from this instrument.

Unlike modifying the parameters dict directly, this method will make sure that the parameter is properly unbound from the instrument if the parameter is added as a real attribute to the instrument. If a property of the same name exists it will not be modified. If name is an attribute but not a parameter, it will not be modified.

Parameters:

name – The name of the parameter to remove.

Raises:

KeyError – If the parameter does not exist on the instrument.

property root_instrument: InstrumentBase

The topmost parent of this module.

For the root_instrument this is self.

set(param_name: str, value: Any) None

Shortcut for setting a parameter from its name and new value.

Parameters:
  • param_name – The name of a parameter of this instrument.

  • value – The new value to set.

property short_name: str

Short name of the instrument.

For an InstrumentModule this does not include any parent names.

snapshot(update: bool | None = False) dict[str, 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: bool | None = False, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None update the state if known to be invalid. If False, just use the latest values in memory and never update state.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters instead.

Returns:

base snapshot

Return type:

dict

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

The validation is done for all parameters that have both a get and set method.

Parameters:

verbose – If True, then information about the parameters that are being check is printed.

parameters: dict[str, ParameterBase] = {}

All the parameters supported by this instrument. Usually populated via add_parameter().

functions: dict[str, Function] = {}

All the functions supported by this instrument. Usually populated via add_function().

submodules: dict[str, InstrumentModule | ChannelTuple] = {}

All the submodules of this instrument such as channel lists or logical groupings of parameters. Usually populated via add_submodule().

instrument_modules: dict[str, InstrumentModule] = {}

All the InstrumentModule of this instrument Usually populated via add_submodule().

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
metadata: dict[str, Any] = {}
ask_raw(cmd: str) str[source]

Low level method to write to the hardware and return a response.

Subclasses that define a new hardware communication should override this method. Subclasses that transform cmd should instead override ask.

Parameters:

cmd – The string to send to the instrument.

class qcodes.instrument.InstrumentBase(name: str, metadata: Mapping[Any, Any] | None = None, label: str | None = None)[source]

Bases: MetadatableWithName, DelegateAttributes

Base class for all QCodes instruments and instrument channels

Parameters:
  • name – an identifier for this instrument, particularly for attaching it to a Station.

  • metadata – additional static metadata to add to this instrument’s JSON snapshot.

  • label – nicely formatted name of the instrument; if None, the name is used.

Attributes:

parameters

All the parameters supported by this instrument.

functions

All the functions supported by this instrument.

submodules

All the submodules of this instrument such as channel lists or logical groupings of parameters.

instrument_modules

All the InstrumentModule of this instrument Usually populated via add_submodule().

label

Nicely formatted label of the instrument.

parent

The parent instrument.

ancestors

Ancestors in the form of a list of InstrumentBase

root_instrument

The topmost parent of this module.

name_parts

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

full_name

Full name of the instrument.

name

Full name of the instrument

delegate_attr_objects

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

omit_delegate_attrs

A list of attribute names (strings) to not delegate to any other dictionary or object.

short_name

Short name of the instrument.

delegate_attr_dicts

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

Methods:

add_parameter(name[, parameter_class])

Bind one Parameter to this instrument.

remove_parameter(name)

Remove a Parameter from this instrument.

add_function(name, **kwargs)

Bind one Function to this instrument.

add_submodule(name, submodule)

Bind one submodule to this instrument.

get_component(full_name)

Recursively get a component of the instrument by full_name.

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

print_readable_snapshot([update, max_chars])

Prints a readable version of the snapshot.

invalidate_cache()

Invalidate the cache of all parameters on the instrument.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

snapshot([update])

Decorate a snapshot dictionary with metadata.

__getitem__(key)

Delegate instrument['name'] to parameter or function 'name'.

set(param_name, value)

Shortcut for setting a parameter from its name and new value.

get(param_name)

Shortcut for getting a parameter from its name.

call(func_name, *args)

Shortcut for calling a function from its name.

__getstate__()

Prevent pickling instruments, and give a nice error message.

validate_status([verbose])

Validate the values of all gettable parameters

parameters: dict[str, ParameterBase] = {}

All the parameters supported by this instrument. Usually populated via add_parameter().

functions: dict[str, Function] = {}

All the functions supported by this instrument. Usually populated via add_function().

submodules: dict[str, InstrumentModule | ChannelTuple] = {}

All the submodules of this instrument such as channel lists or logical groupings of parameters. Usually populated via add_submodule().

instrument_modules: dict[str, InstrumentModule] = {}

All the InstrumentModule of this instrument Usually populated via add_submodule().

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
property label: str

Nicely formatted label of the instrument.

add_parameter(name: str, parameter_class: type[TParameter] | None = None, **kwargs: Any) TParameter[source]

Bind one Parameter to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real parameter of the instrument.

In this sense, parameters are the state variables of the instrument, anything the user can set and/or get.

Parameters:
  • name – How the parameter will be stored within parameters and also how you address it using the shortcut methods: instrument.set(param_name, value) etc.

  • parameter_class – You can construct the parameter out of any class. Default parameters.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

Raises:
  • KeyError – If this instrument already has a parameter with this name and the parameter being replaced is not an abstract parameter.

  • ValueError – If there is an existing abstract parameter and the unit of the new parameter is inconsistent with the existing one.

remove_parameter(name: str) None[source]

Remove a Parameter from this instrument.

Unlike modifying the parameters dict directly, this method will make sure that the parameter is properly unbound from the instrument if the parameter is added as a real attribute to the instrument. If a property of the same name exists it will not be modified. If name is an attribute but not a parameter, it will not be modified.

Parameters:

name – The name of the parameter to remove.

Raises:

KeyError – If the parameter does not exist on the instrument.

add_function(name: str, **kwargs: Any) None[source]

Bind one Function to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real function of the instrument.

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only.

Note

We do not recommend the usage of Function for any new driver. Function does not add any significant features over a method defined on the class.

Parameters:
  • name – How the Function will be stored within instrument.Functions and also how you address it using the shortcut methods: instrument.call(func_name, *args) etc.

  • **kwargs – constructor kwargs for Function

Raises:

KeyError – If this instrument already has a function with this name.

add_submodule(name: str, submodule: InstrumentModule | ChannelTuple) None[source]

Bind one submodule to this instrument.

Instrument subclasses can call this repeatedly in their __init__ method for every submodule of the instrument.

Submodules can effectively be considered as instruments within the main instrument, and should at minimum be snapshottable. For example, they can be used to either store logical groupings of parameters, which may or may not be repeated, or channel lists. They should either be an instance of an InstrumentModule or a ChannelTuple.

Parameters:
  • name – How the submodule will be stored within instrument.submodules and also how it can be addressed.

  • submodule – The submodule to be stored.

Raises:
  • KeyError – If this instrument already contains a submodule with this name.

  • TypeError – If the submodule that we are trying to add is not an instance of an Metadatable object.

get_component(full_name: str) MetadatableWithName[source]

Recursively get a component of the instrument by full_name.

Parameters:

full_name – The name of the component to get.

Returns:

The component with the given name.

Raises:

KeyError – If the component does not exist.

snapshot_base(update: bool | None = False, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any][source]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None update the state if known to be invalid. If False, just use the latest values in memory and never update state.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters instead.

Returns:

base snapshot

Return type:

dict

print_readable_snapshot(update: bool = False, max_chars: int = 80) None[source]

Prints a readable version of the snapshot. The readable snapshot includes the name, value and unit of each parameter. A convenience function to quickly get an overview of the status of an instrument.

Parameters:
  • update – If True, update the state by querying the instrument. If False, just use the latest values in memory. This argument gets passed to the snapshot function.

  • max_chars – the maximum number of characters per line. The readable snapshot will be cropped if this value is exceeded. Defaults to 80 to be consistent with default terminal width.

invalidate_cache() None[source]

Invalidate the cache of all parameters on the instrument. Calling this method will recursively mark the cache of all parameters on the instrument and any parameter on instrument modules as invalid.

This is useful if you have performed manual operations (e.g. using the frontpanel) which changes the state of the instrument outside QCoDeS.

This in turn means that the next snapshot of the instrument will trigger a (potentially slow) reread of all parameters of the instrument if you pass update=None to snapshot.

property parent: InstrumentBase | None

The parent instrument. By default, this is None. Any SubInstrument should subclass this to return the parent instrument.

property ancestors: tuple[InstrumentBase, ...]

Ancestors in the form of a list of InstrumentBase

The list starts with the current module then the parent and the parents parent until the root instrument is reached.

property root_instrument: InstrumentBase

The topmost parent of this module.

For the root_instrument this is self.

property name_parts: list[str]

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

property full_name: str

Full name of the instrument.

For an InstrumentModule this includes all parents separated by _

property name: str

Full name of the instrument

This is equivalent to full_name() for backwards compatibility.

delegate_attr_objects: ClassVar[list[str]] = []

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

omit_delegate_attrs: ClassVar[list[str]] = []

A list of attribute names (strings) to not delegate to any other dictionary or object.

snapshot(update: bool | None = False) dict[str, 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.

metadata: dict[str, Any] = {}
property short_name: str

Short name of the instrument.

For an InstrumentModule this does not include any parent names.

delegate_attr_dicts: ClassVar[list[str]] = ['parameters', 'functions', 'submodules']

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

__getitem__(key: str) Callable[[...], Any] | Parameter[source]

Delegate instrument[‘name’] to parameter or function ‘name’.

set(param_name: str, value: Any) None[source]

Shortcut for setting a parameter from its name and new value.

Parameters:
  • param_name – The name of a parameter of this instrument.

  • value – The new value to set.

get(param_name: str) Any[source]

Shortcut for getting a parameter from its name.

Parameters:

param_name – The name of a parameter of this instrument.

Returns:

The current value of the parameter.

call(func_name: str, *args: Any) Any[source]

Shortcut for calling a function from its name.

Parameters:
  • func_name – The name of a function of this instrument.

  • *args – any arguments to the function.

Returns:

The return value of the function.

__getstate__() None[source]

Prevent pickling instruments, and give a nice error message.

validate_status(verbose: bool = False) None[source]

Validate the values of all gettable parameters

The validation is done for all parameters that have both a get and set method.

Parameters:

verbose – If True, then information about the parameters that are being check is printed.

class qcodes.instrument.InstrumentBaseKWArgs[source]

Bases: TypedDict

This TypedDict defines the type of the kwargs that can be passed to the InstrumentBase class. A subclass of VisaInstrument should take **kwargs: Unpack[InstrumentBaseKWArgs] as input and forward this to the super class to ensure that it can accept all the arguments defined here.

Attributes:

metadata

Additional static metadata to add to this instrument's JSON snapshot.

label

Nicely formatted name of the instrument; if None, the name is used.

Methods:

clear()

copy()

fromkeys([value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(k[,d])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

metadata: NotRequired[Mapping[Any, Any] | None]

Additional static metadata to add to this instrument’s JSON snapshot.

label: NotRequired[str | None]

Nicely formatted name of the instrument; if None, the name is used.

clear() None.  Remove all items from D.
copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
class qcodes.instrument.InstrumentChannel(parent: InstrumentBase, name: str, **kwargs: Unpack[InstrumentBaseKWArgs])[source]

Bases: InstrumentModule

Methods:

__getitem__(key)

Delegate instrument['name'] to parameter or function 'name'.

__getstate__()

Prevent pickling instruments, and give a nice error message.

__repr__()

Custom repr to give parent information

add_function(name, **kwargs)

Bind one Function to this instrument.

add_parameter(name[, parameter_class])

Bind one Parameter to this instrument.

add_submodule(name, submodule)

Bind one submodule to this instrument.

ask(cmd)

ask_raw(cmd)

call(func_name, *args)

Shortcut for calling a function from its name.

get(param_name)

Shortcut for getting a parameter from its name.

get_component(full_name)

Recursively get a component of the instrument by full_name.

invalidate_cache()

Invalidate the cache of all parameters on the instrument.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

print_readable_snapshot([update, max_chars])

Prints a readable version of the snapshot.

remove_parameter(name)

Remove a Parameter from this instrument.

set(param_name, value)

Shortcut for setting a parameter from its name and new value.

snapshot([update])

Decorate a snapshot dictionary with metadata.

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

validate_status([verbose])

Validate the values of all gettable parameters

write(cmd)

write_raw(cmd)

Attributes:

ancestors

Ancestors in the form of a list of InstrumentBase

delegate_attr_dicts

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

full_name

Full name of the instrument.

label

Nicely formatted label of the instrument.

name

Full name of the instrument

name_parts

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs

A list of attribute names (strings) to not delegate to any other dictionary or object.

parent

The parent instrument.

root_instrument

The topmost parent of this module.

short_name

Short name of the instrument.

parameters

All the parameters supported by this instrument.

functions

All the functions supported by this instrument.

submodules

All the submodules of this instrument such as channel lists or logical groupings of parameters.

instrument_modules

All the InstrumentModule of this instrument Usually populated via add_submodule().

log

metadata

__getitem__(key: str) Callable[[...], Any] | Parameter

Delegate instrument[‘name’] to parameter or function ‘name’.

__getstate__() None

Prevent pickling instruments, and give a nice error message.

__repr__() str

Custom repr to give parent information

add_function(name: str, **kwargs: Any) None

Bind one Function to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real function of the instrument.

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only.

Note

We do not recommend the usage of Function for any new driver. Function does not add any significant features over a method defined on the class.

Parameters:
  • name – How the Function will be stored within instrument.Functions and also how you address it using the shortcut methods: instrument.call(func_name, *args) etc.

  • **kwargs – constructor kwargs for Function

Raises:

KeyError – If this instrument already has a function with this name.

add_parameter(name: str, parameter_class: type[TParameter] | None = None, **kwargs: Any) TParameter

Bind one Parameter to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real parameter of the instrument.

In this sense, parameters are the state variables of the instrument, anything the user can set and/or get.

Parameters:
  • name – How the parameter will be stored within parameters and also how you address it using the shortcut methods: instrument.set(param_name, value) etc.

  • parameter_class – You can construct the parameter out of any class. Default parameters.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

Raises:
  • KeyError – If this instrument already has a parameter with this name and the parameter being replaced is not an abstract parameter.

  • ValueError – If there is an existing abstract parameter and the unit of the new parameter is inconsistent with the existing one.

add_submodule(name: str, submodule: InstrumentModule | ChannelTuple) None

Bind one submodule to this instrument.

Instrument subclasses can call this repeatedly in their __init__ method for every submodule of the instrument.

Submodules can effectively be considered as instruments within the main instrument, and should at minimum be snapshottable. For example, they can be used to either store logical groupings of parameters, which may or may not be repeated, or channel lists. They should either be an instance of an InstrumentModule or a ChannelTuple.

Parameters:
  • name – How the submodule will be stored within instrument.submodules and also how it can be addressed.

  • submodule – The submodule to be stored.

Raises:
  • KeyError – If this instrument already contains a submodule with this name.

  • TypeError – If the submodule that we are trying to add is not an instance of an Metadatable object.

property ancestors: tuple[InstrumentBase, ...]

Ancestors in the form of a list of InstrumentBase

The list starts with the current module then the parent and the parents parent until the root instrument is reached.

ask(cmd: str) str
ask_raw(cmd: str) str
call(func_name: str, *args: Any) Any

Shortcut for calling a function from its name.

Parameters:
  • func_name – The name of a function of this instrument.

  • *args – any arguments to the function.

Returns:

The return value of the function.

delegate_attr_dicts: ClassVar[list[str]] = ['parameters', 'functions', 'submodules']

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects: ClassVar[list[str]] = []

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

property full_name: str

Full name of the instrument.

For an InstrumentModule this includes all parents separated by _

get(param_name: str) Any

Shortcut for getting a parameter from its name.

Parameters:

param_name – The name of a parameter of this instrument.

Returns:

The current value of the parameter.

get_component(full_name: str) MetadatableWithName

Recursively get a component of the instrument by full_name.

Parameters:

full_name – The name of the component to get.

Returns:

The component with the given name.

Raises:

KeyError – If the component does not exist.

invalidate_cache() None

Invalidate the cache of all parameters on the instrument. Calling this method will recursively mark the cache of all parameters on the instrument and any parameter on instrument modules as invalid.

This is useful if you have performed manual operations (e.g. using the frontpanel) which changes the state of the instrument outside QCoDeS.

This in turn means that the next snapshot of the instrument will trigger a (potentially slow) reread of all parameters of the instrument if you pass update=None to snapshot.

property label: str

Nicely formatted label of the instrument.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

property name: str

Full name of the instrument

This is equivalent to full_name() for backwards compatibility.

property name_parts: list[str]

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs: ClassVar[list[str]] = []

A list of attribute names (strings) to not delegate to any other dictionary or object.

property parent: InstrumentBase

The parent instrument. By default, this is None. Any SubInstrument should subclass this to return the parent instrument.

print_readable_snapshot(update: bool = False, max_chars: int = 80) None

Prints a readable version of the snapshot. The readable snapshot includes the name, value and unit of each parameter. A convenience function to quickly get an overview of the status of an instrument.

Parameters:
  • update – If True, update the state by querying the instrument. If False, just use the latest values in memory. This argument gets passed to the snapshot function.

  • max_chars – the maximum number of characters per line. The readable snapshot will be cropped if this value is exceeded. Defaults to 80 to be consistent with default terminal width.

remove_parameter(name: str) None

Remove a Parameter from this instrument.

Unlike modifying the parameters dict directly, this method will make sure that the parameter is properly unbound from the instrument if the parameter is added as a real attribute to the instrument. If a property of the same name exists it will not be modified. If name is an attribute but not a parameter, it will not be modified.

Parameters:

name – The name of the parameter to remove.

Raises:

KeyError – If the parameter does not exist on the instrument.

property root_instrument: InstrumentBase

The topmost parent of this module.

For the root_instrument this is self.

set(param_name: str, value: Any) None

Shortcut for setting a parameter from its name and new value.

Parameters:
  • param_name – The name of a parameter of this instrument.

  • value – The new value to set.

property short_name: str

Short name of the instrument.

For an InstrumentModule this does not include any parent names.

snapshot(update: bool | None = False) dict[str, 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: bool | None = False, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None update the state if known to be invalid. If False, just use the latest values in memory and never update state.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters instead.

Returns:

base snapshot

Return type:

dict

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

The validation is done for all parameters that have both a get and set method.

Parameters:

verbose – If True, then information about the parameters that are being check is printed.

write(cmd: str) None
write_raw(cmd: str) None
parameters: dict[str, ParameterBase] = {}

All the parameters supported by this instrument. Usually populated via add_parameter().

functions: dict[str, Function] = {}

All the functions supported by this instrument. Usually populated via add_function().

submodules: dict[str, InstrumentModule | ChannelTuple] = {}

All the submodules of this instrument such as channel lists or logical groupings of parameters. Usually populated via add_submodule().

instrument_modules: dict[str, InstrumentModule] = {}

All the InstrumentModule of this instrument Usually populated via add_submodule().

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
metadata: dict[str, Any] = {}
class qcodes.instrument.InstrumentModule(parent: InstrumentBase, name: str, **kwargs: Unpack[InstrumentBaseKWArgs])[source]

Bases: InstrumentBase

Base class for a module in an instrument. This could be in the form of a channel (e.g. something that the instrument has multiple instances of) or another logical grouping of parameters that you wish to group together separate from the rest of the instrument.

Parameters:
  • parent – The instrument to which this module should be attached.

  • name – The name of this module.

  • **kwargs – Forwarded to the base class.

Methods:

__repr__()

Custom repr to give parent information

write(cmd)

write_raw(cmd)

ask(cmd)

ask_raw(cmd)

__getitem__(key)

Delegate instrument['name'] to parameter or function 'name'.

__getstate__()

Prevent pickling instruments, and give a nice error message.

add_function(name, **kwargs)

Bind one Function to this instrument.

add_parameter(name[, parameter_class])

Bind one Parameter to this instrument.

add_submodule(name, submodule)

Bind one submodule to this instrument.

call(func_name, *args)

Shortcut for calling a function from its name.

get(param_name)

Shortcut for getting a parameter from its name.

get_component(full_name)

Recursively get a component of the instrument by full_name.

invalidate_cache()

Invalidate the cache of all parameters on the instrument.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

print_readable_snapshot([update, max_chars])

Prints a readable version of the snapshot.

remove_parameter(name)

Remove a Parameter from this instrument.

set(param_name, value)

Shortcut for setting a parameter from its name and new value.

snapshot([update])

Decorate a snapshot dictionary with metadata.

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

validate_status([verbose])

Validate the values of all gettable parameters

Attributes:

parent

The parent instrument.

root_instrument

The topmost parent of this module.

name_parts

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

ancestors

Ancestors in the form of a list of InstrumentBase

delegate_attr_dicts

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

full_name

Full name of the instrument.

label

Nicely formatted label of the instrument.

name

Full name of the instrument

omit_delegate_attrs

A list of attribute names (strings) to not delegate to any other dictionary or object.

short_name

Short name of the instrument.

parameters

All the parameters supported by this instrument.

functions

All the functions supported by this instrument.

submodules

All the submodules of this instrument such as channel lists or logical groupings of parameters.

instrument_modules

All the InstrumentModule of this instrument Usually populated via add_submodule().

log

metadata

__repr__() str[source]

Custom repr to give parent information

write(cmd: str) None[source]
write_raw(cmd: str) None[source]
ask(cmd: str) str[source]
ask_raw(cmd: str) str[source]
property parent: InstrumentBase

The parent instrument. By default, this is None. Any SubInstrument should subclass this to return the parent instrument.

property root_instrument: InstrumentBase

The topmost parent of this module.

For the root_instrument this is self.

property name_parts: list[str]

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

__getitem__(key: str) Callable[[...], Any] | Parameter

Delegate instrument[‘name’] to parameter or function ‘name’.

__getstate__() None

Prevent pickling instruments, and give a nice error message.

add_function(name: str, **kwargs: Any) None

Bind one Function to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real function of the instrument.

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only.

Note

We do not recommend the usage of Function for any new driver. Function does not add any significant features over a method defined on the class.

Parameters:
  • name – How the Function will be stored within instrument.Functions and also how you address it using the shortcut methods: instrument.call(func_name, *args) etc.

  • **kwargs – constructor kwargs for Function

Raises:

KeyError – If this instrument already has a function with this name.

add_parameter(name: str, parameter_class: type[TParameter] | None = None, **kwargs: Any) TParameter

Bind one Parameter to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real parameter of the instrument.

In this sense, parameters are the state variables of the instrument, anything the user can set and/or get.

Parameters:
  • name – How the parameter will be stored within parameters and also how you address it using the shortcut methods: instrument.set(param_name, value) etc.

  • parameter_class – You can construct the parameter out of any class. Default parameters.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

Raises:
  • KeyError – If this instrument already has a parameter with this name and the parameter being replaced is not an abstract parameter.

  • ValueError – If there is an existing abstract parameter and the unit of the new parameter is inconsistent with the existing one.

add_submodule(name: str, submodule: InstrumentModule | ChannelTuple) None

Bind one submodule to this instrument.

Instrument subclasses can call this repeatedly in their __init__ method for every submodule of the instrument.

Submodules can effectively be considered as instruments within the main instrument, and should at minimum be snapshottable. For example, they can be used to either store logical groupings of parameters, which may or may not be repeated, or channel lists. They should either be an instance of an InstrumentModule or a ChannelTuple.

Parameters:
  • name – How the submodule will be stored within instrument.submodules and also how it can be addressed.

  • submodule – The submodule to be stored.

Raises:
  • KeyError – If this instrument already contains a submodule with this name.

  • TypeError – If the submodule that we are trying to add is not an instance of an Metadatable object.

property ancestors: tuple[InstrumentBase, ...]

Ancestors in the form of a list of InstrumentBase

The list starts with the current module then the parent and the parents parent until the root instrument is reached.

call(func_name: str, *args: Any) Any

Shortcut for calling a function from its name.

Parameters:
  • func_name – The name of a function of this instrument.

  • *args – any arguments to the function.

Returns:

The return value of the function.

delegate_attr_dicts: ClassVar[list[str]] = ['parameters', 'functions', 'submodules']

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects: ClassVar[list[str]] = []

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

property full_name: str

Full name of the instrument.

For an InstrumentModule this includes all parents separated by _

get(param_name: str) Any

Shortcut for getting a parameter from its name.

Parameters:

param_name – The name of a parameter of this instrument.

Returns:

The current value of the parameter.

get_component(full_name: str) MetadatableWithName

Recursively get a component of the instrument by full_name.

Parameters:

full_name – The name of the component to get.

Returns:

The component with the given name.

Raises:

KeyError – If the component does not exist.

invalidate_cache() None

Invalidate the cache of all parameters on the instrument. Calling this method will recursively mark the cache of all parameters on the instrument and any parameter on instrument modules as invalid.

This is useful if you have performed manual operations (e.g. using the frontpanel) which changes the state of the instrument outside QCoDeS.

This in turn means that the next snapshot of the instrument will trigger a (potentially slow) reread of all parameters of the instrument if you pass update=None to snapshot.

property label: str

Nicely formatted label of the instrument.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

property name: str

Full name of the instrument

This is equivalent to full_name() for backwards compatibility.

omit_delegate_attrs: ClassVar[list[str]] = []

A list of attribute names (strings) to not delegate to any other dictionary or object.

print_readable_snapshot(update: bool = False, max_chars: int = 80) None

Prints a readable version of the snapshot. The readable snapshot includes the name, value and unit of each parameter. A convenience function to quickly get an overview of the status of an instrument.

Parameters:
  • update – If True, update the state by querying the instrument. If False, just use the latest values in memory. This argument gets passed to the snapshot function.

  • max_chars – the maximum number of characters per line. The readable snapshot will be cropped if this value is exceeded. Defaults to 80 to be consistent with default terminal width.

remove_parameter(name: str) None

Remove a Parameter from this instrument.

Unlike modifying the parameters dict directly, this method will make sure that the parameter is properly unbound from the instrument if the parameter is added as a real attribute to the instrument. If a property of the same name exists it will not be modified. If name is an attribute but not a parameter, it will not be modified.

Parameters:

name – The name of the parameter to remove.

Raises:

KeyError – If the parameter does not exist on the instrument.

set(param_name: str, value: Any) None

Shortcut for setting a parameter from its name and new value.

Parameters:
  • param_name – The name of a parameter of this instrument.

  • value – The new value to set.

property short_name: str

Short name of the instrument.

For an InstrumentModule this does not include any parent names.

snapshot(update: bool | None = False) dict[str, 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: bool | None = False, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None update the state if known to be invalid. If False, just use the latest values in memory and never update state.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters instead.

Returns:

base snapshot

Return type:

dict

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

The validation is done for all parameters that have both a get and set method.

Parameters:

verbose – If True, then information about the parameters that are being check is printed.

parameters: dict[str, ParameterBase] = {}

All the parameters supported by this instrument. Usually populated via add_parameter().

functions: dict[str, Function] = {}

All the functions supported by this instrument. Usually populated via add_function().

submodules: dict[str, InstrumentModule | ChannelTuple] = {}

All the submodules of this instrument such as channel lists or logical groupings of parameters. Usually populated via add_submodule().

instrument_modules: dict[str, InstrumentModule] = {}

All the InstrumentModule of this instrument Usually populated via add_submodule().

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
metadata: dict[str, Any] = {}
class qcodes.instrument.VisaInstrument(name: str, address: str, timeout: float | None | Literal['Unset'] = 'Unset', terminator: str | None | Literal['Unset'] = 'Unset', device_clear: bool = True, visalib: str | None = None, pyvisa_sim_file: str | None = None, **kwargs: Unpack[InstrumentBaseKWArgs])[source]

Bases: Instrument

Base class for all instruments using visa connections.

Parameters:
  • name – What this instrument is called locally.

  • address – The visa resource name to use to connect.

  • timeout – seconds to allow for responses. If “unset” will read the value from self.default_timeout. None means wait forever. Default 5.

  • terminator – Read and write termination character(s). If unset will use self.default_terminator. If None the terminator will not be set and we rely on the defaults from PyVisa. Default None.

  • device_clear – Perform a device clear. Default True.

  • visalib – Visa backend to use when connecting to this instrument. This should be in the form of a string ‘<pathtofile>@<backend>’. Both parts can be omitted and pyvisa will try to infer the path to the visa backend file. By default the IVI backend is used if found, but @py’ will use the pyvisa-py backend. Note that QCoDeS does not install (or even require) ANY backends, it is up to the user to do that. see eg: http://pyvisa.readthedocs.org/en/stable/names.html

  • metadata – additional static metadata to add to this instrument’s JSON snapshot.

  • pyvisa_sim_file – Name of a pyvisa-sim yaml file used to simulate the instrument. The file is expected to be loaded from a python module. The file can be given either as only the file name in which case it is loaded from qcodes.instruments.sims or in the format module:filename e.g. qcodes.instruments.sims:AimTTi_PL601P.yaml in which case it is loaded from the supplied module. Note that it is an error to pass both pyvisa_sim_file and visalib.

  • **kwargs – Other kwargs are forwarded to the baseclass.

See help for Instrument for additional information on writing instrument subclasses.

Attributes:

default_terminator

The default terminator to use if the terminator is not specified when creating the instrument.

default_timeout

The default timeout in seconds if the timeout is not specified when creating the instrument.

visa_handle

The VISA resource used by this instrument.

resource_manager

The VISA resource manager used by this instrument.

ancestors

Ancestors in the form of a list of InstrumentBase

delegate_attr_dicts

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

full_name

Full name of the instrument.

label

Nicely formatted label of the instrument.

name

Full name of the instrument

name_parts

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs

A list of attribute names (strings) to not delegate to any other dictionary or object.

parent

The parent instrument.

root_instrument

The topmost parent of this module.

short_name

Short name of the instrument.

parameters

All the parameters supported by this instrument.

functions

All the functions supported by this instrument.

submodules

All the submodules of this instrument such as channel lists or logical groupings of parameters.

instrument_modules

All the InstrumentModule of this instrument Usually populated via add_submodule().

log

metadata

Methods:

__del__()

Close the instrument and remove its instance record.

__getitem__(key)

Delegate instrument['name'] to parameter or function 'name'.

__getstate__()

Prevent pickling instruments, and give a nice error message.

__repr__()

Simplified repr giving just the class and name.

add_function(name, **kwargs)

Bind one Function to this instrument.

add_parameter(name[, parameter_class])

Bind one Parameter to this instrument.

add_submodule(name, submodule)

Bind one submodule to this instrument.

ask(cmd)

Write a command string to the hardware and return a response.

call(func_name, *args)

Shortcut for calling a function from its name.

close_all()

Try to close all instruments registered in _all_instruments This is handy for use with atexit to ensure that all instruments are closed when a python session is closed.

connect_message([idn_param, begin_time])

Print a standard message on initial connection to an instrument.

exist(name[, instrument_class])

Check if an instrument with a given names exists (i.e. is already instantiated).

find_instrument(name[, instrument_class])

Find an existing instrument by name.

get(param_name)

Shortcut for getting a parameter from its name.

get_component(full_name)

Recursively get a component of the instrument by full_name.

get_idn()

Parse a standard VISA *IDN? response into an ID dict.

instances()

Get all currently defined instances of this instrument class.

invalidate_cache()

Invalidate the cache of all parameters on the instrument.

is_valid(instr_instance)

Check if a given instance of an instrument is valid: if an instrument has been closed, its instance is not longer a "valid" instrument.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

print_readable_snapshot([update, max_chars])

Prints a readable version of the snapshot.

record_instance(instance)

Record (a weak ref to) an instance in a class's instance list.

remove_instance(instance)

Remove a particular instance from the record.

remove_parameter(name)

Remove a Parameter from this instrument.

set(param_name, value)

Shortcut for setting a parameter from its name and new value.

snapshot([update])

Decorate a snapshot dictionary with metadata.

validate_status([verbose])

Validate the values of all gettable parameters

write(cmd)

Write a command string with NO response to the hardware.

set_address(address)

Set the address for this instrument.

device_clear()

Clear the buffers of the device

set_terminator(terminator)

Change the read terminator to use.

close()

Disconnect and irreversibly tear down the instrument.

write_raw(cmd)

Low-level interface to visa_handle.write.

ask_raw(cmd)

Low-level interface to visa_handle.ask.

snapshot_base([update, params_to_skip_update])

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

default_terminator: str | None = None

The default terminator to use if the terminator is not specified when creating the instrument. None means use the default terminator from PyVisa.

default_timeout: float | None = 5

The default timeout in seconds if the timeout is not specified when creating the instrument. None means no timeout e.g. wait forever.

visabackend: str = visabackend
visa_handle: pyvisa.resources.MessageBasedResource = visa_handle

The VISA resource used by this instrument.

resource_manager = resource_manager

The VISA resource manager used by this instrument.

visalib: str | None = visalib
__del__() None

Close the instrument and remove its instance record.

__getitem__(key: str) Callable[[...], Any] | Parameter

Delegate instrument[‘name’] to parameter or function ‘name’.

__getstate__() None

Prevent pickling instruments, and give a nice error message.

__repr__() str

Simplified repr giving just the class and name.

add_function(name: str, **kwargs: Any) None

Bind one Function to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real function of the instrument.

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only.

Note

We do not recommend the usage of Function for any new driver. Function does not add any significant features over a method defined on the class.

Parameters:
  • name – How the Function will be stored within instrument.Functions and also how you address it using the shortcut methods: instrument.call(func_name, *args) etc.

  • **kwargs – constructor kwargs for Function

Raises:

KeyError – If this instrument already has a function with this name.

add_parameter(name: str, parameter_class: type[TParameter] | None = None, **kwargs: Any) TParameter

Bind one Parameter to this instrument.

Instrument subclasses can call this repeatedly in their __init__ for every real parameter of the instrument.

In this sense, parameters are the state variables of the instrument, anything the user can set and/or get.

Parameters:
  • name – How the parameter will be stored within parameters and also how you address it using the shortcut methods: instrument.set(param_name, value) etc.

  • parameter_class – You can construct the parameter out of any class. Default parameters.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

Raises:
  • KeyError – If this instrument already has a parameter with this name and the parameter being replaced is not an abstract parameter.

  • ValueError – If there is an existing abstract parameter and the unit of the new parameter is inconsistent with the existing one.

add_submodule(name: str, submodule: InstrumentModule | ChannelTuple) None

Bind one submodule to this instrument.

Instrument subclasses can call this repeatedly in their __init__ method for every submodule of the instrument.

Submodules can effectively be considered as instruments within the main instrument, and should at minimum be snapshottable. For example, they can be used to either store logical groupings of parameters, which may or may not be repeated, or channel lists. They should either be an instance of an InstrumentModule or a ChannelTuple.

Parameters:
  • name – How the submodule will be stored within instrument.submodules and also how it can be addressed.

  • submodule – The submodule to be stored.

Raises:
  • KeyError – If this instrument already contains a submodule with this name.

  • TypeError – If the submodule that we are trying to add is not an instance of an Metadatable object.

property ancestors: tuple[InstrumentBase, ...]

Ancestors in the form of a list of InstrumentBase

The list starts with the current module then the parent and the parents parent until the root instrument is reached.

ask(cmd: str) str

Write a command string to the hardware and return a response.

Subclasses that transform cmd should override this method, and in it call super().ask(new_cmd). Subclasses that define a new hardware communication should instead override ask_raw.

Parameters:

cmd – The string to send to the instrument.

Returns:

response

Raises:

Exception – Wraps any underlying exception with extra context, including the command and the instrument.

call(func_name: str, *args: Any) Any

Shortcut for calling a function from its name.

Parameters:
  • func_name – The name of a function of this instrument.

  • *args – any arguments to the function.

Returns:

The return value of the function.

classmethod close_all() None

Try to close all instruments registered in _all_instruments This is handy for use with atexit to ensure that all instruments are closed when a python session is closed.

Examples

>>> atexit.register(qc.Instrument.close_all())
connect_message(idn_param: str = 'IDN', begin_time: float | None = None) None

Print a standard message on initial connection to an instrument.

Parameters:
  • idn_param – Name of parameter that returns ID dict. Default IDN.

  • begin_timetime.time() when init started. Default is self._t0, set at start of Instrument.__init__.

delegate_attr_dicts: ClassVar[list[str]] = ['parameters', 'functions', 'submodules']

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

delegate_attr_objects: ClassVar[list[str]] = []

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

static exist(name: str, instrument_class: type[Instrument] | None = None) bool

Check if an instrument with a given names exists (i.e. is already instantiated).

Parameters:
  • name – Name of the instrument.

  • instrument_class – The type of instrument you are looking for.

classmethod find_instrument(name: str, instrument_class: type[T] | None = None) T | Instrument

Find an existing instrument by name.

Parameters:
  • name – Name of the instrument.

  • instrument_class – The type of instrument you are looking for.

Returns:

The instrument found.

Raises:
  • KeyError – If no instrument of that name was found, or if its reference is invalid (dead).

  • TypeError – If a specific class was requested but a different type was found.

property full_name: str

Full name of the instrument.

For an InstrumentModule this includes all parents separated by _

get(param_name: str) Any

Shortcut for getting a parameter from its name.

Parameters:

param_name – The name of a parameter of this instrument.

Returns:

The current value of the parameter.

get_component(full_name: str) MetadatableWithName

Recursively get a component of the instrument by full_name.

Parameters:

full_name – The name of the component to get.

Returns:

The component with the given name.

Raises:

KeyError – If the component does not exist.

get_idn() dict[str, str | None]

Parse a standard VISA *IDN? response into an ID dict.

Even though this is the VISA standard, it applies to various other types as well, such as IPInstruments, so it is included here in the Instrument base class.

Override this if your instrument does not support *IDN? or returns a nonstandard IDN string. This string is supposed to be a comma-separated list of vendor, model, serial, and firmware, but semicolon and colon are also common separators so we accept them here as well.

Returns:

A dict containing vendor, model, serial, and firmware.

classmethod instances() list[T]

Get all currently defined instances of this instrument class.

You can use this to get the objects back if you lose track of them, and it’s also used by the test system to find objects to test against.

Returns:

A list of instances.

invalidate_cache() None

Invalidate the cache of all parameters on the instrument. Calling this method will recursively mark the cache of all parameters on the instrument and any parameter on instrument modules as invalid.

This is useful if you have performed manual operations (e.g. using the frontpanel) which changes the state of the instrument outside QCoDeS.

This in turn means that the next snapshot of the instrument will trigger a (potentially slow) reread of all parameters of the instrument if you pass update=None to snapshot.

static is_valid(instr_instance: Instrument) bool

Check if a given instance of an instrument is valid: if an instrument has been closed, its instance is not longer a “valid” instrument.

Parameters:

instr_instance – Instance of an Instrument class or its subclass.

property label: str

Nicely formatted label of the instrument.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

property name: str

Full name of the instrument

This is equivalent to full_name() for backwards compatibility.

property name_parts: list[str]

A list of all the parts of the instrument name from root_instrument() to the current InstrumentModule.

omit_delegate_attrs: ClassVar[list[str]] = []

A list of attribute names (strings) to not delegate to any other dictionary or object.

property parent: InstrumentBase | None

The parent instrument. By default, this is None. Any SubInstrument should subclass this to return the parent instrument.

print_readable_snapshot(update: bool = False, max_chars: int = 80) None

Prints a readable version of the snapshot. The readable snapshot includes the name, value and unit of each parameter. A convenience function to quickly get an overview of the status of an instrument.

Parameters:
  • update – If True, update the state by querying the instrument. If False, just use the latest values in memory. This argument gets passed to the snapshot function.

  • max_chars – the maximum number of characters per line. The readable snapshot will be cropped if this value is exceeded. Defaults to 80 to be consistent with default terminal width.

classmethod record_instance(instance: Instrument) None

Record (a weak ref to) an instance in a class’s instance list.

Also records the instance in list of all instruments, and verifies that there are no other instruments with the same name.

This method is called after initialization of the instrument is completed.

Parameters:

instance – Instance to record.

Raises:

KeyError – If another instance with the same name is already present.

classmethod remove_instance(instance: Instrument) None

Remove a particular instance from the record.

Parameters:

instance – The instance to remove

remove_parameter(name: str) None

Remove a Parameter from this instrument.

Unlike modifying the parameters dict directly, this method will make sure that the parameter is properly unbound from the instrument if the parameter is added as a real attribute to the instrument. If a property of the same name exists it will not be modified. If name is an attribute but not a parameter, it will not be modified.

Parameters:

name – The name of the parameter to remove.

Raises:

KeyError – If the parameter does not exist on the instrument.

property root_instrument: InstrumentBase

The topmost parent of this module.

For the root_instrument this is self.

set(param_name: str, value: Any) None

Shortcut for setting a parameter from its name and new value.

Parameters:
  • param_name – The name of a parameter of this instrument.

  • value – The new value to set.

property short_name: str

Short name of the instrument.

For an InstrumentModule this does not include any parent names.

snapshot(update: bool | None = False) dict[str, 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.

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

The validation is done for all parameters that have both a get and set method.

Parameters:

verbose – If True, then information about the parameters that are being check is printed.

write(cmd: str) None

Write a command string with NO response to the hardware.

Subclasses that transform cmd should override this method, and in it call super().write(new_cmd). Subclasses that define a new hardware communication should instead override write_raw.

Parameters:

cmd – The string to send to the instrument.

Raises:

Exception – Wraps any underlying exception with extra context, including the command and the instrument.

parameters: dict[str, ParameterBase] = {}

All the parameters supported by this instrument. Usually populated via add_parameter().

functions: dict[str, Function] = {}

All the functions supported by this instrument. Usually populated via add_function().

submodules: dict[str, InstrumentModule | ChannelTuple] = {}

All the submodules of this instrument such as channel lists or logical groupings of parameters. Usually populated via add_submodule().

instrument_modules: dict[str, InstrumentModule] = {}

All the InstrumentModule of this instrument Usually populated via add_submodule().

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
metadata: dict[str, Any] = {}
set_address(address: str) None[source]

Set the address for this instrument.

Parameters:

address – The visa resource name to use to connect. The address should be the actual address and just that. If you wish to change the backend for VISA, use the self.visalib attribute (and then call this function).

device_clear() None[source]

Clear the buffers of the device

set_terminator(terminator: str | None) None[source]

Change the read terminator to use.

Parameters:

terminator – Character(s) to look for at the end of a read and to end each write command with. eg. \r\n. If None the terminator will not be set.

close() None[source]

Disconnect and irreversibly tear down the instrument.

write_raw(cmd: str) None[source]

Low-level interface to visa_handle.write.

Parameters:

cmd – The command to send to the instrument.

ask_raw(cmd: str) str[source]

Low-level interface to visa_handle.ask.

Parameters:

cmd – The command to send to the instrument.

Returns:

The instrument’s response.

Return type:

str

snapshot_base(update: bool | None = True, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any][source]

State of the instrument as a JSON-compatible dict (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Parameters:
  • update – If True, update the state by querying the instrument. If None only update if the state is known to be invalid. If False, just use the latest values in memory and never update.

  • params_to_skip_update – List of parameter names that will be skipped in update even if update is True. This is useful if you have parameters that are slow to update but can be updated in a different way (as in the qdac). If you want to skip the update of certain parameters in all snapshots, use the snapshot_get attribute of those parameters instead.

Returns:

base snapshot

Return type:

dict

class qcodes.instrument.VisaInstrumentKWArgs[source]

Bases: TypedDict

This TypedDict defines the type of the kwargs that can be passed to the VisaInstrument class. A subclass of VisaInstrument should take **kwargs: Unpack[VisaInstrumentKWArgs] as input and forward this to the super class to ensure that it can accept all the arguments defined here.

Consult the documentation of VisaInstrument for more information on the arguments.

Attributes:

metadata

Additional static metadata to add to this instrument's JSON snapshot.

label

Nicely formatted name of the instrument; if None, the name is used.

terminator

Read and write termination character(s).

timeout

Seconds to allow for responses.

device_clear

Perform a device clear.

visalib

Visa backend to use when connecting to this instrument.

pyvisa_sim_file

Name of a pyvisa-sim yaml file used to simulate the instrument.

Methods:

clear()

copy()

fromkeys([value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(k[,d])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

metadata: NotRequired[Mapping[Any, Any] | None]

Additional static metadata to add to this instrument’s JSON snapshot.

label: NotRequired[str | None]

Nicely formatted name of the instrument; if None, the name is used.

terminator: NotRequired[str | None]

Read and write termination character(s).

timeout: NotRequired[float]

Seconds to allow for responses.

device_clear: NotRequired[bool]

Perform a device clear.

visalib: NotRequired[str | None]

Visa backend to use when connecting to this instrument.

pyvisa_sim_file: NotRequired[str | None]

Name of a pyvisa-sim yaml file used to simulate the instrument.

clear() None.  Remove all items from D.
copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
qcodes.instrument.find_or_create_instrument(instrument_class: type[T], name: str, *args: Any, recreate: bool = False, **kwargs: Any) T[source]

Find an instrument with the given name of a given class, or create one if it is not found. In case the instrument was found, and recreate is True, the instrument will be re-instantiated.

Note that the class of the existing instrument has to be equal to the instrument class of interest. For example, if an instrument with the same name but of a different class exists, the function will raise an exception.

This function is very convenient because it allows not to bother about which instruments are already instantiated and which are not.

If an instrument is found, a connection message is printed, as if the instrument has just been instantiated.

Parameters:
  • instrument_class – Class of the instrument to find or create.

  • name – Name of the instrument to find or create.

  • *args – Positional arguments passed to the instrument class.

  • recreate – When True, the instruments gets recreated if it is found.

  • **kwargs – Keyword arguments passed to the instrument class.

Returns:

The found or created instrument.