qcodes.instrument_drivers.american_magnetics package

Submodules

qcodes.instrument_drivers.american_magnetics.AMI430 module

class qcodes.instrument_drivers.american_magnetics.AMI430.AMI430(name: str, address: str, port: Optional[int] = None, reset: bool = False, terminator: str = '\r\n', current_ramp_limit: Optional[float] = None, **kwargs: Any)[source]

Bases: qcodes.instrument.ip.IPInstrument

Driver for the American Magnetics Model 430 magnet power supply programmer.

This class controls a single magnet power supply. In order to use two or three magnets simultaneously to set field vectors, first instantiate the individual magnets using this class and then pass them as arguments to either the AMI430_2D or AMI430_3D virtual instrument classes.

Parameters
  • name – a name for the instrument

  • address – IP address of the power supply programmer

  • current_ramp_limit – A current ramp limit, in units of A/s

set_field(value: float, *, block: bool = True, perform_safety_check: bool = True) None[source]

Ramp to a certain field

Parameters
  • value – Value to ramp to.

  • block – Whether to wait unit the field has finished setting

  • perform_safety_check – Whether to set the field via a parent driver (if present), which might perform additional safety checks.

wait_while_ramping() str[source]
__del__() None

Close the instrument and remove its instance record.

__getitem__(key: str) Union[Callable[[...], Any], qcodes.instrument.parameter.Parameter]

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

__getstate__() None

Prevent pickling instruments, and give a nice error message.

__repr__() str

Simplified repr giving just the class and name.

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

Bind one Function to this instrument.

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

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only. If your case is more complicated, you’re probably better off simply making a new method in your Instrument subclass definition.

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

  • **kwargs – constructor kwargs for Function

Raises

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

add_parameter(name: str, parameter_class: type = <class 'qcodes.instrument.parameter.Parameter'>, **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 instrument.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 parameter.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

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

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

add_submodule(name: str, submodule: Union[InstrumentBase, ChannelList]) 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.

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

  • submodule – The submodule to be stored.

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

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

property ancestors: List[qcodes.instrument.base.InstrumentBase]

Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument until the root instrument is reached.

ask(cmd: str) str

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

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

Parameters

cmd – The string to send to the instrument.

Returns

response

Raises

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

ask_raw(cmd: str) str

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

Parameters

cmd – The command to send to the instrument.

Returns

The instrument’s string response.

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

Disconnect and irreversibly tear down the instrument.

classmethod close_all() None

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

Examples

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

Print a standard message on initial connection to an instrument.

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

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

delegate_attr_dicts: List[str] = ['parameters', 'functions', 'submodules']

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

delegate_attr_objects: List[str] = []

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

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

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

Parameters
  • name – Name of the instrument.

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

classmethod find_instrument(name: str, instrument_class: Optional[type] = None) qcodes.instrument.base.Instrument

Find an existing instrument by name.

Parameters
  • name – Name of the instrument.

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

Returns

The instrument found.

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

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

flush_connection() None
property full_name: str
get(param_name: str) Any

Shortcut for getting a parameter from its name.

Parameters

param_name – The name of a parameter of this instrument.

Returns

The current value of the parameter.

get_idn() Dict[str, Optional[str]]

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

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

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

Returns

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

classmethod instances() List[qcodes.instrument.base.Instrument]

Get all currently defined instances of this instrument class.

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

Returns

A list of instances.

static is_valid(instr_instance: qcodes.instrument.base.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: Dict[Any, Any]) None

Load metadata into this classes metadata dictionary.

Parameters

metadata – Metadata to load.

property name: str

Name of the instrument

property name_parts: List[str]
omit_delegate_attrs: List[str] = []

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

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

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

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

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

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

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

classmethod record_instance(instance: qcodes.instrument.base.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.

Parameters

instance – Instance to record.

Raises

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

classmethod remove_instance(instance: qcodes.instrument.base.Instrument) None

Remove a particular instance from the record.

Parameters

instance – The instance to remove

property root_instrument: qcodes.instrument.base.InstrumentBase
set(param_name: str, value: Any) None

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

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

  • value – The new value to set.

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

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

Parameters
  • address – The IP address or name.

  • port – The IP port.

set_persistent(persistent: bool) None

Change whether this instrument keeps its socket open between calls.

Parameters

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

set_terminator(terminator: str) None

Change the write terminator to use.

Parameters

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

set_timeout(timeout: float) None

Change the read timeout for the socket.

Parameters

timeout – Seconds to allow for responses.

shared_kwargs = ()
property short_name: str

Short name of the instrument

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

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

Parameters

update – Passed to snapshot_base.

Returns

Base snapshot.

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

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

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

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

Returns

base snapshot

Return type

dict

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

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

Parameters

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

write(cmd: str) None

Write a command string with NO response to the hardware.

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

Parameters

cmd – The string to send to the instrument.

Raises

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

write_raw(cmd: str) None

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

Parameters

cmd – The command to send to the instrument.

parameters: Dict[str, _BaseParameter] = {}

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

functions: Dict[str, Function] = {}

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

submodules: Dict[str, Union['InstrumentBase', 'ChannelList']] = {}

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

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)
exception qcodes.instrument_drivers.american_magnetics.AMI430.AMI430Exception[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class qcodes.instrument_drivers.american_magnetics.AMI430.AMI430SwitchHeater(parent: qcodes.instrument_drivers.american_magnetics.AMI430.AMI430)[source]

Bases: qcodes.instrument.channel.InstrumentChannel

disable() None[source]

Turn measurement off

enable() None[source]

Turn measurement on

check_enabled() bool[source]
on(*args: Any, **kwargs: Any) qcodes.instrument_drivers.american_magnetics.AMI430.T[source]
off(*args: Any, **kwargs: Any) qcodes.instrument_drivers.american_magnetics.AMI430.T[source]
check_state(*args: Any, **kwargs: Any) qcodes.instrument_drivers.american_magnetics.AMI430.T[source]
__getitem__(key: str) Union[Callable[[...], Any], qcodes.instrument.parameter.Parameter]

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

__getstate__() None

Prevent pickling instruments, and give a nice error message.

__repr__() str

Custom repr to give parent information

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

Bind one Function to this instrument.

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

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only. If your case is more complicated, you’re probably better off simply making a new method in your Instrument subclass definition.

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

  • **kwargs – constructor kwargs for Function

Raises

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

add_parameter(name: str, parameter_class: type = <class 'qcodes.instrument.parameter.Parameter'>, **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 instrument.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 parameter.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

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

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

add_submodule(name: str, submodule: Union[InstrumentBase, ChannelList]) 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.

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

  • submodule – The submodule to be stored.

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

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

property ancestors: List[qcodes.instrument.base.InstrumentBase]

Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument until the root instrument is reached.

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

Shortcut for calling a function from its name.

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

  • *args – any arguments to the function.

Returns

The return value of the function.

delegate_attr_dicts: List[str] = ['parameters', 'functions', 'submodules']

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

delegate_attr_objects: List[str] = []

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

property full_name: str
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.

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

Load metadata into this classes metadata dictionary.

Parameters

metadata – Metadata to load.

property name: str

Name of the instrument

property name_parts: List[str]
omit_delegate_attrs: List[str] = []

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

property parent: qcodes.instrument.base.InstrumentBase

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

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

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

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

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

property root_instrument: qcodes.instrument.base.InstrumentBase
set(param_name: str, value: Any) None

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

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

  • value – The new value to set.

property short_name: str

Short name of the instrument

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

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

Parameters

update – Passed to snapshot_base.

Returns

Base snapshot.

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

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

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

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

Returns

base snapshot

Return type

dict

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

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

Parameters

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

write(cmd: str) None
write_raw(cmd: str) None
parameters: Dict[str, _BaseParameter] = {}

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

functions: Dict[str, Function] = {}

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

submodules: Dict[str, Union['InstrumentBase', 'ChannelList']] = {}

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

exception qcodes.instrument_drivers.american_magnetics.AMI430.AMI430Warning[source]

Bases: UserWarning

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class qcodes.instrument_drivers.american_magnetics.AMI430.AMI430_3D(name: str, instrument_x: Union[qcodes.instrument_drivers.american_magnetics.AMI430.AMI430, str], instrument_y: Union[qcodes.instrument_drivers.american_magnetics.AMI430.AMI430, str], instrument_z: Union[qcodes.instrument_drivers.american_magnetics.AMI430.AMI430, str], field_limit: Union[numbers.Real, Iterable[Callable[[float, float, float], bool]]], **kwargs: Any)[source]

Bases: qcodes.instrument.base.Instrument

Driver for controlling three American Magnetics Model 430 magnet power supplies simultaneously for setting magnetic field vectors.

The individual magnet power supplies can be passed in as either instances of AMI430 driver or as names of existing AMI430 instances. In the latter case, the instances will be found via the passed names.

Parameters
  • name – a name for the instrument

  • instrument_x – AMI430 instance or a names of existing AMI430 instance for controlling the X axis of magnetic field

  • instrument_y – AMI430 instance or a names of existing AMI430 instance for controlling the Y axis of magnetic field

  • instrument_z – AMI430 instance or a names of existing AMI430 instance for controlling the Z axis of magnetic field

  • field_limit – a number for maximum allows magnetic field or an iterable of callable field limit functions that define region(s) of allowed values in 3D magnetic field space

vector_ramp_rate = Parameter( name="vector_ramp_rate", instrument=self, unit="T/s", vals=Numbers(min_value=0.0), set_cmd=None, get_cmd=None, set_parser=self._set_vector_ramp_rate_units, docstring="Ramp rate along a line (vector) in 3D space. Only active" " if `ramp_mode='simultaneous'`." )

Ramp rate along a line (vector) in 3D field space

ramp_simultaneously(setpoint: qcodes.math_utils.field_vector.FieldVector, duration: float) None[source]

Ramp all axes simultaneously to the given setpoint and in the given time

The method calculates and sets the required ramp rates per magnet axis, and then initiates a ramp simultaneously on all the axes. The trajectory of the tip of the magnetic field vector is thus linear in 3D space, from the current field value to the setpoint.

If block_during_ramp parameter is True, the method will block until all axes finished ramping.

It is required for all axis instruments to have the same units for ramp rate and field, otherwise an exception is raised. The given setpoint and time are assumed to be in those common units.

Parameters
  • setpointFieldVector setpoint

  • duration – time in which the setpoint field has to be reached on all axes

static calculate_axes_ramp_rates_for(start: qcodes.math_utils.field_vector.FieldVector, setpoint: qcodes.math_utils.field_vector.FieldVector, duration: float) Tuple[float, float, float][source]

Given starting and setpoint fields and expected ramp time calculates required ramp rates for x, y, z axes (in this order) where axes are ramped simultaneously.

static calculate_vector_ramp_rate_from_duration(start: qcodes.math_utils.field_vector.FieldVector, setpoint: qcodes.math_utils.field_vector.FieldVector, duration: float) float[source]
static calculate_axes_ramp_rates_from_vector_ramp_rate(start: qcodes.math_utils.field_vector.FieldVector, setpoint: qcodes.math_utils.field_vector.FieldVector, vector_ramp_rate: float) Tuple[float, float, float][source]
wait_while_all_axes_ramping() None[source]

Wait and blocks as long as any magnet axis is ramping.

any_axis_is_ramping() bool[source]

Returns True if any of the magnet axes are currently ramping, or False if none of the axes are ramping.

pause() None[source]

Pause all magnet axes.

__del__() None

Close the instrument and remove its instance record.

__getitem__(key: str) Union[Callable[[...], Any], qcodes.instrument.parameter.Parameter]

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

__getstate__() None

Prevent pickling instruments, and give a nice error message.

__repr__() str

Simplified repr giving just the class and name.

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

Bind one Function to this instrument.

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

This functionality is meant for simple cases, principally things that map to simple commands like *RST (reset) or those with just a few arguments. It requires a fixed argument count, and positional args only. If your case is more complicated, you’re probably better off simply making a new method in your Instrument subclass definition.

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

  • **kwargs – constructor kwargs for Function

Raises

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

add_parameter(name: str, parameter_class: type = <class 'qcodes.instrument.parameter.Parameter'>, **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 instrument.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 parameter.Parameter.

  • **kwargs – Constructor arguments for parameter_class.

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

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

add_submodule(name: str, submodule: Union[InstrumentBase, ChannelList]) 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.

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

  • submodule – The submodule to be stored.

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

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

property ancestors: List[qcodes.instrument.base.InstrumentBase]

Returns a list of instruments, starting from the current instrument and following to the parent instrument and the parents parent instrument until the root instrument is reached.

ask(cmd: str) str

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

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

Parameters

cmd – The string to send to the instrument.

Returns

response

Raises

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

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 override ask.

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: Optional[float] = None) None

Print a standard message on initial connection to an instrument.

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

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

delegate_attr_dicts: List[str] = ['parameters', 'functions', 'submodules']

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

delegate_attr_objects: List[str] = []

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

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

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

Parameters
  • name – Name of the instrument.

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

classmethod find_instrument(name: str, instrument_class: Optional[type] = None) qcodes.instrument.base.Instrument

Find an existing instrument by name.

Parameters
  • name – Name of the instrument.

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

Returns

The instrument found.

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

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

property full_name: str
get(param_name: str) Any

Shortcut for getting a parameter from its name.

Parameters

param_name – The name of a parameter of this instrument.

Returns

The current value of the parameter.

get_idn() Dict[str, Optional[str]]

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

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

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

Returns

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

classmethod instances() List[qcodes.instrument.base.Instrument]

Get all currently defined instances of this instrument class.

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

Returns

A list of instances.

static is_valid(instr_instance: qcodes.instrument.base.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: Dict[Any, Any]) None

Load metadata into this classes metadata dictionary.

Parameters

metadata – Metadata to load.

property name: str

Name of the instrument

property name_parts: List[str]
omit_delegate_attrs: List[str] = []

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

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

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

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

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

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

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

classmethod record_instance(instance: qcodes.instrument.base.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.

Parameters

instance – Instance to record.

Raises

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

classmethod remove_instance(instance: qcodes.instrument.base.Instrument) None

Remove a particular instance from the record.

Parameters

instance – The instance to remove

property root_instrument: qcodes.instrument.base.InstrumentBase
set(param_name: str, value: Any) None

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

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

  • value – The new value to set.

shared_kwargs = ()
property short_name: str

Short name of the instrument

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

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

Parameters

update – Passed to snapshot_base.

Returns

Base snapshot.

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

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

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

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

Returns

base snapshot

Return type

dict

validate_status(verbose: bool = False) None

Validate the values of all gettable parameters

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

Parameters

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

write(cmd: str) None

Write a command string with NO response to the hardware.

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

Parameters

cmd – The string to send to the instrument.

Raises

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

write_raw(cmd: str) None

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

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

Parameters

cmd – The string to send to the instrument.

parameters: Dict[str, _BaseParameter] = {}

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

functions: Dict[str, Function] = {}

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

submodules: Dict[str, Union['InstrumentBase', 'ChannelList']] = {}

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

log: InstrumentLoggerAdapter = get_instrument_logger(self, __name__)

Module contents