-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4355: API: Split metadata module and make public r=jenshnielsen a=jenshnielsen Move functions that need to know about dataset to that module and extend with a function that takes dataset rather than runid Split Metadatable class and shapshot diff functions into different submodules and make all public 4358: Remove deprecated units from data array r=jenshnielsen a=jenshnielsen This was missed as part of #4330 Co-authored-by: Jens H. Nielsen <[email protected]> Co-authored-by: Jens Hedegaard Nielsen <[email protected]>
- Loading branch information
Showing
22 changed files
with
202 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. _metadatable_api : | ||
|
||
qcodes.metadatable | ||
================== | ||
|
||
.. automodule:: qcodes.metadatable | ||
:autosummary: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from qcodes.utils import ParameterDiff, diff_param_values | ||
|
||
from .data_set import load_by_id | ||
from .data_set_protocol import DataSetProtocol | ||
|
||
|
||
def diff_param_snapshots( | ||
left: DataSetProtocol, right: DataSetProtocol | ||
) -> ParameterDiff: | ||
""" | ||
Given two datasets, returns the differences between | ||
parameter values in each of their snapshots. | ||
""" | ||
left_snapshot = left.snapshot | ||
right_snapshot = right.snapshot | ||
|
||
if left_snapshot is None or right_snapshot is None: | ||
if left_snapshot is None: | ||
empty = left | ||
else: | ||
empty = right | ||
raise RuntimeError( | ||
f"Tried to compare two snapshots" | ||
f"but the snapshot of {empty.run_id} " | ||
f"is empty." | ||
) | ||
|
||
return diff_param_values(left_snapshot, right_snapshot) | ||
|
||
|
||
def diff_param_values_by_id(left_id: int, right_id: int) -> ParameterDiff: | ||
""" | ||
Given the IDs of two datasets, returns the differences between | ||
parameter values in each of their snapshots. | ||
""" | ||
return diff_param_snapshots(load_by_id(left_id), load_by_id(right_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .metadatable_base import Metadatable | ||
|
||
__all__ = ["Metadatable"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Any, Dict, Mapping, Optional, Sequence | ||
|
||
from qcodes.utils import deep_update | ||
|
||
# NB: At the moment, the Snapshot type is a bit weak, as the Any | ||
# for the value type doesn't tell us anything about the schema | ||
# followed by snapshots. | ||
# This is needed, however, since snapshots are Dict instances with | ||
# homogeneous keys and heterogeneous values, something that | ||
# recent Python versions largely replace with features like | ||
# typing.NamedTuple and @dataclass. | ||
# As those become more widely available, the weakness of this | ||
# type constraint will become less of an issue. | ||
Snapshot = Dict[str, Any] | ||
|
||
|
||
class Metadatable: | ||
def __init__(self, metadata: Optional[Mapping[str, Any]] = None): | ||
self.metadata: Dict[str, Any] = {} | ||
self.load_metadata(metadata or {}) | ||
|
||
def load_metadata(self, metadata: Mapping[str, Any]) -> None: | ||
""" | ||
Load metadata into this classes metadata dictionary. | ||
Args: | ||
metadata: Metadata to load. | ||
""" | ||
deep_update(self.metadata, metadata) | ||
|
||
def snapshot(self, update: Optional[bool] = False) -> Snapshot: | ||
""" | ||
Decorate a snapshot dictionary with metadata. | ||
DO NOT override this method if you want metadata in the snapshot | ||
instead, override :meth:`snapshot_base`. | ||
Args: | ||
update: Passed to snapshot_base. | ||
Returns: | ||
Base snapshot. | ||
""" | ||
|
||
snap = self.snapshot_base(update=update) | ||
|
||
if len(self.metadata): | ||
snap["metadata"] = self.metadata | ||
|
||
return snap | ||
|
||
def snapshot_base( | ||
self, | ||
update: Optional[bool] = False, | ||
params_to_skip_update: Optional[Sequence[str]] = None, | ||
) -> Snapshot: | ||
""" | ||
Override this with the primary information for a subclass. | ||
""" | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.