Exemple #1
0
def do1d(param_set: _BaseParameter,
         start: float,
         stop: float,
         num_points: int,
         delay: float,
         *param_meas: ParamMeasT,
         enter_actions: ActionsT = (),
         exit_actions: ActionsT = (),
         write_period: Optional[float] = None,
         do_plot: bool = True) -> AxesTupleListWithRunId:
    """
    Perform a 1D scan of ``param_set`` from ``start`` to ``stop`` in
    ``num_points`` measuring param_meas at each step. In case param_meas is
    an ArrayParameter this is effectively a 2d scan.

    Args:
        param_set: The QCoDeS parameter to sweep over
        start: Starting point of sweep
        stop: End point of sweep
        num_points: Number of points in sweep
        delay: Delay after setting paramter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The run_id of the DataSet created
    """
    meas = Measurement()
    _register_parameters(meas, (param_set, ))
    _register_parameters(meas, param_meas, setpoints=(param_set, ))
    _set_write_period(meas, write_period)
    _register_actions(meas, enter_actions, exit_actions)
    param_set.post_delay = delay

    # do1D enforces a simple relationship between measured parameters
    # and set parameters. For anything more complicated this should be
    # reimplemented from scratch
    with _catch_keyboard_interrupts() as interrupted, meas.run() as datasaver:
        for set_point in np.linspace(start, stop, num_points):
            param_set.set(set_point)
            datasaver.add_result((param_set, set_point),
                                 *_process_params_meas(param_meas))
    return _handle_plotting(datasaver, do_plot, interrupted())
Exemple #2
0
def do2d(
    param_set1: _BaseParameter,
    start1: float,
    stop1: float,
    num_points1: int,
    delay1: float,
    param_set2: _BaseParameter,
    start2: float,
    stop2: float,
    num_points2: int,
    delay2: float,
    *param_meas: ParamMeasT,
    set_before_sweep: Optional[bool] = True,
    enter_actions: ActionsT = (),
    exit_actions: ActionsT = (),
    before_inner_actions: ActionsT = (),
    after_inner_actions: ActionsT = (),
    write_period: Optional[float] = None,
    flush_columns: bool = False,
    do_plot: bool = True,
    additional_setpoints: Sequence[ParamMeasT] = tuple(),
) -> AxesTupleListWithDataSet:
    """
    Perform a 1D scan of ``param_set1`` from ``start1`` to ``stop1`` in
    ``num_points1`` and ``param_set2`` from ``start2`` to ``stop2`` in
    ``num_points2`` measuring param_meas at each step.

    Args:
        param_set1: The QCoDeS parameter to sweep over in the outer loop
        start1: Starting point of sweep in outer loop
        stop1: End point of sweep in the outer loop
        num_points1: Number of points to measure in the outer loop
        delay1: Delay after setting parameter in the outer loop
        param_set2: The QCoDeS parameter to sweep over in the inner loop
        start2: Starting point of sweep in inner loop
        stop2: End point of sweep in the inner loop
        num_points2: Number of points to measure in the inner loop
        delay2: Delay after setting parameter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        set_before_sweep: if True the outer parameter is set to its first value
            before the inner parameter is swept to its next value.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        before_inner_actions: Actions executed before each run of the inner loop
        after_inner_actions: Actions executed after each run of the inner loop
        write_period: The time after which the data is actually written to the
            database.
        flush_columns: The data is written after a column is finished
            independent of the passed time and write period.
        additional_setpoints: A list of setpoint parameters to be registered in
            the measurement but not scanned.
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The QCoDeS dataset.
    """

    meas = Measurement()
    all_setpoint_params = (
        param_set1,
        param_set2,
    ) + tuple(s for s in additional_setpoints)

    measured_parameters = tuple(param for param in param_meas
                                if isinstance(param, _BaseParameter))

    try:
        loop_shape = tuple(
            1 for _ in additional_setpoints) + (num_points1, num_points2)
        shapes: Shapes = detect_shape_of_measurement(measured_parameters,
                                                     loop_shape)
    except TypeError:
        LOG.exception(f"Could not detect shape of {measured_parameters} "
                      f"falling back to unknown shape.")
        shapes = None

    _register_parameters(meas, all_setpoint_params)
    _register_parameters(meas,
                         param_meas,
                         setpoints=all_setpoint_params,
                         shapes=shapes)
    _set_write_period(meas, write_period)
    _register_actions(meas, enter_actions, exit_actions)

    param_set1.post_delay = delay1
    param_set2.post_delay = delay2

    with _catch_keyboard_interrupts() as interrupted, meas.run() as datasaver:
        additional_setpoints_data = _process_params_meas(additional_setpoints)
        for set_point1 in np.linspace(start1, stop1, num_points1):
            if set_before_sweep:
                param_set2.set(start2)

            param_set1.set(set_point1)
            for action in before_inner_actions:
                action()
            for set_point2 in np.linspace(start2, stop2, num_points2):
                # skip first inner set point if `set_before_sweep`
                if set_point2 == start2 and set_before_sweep:
                    pass
                else:
                    param_set2.set(set_point2)

                datasaver.add_result((param_set1, set_point1),
                                     (param_set2, set_point2),
                                     *_process_params_meas(param_meas),
                                     *additional_setpoints_data)
            for action in after_inner_actions:
                action()
            if flush_columns:
                datasaver.flush_data_to_database()
        dataset = datasaver.dataset
    return _handle_plotting(dataset, do_plot, interrupted())
Exemple #3
0
def do1d(
    param_set: _BaseParameter,
    start: float,
    stop: float,
    num_points: int,
    delay: float,
    *param_meas: ParamMeasT,
    enter_actions: ActionsT = (),
    exit_actions: ActionsT = (),
    write_period: Optional[float] = None,
    do_plot: bool = True,
    additional_setpoints: Sequence[ParamMeasT] = tuple(),
) -> AxesTupleListWithDataSet:
    """
    Perform a 1D scan of ``param_set`` from ``start`` to ``stop`` in
    ``num_points`` measuring param_meas at each step. In case param_meas is
    an ArrayParameter this is effectively a 2d scan.

    Args:
        param_set: The QCoDeS parameter to sweep over
        start: Starting point of sweep
        stop: End point of sweep
        num_points: Number of points in sweep
        delay: Delay after setting parameter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        write_period: The time after which the data is actually written to the
            database.
        additional_setpoints: A list of setpoint parameters to be registered in
            the measurement but not scanned.
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The QCoDeS dataset.
    """
    meas = Measurement()

    all_setpoint_params = (param_set, ) + tuple(s
                                                for s in additional_setpoints)

    measured_parameters = tuple(param for param in param_meas
                                if isinstance(param, _BaseParameter))
    try:
        loop_shape = tuple(1 for _ in additional_setpoints) + (num_points, )
        shapes: Shapes = detect_shape_of_measurement(measured_parameters,
                                                     loop_shape)
    except TypeError:
        LOG.exception(f"Could not detect shape of {measured_parameters} "
                      f"falling back to unknown shape.")
        shapes = None

    _register_parameters(meas, all_setpoint_params)
    _register_parameters(meas,
                         param_meas,
                         setpoints=all_setpoint_params,
                         shapes=shapes)
    _set_write_period(meas, write_period)
    _register_actions(meas, enter_actions, exit_actions)
    param_set.post_delay = delay

    # do1D enforces a simple relationship between measured parameters
    # and set parameters. For anything more complicated this should be
    # reimplemented from scratch
    with _catch_keyboard_interrupts() as interrupted, meas.run() as datasaver:
        additional_setpoints_data = _process_params_meas(additional_setpoints)
        for set_point in np.linspace(start, stop, num_points):
            param_set.set(set_point)
            datasaver.add_result((param_set, set_point),
                                 *_process_params_meas(param_meas),
                                 *additional_setpoints_data)
        dataset = datasaver.dataset
    return _handle_plotting(dataset, do_plot, interrupted())
Exemple #4
0
def do2d(param_set1: _BaseParameter,
         start1: float,
         stop1: float,
         num_points1: int,
         delay1: float,
         param_set2: _BaseParameter,
         start2: float,
         stop2: float,
         num_points2: int,
         delay2: float,
         *param_meas: ParamMeasT,
         set_before_sweep: Optional[bool] = False,
         enter_actions: ActionsT = (),
         exit_actions: ActionsT = (),
         before_inner_actions: ActionsT = (),
         after_inner_actions: ActionsT = (),
         write_period: Optional[float] = None,
         flush_columns: bool = False,
         do_plot: bool = True) -> AxesTupleListWithRunId:
    """
    Perform a 1D scan of ``param_set1`` from ``start1`` to ``stop1`` in
    ``num_points1`` and ``param_set2`` from ``start2`` to ``stop2`` in
    ``num_points2`` measuring param_meas at each step.

    Args:
        param_set1: The QCoDeS parameter to sweep over in the outer loop
        start1: Starting point of sweep in outer loop
        stop1: End point of sweep in the outer loop
        num_points1: Number of points to measure in the outer loop
        delay1: Delay after setting parameter in the outer loop
        param_set2: The QCoDeS parameter to sweep over in the inner loop
        start2: Starting point of sweep in inner loop
        stop2: End point of sweep in the inner loop
        num_points2: Number of points to measure in the inner loop
        delay2: Delay after setting paramter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        set_before_sweep: if True the outer parameter is set to its first value
            before the inner parameter is swept to its next value.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        before_inner_actions: Actions executed before each run of the inner loop
        after_inner_actions: Actions executed after each run of the inner loop
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The run_id of the DataSet created
    """

    meas = Measurement()
    _register_parameters(meas, (param_set1, param_set2))
    _register_parameters(meas, param_meas, setpoints=(param_set1, param_set2))
    _set_write_period(meas, write_period)
    _register_actions(meas, enter_actions, exit_actions)

    param_set1.post_delay = delay1
    param_set2.post_delay = delay2

    with _catch_keyboard_interrupts() as interrupted, meas.run() as datasaver:
        for set_point1 in np.linspace(start1, stop1, num_points1):
            if set_before_sweep:
                param_set2.set(start2)

            param_set1.set(set_point1)
            for action in before_inner_actions:
                action()
            for set_point2 in np.linspace(start2, stop2, num_points2):
                # skip first inner set point if `set_before_sweep`
                if set_point2 == start2 and set_before_sweep:
                    pass
                else:
                    param_set2.set(set_point2)

                datasaver.add_result((param_set1, set_point1),
                                     (param_set2, set_point2),
                                     *_process_params_meas(param_meas))
            for action in after_inner_actions:
                action()
            if flush_columns:
                datasaver.flush_data_to_database()

    return _handle_plotting(datasaver, do_plot, interrupted())
Exemple #5
0
def do1d(param_set: _BaseParameter, start: number, stop: number,
         num_points: int, delay: number,
         *param_meas: Union[_BaseParameter, Callable[[], None]],
         enter_actions: Sequence[Callable[[], None]] = (),
         exit_actions: Sequence[Callable[[], None]] = (),
         do_plot: bool = True,
         do2dbuf: str = '',
         conDuct: Instrument = None) \
        -> AxesTupleListWithRunId:
    """
	adapted for logging settings by felix 17.04.2020
		-added argument do2buf
		-added _export_settings functionality

	adapted for live plotting of conductance by felix 17.04.2020
		-added argument conDuct
		-conDuct is a virtual parameter who has to be called as an optional argument in do1D.
		 conDuct has a function calcG() which allows to calculate the division of two given 
		 parameters or one parameter and a float number. See init file for more info.

    Perform a 1D scan of ``param_set`` from ``start`` to ``stop`` in
    ``num_points`` measuring param_meas at each step. In case param_meas is
    an ArrayParameter this is effectively a 2d scan.

    Args:
        param_set: The QCoDeS parameter to sweep over
        start: Starting point of sweep
        stop: End point of sweep
        num_points: Number of points in sweep
        delay: Delay after setting paramter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The run_id of the DataSet created
    """
    meas = Measurement()
    meas.register_parameter(
        param_set)  # register the first independent parameter
    output = []
    param_set.post_delay = delay
    interrupted = False

    for action in enter_actions:
        # this omits the posibility of passing
        # argument to enter and exit actions.
        # Do we want that?
        meas.add_before_run(action, ())
    for action in exit_actions:
        meas.add_after_run(action, ())

    # do1D enforces a simple relationship between measured parameters
    # and set parameters. For anything more complicated this should be
    # reimplemented from scratch
    for parameter in param_meas:
        if isinstance(parameter, _BaseParameter):
            meas.register_parameter(parameter, setpoints=(param_set, ))
            output.append([parameter, None])
        if conDuct != None:
            meas.register_parameter(conDuct.G, setpoints=(param_set, ))
            output.append([conDuct.G, None])
    try:
        with meas.run() as datasaver:
            start_time = time.perf_counter()
            os.makedirs(datapath + '{}'.format(datasaver.run_id))
            for set_point in np.linspace(start, stop, num_points):
                param_set.set(set_point)
                output = []
                for parameter in param_meas:
                    if isinstance(parameter, _BaseParameter):
                        output.append((parameter, parameter.get()))
                    elif callable(parameter):
                        parameter()
                if conDuct != None:
                    output.append((conDuct.G, conDuct.calcG(output)))

                datasaver.add_result((param_set, set_point), *output)
    except KeyboardInterrupt:
        interrupted = True

    stop_time = time.perf_counter()

    dataid = datasaver.run_id  # convenient to have for plotting

    if interrupted:
        inst = list(meas.parameters.values())
        exportpath = datapath + '{}'.format(
            datasaver.run_id) + '/{}_set_{}_set.dat'.format(
                inst[0].name, inst[1].name)
        exportsnapshot = datapath + '{}'.format(
            datasaver.run_id) + '/snapshot.txt'
        #export_by_id(dataid,exportpath)
        export_by_id_pd(dataid, exportpath)
        export_snapshot_by_id(dataid, exportsnapshot)
        _export_settings(datasaver.run_id, inst, do2dbuf)
        stop_time = time.perf_counter()
        print("Acquisition took:  %s seconds " % (stop_time - start_time))
        raise KeyboardInterrupt

    print("Acquisition took:  %s seconds " % (stop_time - start_time))
    inst = list(meas.parameters.values())
    exportpath = datapath + '{}'.format(
        datasaver.run_id) + '/{}_set_{}_set.dat'.format(
            inst[0].name, inst[1].name)
    exportsnapshot = datapath + '{}'.format(datasaver.run_id) + '/snapshot.txt'
    #export_by_id(dataid,exportpath)
    export_by_id_pd(dataid, exportpath)
    export_snapshot_by_id(dataid, exportsnapshot)
    #added by felix 05.03.2020
    _export_settings(datasaver.run_id, inst, do2dbuf)

    if do_plot is True:
        ax, cbs = _save_image(datasaver, inst)
    else:
        ax = None,
        cbs = None

    return dataid, ax, cbs
Exemple #6
0
def do2d(param_set1: _BaseParameter,
         start1: number,
         stop1: number,
         num_points1: int,
         delay1: number,
         param_set2: _BaseParameter,
         start2: number,
         stop2: number,
         num_points2: int,
         delay2: number,
         *param_meas: Union[_BaseParameter, Callable[[], None]],
         set_before_sweep: Optional[bool] = False,
         enter_actions: Sequence[Callable[[], None]] = (),
         exit_actions: Sequence[Callable[[], None]] = (),
         before_inner_actions: Sequence[Callable[[], None]] = (),
         after_inner_actions: Sequence[Callable[[], None]] = (),
         write_period: Optional[float] = None,
         flush_columns: bool = False,
         do_plot: bool = True,
         conDuct: Instrument = None) -> AxesTupleListWithRunId:
    """
    adapted for logging settings by felix 17.04.2020
		-added argument do2buf
		-added _export_settings functionality

	adapted for live plotting of conductance by felix 17.04.2020
		-added argument conDuct
		-conDuct is a virtual parameter who has to be called as an optional argument in do1D.
		 conDuct has a function calcG() which allows to calculate the division of two given 
		 parameters or one parameter and a float number. See init file for more info.

    Perform a 1D scan of ``param_set1`` from ``start1`` to ``stop1`` in
    ``num_points1`` and ``param_set2`` from ``start2`` to ``stop2`` in
    ``num_points2`` measuring param_meas at each step.

    Args:
        param_set1: The QCoDeS parameter to sweep over in the outer loop
        start1: Starting point of sweep in outer loop
        stop1: End point of sweep in the outer loop
        num_points1: Number of points to measure in the outer loop
        delay1: Delay after setting parameter in the outer loop
        param_set2: The QCoDeS parameter to sweep over in the inner loop
        start2: Starting point of sweep in inner loop
        stop2: End point of sweep in the inner loop
        num_points2: Number of points to measure in the inner loop
        delay2: Delay after setting paramter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        set_before_sweep: if True the outer parameter is set to its first value
            before the inner parameter is swept to its next value.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        before_inner_actions: Actions executed before each run of the inner loop
        after_inner_actions: Actions executed after each run of the inner loop
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The run_id of the DataSet created
    """

    meas = Measurement()
    if write_period:
        meas.write_period = write_period
    meas.register_parameter(param_set1)
    param_set1.post_delay = delay1
    meas.register_parameter(param_set2)
    param_set2.post_delay = delay2
    interrupted = False
    for action in enter_actions:
        # this omits the possibility of passing
        # argument to enter and exit actions.
        # Do we want that?
        meas.add_before_run(action, ())

    for action in exit_actions:
        meas.add_after_run(action, ())

    for parameter in param_meas:
        if isinstance(parameter, _BaseParameter):
            meas.register_parameter(parameter,
                                    setpoints=(param_set1, param_set2))
        if conDuct != None:
            meas.register_parameter(conDuct.G,
                                    setpoints=(param_set1, param_set2))

    try:
        with meas.run() as datasaver:
            start_time = time.perf_counter()
            os.makedirs(datapath + '{}'.format(datasaver.run_id))
            for set_point1 in np.linspace(start1, stop1, num_points1):
                if set_before_sweep:
                    param_set2.set(start2)

                param_set1.set(set_point1)
                for action in before_inner_actions:
                    action()
                for set_point2 in np.linspace(start2, stop2, num_points2):
                    # skip first inner set point if `set_before_sweep`
                    if set_point2 == start2 and set_before_sweep:
                        pass
                    else:
                        param_set2.set(set_point2)
                    output = []
                    for parameter in param_meas:
                        if isinstance(parameter, _BaseParameter):
                            output.append((parameter, parameter.get()))
                        elif callable(parameter):
                            parameter()

                        if conDuct != None:
                            output.append((conDuct.G, conDuct.calcG(output)))

                    datasaver.add_result((param_set1, set_point1),
                                         (param_set2, set_point2), *output)
                for action in after_inner_actions:
                    action()
                if flush_columns:
                    datasaver.flush_data_to_database()

        stop_time = time.perf_counter()
    except KeyboardInterrupt:
        interrupted = True

    dataid = datasaver.run_id

    if interrupted:
        inst = list(meas.parameters.values())
        exportpath = datapath + '{}'.format(
            datasaver.run_id) + '/{}_set_{}_set.dat'.format(
                inst[0].name, inst[1].name)
        exportsnapshot = datapath + '{}'.format(
            datasaver.run_id) + '/snapshot.txt'
        #export_by_id(dataid,exportpath)
        export_by_id_pd(dataid, exportpath)
        export_snapshot_by_id(dataid, exportsnapshot)
        #added by felix 05.03.2020
        _export_settings(datasaver.run_id, inst)

        stop_time = time.perf_counter()
        print("Acquisition took:  %s seconds " % (stop_time - start_time))
        raise KeyboardInterrupt

    inst = list(meas.parameters.values())
    exportpath = datapath + '{}'.format(
        datasaver.run_id) + '/{}_set_{}_set.dat'.format(
            inst[0].name, inst[1].name)
    exportsnapshot = datapath + '{}'.format(datasaver.run_id) + '/snapshot.txt'
    #export_by_id(dataid,exportpath)
    export_by_id_pd(dataid, exportpath)
    export_snapshot_by_id(dataid, exportsnapshot)
    # _export_settings(datasaver.run_id,inst)

    if do_plot is True:
        ax, cbs = _save_image(datasaver, inst)
    else:
        ax = None,
        cbs = None

    print("Acquisition took:  %s seconds " % (stop_time - start_time))

    return dataid, ax, cbs
Exemple #7
0
def do1d(param_set: _BaseParameter, start: number, stop: number,
         num_points: int, delay: number,
         *param_meas: Union[_BaseParameter, Callable[[], None]],
         enter_actions: Sequence[Callable[[], None]] = (),
         exit_actions: Sequence[Callable[[], None]] = (),
         do_plot: bool = True) \
        -> AxesTupleListWithRunId:
    """
    Perform a 1D scan of ``param_set`` from ``start`` to ``stop`` in
    ``num_points`` measuring param_meas at each step. In case param_meas is
    an ArrayParameter this is effectively a 2d scan.

    Args:
        param_set: The QCoDeS parameter to sweep over
        start: Starting point of sweep
        stop: End point of sweep
        num_points: Number of points in sweep
        delay: Delay after setting paramter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The run_id of the DataSet created
    """
    meas = Measurement()
    meas.register_parameter(
        param_set)  # register the first independent parameter
    output = []
    param_set.post_delay = delay
    interrupted = False

    for action in enter_actions:
        # this omits the posibility of passing
        # argument to enter and exit actions.
        # Do we want that?
        meas.add_before_run(action, ())
    for action in exit_actions:
        meas.add_after_run(action, ())

    # do1D enforces a simple relationship between measured parameters
    # and set parameters. For anything more complicated this should be
    # reimplemented from scratch
    for parameter in param_meas:
        if isinstance(parameter, _BaseParameter):
            meas.register_parameter(parameter, setpoints=(param_set, ))
            output.append([parameter, None])

    try:
        with meas.run() as datasaver:

            for set_point in np.linspace(start, stop, num_points):
                param_set.set(set_point)
                output = []
                for parameter in param_meas:
                    if isinstance(parameter, _BaseParameter):
                        output.append((parameter, parameter.get()))
                    elif callable(parameter):
                        parameter()
                datasaver.add_result((param_set, set_point), *output)
    except KeyboardInterrupt:
        interrupted = True

    dataid = datasaver.run_id  # convenient to have for plotting

    if do_plot is True:
        ax, cbs = _save_image(datasaver)
    else:
        ax = None,
        cbs = None

    if interrupted:
        raise KeyboardInterrupt
    return dataid, ax, cbs
Exemple #8
0
def do2d(param_set1: _BaseParameter,
         start1: number,
         stop1: number,
         num_points1: int,
         delay1: number,
         param_set2: _BaseParameter,
         start2: number,
         stop2: number,
         num_points2: int,
         delay2: number,
         *param_meas: Union[_BaseParameter, Callable[[], None]],
         set_before_sweep: Optional[bool] = False,
         enter_actions: Sequence[Callable[[], None]] = (),
         exit_actions: Sequence[Callable[[], None]] = (),
         before_inner_actions: Sequence[Callable[[], None]] = (),
         after_inner_actions: Sequence[Callable[[], None]] = (),
         do_plot: bool = True) -> AxesTupleListWithRunId:
    """
    Perform a 1D scan of ``param_set1`` from ``start1`` to ``stop1`` in
    ``num_points1`` and ``param_set2`` from ``start2`` to ``stop2`` in
    ``num_points2`` measuring param_meas at each step.

    Args:
        param_set1: The QCoDeS parameter to sweep over in the outer loop
        start1: Starting point of sweep in outer loop
        stop1: End point of sweep in the outer loop
        num_points1: Number of points to measure in the outer loop
        delay1: Delay after setting parameter in the outer loop
        param_set2: The QCoDeS parameter to sweep over in the inner loop
        start2: Starting point of sweep in inner loop
        stop2: End point of sweep in the inner loop
        num_points2: Number of points to measure in the inner loop
        delay2: Delay after setting paramter before measurement is performed
        *param_meas: Parameter(s) to measure at each step or functions that
          will be called at each step. The function should take no arguments.
          The parameters and functions are called in the order they are
          supplied.
        set_before_sweep: if True the outer parameter is set to its first value
            before the inner parameter is swept to its next value.
        enter_actions: A list of functions taking no arguments that will be
            called before the measurements start
        exit_actions: A list of functions taking no arguments that will be
            called after the measurements ends
        before_inner_actions: Actions executed before each run of the inner loop
        after_inner_actions: Actions executed after each run of the inner loop
        do_plot: should png and pdf versions of the images be saved after the
            run.

    Returns:
        The run_id of the DataSet created
    """

    meas = Measurement()
    meas.register_parameter(param_set1)
    param_set1.post_delay = delay1
    meas.register_parameter(param_set2)
    param_set2.post_delay = delay2
    interrupted = False
    for action in enter_actions:
        # this omits the possibility of passing
        # argument to enter and exit actions.
        # Do we want that?
        meas.add_before_run(action, ())

    for action in exit_actions:
        meas.add_after_run(action, ())

    for parameter in param_meas:
        if isinstance(parameter, _BaseParameter):
            meas.register_parameter(parameter,
                                    setpoints=(param_set1, param_set2))
    try:
        with meas.run() as datasaver:
            for set_point1 in np.linspace(start1, stop1, num_points1):
                if set_before_sweep:
                    param_set2.set(start2)

                param_set1.set(set_point1)
                for action in before_inner_actions:
                    action()
                for set_point2 in np.linspace(start2, stop2, num_points2):
                    # skip first inner set point if `set_before_sweep`
                    if set_point2 == start2 and set_before_sweep:
                        pass
                    else:
                        param_set2.set(set_point2)
                    output = []
                    for parameter in param_meas:
                        if isinstance(parameter, _BaseParameter):
                            output.append((parameter, parameter.get()))
                        elif callable(parameter):
                            parameter()
                    datasaver.add_result((param_set1, set_point1),
                                         (param_set2, set_point2), *output)
                for action in after_inner_actions:
                    action()
    except KeyboardInterrupt:
        interrupted = True

    dataid = datasaver.run_id

    if do_plot is True:
        ax, cbs = _save_image(datasaver)
    else:
        ax = None,
        cbs = None
    if interrupted:
        raise KeyboardInterrupt

    return dataid, ax, cbs