Source code for semi_cr.core.station.manifest

from __future__ import annotations

import tomllib
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from pathlib import Path

from semi_cr.core.lab.station.base import ConfigBundle


# TODO: Consider whether `loaded_chip_id` is the better option for specifying the currently loaded chip, and how are we
#       going to tackle the question of which device on the chip we're currently using. Could we abstract all this away
#       somehow?
[docs] class NQCPStationManifest: """ Helper class for loading a station manifest. The main value proposition is that we don't leak to the callers how the manifest is encoded (TOML) or where it's stored. The TOML manifest `station.toml` has three sections of interest; `wiring`, `electronics`, and `device`. Each section has a `files` key that lists the configuration files to load for that section. Besides that it carries a few keys at the top level, like name. The `device` section contains a list of files describing individual chips (and the devices on these chips). Moreover it has a `loaded_chip_id` key that indicates which chip is currently loaded in the station. """ manifest: dict[str, Any] manifest_path: Path basedir: Path def __init__(self, manifest_path: Path) -> None: self.manifest_path: Path = manifest_path self.basedir: Path = manifest_path.parent # Load the manifest configuration sections, and bundle them up with manifest_path.open("rb") as file: self.manifest = tomllib.load(file)
[docs] def get_config_bundle(self) -> ConfigBundle: config_files_combined = self.manifest["device"]["files"] + self.manifest["wiring"]["files"] + self.manifest["electronics"]["files"] return ConfigBundle(tuple(self.basedir / path for path in config_files_combined))
@property def name(self) -> str: return self.manifest["name"] @property def loaded_chip_id(self) -> str: """ In the manifest, the loaded chip ID is stored under the `device` section. This property provides a convenient way to access it. """ return self.manifest["device"]["loaded_chip_id"]