qblox_scheduler.structure.model#
Root models for data structures used within the package.
Attributes#
Classes#
Dict used to emulate the behaviour of the |
|
Mixin class that enables dict, JSON and YAML serialization and deserialization |
|
Pydantic base model to support qcodes-style instrument and parameter definitions. |
|
Compatibility class emulating the behaviour of |
|
A parent for all data structures. |
Functions#
|
Wrapper function around :func:~pydantic.Field that tries to emulate qcodes parameters |
|
Pydantic validator for names that are valid identifiers. |
|
Import a python function from a dotted import string (e.g., |
|
Import a python class from a dotted import string (e.g., |
Module Contents#
- class Numbers[source]#
Bases:
TypedDictDict used to emulate the behaviour of the
Numbersqcodes validator.
- Parameter(*, initial_value: Any = _Unset, label: str | None = _Unset, docstring: str | None = _Unset, unit: str | None = _Unset, vals: Numbers | None = _Unset, **kwargs: Any) Any[source]#
Wrapper function around :func:~pydantic.Field that tries to emulate qcodes parameters as closely as possible, to facilitate migration and reduce diff lines.
- Parameters:
initial_value – Maps to
defaultordefault_factory(if callable).label – Maps to
title, displayed on the JSON schema.docstring – Maps to
description, displayed on the JSON schema.unit – Stored internally, retrievable using
get_unit().vals – Maps to
allow_inf_nan,geandle.kwargs – Other arguments passed on to the original
Fieldfunction.
- Returns:
Any: To appease the linters; actually a :class:~pydantic.fields.FieldInfo instance.
- class _SerializableBaseModel(/, **data: Any)[source]#
Bases:
pydantic.BaseModelMixin class that enables dict, JSON and YAML serialization and deserialization by attaching to_ and from_ helper methods.
- classmethod from_dict(data: dict[str, Any]) typing_extensions.Self[source]#
Alias for BaseModel.model_validate.
- classmethod from_json(json_data: str) typing_extensions.Self[source]#
Alias for BaseModel.model_validate_json.
- _generate_file_name(path: str | None, add_timestamp: bool, extension: str) str[source]#
Generate a file name to be used by to_*_file methods.
- to_json_file(path: str | None = None, add_timestamp: bool = True) str[source]#
Convert the object’s data structure to a JSON string and store it in a file.
- classmethod from_json_file(filename: str | pathlib.Path) typing_extensions.Self[source]#
Read JSON data from a file and convert it to an instance of the attached class.
- to_yaml() str[source]#
Convert the object’s data structure to a YAML string.
For performance reasons, to save to file use
to_yaml_file()instead.
- classmethod from_yaml(yaml_data: str) typing_extensions.Self[source]#
Convert YAML data to an instance of the attached class.
For performance reasons, to load from file use
from_yaml_file()instead.
- to_yaml_file(path: str | None = None, add_timestamp: bool = True) str[source]#
Convert the object’s data structure to a YAML string and store it in a file.
- 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.
- class SchedulerBaseModel(/, name, **data: Any)[source]#
Bases:
_SerializableBaseModelPydantic base model to support qcodes-style instrument and parameter definitions.
- model_config[source]#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod get_unit(field_name: str) str | None[source]#
Get the unit declared for a certain field/parameter.
- classmethod create_submodule_instances(data: Any) Any[source]#
During model instantiation, create an empty/default instance of all submodules.
- class SchedulerSubmodule(/, name, *, parent: SchedulerBaseModel | None = None, **data: Any)[source]#
Bases:
SchedulerBaseModelCompatibility class emulating the behaviour of
InstrumentModule/InstrumentChannel.- _parent: SchedulerBaseModel | SchedulerSubmodule | None = None[source]#
- property parent: SchedulerBaseModel | None[source]#
- class DataStructure(/, **data: Any)[source]#
Bases:
_SerializableBaseModelA parent for all data structures.
Data attributes are generated from the class’ type annotations, similarly to dataclasses. If data attributes are JSON-serializable, data structure can be serialized using
json()method. This string can be deserialized usingparse_raw()classmethod of a correspondent child class.If required, data fields can be validated, see examples for more information. It is also possible to define custom field types with advanced validation.
This class is a pre-configured pydantic model. See its documentation for details of usage information.
Examples
- deserialize_function(fun: str) collections.abc.Callable[Ellipsis, Any][source]#
Import a python function from a dotted import string (e.g., “qblox_scheduler.structure.model.deserialize_function”).
- Parameters:
fun (str) – A dotted import path to a function (e.g., “qblox_scheduler.waveforms.square”), or a function pointer.
- Returns:
Callable[[Any], Any]
- Raises:
ValueError – Raised if the function cannot be imported from path in the string.
- deserialize_class(cls: str) type[source]#
Import a python class from a dotted import string (e.g., “qblox_scheduler.structure.model.DataStructure”).
- Parameters:
cls (str) – A dotted import path to a class (e.g., “qblox_scheduler.structure.model.DataStructure”), or a class pointer.
- Returns:
: The type you are trying to import.
- Raises:
ValueError – Raised if the class cannot be imported from path in the string.