Skip to content

Commit

Permalink
Merge pull request #113 from qutech/feature/parameter_whitelists
Browse files Browse the repository at this point in the history
Moved allowed params into json file.
  • Loading branch information
THuckemann authored Nov 22, 2024
2 parents ef4f4b2 + 4065ca0 commit e13dc6a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
24 changes: 24 additions & 0 deletions src/qumada/instrument/parameter_whitelists/param_whitelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"parameters": [
"voltage",
"voltage_x_component",
"voltage_y_component",
"voltage_offset",
"current",
"current_x_component",
"current_y_component",
"current_compliance",
"amplitude",
"frequency",
"output_enabled",
"time_constant",
"phase",
"count",
"aux_voltage_1",
"aux_voltage_2",
"temperature",
"test_parameter",
"demod0_aux_in_1",
"demod0_aux_in_2"
]
}
22 changes: 2 additions & 20 deletions src/qumada/measurement/device_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from qumada.instrument.buffers.buffer import map_triggers
from qumada.instrument.mapping import map_terminals_gui
from qumada.measurement.measurement import load_param_whitelist
from qumada.measurement.scripts import (
Generic_1D_Hysteresis_buffered,
Generic_1D_parallel_asymm_Sweep,
Expand Down Expand Up @@ -513,26 +514,7 @@ class Terminal(ABC):
"""

# TODO: Put list elsewhere! Remove names that were added as workarounds (e.g. aux_voltage) as soon as possible
PARAMETER_NAMES: set[str] = {
"voltage",
"voltage_x_component",
"voltage_y_component",
"voltage_offset",
"current",
"current_x_component",
"current_y_component",
"current_compliance",
"amplitude",
"frequency",
"output_enabled",
"time_constant",
"phase",
"count",
"aux_voltage_1",
"aux_voltage_2",
"temperature",
"test_parameter",
}
PARAMETER_NAMES: set[str] = load_param_whitelist()

def __init__(self, name, parent: QumadaDevice | None = None, type: str | None = None):
# Create function hooks for metadata
Expand Down
43 changes: 20 additions & 23 deletions src/qumada/measurement/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import inspect
import json
import logging
import os
from abc import ABC, abstractmethod
from collections.abc import MutableSequence
from contextlib import suppress
Expand All @@ -48,6 +49,20 @@
logger = logging.getLogger(__name__)


def load_param_whitelist(folder_path=None):
combined_params = set()
if folder_path is None:
folder_path = os.path.join(os.path.dirname(__file__), "../instrument/parameter_whitelists")
for filename in os.listdir(folder_path):
if filename.endswith(".json"): # Nur JSON-Dateien laden
file_path = os.path.join(folder_path, filename)
with open(file_path) as file:
data = json.load(file)
for key in data.keys():
combined_params.update(data.get(key, []))
return combined_params


def is_measurement_script(o):
return inspect.isclass(o) and issubclass(o, MeasurementScript)

Expand Down Expand Up @@ -87,28 +102,7 @@ class MeasurementScript(ABC):
"""

# TODO: Put list elsewhere! Remove names that were added as workarounds (e.g. aux_voltage) as soon as possible
PARAMETER_NAMES: set[str] = {
"voltage",
"voltage_x_component",
"voltage_y_component",
"voltage_offset",
"current",
"current_x_component",
"current_y_component",
"current_compliance",
"amplitude",
"frequency",
"output_enabled",
"time_constant",
"phase",
"count",
"aux_voltage_1",
"aux_voltage_2",
"temperature",
"test_parameter",
"demod0_aux_in_1",
"demod0_aux_in_2",
}
PARAMETER_NAMES: set[str] = load_param_whitelist()

def __init__(self):
# Create function hooks for metadata
Expand All @@ -132,7 +126,10 @@ def add_gate_parameter(self, parameter_name: str, gate_name: str = None, paramet
parameter (Parameter): Custom parameter. Set this, if you want to set a custom parameter. Defaults to None.
"""
if parameter_name not in MeasurementScript.PARAMETER_NAMES:
raise NameError(f'parameter_name "{parameter_name}" not in MeasurementScript.PARAMETER_NAMES.')
raise NameError(
f'parameter_name "{parameter_name}" not in MeasurementScript.PARAMETER_NAMES. \
Allowed parameters are listed in qumada.instrument.parameter_whitelists'
)
if not gate_name:
self.gate_parameters[parameter_name] = parameter
else:
Expand Down

0 comments on commit e13dc6a

Please sign in to comment.