model#

Root models for data structures used within the package.

Module Contents#

Classes#

DataStructure

A parent for all data structures.

Functions#

orjson_dumps(→ str)

Dump an object to a JSON string using orjson library.

deserialize_function(→ Callable[Ellipsis, Any])

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.,

orjson_dumps(obj: Any, *, default: Callable[[Any], Any]) str[source]#

Dump an object to a JSON string using orjson library.

Parameters:
  • obj – Object to dump

  • default – A function that is called if an object can’t be serialized otherwise. It should return a JSON-encodable version of an object or raise a TypeError.

Returns:

JSON-encoded string representation of an object

Return type:

str

Raises:

TypeError – If value can’t be serialized.

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.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

model_config[source]#
deserialize_function(fun: str) Callable[Ellipsis, Any][source]#

Import a python function from a dotted import string (e.g., “quantify_scheduler.structure.model.deserialize_function”).

Parameters:

fun (str) – A dotted import path to a function (e.g., “quantify_scheduler.waveforms.square”), or a function pointer.

Return type:

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., “quantify_scheduler.structure.model.DataStructure”).

Parameters:

cls (str) –

Returns:

The type you are trying to import.

Raises:

ValueError – Raised if the class cannot be imported from path in the string.