labscript.base.Device

class Device(name, parent_device, connection, call_parents_add_device=True, added_properties={}, gui=None, worker=None, start_order=None, stop_order=None, **kwargs)[source]

Bases: object

Parent class of all device and input/output channels.

You usually won’t interact directly with this class directly (i.e. you never instantiate this class directly) but it provides some useful functionality that is then available to all subclasses.

__init__(name, parent_device, connection, call_parents_add_device=True, added_properties={}, gui=None, worker=None, start_order=None, stop_order=None, **kwargs)[source]

Creates a Device.

Parameters:
  • name (str) – python variable name to assign this device to.

  • parent_device (Device) – Parent of this device.

  • connection (str) – Connection on this device that links to parent.

  • call_parents_add_device (bool, optional) – Flag to command device to call its parent device’s add_device when adding a device.

  • added_properties (dict, optional) –

  • gui

  • worker

  • start_order (int, optional) – Priority when starting, sorted with all devices.

  • stop_order (int, optional) – Priority when stopping, sorted with all devices.

  • **kwargs – Other options to pass to parent.

Methods

__init__(name, parent_device, connection[, ...])

Creates a Device.

add_device(device)

Adds a child device to this device.

generate_code(hdf5_file)

Generate hardware instructions for device and children, then save to h5 file.

get_all_children()

Get all children devices for this device.

get_all_outputs()

Get all children devices that are outputs.

get_properties([location])

Get all properties in location.

get_property(name[, location])

Method to get a property of this device already set using Device.set_property().

init_device_group(hdf5_file)

Creates the device group in the shot file.

quantise_to_pseudoclock(times)

Quantises times to the resolution of the controlling pseudoclock.

set_properties(properties_dict, property_names)

Add one or a bunch of properties packed into properties_dict

set_property(name, value[, location, overwrite])

Method to set a property for this device.

Attributes

allowed_children

Defines types of devices that are allowed to be children of this device.

description

Brief description of the device.

parent_clock_line

Stores the clocking clockline, which may be itself.

pseudoclock_device

Stores the clocking pseudoclock, which may be itself.

t0

The earliest time output can be commanded from this device at the start of the experiment.

add_device(device)[source]

Adds a child device to this device.

Parameters:

device (Device) – Device to add.

Raises:

LabscriptError – If device is not an allowed child of this device.

allowed_children = None

Defines types of devices that are allowed to be children of this device.

Type:

list

description = 'Generic Device'

Brief description of the device.

generate_code(hdf5_file)[source]

Generate hardware instructions for device and children, then save to h5 file.

Will recursively call generate_code for all children devices.

Parameters:

hdf5_file (h5py.File) – Handle to shot file.

get_all_children()[source]

Get all children devices for this device.

Returns:

List of children Device.

Return type:

list

get_all_outputs()[source]

Get all children devices that are outputs.

Recursively calls get_all_outputs() on each child device. Output’s will return a list containing just themselves.

Returns:

List of children Output.

Return type:

list

get_properties(location=None)[source]

Get all properties in location.

Parameters:

location (str, optional) – Location to get properties from. If None, return all properties.

Returns:

Dictionary of properties.

Return type:

dict

get_property(name, location=None, *args, **kwargs)[source]

Method to get a property of this device already set using Device.set_property().

If the property is not already set, a default value will be returned if specified as the argument after 'name', if there is only one argument after 'name' and the argument is either not a keyword argurment or is a keyword argument with the name 'default'.

Parameters:
  • name (str) – Name of property to get.

  • location (str, optional) – If not None, only search for name in location.

  • default – The default value. If not provided, an exception is raised if the value is not set.

Returns:

Property value.

Raises:

LabscriptError – If property not set and default not provided, or default conventions not followed.

Examples

Examples of acceptable signatures:

>>> get_property('example')             # 'example' will be returned if set, or an exception raised
>>> get_property('example', 7)          # 7 returned if 'example' is not set
>>> get_property('example', default=7)  # 7 returnd if 'example' is not set

Example signatures that WILL ALWAYS RAISE AN EXCEPTION:

>>> get_property('example', 7, 8)
>>> get_property('example', 7, default=9)
>>> get_property('example', default=7, x=9)
init_device_group(hdf5_file)[source]

Creates the device group in the shot file.

Parameters:

hdf5_file (h5py.File) – File handle to create the group in.

Returns:

Created group handle.

Return type:

h5py.Group

property parent_clock_line

Stores the clocking clockline, which may be itself.

Type:

ClockLine

property pseudoclock_device

Stores the clocking pseudoclock, which may be itself.

Type:

PseudoclockDevice

quantise_to_pseudoclock(times)[source]

Quantises times to the resolution of the controlling pseudoclock.

Parameters:

times (numpy.ndarray or list or set or float) – Time, in seconds, to quantise.

Returns:

Quantised times.

Return type:

same type as times

set_properties(properties_dict, property_names, overwrite=False)[source]

Add one or a bunch of properties packed into properties_dict

Parameters:
  • properties_dict (dict) – Dictionary of properties and their values.

  • property_names (dict) – Is a dictionary {key:val, …} where each val is a list [var1, var2, …] of variables to be pulled from properties_dict and added to the property localtion with name key

  • overwrite (bool, optional) – Toggles overwriting of existing properties.

set_property(name, value, location=None, overwrite=False)[source]

Method to set a property for this device.

Property will be stored in the connection table and used during connection table comparisons.

Value must satisfy eval(repr(value)) == value.

Parameters:
  • name (str) – Name to save property value to.

  • value – Value to set property to.

  • location (str, optional) – Specify a location to save property to, such as 'device_properties' or 'connection_table_properties'.

  • overwrite (bool, optional) – If True, allow overwriting a property already set.

Raises:

LabscriptError – If 'location' is not valid or trying to overwrite an existing property with 'overwrite'=False.

property t0

The earliest time output can be commanded from this device at the start of the experiment. This is nonzero on secondary pseudoclock devices due to triggering delays.

Type:

float