Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions plottr/apps/inspectr.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,10 @@ def setDateSelection(self, dates: Sequence[str]) -> None:
@Slot(int)
def setRunSelection(self, runId: int) -> None:
assert self.filepath is not None
ds = load_dataset_from(self.filepath, runId)
if sys.version_info >= (3, 11):
ds = load_dataset_from(self.filepath, runId, read_only=True)
else:
ds = load_dataset_from(self.filepath, runId)
snap = None
if hasattr(ds, 'snapshot'):
snap = ds.snapshot
Expand Down Expand Up @@ -607,7 +610,10 @@ def setTag(self, item: QtWidgets.QTreeWidgetItem, tag: str) -> None:
# set tag in the database
assert self.filepath is not None
runId = int(item.text(0))
ds = load_dataset_from(self.filepath, runId)
if sys.version_info >= (3, 11):
ds = load_dataset_from(self.filepath, runId, read_only=False)
else:
ds = load_dataset_from(self.filepath, runId)
ds.add_metadata('inspectr_tag', tag)

# set tag in self.dbdf
Expand Down
34 changes: 22 additions & 12 deletions plottr/data/qcodes_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Dealing with qcodes dataset (the database) data in plottr.
"""
import os
import sys
from contextlib import closing
from itertools import chain
from operator import attrgetter
from typing import Dict, List, Set, Union, TYPE_CHECKING, Any, Tuple, Optional, cast
Expand All @@ -14,7 +16,7 @@

from qcodes.dataset.data_set import load_by_id
from qcodes.dataset.experiment_container import experiments
from qcodes.dataset.sqlite.database import initialise_or_create_database_at
from qcodes.dataset.sqlite.database import conn_from_dbpath_or_conn, initialise_or_create_database_at

from .datadict import DataDictBase, DataDict, combine_datadicts
from ..node.node import Node, updateOption
Expand Down Expand Up @@ -160,7 +162,7 @@ def get_ds_info(ds: 'DataSetProtocol', get_structure: bool = True) -> DataSetInf
return data


def load_dataset_from(path: str, run_id: int) -> 'DataSetProtocol':
def load_dataset_from(path: str, run_id: int, read_only: bool = True) -> 'DataSetProtocol':
"""
Loads ``DataSet`` with the given ``run_id`` from a database file that
is located in in the given ``path``.
Expand All @@ -169,6 +171,8 @@ def load_dataset_from(path: str, run_id: int) -> 'DataSetProtocol':
qcodes config of the current python process is changed to ``path``.
"""
initialise_or_create_database_at(path)
if sys.version_info >= (3, 11):
return load_by_id(run_id=run_id, read_only=read_only)
return load_by_id(run_id=run_id)


Expand All @@ -187,18 +191,24 @@ def get_runs_from_db(path: str, start: int = 0,
in the return dict.
"""
initialise_or_create_database_at(path)
if sys.version_info >= (3, 11):
conn = conn_from_dbpath_or_conn(conn=None, path_to_db=path, read_only=True)
else:
conn = conn_from_dbpath_or_conn(conn=None, path_to_db=path)
with closing(conn) as conn_:
exps = experiments(conn=conn_)

datasets = sorted(
chain.from_iterable(exp.data_sets() for exp in experiments()),
key=attrgetter('run_id')
)
datasets = sorted(
chain.from_iterable(exp.data_sets() for exp in exps),
key=attrgetter('run_id')
)

# There is no need for checking whether ``stop`` is ``None`` because if
# it is the following is simply equivalent to ``datasets[start:]``
datasets = datasets[start:stop]
# There is no need for checking whether ``stop`` is ``None`` because if
# it is the following is simply equivalent to ``datasets[start:]``
datasets = datasets[start:stop]

overview = {ds.run_id: get_ds_info(ds, get_structure=get_structure)
for ds in datasets}
overview = {ds.run_id: get_ds_info(ds, get_structure=get_structure)
for ds in datasets}
return overview


Expand Down Expand Up @@ -286,7 +296,7 @@ def process(self, dataIn: Optional[DataDictBase] = None) -> Optional[Dict[str, A
path, runId = cast(Tuple[str, int], self._pathAndId)

if self._dataset is None:
self._dataset = load_dataset_from(path, runId)
self._dataset = load_dataset_from(path, runId, read_only=True)

if self._dataset.number_of_results > self.nLoadedRecords:

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Tracker = "https://github.com/toolsforexperiments/plottr/issues"
pyqt5 = ["PyQt5"]
pyqt6 = ["PyQt6"]
pyside2 = ["PySide2>=5.12"]
qcodes = ["qcodes"]
qcodes = ["qcodes>=0.54.1"]

[project.scripts]
plottr-monitr = "plottr.apps.monitr:script"
Expand Down