# %%
from semi_cr.core.lab.drivers.qdacii import Qdacii
from semi_cr.core.lab.utils.validation_classes import QDACTrigger
from typing import Sequence
[docs]
def init_qdac(qdac: Qdacii, channels: list[int], trigger: QDACTrigger):
dc_lists = qdac.setup_one_hot_dc_lists(
channels=channels,
high_voltage=trigger.voltage.high,
low_voltage=trigger.voltage.low,
trigger_port=trigger.port,
delay_s=trigger.delay,
reset=False,
)
return dc_lists
[docs]
def make_one_hot_pattern(
n_channels: int,
channel_index: int,
high_voltage: float,
low_voltage: float,
include_all_off: bool = True,
) -> list[float]:
"""
Build the voltage list for one QDAC channel in a one-hot pattern.
Example for n_channels=4, channel_index=0:
[high, low, low, low, low]
The final low is the all-off state.
"""
n_steps = n_channels + int(include_all_off)
voltages = [float(low_voltage)] * n_steps
voltages[channel_index] = float(high_voltage)
return voltages
# Single one-hot setup
[docs]
def setup_one_hot_dc_lists(
qdac: Qdacii,
channels: list[int],
high_voltage: float = 5,
low_voltage: float = -5,
trigger_port: int = 1,
delay_s: float = 0.1,
reset: bool = True,
):
"""
Configure channels and create one-hot DC lists.
Example for channels [1, 2, 3, 4]:
ch1: [ 5, -5, -5, -5, -5]
ch2: [-5, 5, -5, -5, -5]
ch3: [-5, -5, 5, -5, -5]
ch4: [-5, -5, -5, 5, -5]
"""
if reset:
qdac.reset()
qdac_channels = qdac.configure_channels(channels)
dc_lists = {}
n_channels = len(channels)
for channel_index, qdac_ch in enumerate(qdac_channels):
voltages = make_one_hot_pattern(
n_channels=n_channels,
channel_index=channel_index,
high_voltage=high_voltage,
low_voltage=low_voltage,
include_all_off=True,
)
dc_list = qdac_ch.dc_list(
voltages=voltages,
stepped=True,
delay_s=delay_s,
)
dc_list.start_on_external(trigger=trigger_port)
dc_lists[qdac_ch.short_name] = dc_list
confirm_trigger = list(dc_lists.values())[0].step_end_marker()
qdac.connect_external_trigger(
port=trigger_port,
trigger=confirm_trigger,
)
return dc_lists
# Grid version
[docs]
def make_one_hot_voltage_grid(
channels: Sequence[int],
low_voltages: Sequence[float],
high_voltages: Sequence[float],
include_all_off: bool = True,
) -> dict[int, list[float]]:
"""
Build concatenated one-hot voltage lists for all high/low combinations.
Ordering:
for high in high_voltages:
for low in low_voltages:
append one-hot + all-off
"""
n_channels = len(channels)
voltage_lists = {
ch: []
for ch in channels
}
for high in high_voltages:
for low in low_voltages:
for channel_index, ch in enumerate(channels):
voltage_lists[ch].extend(
make_one_hot_pattern(
n_channels=n_channels,
channel_index=channel_index,
high_voltage=float(high),
low_voltage=float(low),
include_all_off=include_all_off,
)
)
return voltage_lists
[docs]
def setup_qdac_voltage_grid_lists(
qdac: Qdacii,
channels: list[int],
low_voltages: Sequence[float],
high_voltages: Sequence[float],
trigger_port: int,
delay_s: float,
reset: bool = False,
):
if reset:
qdac.reset()
qdac_channels = qdac.configure_channels(channels)
voltage_lists = make_one_hot_voltage_grid(
channels=channels,
low_voltages=low_voltages,
high_voltages=high_voltages,
include_all_off=True,
)
dc_lists = {}
for ch_number, qdac_ch in zip(channels, qdac_channels):
dc_list = qdac_ch.dc_list(
voltages=voltage_lists[ch_number],
stepped=True,
delay_s=delay_s,
)
dc_list.start_on_external(trigger=trigger_port)
dc_lists[qdac_ch.short_name] = dc_list
confirm_trigger = list(dc_lists.values())[0].step_end_marker()
qdac.connect_external_trigger(
port=trigger_port,
trigger=confirm_trigger,
)
return dc_lists
# def setup_one_hot_dc_lists(
# qdac: Qdacii,
# channels: list[int],
# high_voltage: float = 5,
# low_voltage: float = -5,
# trigger_port: int = 1,
# delay_s: float = 0.1,
# reset: bool = True,
# ):
# """
# Configure channels and create one-hot DC lists.
# Example for channels [1, 2, 3, 4]:
# ch1: [ 5, -5, -5, -5, -5]
# ch2: [-5, 5, -5, -5, -5]
# ch3: [-5, -5, 5, -5, -5]
# ch4: [-5, -5, -5, 5, -5]
# """
# if reset:
# qdac.reset()
# qdac_channels = qdac.configure_channels(channels)
# dc_lists = {}
# n_steps = len(channels) + 1
# for i, ch in enumerate(qdac_channels):
# voltages = [low_voltage] * n_steps
# voltages[i] = high_voltage
# dc_list = ch.dc_list(
# voltages=voltages,
# stepped=True,
# delay_s=delay_s,
# )
# dc_list.start_on_external(trigger=trigger_port)
# dc_lists[ch.short_name] = dc_list
# confirm_trigger = list(dc_lists.values())[0].step_end_marker()
# qdac.connect_external_trigger(
# port=trigger_port,
# trigger=confirm_trigger,
# )
# return dc_lists