structure#

Validated and serializable data structures using pydantic.

In this module we provide pre-configured Pydantic model and custom field types that allow serialization of typical data objects that we frequently use in quantify-scheduler, like functions and arrays.

Submodules#

Package Contents#

Classes#

DataStructure

A parent for all data structures.

Graph

Pydantic-compatible version of networkx.Graph.

NDArray

Pydantic-compatible version of numpy.ndarray.

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

Bases: pydantic.BaseModel

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#

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

class Graph(incoming_graph_data=None, **attr)[source]#

Bases: networkx.Graph

Pydantic-compatible version of networkx.Graph.

classmethod validate(v: Any) Graph[source]#

Validate the data and cast from all known representations.

class NDArray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)[source]#

Bases: numpy.ndarray

Pydantic-compatible version of numpy.ndarray.

Serialization is implemented using custom methods to_dict() and from_dict(). Data array is encoded in Base64.

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

Convert the array to JSON-compatible dictionary.

classmethod from_dict(serialized: collections.abc.Mapping[str, Any]) NDArray[source]#

Construct an instance from a dictionary generated by :meth`to_dict`.

Parameters:

serialized – Dictionary that has "data", "shape" and "dtype" keys.”, where data is a base64-encoded bytes array, shape is a tuple and dtype is a string representation of a Numpy data type.

classmethod validate(v: Any) NDArray[source]#

Validate the data and cast from all known representations.