Skip to content

Commit a8de479

Browse files
committed
Replace do0d with a wrapper arond dond
1 parent ed8bc51 commit a8de479

File tree

2 files changed

+60
-66
lines changed

2 files changed

+60
-66
lines changed

src/qcodes/dataset/dond/do_0d.py

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,71 @@
11
from __future__ import annotations
22

33
import logging
4-
from typing import TYPE_CHECKING, cast
4+
from typing import TYPE_CHECKING, Literal, overload
55

66
from opentelemetry import trace
77

8-
from qcodes import config
9-
from qcodes.parameters import ParameterBase
8+
from .do_nd import DondKWargs, dond
109

11-
from ..descriptions.detect_shapes import detect_shape_of_measurement
12-
from ..measurements import Measurement
13-
from ..threading import process_params_meas
14-
from .do_nd_utils import _handle_plotting, _register_parameters, _set_write_period
10+
if TYPE_CHECKING:
11+
from typing_extensions import Unpack
12+
13+
from .do_nd_utils import (
14+
AxesTupleListWithDataSet,
15+
MultiAxesTupleListWithDataSet,
16+
ParamMeasT,
17+
)
1518

1619
LOG = logging.getLogger(__name__)
1720
TRACER = trace.get_tracer(__name__)
1821

19-
if TYPE_CHECKING:
20-
from ..descriptions.versioning.rundescribertypes import Shapes
21-
from ..experiment_container import Experiment
22-
from .do_nd_utils import AxesTupleListWithDataSet, ParamMeasT
22+
23+
@overload
24+
def do0d(
25+
*param_meas: ParamMeasT, squeeze: Literal[False], **kwargs: Unpack[DondKWargs]
26+
) -> MultiAxesTupleListWithDataSet: ...
27+
28+
29+
@overload
30+
def do0d(
31+
*param_meas: ParamMeasT, squeeze: Literal[True], **kwargs: Unpack[DondKWargs]
32+
) -> AxesTupleListWithDataSet | MultiAxesTupleListWithDataSet: ...
33+
34+
35+
@overload
36+
def do0d(
37+
*param_meas: ParamMeasT, squeeze: bool = True, **kwargs: Unpack[DondKWargs]
38+
) -> AxesTupleListWithDataSet | MultiAxesTupleListWithDataSet: ...
2339

2440

2541
@TRACER.start_as_current_span("qcodes.dataset.do0d")
2642
def do0d(
27-
*param_meas: ParamMeasT,
28-
write_period: float | None = None,
29-
measurement_name: str = "",
30-
exp: Experiment | None = None,
31-
do_plot: bool | None = None,
32-
use_threads: bool | None = None,
33-
log_info: str | None = None,
34-
) -> AxesTupleListWithDataSet:
43+
*param_meas: ParamMeasT, squeeze: bool = True, **kwargs: Unpack[DondKWargs]
44+
) -> AxesTupleListWithDataSet | MultiAxesTupleListWithDataSet:
3545
"""
3646
Perform a measurement of a single parameter. This is probably most
37-
useful for an ArrayParameter that already returns an array of data points
47+
useful for a ParameterWithSetpoints that already returns an array of data points.
3848
3949
Args:
4050
*param_meas: Parameter(s) to measure at each step or functions that
4151
will be called at each step. The function should take no arguments.
4252
The parameters and functions are called in the order they are
4353
supplied.
44-
write_period: The time after which the data is actually written to the
45-
database.
46-
measurement_name: Name of the measurement. This will be passed down to
47-
the dataset produced by the measurement. If not given, a default
48-
value of 'results' is used for the dataset.
49-
exp: The experiment to use for this measurement.
50-
do_plot: should png and pdf versions of the images be saved after the
51-
run. If None the setting will be read from ``qcodesrc.json``
52-
use_threads: If True measurements from each instrument will be done on
53-
separate threads. If you are measuring from several instruments
54-
this may give a significant speedup.
55-
log_info: Message that is logged during the measurement. If None a default
56-
message is used.
54+
squeeze: If True, will return a tuple of QCoDeS DataSet, Matplotlib axis,
55+
Matplotlib colorbar if only one group of measurements was performed
56+
and a tuple of tuples of these if more than one group of measurements
57+
was performed. If False, will always return a tuple where the first
58+
member is a tuple of QCoDeS DataSet(s) and the second member is a tuple
59+
of Matplotlib axis(es) and the third member is a tuple of Matplotlib
60+
colorbar(s).
61+
**kwargs: kwargs are the same as for dond and forwarded directly to dond.
5762
5863
Returns:
5964
The QCoDeS dataset.
6065
6166
"""
62-
if do_plot is None:
63-
do_plot = cast("bool", config.dataset.dond_plot)
64-
meas = Measurement(name=measurement_name, exp=exp)
65-
if log_info is not None:
66-
meas._extra_log_info = log_info
67-
else:
68-
meas._extra_log_info = "Using 'qcodes.dataset.do0d'"
69-
70-
measured_parameters = tuple(
71-
param for param in param_meas if isinstance(param, ParameterBase)
67+
return dond(
68+
*param_meas,
69+
squeeze=squeeze,
70+
**kwargs,
7271
)
73-
74-
try:
75-
shapes: Shapes | None = detect_shape_of_measurement(
76-
measured_parameters,
77-
)
78-
except TypeError:
79-
LOG.exception(
80-
f"Could not detect shape of {measured_parameters} "
81-
f"falling back to unknown shape."
82-
)
83-
shapes = None
84-
85-
_register_parameters(meas, param_meas, shapes=shapes)
86-
_set_write_period(meas, write_period)
87-
88-
with meas.run() as datasaver:
89-
datasaver.add_result(*process_params_meas(param_meas, use_threads=use_threads))
90-
dataset = datasaver.dataset
91-
92-
return _handle_plotting(dataset, do_plot)

src/qcodes/dataset/dond/do_nd.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Callable, Mapping, Sequence
77
from contextlib import ExitStack
88
from dataclasses import dataclass
9-
from typing import TYPE_CHECKING, Any, Literal, cast, overload
9+
from typing import TYPE_CHECKING, Any, Literal, NotRequired, cast, overload
1010

1111
import numpy as np
1212
from opentelemetry import trace
@@ -33,8 +33,6 @@
3333

3434
from .sweeps import AbstractSweep, TogetherSweep
3535

36-
LOG = logging.getLogger(__name__)
37-
3836
if TYPE_CHECKING:
3937
from qcodes.dataset.descriptions.versioning.rundescribertypes import Shapes
4038
from qcodes.dataset.dond.do_nd_utils import (
@@ -46,6 +44,7 @@
4644
)
4745
from qcodes.dataset.experiment_container import Experiment
4846

47+
LOG = logging.getLogger(__name__)
4948
SweepVarType = Any
5049

5150
TRACER = trace.get_tracer(__name__)
@@ -567,6 +566,22 @@ def parameters(self) -> tuple[ParameterBase, ...]:
567566
return self._parameters
568567

569568

569+
class DondKWargs(TypedDict):
570+
write_period: NotRequired[float | None]
571+
measurement_name: NotRequired[str | Sequence[str]]
572+
exp: NotRequired[Experiment | Sequence[Experiment] | None]
573+
enter_actions: NotRequired[ActionsT]
574+
exit_actions: NotRequired[ActionsT]
575+
do_plot: NotRequired[bool | None]
576+
show_progress: NotRequired[bool | None]
577+
use_threads: NotRequired[bool | None]
578+
additional_setpoints: NotRequired[Sequence[ParameterBase]]
579+
log_info: NotRequired[str | None]
580+
break_condition: NotRequired[BreakConditionT | None]
581+
dataset_dependencies: NotRequired[Mapping[str, Sequence[ParamMeasT]]]
582+
in_memory_cache: NotRequired[bool | None]
583+
584+
570585
@overload
571586
def dond(
572587
*params: AbstractSweep | TogetherSweep | ParamMeasT | Sequence[ParamMeasT],

0 commit comments

Comments
 (0)