Skip to content

Commit

Permalink
Merge #3623
Browse files Browse the repository at this point in the history
3623: Add two more methods to dataset protocol r=jenshnielsen a=jenshnielsen

Research shows that these are fairly commonly uses so to make it easier to use the protocol I suggest adding them here. The implementation is also fairly straight forward


Co-authored-by: Jens H. Nielsen <Jens.Nielsen@microsoft.com>
  • Loading branch information
bors[bot] and jenshnielsen committed Nov 25, 2021
2 parents cd0c048 + 1d2ca21 commit 9d7441e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
7 changes: 0 additions & 7 deletions qcodes/dataset/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,6 @@ def paramspecs(self) -> Dict[str, ParamSpec]:
return {ps.name: ps
for ps in self.get_parameters()}

@property
def dependent_parameters(self) -> Tuple[ParamSpecBase, ...]:
"""
Return all the parameters that explicitly depend on other parameters
"""
return tuple(self._rundescriber.interdeps.dependencies.keys())

@property
def exp_id(self) -> int:
exp_id = select_one_where(self.conn, "runs", "exp_id", "run_id", self.run_id)
Expand Down
16 changes: 15 additions & 1 deletion qcodes/dataset/data_set_in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

import numpy as np

from qcodes.dataset.data_set_protocol import SPECS, BaseDataSet, CompletedError
from qcodes.dataset.data_set_protocol import (
SPECS,
BaseDataSet,
CompletedError,
ParameterData,
)
from qcodes.dataset.descriptions.dependencies import InterDependencies_
from qcodes.dataset.descriptions.param_spec import ParamSpec, ParamSpecBase
from qcodes.dataset.descriptions.rundescriber import RunDescriber
Expand Down Expand Up @@ -825,6 +830,15 @@ def to_pandas_dataframe(
self._warn_if_set(*params, start=start, end=end)
return self.cache.to_pandas_dataframe()

def get_parameter_data(
self,
*params: Union[str, ParamSpec, _BaseParameter],
start: Optional[int] = None,
end: Optional[int] = None,
) -> ParameterData:
self._warn_if_set(*params, start=start, end=end)
return self.cache.data()

@staticmethod
def _warn_if_set(
*params: Union[str, ParamSpec, _BaseParameter],
Expand Down
19 changes: 19 additions & 0 deletions qcodes/dataset/data_set_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,22 @@ def export_info(self) -> ExportInfo:
def cache(self) -> DataSetCache[DataSetProtocol]:
pass

def get_parameter_data(
self,
*params: Union[str, ParamSpec, _BaseParameter],
start: Optional[int] = None,
end: Optional[int] = None,
) -> ParameterData:
pass

def get_parameters(self) -> SPECS:
# used by plottr
pass

@property
def dependent_parameters(self) -> Tuple[ParamSpecBase, ...]:
pass

# exporters to other in memory formats

def to_xarray_dataarray_dict(
Expand Down Expand Up @@ -501,6 +513,13 @@ def completed_timestamp(self, fmt: str = "%Y-%m-%d %H:%M:%S") -> Optional[str]:
"""
return raw_time_to_str_time(self.completed_timestamp_raw, fmt)

@property
def dependent_parameters(self) -> Tuple[ParamSpecBase, ...]:
"""
Return all the parameters that explicitly depend on other parameters
"""
return tuple(self.description.interdeps.dependencies.keys())


class DataSetType(str, Enum):

Expand Down

0 comments on commit 9d7441e

Please sign in to comment.