instrumentserver.helpers#
Functions
|
Converts a flat dictionary with keys separated by dots into a nested dictionary. |
|
Detects if a dictionary is flat (i.e. all values are non-dicts). |
|
Return the methods of an instrument. |
Return the parameters of an instrument. |
|
|
Detects if a dictionary is flat (i.e. all values are non-dicts). |
|
Return a sub-object. Example::. |
|
Create argument list and kwarg dict from a string. |
- instrumentserver.helpers.flat_to_nested_dict(flat_dict: Dict) Dict[source]#
Converts a flat dictionary with keys separated by dots into a nested dictionary.
- Parameters:
flat_dict – A flat dictionary where keys are strings with dot-separated parts.
- Returns:
A nested dictionary reconstructed from the flat structure.
Example:
flat = { "a.b.c": 1, "a.b.d": 2, "x": 3 } result = flat_to_nested_dict(flat) # result: {"a": {"b": {"c": 1,"d": 2}},"x": 3}
- instrumentserver.helpers.flatten_dict(d: Dict[str, Any], sep: str = '.') Dict[str, Any][source]#
Detects if a dictionary is flat (i.e. all values are non-dicts). If it is not flat, recursively flattens it using dot-separated keys.
- Parameters:
d – A dictionary, potentially nested.
sep – Separator to use for the flattened keys.
- Returns:
A flat dictionary if input was nested; original dictionary if already flat.
Example:
flatten_dict({"a": 1, "b.c": 2}) # returns: {"a": 1, "b.c": 2} flatten_dict({"a": {"b": 1}, "x": 3}) # returns: {"a.b": 1, "x": 3}
- instrumentserver.helpers.getInstrumentMethods(ins: Instrument) Dict[str, Dict[str, str | List[str]]][source]#
Return the methods of an instrument.
- Parameters:
ins – instrument instance
- Returns:
a dictionary, with keys being the names of methods that are not private and not inherited from qcodes.Instrument. Each entry is a dictionary containing: - ‘parameters’: List of string representations of the parameters - ‘doc’: Docstring of the method - ‘return’: string representation of the return type.
- instrumentserver.helpers.getInstrumentParameters(ins: Instrument) Dict[str, Dict[str, str]][source]#
Return the parameters of an instrument.
- Parameters:
ins – instrument instance
- Returns:
a param dict with entries unit, vals, for each instrument parameter.
- instrumentserver.helpers.is_flat_dict(d: dict) bool[source]#
Detects if a dictionary is flat (i.e. all values are non-dicts).
- instrumentserver.helpers.nestedAttributeFromString(root: Any, loc: str) Any[source]#
Return a sub-object. Example:
>>> nestedAttributeFromString(parent_object, 'foo.bar.spam.bacon')
returns the object that can be found at parent_object.foo.bar.spam.bacon.
- instrumentserver.helpers.stringToArgsAndKwargs(value: str) Tuple[List[Any], Dict[str, Any]][source]#
Create argument list and kwarg dict from a string.
- Example::
>>> stringToArgsAndKwargs("1, True, abc=12.3") [1, True], {'abc': 12.3}
- Returns:
list of arguments and dictionary with keyword arguments.
- Raises:
ValueErrorif: - kwargs are not in the right format (i.e. not``key=value``) - args or kwarg values cannot be evaluated witheval.