Introduce Pydantic-based model for data structures
Explanation of changes
This MR introduces a DataStructure parent class for usage as a parent class for data structures in quantify-scheduler in future. DataStructure is an empty pydantic model with some basic configuration.
Porting existing data structures is out of scope of this MR, it only establishes a framework for this.
This MR does not do resolve problems with serialization of array data types, it should be a separate discussion.
Motivation of changes
Currently all data structures are inheriting from UserDicts, which makes APIs ugly and hard to work with. There are long-standing issues to fix that (#159 #222 (closed)). Before there were two competitive proposals: use dataclasses and use traitlets (!185 (closed)). This MR replaces them with pydantic
While I feel that traitlets are more stable and straightforward to use for now, I found that they lack some features of the level "must have" and "good to have" (raising exceptions for uninitialized traits, autogeneration of __init__ call signatures, generation of __str__, __repr__, __eq__ that make sense), that are offered by pydantic for free. Also, pydantic has flexible and configurable serialization mechanism, schema validation and some more cool features (see its documentation).
Downsides of using pydantic are its code complexity (it is very hard to figure out what is going in that Cython-compiled spaghetti mess, no offense to authors, I understand the reasons that lead to it traitlets and observer pattern from the box, present in traitlets. However, in this case the advantages of pydantic are dominating, in my opinion.
Merge checklist
See also merge request guidelines
-
Merge request has been reviewed and approved by a project maintainer. -
Merge request contains a clear description of the proposed changes and the issue it addresses. -
Merge request made onto appropriate branch (develop for most MRs). -
New code is fully tested. -
New code is documented and docstrings use numpydoc format. -
CHANGELOG.rstandAUTHORS.rsthave been updated (when applicable). -
CI pipelines pass -
pre-commit run --all-files --hook-stage commitpasses (gitlab-ci), - test suite passes (gitlab-ci),
- no degradation in code-coverage (codacy),
- no (serious) new pylint code quality issues introduced (codacy),
- documentation builds successfully (CI and readthedocs),
-
windows tests pass (manually triggered by maintainers before merging).
-
For reference, the issues workflow is described in the contribution guidelines.