yaml_utils#
Module containing quantify YAML utilities.
Module Contents#
Classes#
Mixin to allow (de)serialization of instruments from/to YAML. |
Attributes#
- class YAMLSerializable[source]#
Mixin to allow (de)serialization of instruments from/to YAML.
NOTE: Only works with
Instrument
subclasses, for others use @yaml.register_class.- NOTE: to_yaml and from_yaml methods cannot be created because they would be found
and used by the
ruamel.yaml
representers and constructors.
- to_yaml_file(path: str | pathlib.Path | None = None, add_timestamp: bool = True) str [source]#
Convert the object’s data structure to a YAML string and store it in a file.
- Parameters:
path – The path to the directory where the file is created. Default is None, in which case the file will be saved in the directory determined by
get_datadir()
.add_timestamp – Specify whether to append timestamp to the filename. Default is True.
- Returns:
The name of the file containing the serialized object.
- classmethod from_yaml_file(filename: str | pathlib.Path) typing_extensions.Self [source]#
Read YAML data from a file and convert it to an instance of the attached class.
- Parameters:
filename – The name of the file containing the serialized object.
- Returns:
The deserialized object.