配置仪器设备
通过 device_db.py 将实验仪器接入 Quatm 框架。
Quatm 通过 configuration/device_db.py 管理所有实验仪器。该文件定义一个名为 device_db 的字典,每个键对应一个可在实验中使用的设备名称。
设备类型
device_db 支持三种设备类型:
| type | 说明 | 使用场景 |
|---|---|---|
local | 驱动类实例 | FPGA 控制器、相机等需要完整驱动对象的设备 |
attr | 属性映射 | 将驱动的某个通道映射为实验属性(如 DAC、TTL) |
generic_attr | 通用属性 | 调用驱动的任意函数,实现灵活的功能映射 |
配置示例
device_db = {
# 驱动设备:加载完整的驱动实例
"fpga": {
"type": "local",
"module": "quatm.drivers.fpga.client",
"class": "fpgaClient",
"arguments": {},
},
# 属性设备:TTL 通道映射
"cooling_aom": {
"type": "attr",
"module": "quatm.experiment.attributes",
"class": "TTLOut",
"arguments": {"channel": 5, "logic": "a"},
},
# 属性设备:DAC 通道映射
"trap_coil_x": {
"type": "attr",
"module": "quatm.experiment.attributes",
"class": "DAC",
"arguments": {"channel": 2},
},
}
属性设备参数
TTLOut — 数字输出
| 参数 | 说明 |
|---|---|
channel | FPGA 控制器 TTL 通道编号 |
logic | "l" 为正逻辑,"a" 为反逻辑 |
DAC — 模拟输出
| 参数 | 说明 |
|---|---|
channel | FPGA 控制器 DAC 通道编号 |
gaugefile | 校准文件路径(可选) |
通用属性配置
对于需要灵活映射的驱动功能,使用 genericAttr:
"Li_frequency": {
"type": "generic_attr",
"module": "quatm.experiment.attributes",
"class": "genericAttr",
"driver": "lithium_dds_0",
"function": "set_frequency",
"arguments": {
"function_kwargs": {"channel": [0]},
"minval": 40, "maxval": 90,
"multiplier": 1E6, "display_unit": "MHz",
},
}
校准文件
对于非线性响应的设备,可使用两列空格分隔的文本文件进行校准:
2.2 4.0
2.0 3.8
1.8 3.6
1.6 3.34
在 DAC 配置中通过 gauge 参数引用:
"rf_power": {
"type": "attr",
"module": "quatm.experiment.attributes",
"class": "DAC",
"arguments": {"channel": 3, "gauge": "configuration/gauge-rf-power.txt"},
}
自定义驱动接入
编写自定义驱动类后,在 device_db 中以 type: "local" 注册:
"my_laser": {
"type": "local",
"module": "my_lab.my_laser_driver",
"class": "MyLaserDriver",
"arguments": {"port": "/dev/ttyUSB0"},
}
然后在实验中通过 self.setattr_device("my_laser") 使用。