Source code for qumada.metadata

# Copyright (c) 2023 JARA Institute for Quantum Information
#
# This file is part of QuMADA.
#
# QuMADA is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# QuMADA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# QuMADA. If not, see <https://www.gnu.org/licenses/>.
#
# Contributors:
# - Daniel Grothe


from __future__ import annotations

from datetime import datetime
from typing import Protocol


[docs]class Metadata(Protocol): """ Protocol for a Metadata object. Defines the methods to handle specific metadata portions collected with QuMADA. """
[docs] def add_terminal_mapping(self, mapping: str, name: str): """Adds metadata of the mapping between terminals and instrument parameters as a (JSON) string."""
[docs] def add_script_to_metadata(self, script: str, language: str, name: str): """Adds metadata of the used measurement script."""
[docs] def add_parameters_to_metadata(self, parameters: str, name: str): """Adds parameters and their settings to metadata."""
[docs] def add_datetime_to_metadata(self, dt: datetime): """Adds datetime to metadata."""
[docs] def add_data_to_metadata(self, location: str, datatype: str, name: str): """Adds metadata related to the measurement data to metadata."""
[docs]class Savable(Protocol): """Protocol for a savable / updatable (metadata) object."""
[docs] def save(self): """Saves metadata to new objects."""
[docs] def update(self): """Updates the already saved metadata."""
[docs]class BasicMetadata: """Example implementation of a MetadataHandler.""" def __init__(self): self.metadata = {}
[docs] def add_terminal_mapping(self, mapping: str, name: str = "mapping"): self.metadata[name] = mapping
[docs] def add_script_to_metadata(self, script: str, language: str, name: str = "script"): self.metadata[name] = (language, script)
[docs] def add_parameters_to_metadata(self, parameters: str, name: str = "parameters"): self.metadata[name] = parameters
[docs] def add_datetime_to_metadata(self, dt: datetime): self.metadata["datetime"] = dt
[docs] def add_data_to_metadata(self, location: str, datatype: str, name: str = "data"): self.metadata[name] = (datatype, location)