qblox_scheduler.structure.model#

Root models for data structures used within the package.

Attributes#

Classes#

Numbers

Dict used to emulate the behaviour of the Numbers qcodes validator.

_SerializableBaseModel

Mixin class that enables dict, JSON and YAML serialization and deserialization

SchedulerBaseModel

Pydantic base model to support qcodes-style instrument and parameter definitions.

SchedulerSubmodule

Compatibility class emulating the behaviour of InstrumentModule/InstrumentChannel.

DataStructure

A parent for all data structures.

Functions#

Parameter(→ Any)

Wrapper function around :func:~pydantic.Field that tries to emulate qcodes parameters

is_identifier(→ str)

Pydantic validator for names that are valid identifiers.

deserialize_function(...)

Import a python function from a dotted import string (e.g.,

deserialize_class(→ type)

Import a python class from a dotted import string (e.g.,

Module Contents#

_Unset: Any[source]#
class Numbers[source]#

Bases: TypedDict

Dict used to emulate the behaviour of the Numbers qcodes validator.

min_value: float[source]#
max_value: float[source]#
allow_nan: bool[source]#
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 default or default_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, ge and le.

  • kwargs – Other arguments passed on to the original Field function.

Returns:

Any: To appease the linters; actually a :class:~pydantic.fields.FieldInfo instance.

is_identifier(value: str) str[source]#

Pydantic validator for names that are valid identifiers.

class _SerializableBaseModel(/, **data: Any)[source]#

Bases: pydantic.BaseModel

Mixin class that enables dict, JSON and YAML serialization and deserialization by attaching to_ and from_ helper methods.

to_dict() dict[str, Any][source]#

Alias for BaseModel.model_dump.

classmethod from_dict(data: dict[str, Any]) typing_extensions.Self[source]#

Alias for BaseModel.model_validate.

to_json(indent: int | None = None) str[source]#

Alias for BaseModel.model_dump_json.

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: _SerializableBaseModel

Pydantic 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].

name: Annotated[str, AfterValidator(is_identifier)] = None[source]#
property parameters: dict[str, Any][source]#

Mapping of parameters of this element.

property submodules: dict[str, Any][source]#

Mapping of submodules of this element.

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.

fill_submodule_parent_defaults() typing_extensions.Self[source]#

After module creation, for each submodule, fill in the default values for fields that read from an attribute of the parent model.

close() None[source]#

Does nothing.

classmethod close_all() None[source]#

Does nothing.

class SchedulerSubmodule(/, name, *, parent: SchedulerBaseModel | None = None, **data: Any)[source]#

Bases: SchedulerBaseModel

Compatibility class emulating the behaviour of InstrumentModule/InstrumentChannel.

_parent: SchedulerBaseModel | SchedulerSubmodule | None = None[source]#
property parent: SchedulerBaseModel | None[source]#
class DataStructure(/, **data: Any)[source]#

Bases: _SerializableBaseModel

A 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 using parse_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.

model_config[source]#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

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.