Skip to content

Commit d37a909

Browse files
committed
Replace do1d with a wrapper around dond
1 parent 99a7707 commit d37a909

File tree

1 file changed

+24
-134
lines changed

1 file changed

+24
-134
lines changed

src/qcodes/dataset/dond/do_1d.py

Lines changed: 24 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,24 @@
11
from __future__ import annotations
22

33
import logging
4-
import sys
5-
import time
64
from typing import TYPE_CHECKING, cast
75

8-
import numpy as np
96
from opentelemetry import trace
10-
from tqdm.auto import tqdm
117

12-
from qcodes import config
13-
from qcodes.dataset.descriptions.detect_shapes import detect_shape_of_measurement
14-
from qcodes.dataset.dond.do_nd_utils import (
15-
BreakConditionInterrupt,
16-
_handle_plotting,
17-
_register_actions,
18-
_register_parameters,
19-
_set_write_period,
20-
catch_interrupts,
21-
)
22-
from qcodes.dataset.measurements import Measurement
23-
from qcodes.dataset.threading import (
24-
SequentialParamsCaller,
25-
ThreadPoolParamsCaller,
26-
process_params_meas,
27-
)
28-
from qcodes.parameters import ParameterBase
29-
30-
LOG = logging.getLogger(__name__)
31-
TRACER = trace.get_tracer(__name__)
8+
from .do_nd import DondKWargs, dond
9+
from .sweeps import LinSweep
3210

3311
if TYPE_CHECKING:
34-
from collections.abc import Sequence
12+
from typing_extensions import Unpack
3513

36-
from qcodes.dataset.descriptions.versioning.rundescribertypes import Shapes
3714
from qcodes.dataset.dond.do_nd_utils import (
38-
ActionsT,
3915
AxesTupleListWithDataSet,
40-
BreakConditionT,
4116
ParamMeasT,
4217
)
43-
from qcodes.dataset.experiment_container import Experiment
18+
from qcodes.parameters import ParameterBase
19+
20+
LOG = logging.getLogger(__name__)
21+
TRACER = trace.get_tracer(__name__)
4422

4523

4624
@TRACER.start_as_current_span("qcodes.dataset.do1d")
@@ -51,17 +29,7 @@ def do1d(
5129
num_points: int,
5230
delay: float,
5331
*param_meas: ParamMeasT,
54-
enter_actions: ActionsT = (),
55-
exit_actions: ActionsT = (),
56-
write_period: float | None = None,
57-
measurement_name: str = "",
58-
exp: Experiment | None = None,
59-
do_plot: bool | None = None,
60-
use_threads: bool | None = None,
61-
additional_setpoints: Sequence[ParameterBase] = tuple(),
62-
show_progress: bool | None = None,
63-
log_info: str | None = None,
64-
break_condition: BreakConditionT | None = None,
32+
**kwargs: Unpack[DondKWargs],
6533
) -> AxesTupleListWithDataSet:
6634
"""
6735
Perform a 1D scan of ``param_set`` from ``start`` to ``stop`` in
@@ -74,106 +42,28 @@ def do1d(
7442
stop: End point of sweep
7543
num_points: Number of points in sweep
7644
delay: Delay after setting parameter before measurement is performed
77-
param_meas: Parameter(s) to measure at each step or functions that
45+
*param_meas: Parameter(s) to measure at each step or functions that
7846
will be called at each step. The function should take no arguments.
7947
The parameters and functions are called in the order they are
8048
supplied.
81-
enter_actions: A list of functions taking no arguments that will be
82-
called before the measurements start
83-
exit_actions: A list of functions taking no arguments that will be
84-
called after the measurements ends
85-
write_period: The time after which the data is actually written to the
86-
database.
87-
additional_setpoints: A list of setpoint parameters to be registered in
88-
the measurement but not scanned.
89-
measurement_name: Name of the measurement. This will be passed down to
90-
the dataset produced by the measurement. If not given, a default
91-
value of 'results' is used for the dataset.
92-
exp: The experiment to use for this measurement.
93-
do_plot: should png and pdf versions of the images be saved after the
94-
run. If None the setting will be read from ``qcodesrc.json``
95-
use_threads: If True measurements from each instrument will be done on
96-
separate threads. If you are measuring from several instruments
97-
this may give a significant speedup.
98-
show_progress: should a progress bar be displayed during the
99-
measurement. If None the setting will be read from ``qcodesrc.json``
100-
log_info: Message that is logged during the measurement. If None a default
101-
message is used.
102-
break_condition: Callable that takes no arguments. If returned True,
103-
measurement is interrupted.
49+
**kwargs: kwargs are the same as for dond and forwarded directly to dond.
10450
10551
Returns:
10652
The QCoDeS dataset.
10753
10854
"""
109-
if do_plot is None:
110-
do_plot = cast("bool", config.dataset.dond_plot)
111-
if show_progress is None:
112-
show_progress = config.dataset.dond_show_progress
113-
114-
meas = Measurement(name=measurement_name, exp=exp)
115-
if log_info is not None:
116-
meas._extra_log_info = log_info
117-
else:
118-
meas._extra_log_info = "Using 'qcodes.dataset.do1d'"
119-
120-
all_setpoint_params = (param_set, *tuple(s for s in additional_setpoints))
121-
122-
measured_parameters = tuple(
123-
param for param in param_meas if isinstance(param, ParameterBase)
55+
return cast(
56+
"AxesTupleListWithDataSet",
57+
dond(
58+
LinSweep(
59+
param=param_set,
60+
start=start,
61+
stop=stop,
62+
delay=delay,
63+
num_points=num_points,
64+
),
65+
*param_meas,
66+
**kwargs,
67+
squeeze=True,
68+
),
12469
)
125-
try:
126-
loop_shape = (num_points, *tuple(1 for _ in additional_setpoints))
127-
shapes: Shapes | None = detect_shape_of_measurement(
128-
measured_parameters, loop_shape
129-
)
130-
except TypeError:
131-
LOG.exception(
132-
f"Could not detect shape of {measured_parameters} "
133-
f"falling back to unknown shape."
134-
)
135-
shapes = None
136-
137-
_register_parameters(meas, all_setpoint_params)
138-
_register_parameters(meas, param_meas, setpoints=all_setpoint_params, shapes=shapes)
139-
_set_write_period(meas, write_period)
140-
_register_actions(meas, enter_actions, exit_actions)
141-
142-
if use_threads is None:
143-
use_threads = config.dataset.use_threads
144-
145-
param_meas_caller = (
146-
ThreadPoolParamsCaller(*param_meas)
147-
if use_threads
148-
else SequentialParamsCaller(*param_meas)
149-
)
150-
151-
# do1D enforces a simple relationship between measured parameters
152-
# and set parameters. For anything more complicated this should be
153-
# reimplemented from scratch
154-
with (
155-
catch_interrupts() as interrupted,
156-
meas.run() as datasaver,
157-
param_meas_caller as call_param_meas,
158-
):
159-
dataset = datasaver.dataset
160-
additional_setpoints_data = process_params_meas(additional_setpoints)
161-
setpoints = np.linspace(start, stop, num_points)
162-
163-
# flush to prevent unflushed print's to visually interrupt tqdm bar
164-
# updates
165-
sys.stdout.flush()
166-
sys.stderr.flush()
167-
168-
for set_point in tqdm(setpoints, disable=not show_progress):
169-
param_set.set(set_point)
170-
time.sleep(delay)
171-
datasaver.add_result(
172-
(param_set, set_point), *call_param_meas(), *additional_setpoints_data
173-
)
174-
175-
if callable(break_condition):
176-
if break_condition():
177-
raise BreakConditionInterrupt("Break condition was met.")
178-
179-
return _handle_plotting(dataset, do_plot, interrupted())

0 commit comments

Comments
 (0)