Stanford Research Systems Drivers
Classes:
|
QCoDeS driver for the Stanford Research Systems SG384 RF Signal Generator. |
|
QCoDeS driver for the Stanford Research Systems SR560 Voltage-preamplifier. |
|
QCoDeS driver for the Stanford Research Systems SR830 Lock-in Amplifier. |
|
QCoDeS driver for the Stanford Research Systems SR860 Lock-in Amplifier. |
|
QCoDeS driver for the Stanford Research Systems SR865 Lock-in Amplifier. |
|
QCoDeS driver for the Stanford Research Systems SR865A Lock-in Amplifier. |
|
Buffer module for the SR86x drivers. |
- class qcodes.instrument_drivers.stanford_research.SG384(name: str, address: str, reset: bool = False, **kwargs: Any)[source]
Bases:
VisaInstrument
QCoDeS driver for the Stanford Research Systems SG384 RF Signal Generator.
Status: beta version Includes the essential commands from the manual
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.
ask_raw
(cmd)Low-level interface to
visa_handle.ask
.call
(func_name, *args)Shortcut for calling a function from its name.
close
()Disconnect and irreversibly tear down the instrument.
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.
device_clear
()Clear the buffers of the device
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.
set
(param_name, value)Shortcut for setting a parameter from its name and new value.
set_address
(address)Set the address for this instrument.
set_terminator
(terminator)Change the read terminator to use.
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 a command string with NO response to the hardware.
write_raw
(cmd)Low-level interface to
visa_handle.write
.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 ofself
.delegate_attr_objects
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.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 currentInstrumentModule
.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.
visa_handle
The VISA resource used by this instrument.
resource_manager
The VISA resource manager used by this 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 viaadd_submodule()
.- __getitem__(key: str) 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.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[ParameterBase] | None = 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: 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: 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 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
Low-level interface to
visa_handle.ask
.- Parameters:
cmd – The command to send to the instrument.
- Returns:
The instrument’s response.
- Return type:
- 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__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 ofself
.
- 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 toself
.
- 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:
- 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:
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.
- 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 currentInstrumentModule
.
- 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. 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: InstrumentBase
The topmost parent of this module.
For the
root_instrument
this isself
.
- 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.
- set_address(address: str) None
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: str | None) None
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.
- 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 = 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:
- 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.
- write_raw(cmd: str) None
Low-level interface to
visa_handle.write
.- Parameters:
cmd – The command to send to the instrument.
- visa_handle: pyvisa.resources.MessageBasedResource = visa_handle
The VISA resource used by this 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 viaadd_submodule()
.
- log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
- resource_manager = resource_manager
The VISA resource manager used by this instrument.
- class qcodes.instrument_drivers.stanford_research.SR560(name: str, **kwargs: Any)[source]
Bases:
Instrument
QCoDeS driver for the Stanford Research Systems SR560 Voltage-preamplifier.
This is a virtual driver only and will not talk to your instrument.
Note:
The
cutoff_lo
andcutoff_hi
parameters will interact with each other on the instrument (hi cannot be <= lo) but this is not managed here, you must ensure yourself that both are correct whenever you change one of them.gain
has a vernier setting, which does not yield a well-defined output. We restrict this driver to only the predefined gain values.
Methods:
get_idn
()Parse a standard VISA
*IDN?
response into an ID dict.__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.
ask_raw
(cmd)Low level method to write to the hardware and return a response.
call
(func_name, *args)Shortcut for calling a function from its name.
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.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.
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.
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 a command string with NO response to the hardware.
write_raw
(cmd)Low level method to write a command string 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 ofself
.delegate_attr_objects
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.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 currentInstrumentModule
.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 viaadd_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.
- __getitem__(key: str) 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.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[ParameterBase] | None = 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: 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: 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 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
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.
- 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.
- close() None
Irreversibly stop this instrument and free its resources.
Subclasses should override this if they have other specific resources to close.
- 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__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 ofself
.
- 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 toself
.
- 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:
- 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:
name – The name of the component to get.
- Returns:
The component with the given name.
- Raises:
KeyError – If the component does not exist.
- 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.
- 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 currentInstrumentModule
.
- 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. 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: InstrumentBase
The topmost parent of this module.
For the
root_instrument
this isself
.
- 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. 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.
- 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.
- write_raw(cmd: str) None
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.
- 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 viaadd_submodule()
.
- log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
- class qcodes.instrument_drivers.stanford_research.SR830(name: str, address: str, **kwargs: Any)[source]
Bases:
VisaInstrument
QCoDeS driver for the Stanford Research Systems SR830 Lock-in Amplifier.
Attributes:
SNAP_PARAMETERS
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 ofself
.delegate_attr_objects
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.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 currentInstrumentModule
.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.
visa_handle
The VISA resource used by this instrument.
resource_manager
The VISA resource manager used by this 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 viaadd_submodule()
.Methods:
snap
(*parameters)Get between 2 and 6 parameters at a single instant.
increment_sensitivity
()Increment the sensitivity setting of the lock-in.
decrement_sensitivity
()Decrement the sensitivity setting of the lock-in.
autorange
([max_changes])Automatically changes the sensitivity of the instrument according to the R value and defined max_changes.
set_sweep_parameters
(sweep_param, start, stop)__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.
ask_raw
(cmd)Low-level interface to
visa_handle.ask
.call
(func_name, *args)Shortcut for calling a function from its name.
close
()Disconnect and irreversibly tear down the instrument.
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.
device_clear
()Clear the buffers of the device
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.
set
(param_name, value)Shortcut for setting a parameter from its name and new value.
set_address
(address)Set the address for this instrument.
set_terminator
(terminator)Change the read terminator to use.
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 a command string with NO response to the hardware.
write_raw
(cmd)Low-level interface to
visa_handle.write
.- SNAP_PARAMETERS: ClassVar[dict[str, str]] = {'aux1': '5', 'aux2': '6', 'aux3': '7', 'aux4': '8', 'ch1': '10', 'ch2': '11', 'freq': '9', 'p': '4', 'phase': '4', 'r': '3', 'x': '1', 'y': '2', 'θ': '4'}
- snap(*parameters: str) tuple[float, ...] [source]
Get between 2 and 6 parameters at a single instant. This provides a coherent snapshot of measured signals. Pick up to 6 from: X, Y, R, θ, the aux inputs 1-4, frequency, or what is currently displayed on channels 1 and 2.
Reading X and Y (or R and θ) gives a coherent snapshot of the signal. Snap is important when the time constant is very short, a time constant less than 100 ms.
- Parameters:
*parameters – From 2 to 6 strings of names of parameters for which the values are requested. including: ‘x’, ‘y’, ‘r’, ‘p’, ‘phase’ or ‘θ’, ‘aux1’, ‘aux2’, ‘aux3’, ‘aux4’, ‘freq’, ‘ch1’, and ‘ch2’.
- Returns:
A tuple of floating point values in the same order as requested.
Examples
>>> lockin.snap('x','y') -> tuple(x,y)
>>> lockin.snap('aux1','aux2','freq','phase') >>> -> tuple(aux1,aux2,freq,phase)
Note
Volts for x, y, r, and aux 1-4 Degrees for θ Hertz for freq Unknown for ch1 and ch2. It will depend on what was set.
If X,Y,R and θ are all read, then the values of X,Y are recorded approximately 10 µs apart from R,θ. Thus, the values of X and Y may not yield the exact values of R and θ from a single snap.
The values of the Aux Inputs may have an uncertainty of up to 32 µs.
The frequency is computed only every other period or 40 ms, whichever is longer.
- increment_sensitivity() bool [source]
Increment the sensitivity setting of the lock-in. This is equivalent to pushing the sensitivity up button on the front panel. This has no effect if the sensitivity is already at the maximum.
- Returns:
Whether or not the sensitivity was actually changed.
- decrement_sensitivity() bool [source]
Decrement the sensitivity setting of the lock-in. This is equivalent to pushing the sensitivity down button on the front panel. This has no effect if the sensitivity is already at the minimum.
- Returns:
Whether or not the sensitivity was actually changed.
- autorange(max_changes: int = 1) None [source]
Automatically changes the sensitivity of the instrument according to the R value and defined max_changes.
- Parameters:
max_changes – Maximum number of steps allowing the function to automatically change the sensitivity (default is 1). The actual number of steps needed to change to the optimal sensitivity may be more or less than this maximum.
- set_sweep_parameters(sweep_param: Parameter, start: float, stop: float, n_points: int = 10, label: str | None = None) None [source]
- __getitem__(key: str) 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.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[ParameterBase] | None = 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: 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: 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 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
Low-level interface to
visa_handle.ask
.- Parameters:
cmd – The command to send to the instrument.
- Returns:
The instrument’s response.
- Return type:
- 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__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 ofself
.
- 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 toself
.
- 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:
- 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:
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.
- 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 currentInstrumentModule
.
- 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. 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: InstrumentBase
The topmost parent of this module.
For the
root_instrument
this isself
.
- 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.
- set_address(address: str) None
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: str | None) None
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.
- 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 = 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:
- 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.
- write_raw(cmd: str) None
Low-level interface to
visa_handle.write
.- Parameters:
cmd – The command to send to the instrument.
- visa_handle: pyvisa.resources.MessageBasedResource = visa_handle
The VISA resource used by this 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 viaadd_submodule()
.
- log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
- resource_manager = resource_manager
The VISA resource manager used by this instrument.
- class qcodes.instrument_drivers.stanford_research.SR860(name: str, address: str, reset: bool = False, **kwargs: str)[source]
Bases:
SR86x
QCoDeS driver for the Stanford Research Systems SR860 Lock-in Amplifier.
The SR860 instrument is almost equal to the SR865, except for the max frequency
Attributes:
PARAMETER_NAMES
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 ofself
.delegate_attr_objects
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.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 currentInstrumentModule
.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.
visa_handle
The VISA resource used by this instrument.
resource_manager
The VISA resource manager used by this 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 viaadd_submodule()
.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.
ask_raw
(cmd)Low-level interface to
visa_handle.ask
.call
(func_name, *args)Shortcut for calling a function from its name.
close
()Disconnect and irreversibly tear down the instrument.
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.
device_clear
()Clear the buffers of the device
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_data_channels_dict
([requery_names])Returns a dictionary where the keys are parameter names currently assigned to the data channels, and values are the values of those parameters.
get_data_channels_parameters
([query_instrument])Convenience method to query a list of parameters which the data channels are currently assigned to.
get_data_channels_values
()Queries the current values of the data channels
get_idn
()Parse a standard VISA
*IDN?
response into an ID dict.get_values
(*parameter_names)Get values of 2 or 3 parameters that are measured by the lock-in amplifier.
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.
set
(param_name, value)Shortcut for setting a parameter from its name and new value.
set_address
(address)Set the address for this instrument.
set_terminator
(terminator)Change the read terminator to use.
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 a command string with NO response to the hardware.
write_raw
(cmd)Low-level interface to
visa_handle.write
.- PARAMETER_NAMES: ClassVar[dict[str, str]] = {'P': '3', 'R': '2', 'X': '0', 'Xnoise': '8', 'Y': '1', 'Ynoise': '9', 'amplitude': '13', 'aux_in1': '4', 'aux_in2': '5', 'aux_in3': '6', 'aux_in4': '7', 'aux_out1': '10', 'aux_out2': '11', 'frequency': '15', 'frequency_ext': '16', 'phase': '12', 'sine_outdc': '14'}
- __getitem__(key: str) 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.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[ParameterBase] | None = 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: 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: 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 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
Low-level interface to
visa_handle.ask
.- Parameters:
cmd – The command to send to the instrument.
- Returns:
The instrument’s response.
- Return type:
- 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__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 ofself
.
- 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 toself
.
- 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:
- 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:
name – The name of the component to get.
- Returns:
The component with the given name.
- Raises:
KeyError – If the component does not exist.
- get_data_channels_dict(requery_names: bool = False) dict[str, float]
Returns a dictionary where the keys are parameter names currently assigned to the data channels, and values are the values of those parameters.
- Parameters:
requery_names – if False, the currently assigned parameter names will not be queries from the instrument in order to save time on communication, in this case the cached assigned parameter names will be used for the keys of the dicitonary; if True, the assigned parameter names will be queried from the instrument
- Returns:
a dictionary where keys are names of parameters assigned to the data channels, and values are the values of those parameters
- get_data_channels_parameters(query_instrument: bool = True) tuple[str, ...]
Convenience method to query a list of parameters which the data channels are currently assigned to.
- Parameters:
query_instrument – If set to False, the internally cashed names of the parameters will be returned; if True, then the names will be queried through the instrument
- Returns:
a tuple of 4 strings of parameter names
- get_data_channels_values() tuple[float, ...]
Queries the current values of the data channels
- Returns:
tuple of 4 values of the data channels
- 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.
- get_values(*parameter_names: str) tuple[float, ...]
Get values of 2 or 3 parameters that are measured by the lock-in amplifier. These values are guaranteed to come from the same measurement cycle as opposed to getting values of parameters one by one (for example, by calling sr.X(), and then sr.Y().
- Parameters:
*parameter_names – 2 or 3 names of parameters for which the values are requested; valid names can be found in PARAMETER_NAMES attribute of the driver class
- Returns:
a tuple of 2 or 3 floating point values
- 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.
- 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 currentInstrumentModule
.
- 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. 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: InstrumentBase
The topmost parent of this module.
For the
root_instrument
this isself
.
- 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.
- set_address(address: str) None
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: str | None) None
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.
- 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 = 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:
- 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.
- write_raw(cmd: str) None
Low-level interface to
visa_handle.write
.- Parameters:
cmd – The command to send to the instrument.
- visa_handle: pyvisa.resources.MessageBasedResource = visa_handle
The VISA resource used by this 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 viaadd_submodule()
.
- log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
- resource_manager = resource_manager
The VISA resource manager used by this instrument.
- class qcodes.instrument_drivers.stanford_research.SR865(name: str, address: str, reset: bool = False, **kwargs: str)[source]
Bases:
SR86x
QCoDeS driver for the Stanford Research Systems SR865 Lock-in Amplifier.
The SR865 instrument is almost equal to the SR860, except for the max frequency
Attributes:
PARAMETER_NAMES
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 ofself
.delegate_attr_objects
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.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 currentInstrumentModule
.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.
visa_handle
The VISA resource used by this instrument.
resource_manager
The VISA resource manager used by this 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 viaadd_submodule()
.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.
ask_raw
(cmd)Low-level interface to
visa_handle.ask
.call
(func_name, *args)Shortcut for calling a function from its name.
close
()Disconnect and irreversibly tear down the instrument.
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.
device_clear
()Clear the buffers of the device
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_data_channels_dict
([requery_names])Returns a dictionary where the keys are parameter names currently assigned to the data channels, and values are the values of those parameters.
get_data_channels_parameters
([query_instrument])Convenience method to query a list of parameters which the data channels are currently assigned to.
get_data_channels_values
()Queries the current values of the data channels
get_idn
()Parse a standard VISA
*IDN?
response into an ID dict.get_values
(*parameter_names)Get values of 2 or 3 parameters that are measured by the lock-in amplifier.
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.
set
(param_name, value)Shortcut for setting a parameter from its name and new value.
set_address
(address)Set the address for this instrument.
set_terminator
(terminator)Change the read terminator to use.
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 a command string with NO response to the hardware.
write_raw
(cmd)Low-level interface to
visa_handle.write
.- PARAMETER_NAMES: ClassVar[dict[str, str]] = {'P': '3', 'R': '2', 'X': '0', 'Xnoise': '8', 'Y': '1', 'Ynoise': '9', 'amplitude': '13', 'aux_in1': '4', 'aux_in2': '5', 'aux_in3': '6', 'aux_in4': '7', 'aux_out1': '10', 'aux_out2': '11', 'frequency': '15', 'frequency_ext': '16', 'phase': '12', 'sine_outdc': '14'}
- __getitem__(key: str) 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.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[ParameterBase] | None = 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: 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: 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 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
Low-level interface to
visa_handle.ask
.- Parameters:
cmd – The command to send to the instrument.
- Returns:
The instrument’s response.
- Return type:
- 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__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 ofself
.
- 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 toself
.
- 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:
- 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:
name – The name of the component to get.
- Returns:
The component with the given name.
- Raises:
KeyError – If the component does not exist.
- get_data_channels_dict(requery_names: bool = False) dict[str, float]
Returns a dictionary where the keys are parameter names currently assigned to the data channels, and values are the values of those parameters.
- Parameters:
requery_names – if False, the currently assigned parameter names will not be queries from the instrument in order to save time on communication, in this case the cached assigned parameter names will be used for the keys of the dicitonary; if True, the assigned parameter names will be queried from the instrument
- Returns:
a dictionary where keys are names of parameters assigned to the data channels, and values are the values of those parameters
- get_data_channels_parameters(query_instrument: bool = True) tuple[str, ...]
Convenience method to query a list of parameters which the data channels are currently assigned to.
- Parameters:
query_instrument – If set to False, the internally cashed names of the parameters will be returned; if True, then the names will be queried through the instrument
- Returns:
a tuple of 4 strings of parameter names
- get_data_channels_values() tuple[float, ...]
Queries the current values of the data channels
- Returns:
tuple of 4 values of the data channels
- 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.
- get_values(*parameter_names: str) tuple[float, ...]
Get values of 2 or 3 parameters that are measured by the lock-in amplifier. These values are guaranteed to come from the same measurement cycle as opposed to getting values of parameters one by one (for example, by calling sr.X(), and then sr.Y().
- Parameters:
*parameter_names – 2 or 3 names of parameters for which the values are requested; valid names can be found in PARAMETER_NAMES attribute of the driver class
- Returns:
a tuple of 2 or 3 floating point values
- 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.
- 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 currentInstrumentModule
.
- 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. 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: InstrumentBase
The topmost parent of this module.
For the
root_instrument
this isself
.
- 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.
- set_address(address: str) None
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: str | None) None
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.
- 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 = 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:
- 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.
- write_raw(cmd: str) None
Low-level interface to
visa_handle.write
.- Parameters:
cmd – The command to send to the instrument.
- visa_handle: pyvisa.resources.MessageBasedResource = visa_handle
The VISA resource used by this 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 viaadd_submodule()
.
- log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
- resource_manager = resource_manager
The VISA resource manager used by this instrument.
- class qcodes.instrument_drivers.stanford_research.SR865A(name: str, address: str, reset: bool = False, **kwargs: str)[source]
Bases:
SR86x
QCoDeS driver for the Stanford Research Systems SR865A Lock-in Amplifier.
The SR865A instrument is almost equal to the SR865, except for the max frequency
Attributes:
PARAMETER_NAMES
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 ofself
.delegate_attr_objects
A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.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 currentInstrumentModule
.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.
visa_handle
The VISA resource used by this instrument.
resource_manager
The VISA resource manager used by this 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 viaadd_submodule()
.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.
ask_raw
(cmd)Low-level interface to
visa_handle.ask
.call
(func_name, *args)Shortcut for calling a function from its name.
close
()Disconnect and irreversibly tear down the instrument.
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.
device_clear
()Clear the buffers of the device
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_data_channels_dict
([requery_names])Returns a dictionary where the keys are parameter names currently assigned to the data channels, and values are the values of those parameters.
get_data_channels_parameters
([query_instrument])Convenience method to query a list of parameters which the data channels are currently assigned to.
get_data_channels_values
()Queries the current values of the data channels
get_idn
()Parse a standard VISA
*IDN?
response into an ID dict.get_values
(*parameter_names)Get values of 2 or 3 parameters that are measured by the lock-in amplifier.
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.
set
(param_name, value)Shortcut for setting a parameter from its name and new value.
set_address
(address)Set the address for this instrument.
set_terminator
(terminator)Change the read terminator to use.
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 a command string with NO response to the hardware.
write_raw
(cmd)Low-level interface to
visa_handle.write
.- PARAMETER_NAMES: ClassVar[dict[str, str]] = {'P': '3', 'R': '2', 'X': '0', 'Xnoise': '8', 'Y': '1', 'Ynoise': '9', 'amplitude': '13', 'aux_in1': '4', 'aux_in2': '5', 'aux_in3': '6', 'aux_in4': '7', 'aux_out1': '10', 'aux_out2': '11', 'frequency': '15', 'frequency_ext': '16', 'phase': '12', 'sine_outdc': '14'}
- __getitem__(key: str) 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.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[ParameterBase] | None = 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: 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: 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 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
Low-level interface to
visa_handle.ask
.- Parameters:
cmd – The command to send to the instrument.
- Returns:
The instrument’s response.
- Return type:
- 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_time –
time.time()
when init started. Default isself._t0
, set at start ofInstrument.__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 ofself
.
- 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 toself
.
- 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:
- 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:
name – The name of the component to get.
- Returns:
The component with the given name.
- Raises:
KeyError – If the component does not exist.
- get_data_channels_dict(requery_names: bool = False) dict[str, float]
Returns a dictionary where the keys are parameter names currently assigned to the data channels, and values are the values of those parameters.
- Parameters:
requery_names – if False, the currently assigned parameter names will not be queries from the instrument in order to save time on communication, in this case the cached assigned parameter names will be used for the keys of the dicitonary; if True, the assigned parameter names will be queried from the instrument
- Returns:
a dictionary where keys are names of parameters assigned to the data channels, and values are the values of those parameters
- get_data_channels_parameters(query_instrument: bool = True) tuple[str, ...]
Convenience method to query a list of parameters which the data channels are currently assigned to.
- Parameters:
query_instrument – If set to False, the internally cashed names of the parameters will be returned; if True, then the names will be queried through the instrument
- Returns:
a tuple of 4 strings of parameter names
- get_data_channels_values() tuple[float, ...]
Queries the current values of the data channels
- Returns:
tuple of 4 values of the data channels
- 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.
- get_values(*parameter_names: str) tuple[float, ...]
Get values of 2 or 3 parameters that are measured by the lock-in amplifier. These values are guaranteed to come from the same measurement cycle as opposed to getting values of parameters one by one (for example, by calling sr.X(), and then sr.Y().
- Parameters:
*parameter_names – 2 or 3 names of parameters for which the values are requested; valid names can be found in PARAMETER_NAMES attribute of the driver class
- Returns:
a tuple of 2 or 3 floating point values
- 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.
- 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 currentInstrumentModule
.
- 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. 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: InstrumentBase
The topmost parent of this module.
For the
root_instrument
this isself
.
- 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.
- set_address(address: str) None
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: str | None) None
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.
- 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 = 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:
- 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.
- write_raw(cmd: str) None
Low-level interface to
visa_handle.write
.- Parameters:
cmd – The command to send to the instrument.
- visa_handle: pyvisa.resources.MessageBasedResource = visa_handle
The VISA resource used by this 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 viaadd_submodule()
.
- log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
- resource_manager = resource_manager
The VISA resource manager used by this instrument.
- class qcodes.instrument_drivers.stanford_research.SR86xBuffer(parent: SR86x, name: str)[source]
Bases:
InstrumentChannel
Buffer module for the SR86x drivers.
This driver has been verified to work with the SR860 and SR865. For reference, please consult the SR860 manual: http://thinksrs.com/downloads/PDFs/Manuals/SR860m.pdf
Methods:
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).Sets the capture rate to maximum.
start_capture
(acquisition_mode, trigger_mode)Start an acquisition.
Stop a capture
set_capture_length_to_fit_samples
(sample_count)Set the capture length of the buffer to fit the given number of samples.
wait_until_samples_captured
(sample_count)Wait until the given number of samples is captured.
get_capture_data
(sample_count)Read the given number of samples of the capture data from the buffer.
Capture one sample per each trigger, and return when the specified number of triggers has been received.
capture_samples_after_trigger
(sample_count, ...)Capture a number of samples after a trigger has been received.
capture_samples
(sample_count)Capture a number of samples at a capture rate, starting immediately.
__getitem__
(key)Delegate instrument['name'] to parameter or function 'name'.
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 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.
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_raw
(cmd)Attributes:
Ancestors in the form of a list of
InstrumentBase
A list of names (strings) of dictionaries which are (or will be) attributes of
self
, whose keys should be treated as attributes ofself
.A list of names (strings) of objects which are (or will be) attributes of
self
, whose attributes should be passed through toself
.Full name of the instrument.
Nicely formatted label of the instrument.
Full name of the instrument
A list of all the parts of the instrument name from
root_instrument()
to the currentInstrumentModule
.A list of attribute names (strings) to not delegate to any other dictionary or object.
The parent instrument.
The topmost parent of this module.
Short name of the instrument.
All the parameters supported by this instrument.
All the functions supported by this instrument.
All the submodules of this instrument such as channel lists or logical groupings of parameters.
All the
InstrumentModule
of this instrument Usually populated viaadd_submodule()
.- 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. 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:
- set_capture_rate_to_maximum() None [source]
Sets the capture rate to maximum. The maximum capture rate is retrieved from the device, and depends on the current value of the time constant.
- start_capture(acquisition_mode: str, trigger_mode: str) None [source]
Start an acquisition. Please see page 137 of the manual for a detailed explanation.
- Parameters:
acquisition_mode – “ONE” | “CONT”
trigger_mode – “IMM” | “TRIG” | “SAMP”
- set_capture_length_to_fit_samples(sample_count: int) None [source]
Set the capture length of the buffer to fit the given number of samples.
- Parameters:
sample_count – Number of samples that the buffer has to fit
- wait_until_samples_captured(sample_count: int) None [source]
Wait until the given number of samples is captured. This function is blocking and has to be used with caution because it does not have a timeout.
- Parameters:
sample_count – Number of samples that needs to be captured
- get_capture_data(sample_count: int) dict[str, ndarray] [source]
Read the given number of samples of the capture data from the buffer.
- Parameters:
sample_count – number of samples to read from the buffer
- Returns:
The keys in the dictionary correspond to the captured variables. For instance, if before the capture, the capture config was set as ‘capture_config(“X,Y”)’, then the keys will be “X” and “Y”. The values in the dictionary are numpy arrays of numbers.
- capture_one_sample_per_trigger(trigger_count: int, start_triggers_pulsetrain: Callable[[...], Any]) dict[str, ndarray] [source]
Capture one sample per each trigger, and return when the specified number of triggers has been received.
- Parameters:
trigger_count – Number of triggers to capture samples for
start_triggers_pulsetrain – By calling this non-blocking function, the train of trigger pulses should start
- Returns:
The keys in the dictionary correspond to the captured variables. For instance, if before the capture, the capture config was set as ‘capture_config(“X,Y”)’, then the keys will be “X” and “Y”. The values in the dictionary are numpy arrays of numbers.
- capture_samples_after_trigger(sample_count: int, send_trigger: Callable[[...], Any]) dict[str, ndarray] [source]
Capture a number of samples after a trigger has been received. Please refer to page 135 of the manual for details.
- Parameters:
sample_count – Number of samples to capture
send_trigger – By calling this non-blocking function, one trigger should be sent that will initiate the capture
- Returns:
The keys in the dictionary correspond to the captured variables. For instance, if before the capture, the capture config was set as ‘capture_config(“X,Y”)’, then the keys will be “X” and “Y”. The values in the dictionary are numpy arrays of numbers.
- capture_samples(sample_count: int) dict[str, ndarray] [source]
Capture a number of samples at a capture rate, starting immediately. Unlike the “continuous” capture mode, here the buffer does not get overwritten with the new data once the buffer is full.
The function blocks until the required number of samples is acquired, and returns them.
- Parameters:
sample_count – Number of samples to capture
- Returns:
The keys in the dictionary correspond to the captured variables. For instance, if before the capture, the capture config was set as ‘capture_config(“X,Y”)’, then the keys will be “X” and “Y”. The values in the dictionary are numpy arrays of numbers.
- __getitem__(key: str) 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.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[ParameterBase] | None = 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: 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: 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 ofself
.
- 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 toself
.
- 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:
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.
- 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 currentInstrumentModule
.
- 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. 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: InstrumentBase
The topmost parent of this module.
For the
root_instrument
this isself
.
- 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.
- 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 viaadd_submodule()
.
- log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)