DeviceExtension
- class caqtus.extension.DeviceExtension(
- *,
- label,
- configuration_type: type[C],
- configuration_factory: Callable[[], C],
- configuration_dumper: Callable[[C], JSON],
- configuration_loader: Callable[[JSON], C],
- editor_type: Callable[[C], DeviceConfigurationEditor[C]],
- device_type: Callable[..., Device],
- compiler_type: type[DeviceCompiler],
- controller_type: type[DeviceController],
- proxy_type: type[DeviceProxy],
Bases:
GenericDefine how to implement a device plugin.
This class is generic in the
DeviceConfigurationtype.- label
A human-readable label for the type of device represented by this extension.
This label describes the type of device and will be displayed to the user when they are selecting a device to add to the experiment.
No two device extensions should have the same label.
- Type:
- configuration_type
The type of configuration used to store the settings of the device.
The name of the type is used to identify the configuration type in the storage. It is thus not recommended to change the name of the type after it has been used in the application, as the new name will not be recognized as the same type.
- Type:
type[C]
- configuration_factory
A factory function that returns a new instance of the configuration type.
This function will be called when a new device of this type is added to the experiment. It should return a default instance of the configuration type.
- Type:
collections.abc.Callable[[], C]
- configuration_dumper
A function that converts a configuration instance to a JSON-serializable format. This function will be used to save the configuration.
- Type:
collections.abc.Callable[[C], JSON]
- configuration_loader
A function that converts a JSON-serializable format to a configuration instance. This function will be used to load the configuration. It is passed the JSON-serializable format saved by the configuration_dumper function.
- Type:
collections.abc.Callable[[JSON], C]
- editor_type
A function that creates an editor for the device configuration.
When the user wants to edit the configuration of a device of this type, this function will be called to create an editor for the configuration. The function is passed as argument the configuration instance to edit.
Once the user has finished editing the configuration, the method
get_configuration()of the editor is called and the result is saved.
- device_type
A callable that returns a new device instance.
This function will be called when a device associated with this extension needs to be created. The arguments passed are obtained by calling the method
caqtus.device.compiler.DeviceCompiler.compile_initialization_parameters()of the compiler associated with the device.This function needs to be pickleable as it will be sent to a remote process.
- compiler_type
The type of compiler used to compile the parameters of the device.
When the sequence is launched, a compiler will be created for each device configuration. The compiler
__init__()method is called with the name of the device and the context of the sequence. If the initialization method raisesDeviceNotUsedException, no further actions will be taken for this device, and it will be ignored for the sequence.The method
compile_initialization_parameters()is called at the beginning of the sequence to get the parameters to pass to thedevice_typefunction to create the device.The method
compile_shot_parameters()is then called for each shot to get the parameters to pass to the device controller for the shot.Warning
The compilation of each shot happens in a new process using each time a new copy of the compiler. This has some consequences:
The compiler should be pickleable.
If the compiler is modified during the compilation of a shot, the changes will not be reflected in the next shot.
print()statements in the compiler will not be displayed in the console.