Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid roundtrip to qcodes format when loading as xarray from netcdf #5627

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
defer converting from xarray until required
  • Loading branch information
jenshnielsen committed Jan 18, 2024
commit c9d55aaf08d886c898001b1ccc5069b8f43219fa
14 changes: 13 additions & 1 deletion src/qcodes/dataset/data_set_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# used in forward refs that cannot be detected
from .data_set import DataSet # noqa F401
from .data_set_in_memory import DataSetInMem # noqa F401
from .data_set_in_memory import DataSetInMem
from .data_set_protocol import DataSetProtocol, ParameterData

DatasetType = TypeVar("DatasetType", bound="DataSetProtocol", covariant=True)
Expand Down Expand Up @@ -453,6 +453,18 @@ class DataSetCacheInMem(DataSetCache["DataSetInMem"]):
pass


class DataSetCacheDeferred(DataSetCacheInMem):
def __init__(self, dataset: DataSetInMem, loaded_data: xr.Dataset):
super().__init__(dataset)
self._xr_dataset = loaded_data

def load_data_from_db(self) -> None:
if self._data == {}:
self._data = self._dataset._from_xarray_dataset_to_qcodes_raw_data(
self._xr_dataset
)


class DataSetCacheWithDBBackend(DataSetCache["DataSet"]):
def load_data_from_db(self) -> None:
"""
Expand Down
5 changes: 2 additions & 3 deletions src/qcodes/dataset/data_set_in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
)
from qcodes.utils import NumpyJSONEncoder

from .data_set_cache import DataSetCacheInMem
from .data_set_cache import DataSetCacheDeferred, DataSetCacheInMem
from .dataset_helpers import _add_run_to_runs_table
from .descriptions.versioning import serialization as serial
from .experiment_settings import get_default_experiment_id
Expand Down Expand Up @@ -298,8 +298,7 @@ def _load_from_netcdf(
export_info=export_info,
jenshnielsen marked this conversation as resolved.
Show resolved Hide resolved
snapshot=loaded_data.snapshot,
)
ds._cache = DataSetCacheInMem(ds)
ds._cache._data = cls._from_xarray_dataset_to_qcodes_raw_data(loaded_data)
ds._cache = DataSetCacheDeferred(ds, loaded_data)

return ds

Expand Down