11from __future__ import annotations
22
33import logging
4- import sys
5- import time
64from typing import TYPE_CHECKING , cast
75
8- import numpy as np
96from opentelemetry import trace
10- from tqdm .auto import tqdm
11-
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__ )
327
8+ from .do_nd import DondKWargs , dond
9+ from .sweeps import LinSweep
3310
3411if TYPE_CHECKING :
35- from collections . abc import Sequence
12+ from typing_extensions import Unpack
3613
37- from qcodes .dataset .descriptions .versioning .rundescribertypes import Shapes
3814 from qcodes .dataset .dond .do_nd_utils import (
39- ActionsT ,
4015 AxesTupleListWithDataSet ,
41- BreakConditionT ,
4216 ParamMeasT ,
4317 )
44- 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__ )
4522
4623
4724@TRACER .start_as_current_span ("qcodes.dataset.do2d" )
@@ -57,21 +34,7 @@ def do2d(
5734 num_points2 : int ,
5835 delay2 : float ,
5936 * param_meas : ParamMeasT ,
60- set_before_sweep : bool | None = True ,
61- enter_actions : ActionsT = (),
62- exit_actions : ActionsT = (),
63- before_inner_actions : ActionsT = (),
64- after_inner_actions : ActionsT = (),
65- write_period : float | None = None ,
66- measurement_name : str = "" ,
67- exp : Experiment | None = None ,
68- flush_columns : bool = False ,
69- do_plot : bool | None = None ,
70- use_threads : bool | None = None ,
71- additional_setpoints : Sequence [ParameterBase ] = tuple (),
72- show_progress : bool | None = None ,
73- log_info : str | None = None ,
74- break_condition : BreakConditionT | None = None ,
37+ ** kwargs : Unpack [DondKWargs ],
7538) -> AxesTupleListWithDataSet :
7639 """
7740 Perform a 1D scan of ``param_set1`` from ``start1`` to ``stop1`` in
@@ -93,134 +56,31 @@ def do2d(
9356 will be called at each step. The function should take no arguments.
9457 The parameters and functions are called in the order they are
9558 supplied.
96- set_before_sweep: if True the outer parameter is set to its first value
97- before the inner parameter is swept to its next value.
98- enter_actions: A list of functions taking no arguments that will be
99- called before the measurements start
100- exit_actions: A list of functions taking no arguments that will be
101- called after the measurements ends
102- before_inner_actions: Actions executed before each run of the inner loop
103- after_inner_actions: Actions executed after each run of the inner loop
104- write_period: The time after which the data is actually written to the
105- database.
106- measurement_name: Name of the measurement. This will be passed down to
107- the dataset produced by the measurement. If not given, a default
108- value of 'results' is used for the dataset.
109- exp: The experiment to use for this measurement.
110- flush_columns: The data is written after a column is finished
111- independent of the passed time and write period.
112- additional_setpoints: A list of setpoint parameters to be registered in
113- the measurement but not scanned.
114- do_plot: should png and pdf versions of the images be saved after the
115- run. If None the setting will be read from ``qcodesrc.json``
116- use_threads: If True measurements from each instrument will be done on
117- separate threads. If you are measuring from several instruments
118- this may give a significant speedup.
119- show_progress: should a progress bar be displayed during the
120- measurement. If None the setting will be read from ``qcodesrc.json``
121- log_info: Message that is logged during the measurement. If None a default
122- message is used.
123- break_condition: Callable that takes no arguments. If returned True,
124- measurement is interrupted.
59+ **kwargs: kwargs are the same as for dond and forwarded directly to dond.
12560
12661 Returns:
12762 The QCoDeS dataset.
12863
12964 """
130-
131- if do_plot is None :
132- do_plot = cast ("bool" , config .dataset .dond_plot )
133- if show_progress is None :
134- show_progress = config .dataset .dond_show_progress
135-
136- meas = Measurement (name = measurement_name , exp = exp )
137- if log_info is not None :
138- meas ._extra_log_info = log_info
139- else :
140- meas ._extra_log_info = "Using 'qcodes.dataset.do2d'"
141- all_setpoint_params = (
142- param_set1 ,
143- param_set2 ,
144- * tuple (s for s in additional_setpoints ),
145- )
146-
147- measured_parameters = tuple (
148- param for param in param_meas if isinstance (param , ParameterBase )
149- )
150-
151- try :
152- loop_shape = (num_points1 , num_points2 , * tuple (1 for _ in additional_setpoints ))
153- shapes : Shapes | None = detect_shape_of_measurement (
154- measured_parameters , loop_shape
155- )
156- except TypeError :
157- LOG .exception (
158- f"Could not detect shape of { measured_parameters } "
159- f"falling back to unknown shape."
160- )
161- shapes = None
162-
163- _register_parameters (meas , all_setpoint_params )
164- _register_parameters (meas , param_meas , setpoints = all_setpoint_params , shapes = shapes )
165- _set_write_period (meas , write_period )
166- _register_actions (meas , enter_actions , exit_actions )
167-
168- if use_threads is None :
169- use_threads = config .dataset .use_threads
170-
171- param_meas_caller = (
172- ThreadPoolParamsCaller (* param_meas )
173- if use_threads
174- else SequentialParamsCaller (* param_meas )
65+ return cast (
66+ "AxesTupleListWithDataSet" ,
67+ dond (
68+ LinSweep (
69+ param = param_set1 ,
70+ start = start1 ,
71+ stop = stop1 ,
72+ delay = delay1 ,
73+ num_points = num_points1 ,
74+ ),
75+ LinSweep (
76+ param = param_set2 ,
77+ start = start2 ,
78+ stop = stop2 ,
79+ delay = delay2 ,
80+ num_points = num_points2 ,
81+ ),
82+ * param_meas ,
83+ ** kwargs ,
84+ squeeze = True ,
85+ ),
17586 )
176-
177- with (
178- catch_interrupts () as interrupted ,
179- meas .run () as datasaver ,
180- param_meas_caller as call_param_meas ,
181- ):
182- dataset = datasaver .dataset
183- additional_setpoints_data = process_params_meas (additional_setpoints )
184- setpoints1 = np .linspace (start1 , stop1 , num_points1 )
185- for set_point1 in tqdm (setpoints1 , disable = not show_progress ):
186- if set_before_sweep :
187- param_set2 .set (start2 )
188-
189- param_set1 .set (set_point1 )
190-
191- for action in before_inner_actions :
192- action ()
193-
194- time .sleep (delay1 )
195-
196- setpoints2 = np .linspace (start2 , stop2 , num_points2 )
197-
198- # flush to prevent unflushed print's to visually interrupt tqdm bar
199- # updates
200- sys .stdout .flush ()
201- sys .stderr .flush ()
202- for set_point2 in tqdm (setpoints2 , disable = not show_progress , leave = False ):
203- # skip first inner set point if `set_before_sweep`
204- if set_point2 == start2 and set_before_sweep :
205- pass
206- else :
207- param_set2 .set (set_point2 )
208- time .sleep (delay2 )
209-
210- datasaver .add_result (
211- (param_set1 , set_point1 ),
212- (param_set2 , set_point2 ),
213- * call_param_meas (),
214- * additional_setpoints_data ,
215- )
216-
217- if callable (break_condition ):
218- if break_condition ():
219- raise BreakConditionInterrupt ("Break condition was met." )
220-
221- for action in after_inner_actions :
222- action ()
223- if flush_columns :
224- datasaver .flush_data_to_database ()
225-
226- return _handle_plotting (dataset , do_plot , interrupted ())
0 commit comments