Skip to content

Commit

Permalink
modifications + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nulinspiratie committed Jun 27, 2024
1 parent 0c2f88a commit b9e1bd2
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 9 deletions.
17 changes: 8 additions & 9 deletions quam/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ 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():
if "fems" in controller_cfg:
for fem in controller_cfg["fems"].values():
if fem.get("type") == "LF":
if "analog_outputs" in fem:
for analog_output in fem["analog_outputs"].values():
analog_output.setdefault("offset", 0.0)
if "analog_inputs" in fem:
for analog_input in fem["analog_inputs"].values():
analog_input.setdefault("offset", 0.0)
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():
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": {},
}
}
}

0 comments on commit b9e1bd2

Please sign in to comment.