Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add final action for setting offset of LF-FEM analog output port. #45

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions quam/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ def generate_config_final_actions(qua_config):
Args:
qua_config (dict): The generated qua config.
"""
# Add default dc offset 0V to all analog outputs and inputs if not set
for controller_cfg in qua_config["controllers"].values():
for fem in controller_cfg.get("fems", {}).values():
if fem.get("type") != "LF":
continue
for analog_output in fem.get("analog_outputs", {}).values():
analog_output.setdefault("offset", 0.0)
for analog_input in fem.get("analog_inputs", {}).values():
analog_input.setdefault("offset", 0.0)

if "analog_outputs" in controller_cfg:
for analog_output in controller_cfg["analog_outputs"].values():
analog_output.setdefault("offset", 0.0)
Expand Down
139 changes: 139 additions & 0 deletions tests/config/test_config_final_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
from quam.utils.config import generate_config_final_actions


def test_config_no_overwrite_existing_offset():
cfg = {
"controllers": {
"con1": {
"analog_outputs": {1: {"offset": 0.5}},
"analog_inputs": {2: {"offset": 0.5}},
},
},
}

generate_config_final_actions(cfg)

assert cfg == {
"controllers": {
"con1": {
"analog_outputs": {1: {"offset": 0.5}},
"analog_inputs": {2: {"offset": 0.5}},
},
},
}


def test_config_default_offset():
cfg = {
"controllers": {
"con1": {
"analog_outputs": {1: {}},
"analog_inputs": {2: {}},
},
},
}

generate_config_final_actions(cfg)

assert cfg == {
"controllers": {
"con1": {
"analog_outputs": {1: {"offset": 0.0}},
"analog_inputs": {2: {"offset": 0.0}},
},
},
}


def test_config_default_offset_LF_FEM():
cfg = {
"controllers": {
"con1": {
"fems": {
2: {
"type": "LF",
"analog_outputs": {1: {}},
"analog_inputs": {2: {}},
},
},
},
},
}

generate_config_final_actions(cfg)

assert cfg == {
"controllers": {
"con1": {
"fems": {
2: {
"type": "LF",
"analog_outputs": {1: {"offset": 0.0}},
"analog_inputs": {2: {"offset": 0.0}},
},
},
},
},
}


def test_config_no_overwrite_existing_offset_LF_FEM():
cfg = {
"controllers": {
"con1": {
"fems": {
2: {
"type": "LF",
"analog_outputs": {1: {"offset": 0.5}},
"analog_inputs": {2: {"offset": 0.5}},
},
},
},
},
}

generate_config_final_actions(cfg)

assert cfg == {
"controllers": {
"con1": {
"fems": {
2: {
"type": "LF",
"analog_outputs": {1: {"offset": 0.5}},
"analog_inputs": {2: {"offset": 0.5}},
},
},
},
},
}


def test_config_default_offset_no_outputs_inputs_entries():
cfg = {"controllers": {"con1": {}}}

generate_config_final_actions(cfg)

assert cfg == {"controllers": {"con1": {}}}


def test_config_default_offset_no_outputs_inputs():
cfg = {
"controllers": {
"con1": {
"analog_outputs": {},
"analog_inputs": {},
}
}
}

generate_config_final_actions(cfg)

assert cfg == {
"controllers": {
"con1": {
"analog_outputs": {},
"analog_inputs": {},
}
}
}