qcodes.instrument
- class qcodes.instrument.ChannelList(parent: InstrumentBase, name: str, chan_type: Type[InstrumentModuleType], chan_list: Optional[Sequence[InstrumentModuleType]] = None, snapshotable: bool = True, multichan_paramclass: Optional[Type[MultiChannelInstrumentParameter]] = 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 theto_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 theChannelList
.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 ofChannelList
. Should be a subclass ofMultiChannelInstrumentParameter
. Defaults toMultiChannelInstrumentParameter
if None.
- Raises
ValueError – If
chan_type
is not a subclass ofInstrumentChannel
ValueError – If
multichan_paramclass
is not a subclass ofMultiChannelInstrumentParameter
(note that a class is a subclass of itself).
- 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.
- 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) Union[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: Union[int, slice, Tuple[int, ...]]) Union[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.
- get_channel_by_name(*names: str) Union[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.
- load_metadata(metadata: Mapping[str, Any]) None
Load metadata into this classes metadata dictionary.
- Parameters
metadata – Metadata to load.
- pop([index]) item -- remove and return item at index (default last).
Raise IndexError if list is empty or index is out of range.
- reverse()
S.reverse() – reverse IN PLACE
- snapshot(update: Optional[bool] = False) Dict[Any, Any]
Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override
snapshot_base()
.- Parameters
update – Passed to snapshot_base.
- Returns
Base snapshot.
- snapshot_base(update: Optional[bool] = True, params_to_skip_update: Optional[Sequence[str]] = None) Dict[Any, Any]
State of the 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
- class qcodes.instrument.ChannelTuple(parent: InstrumentBase, name: str, chan_type: Type[InstrumentModuleType], chan_list: Optional[Sequence[InstrumentModuleType]] = None, snapshotable: bool = True, multichan_paramclass: Optional[Type[MultiChannelInstrumentParameter]] = None)[source]
Bases:
Metadatable
,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 ofChannelTuple
. Should be a subclass ofMultiChannelInstrumentParameter
. Defaults toMultiChannelInstrumentParameter
if None.
- Raises
ValueError – If
chan_type
is not a subclass ofInstrumentChannel
ValueError – If
multichan_paramclass
is not a subclass ofMultiChannelInstrumentParameter
(note that a class is a subclass of itself).
- __getitem__(i: int) InstrumentModuleType [source]
- __getitem__(i: Union[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.
- 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) Union[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: Optional[bool] = True, params_to_skip_update: Optional[Sequence[str]] = 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
- __getattr__(name: str) Union[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.
- class qcodes.instrument.IPInstrument(*args: Any, **kwargs: Any)[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 – additional static metadata to add to this instrument’s JSON snapshot.
See help for
qcodes.Instrument
for additional information on writing instrument subclasses.- set_address(address: Optional[str] = None, port: Optional[int] = 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.
- 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’.
- 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: Optional[bool] = False, params_to_skip_update: Optional[Sequence[str]] = 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
- __getitem__(key: str) Union[Callable[[...], Any], Parameter]
Delegate instrument[‘name’] to parameter or function ‘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. If your case is more complicated, you’re probably better off simply making a new method in yourInstrument
subclass definition.- 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: Optional[Type[ParameterBase]] = None, **kwargs: Any) None
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: Union[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 aChannelTuple
.- 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
- property ancestors: List[qcodes.instrument.instrument_base.InstrumentBase]
Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument 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 callsuper().ask(new_cmd)
. Subclasses that define a new hardware communication should instead overrideask_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: Optional[float] = 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__init__
.
- delegate_attr_dicts: 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 ofself
.
- delegate_attr_objects: List[str] = []
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.
- static exist(name: str, instrument_class: Optional[type] = 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: Optional[Type[T]] = None) 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
- 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_idn() Dict[str, Optional[str]]
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[Instrument]
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.
- load_metadata(metadata: Mapping[str, Any]) None
Load metadata into this classes metadata dictionary.
- Parameters
metadata – Metadata to load.
- property name: str
Name of the instrument This is equivalent to full_name for backwards compatibility.
- omit_delegate_attrs: List[str] = []
A list of attribute names (strings) to not delegate to any other dictionary or object.
- property parent: Optional[qcodes.instrument.instrument_base.InstrumentBase]
Returns 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. IfFalse
, 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
- property root_instrument: qcodes.instrument.instrument_base.InstrumentBase
- 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.
- snapshot(update: Optional[bool] = False) Dict[Any, Any]
Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override
snapshot_base()
.- Parameters
update – Passed to snapshot_base.
- Returns
Base snapshot.
- 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 callsuper().write(new_cmd)
. Subclasses that define a new hardware communication should instead overridewrite_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, Union['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 viaadd_submodule()
.
- class qcodes.instrument.Instrument(*args: Any, **kwargs: Any)[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.
- get_idn() Dict[str, Optional[str]] [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: Optional[float] = 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__init__
.
- 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[Instrument] [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: Optional[Type[T]] = None) T [source]
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
- static exist(name: str, instrument_class: Optional[type] = 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 callsuper().write(new_cmd)
. Subclasses that define a new hardware communication should instead overridewrite_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 overridewrite
.- Parameters
cmd – The string to send to the instrument.
- 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 callsuper().ask(new_cmd)
. Subclasses that define a new hardware communication should instead overrideask_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.
- 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 overrideask
.- Parameters
cmd – The string to send to the instrument.
- __getitem__(key: str) Union[Callable[[...], Any], Parameter]
Delegate instrument[‘name’] to parameter or function ‘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. If your case is more complicated, you’re probably better off simply making a new method in yourInstrument
subclass definition.- 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: Optional[Type[ParameterBase]] = None, **kwargs: Any) None
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: Union[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 aChannelTuple
.- 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
- property ancestors: List[qcodes.instrument.instrument_base.InstrumentBase]
Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument 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: 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 ofself
.
- delegate_attr_objects: List[str] = []
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.
- 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.
- 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.
- load_metadata(metadata: Mapping[str, Any]) None
Load metadata into this classes metadata dictionary.
- Parameters
metadata – Metadata to load.
- property name: str
Name of the instrument This is equivalent to full_name for backwards compatibility.
- omit_delegate_attrs: List[str] = []
A list of attribute names (strings) to not delegate to any other dictionary or object.
- property parent: Optional[qcodes.instrument.instrument_base.InstrumentBase]
Returns 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. IfFalse
, 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.
- property root_instrument: qcodes.instrument.instrument_base.InstrumentBase
- 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.
- snapshot(update: Optional[bool] = False) Dict[Any, Any]
Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override
snapshot_base()
.- Parameters
update – Passed to snapshot_base.
- Returns
Base snapshot.
- snapshot_base(update: Optional[bool] = False, params_to_skip_update: Optional[Sequence[str]] = 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. IfFalse
, 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
- 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, Union['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 viaadd_submodule()
.
- class qcodes.instrument.InstrumentBase(name: str, metadata: Optional[Mapping[Any, Any]] = None)[source]
Bases:
Metadatable
,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.
- 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, Union['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 viaadd_submodule()
.
- add_parameter(name: str, parameter_class: Optional[Type[ParameterBase]] = None, **kwargs: Any) None [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.
- 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. If your case is more complicated, you’re probably better off simply making a new method in yourInstrument
subclass definition.- 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: Union[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 aChannelTuple
.- 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
- snapshot_base(update: Optional[bool] = False, params_to_skip_update: Optional[Sequence[str]] = 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. IfFalse
, 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
- 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. IfFalse
, 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: Optional[qcodes.instrument.instrument_base.InstrumentBase]
Returns the parent instrument. By default this is
None
. Any SubInstrument should subclass this to return the parent instrument.
- property ancestors: List[qcodes.instrument.instrument_base.InstrumentBase]
Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument until the root instrument is reached.
- property root_instrument: qcodes.instrument.instrument_base.InstrumentBase
- property name: str
Name of the instrument This is equivalent to full_name for backwards compatibility.
- delegate_attr_dicts: 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 ofself
.
- __getitem__(key: str) Union[Callable[[...], Any], Parameter] [source]
Delegate instrument[‘name’] to parameter or function ‘name’.
- delegate_attr_objects: List[str] = []
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.
- load_metadata(metadata: Mapping[str, Any]) None
Load metadata into this classes metadata dictionary.
- Parameters
metadata – Metadata to load.
- omit_delegate_attrs: List[str] = []
A list of attribute names (strings) to not delegate to any other dictionary or object.
- 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.
- snapshot(update: Optional[bool] = False) Dict[Any, Any]
Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override
snapshot_base()
.- Parameters
update – Passed to snapshot_base.
- Returns
Base snapshot.
- 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.
- class qcodes.instrument.InstrumentChannel(parent: InstrumentBase, name: str, **kwargs: Any)[source]
Bases:
InstrumentModule
- __getitem__(key: str) Union[Callable[[...], Any], Parameter]
Delegate instrument[‘name’] to parameter or function ‘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. If your case is more complicated, you’re probably better off simply making a new method in yourInstrument
subclass definition.- 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: Optional[Type[ParameterBase]] = None, **kwargs: Any) None
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: Union[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 aChannelTuple
.- 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
- property ancestors: List[qcodes.instrument.instrument_base.InstrumentBase]
Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument 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: 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 ofself
.
- delegate_attr_objects: List[str] = []
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.
- 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.
- 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.
- load_metadata(metadata: Mapping[str, Any]) None
Load metadata into this classes metadata dictionary.
- Parameters
metadata – Metadata to load.
- property name: str
Name of the instrument This is equivalent to full_name for backwards compatibility.
- omit_delegate_attrs: List[str] = []
A list of attribute names (strings) to not delegate to any other dictionary or object.
- property parent: qcodes.instrument.instrument_base.InstrumentBase
Returns 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. IfFalse
, 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.
- property root_instrument: qcodes.instrument.instrument_base.InstrumentBase
- 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.
- snapshot(update: Optional[bool] = False) Dict[Any, Any]
Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override
snapshot_base()
.- Parameters
update – Passed to snapshot_base.
- Returns
Base snapshot.
- snapshot_base(update: Optional[bool] = False, params_to_skip_update: Optional[Sequence[str]] = 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. IfFalse
, 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
- 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, Union['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 viaadd_submodule()
.
- class qcodes.instrument.InstrumentModule(parent: InstrumentBase, name: str, **kwargs: Any)[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.
- property parent: qcodes.instrument.instrument_base.InstrumentBase
Returns the parent instrument. By default this is
None
. Any SubInstrument should subclass this to return the parent instrument.
- property root_instrument: qcodes.instrument.instrument_base.InstrumentBase
- __getitem__(key: str) Union[Callable[[...], Any], Parameter]
Delegate instrument[‘name’] to parameter or function ‘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. If your case is more complicated, you’re probably better off simply making a new method in yourInstrument
subclass definition.- 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: Optional[Type[ParameterBase]] = None, **kwargs: Any) None
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: Union[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 aChannelTuple
.- 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
- property ancestors: List[qcodes.instrument.instrument_base.InstrumentBase]
Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument 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: 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 ofself
.
- delegate_attr_objects: List[str] = []
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.
- 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.
- 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.
- load_metadata(metadata: Mapping[str, Any]) None
Load metadata into this classes metadata dictionary.
- Parameters
metadata – Metadata to load.
- property name: str
Name of the instrument This is equivalent to full_name for backwards compatibility.
- omit_delegate_attrs: 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. IfFalse
, 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.
- 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.
- snapshot(update: Optional[bool] = False) Dict[Any, Any]
Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override
snapshot_base()
.- Parameters
update – Passed to snapshot_base.
- Returns
Base snapshot.
- snapshot_base(update: Optional[bool] = False, params_to_skip_update: Optional[Sequence[str]] = 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. IfFalse
, 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
- 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, Union['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 viaadd_submodule()
.
- class qcodes.instrument.VisaInstrument(*args: Any, **kwargs: Any)[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. Default 5.
terminator – Read and write termination character(s). 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.htmlmetadata – additional static metadata to add to this instrument’s JSON snapshot.
See help for
Instrument
for additional information on writing instrument subclasses.- visa_handle
The communication channel.
- 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).
- set_terminator(terminator: Optional[str]) 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.
- check_error(ret_code: int) None [source]
Default error checking, raises an error if return code
!=0
. Does not differentiate between warnings or specific error messages. Override this function in your driver if you want to add specific error messages.- Parameters
ret_code – A Visa error code. See eg: https://github.com/hgrecco/pyvisa/blob/master/pyvisa/errors.py
- Raises
visa.VisaIOError – if
ret_code
indicates a communication problem.
- 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
- snapshot_base(update: Optional[bool] = True, params_to_skip_update: Optional[Sequence[str]] = 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
- __getitem__(key: str) Union[Callable[[...], Any], Parameter]
Delegate instrument[‘name’] to parameter or function ‘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. If your case is more complicated, you’re probably better off simply making a new method in yourInstrument
subclass definition.- 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: Optional[Type[ParameterBase]] = None, **kwargs: Any) None
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: Union[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 aChannelTuple
.- 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
- property ancestors: List[qcodes.instrument.instrument_base.InstrumentBase]
Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument 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 callsuper().ask(new_cmd)
. Subclasses that define a new hardware communication should instead overrideask_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: Optional[float] = 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__init__
.
- delegate_attr_dicts: 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 ofself
.
- delegate_attr_objects: List[str] = []
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.
- static exist(name: str, instrument_class: Optional[type] = 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: Optional[Type[T]] = None) 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
- 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_idn() Dict[str, Optional[str]]
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[Instrument]
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.
- load_metadata(metadata: Mapping[str, Any]) None
Load metadata into this classes metadata dictionary.
- Parameters
metadata – Metadata to load.
- property name: str
Name of the instrument This is equivalent to full_name for backwards compatibility.
- omit_delegate_attrs: List[str] = []
A list of attribute names (strings) to not delegate to any other dictionary or object.
- property parent: Optional[qcodes.instrument.instrument_base.InstrumentBase]
Returns 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. IfFalse
, 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
- property root_instrument: qcodes.instrument.instrument_base.InstrumentBase
- 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.
- snapshot(update: Optional[bool] = False) Dict[Any, Any]
Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override
snapshot_base()
.- Parameters
update – Passed to snapshot_base.
- Returns
Base snapshot.
- 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 callsuper().write(new_cmd)
. Subclasses that define a new hardware communication should instead overridewrite_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, Union['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 viaadd_submodule()
.
- 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.
recreate – When
True
, the instruments gets recreated if it is found.
- Returns
The found or created instrument.