Example #1
0
def do1d(
        param_set: _BaseParameter,
        xarray,
        delay: float,
        *param_meas: qcnd.ParamMeasT,
        exp: Optional[Experiment] = None,
        use_threads: Optional[bool] = None,
        enter_actions: qcnd.ActionsT = (),
        exit_actions: qcnd.ActionsT = (),
        additional_setpoints: Sequence[qcnd.ParamMeasT] = tuple(),
):

    if not _is_monotonic(xarray):
        warn('Sweep array is not monotonic. This is pretty weird. Reconsider.')

    meas = Measurement(exp=exp)

    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))

    if (len(measured_parameters) > 2) or (use_threads == True):
        use_threads = True
    else:
        use_threads = False

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

    qcnd._register_parameters(meas, all_setpoint_params)
    qcnd._register_parameters(meas,
                              param_meas,
                              setpoints=all_setpoint_params,
                              shapes=shapes)
    qcnd._register_actions(meas, enter_actions, exit_actions)

    with qcnd._catch_keyboard_interrupts() as interrupted, \
        meas.run(write_in_background=True) as datasaver:

        additional_setpoints_data = qcnd._process_params_meas(
            additional_setpoints)
        for set_point in xarray:
            param_set.set(set_point)
            time.sleep(delay)
            datasaver.add_result(
                (param_set, set_point),
                *qcnd._process_params_meas(param_meas,
                                           use_threads=use_threads),
                *additional_setpoints_data)
        dataset = datasaver.dataset

    return dataset
Example #2
0
def readvstime(
        delay: float,
        timeout: float,
        *param_meas: qcnd.ParamMeasT,
        exp: Experiment = None,
        use_threads=False,
        enter_actions: qcnd.ActionsT = (),
        exit_actions: qcnd.ActionsT = (),
        additional_setpoints=tuple(),
):

    meas = Measurement(exp=exp)

    timer = ElapsedTimeParameter("time")

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

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

    if (len(measured_parameters) > 2) or (use_threads == True):
        use_threads = True
    else:
        use_threads = False

    qcnd._register_parameters(meas, all_setpoint_params)
    qcnd._register_parameters(meas,
                              param_meas,
                              setpoints=all_setpoint_params,
                              shapes=None)
    qcnd._register_actions(meas, enter_actions, exit_actions)

    with qcnd._catch_keyboard_interrupts() as interrupted, \
        meas.run(write_in_background=True) as datasaver:

        additional_setpoints_data = qcnd._process_params_meas(
            additional_setpoints)
        timer.reset_clock()

        while True:
            time.sleep(delay)
            datasaver.add_result(
                (timer, timer.get()),
                *qcnd._process_params_meas(param_meas,
                                           use_threads=use_threads),
                *additional_setpoints_data)
            if (timeout - timer.get()) < 0.005:
                break
        dataset = datasaver.dataset

    return dataset
Example #3
0
def field_sweep_ps120(
        field_param,
        start: float,
        stop: float,
        delay: float,
        *param_meas: qcnd.ParamMeasT,
        exp: Experiment = None,
        use_threads=False,
        enter_actions: qcnd.ActionsT = (),
        exit_actions: qcnd.ActionsT = (),
        additional_setpoints=tuple(),
):

    # get instrument for field param
    magnet = field_param.instrument

    # timer param
    timer = ElapsedTimeParameter("time")

    # add field to measured params
    param_meas = list(param_meas)
    param_meas.append(field_param)
    measured_parameters = list(param for param in param_meas
                               if isinstance(param, _BaseParameter))

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

    if (len(measured_parameters) > 2) or (use_threads == True):
        use_threads = True
    elif (use_threads == False):
        use_threads = False
    else:
        use_threads = False

    meas = Measurement(exp=exp)
    qcnd._register_parameters(meas, all_setpoint_params)
    qcnd._register_parameters(meas,
                              param_meas,
                              setpoints=all_setpoint_params,
                              shapes=None)
    qcnd._register_actions(meas, enter_actions, exit_actions)

    with qcnd._catch_keyboard_interrupts() as interrupted, \
        meas.run(write_in_background=True) as datasaver:

        magnet.field_blocking(start)
        additional_setpoints_data = qcnd._process_params_meas(
            additional_setpoints)
        timer.reset_clock()
        magnet.field_non_blocking(stop)

        while magnet.ramp_status() != magnet._GET_STATUS_RAMP[0]:
            time.sleep(delay)
            datasaver.add_result(
                (timer, timer.get()),
                *qcnd._process_params_meas(param_meas,
                                           use_threads=use_threads),
                *additional_setpoints_data)

        dataset = datasaver.dataset

    return dataset
Example #4
0
def field_sweep_ami_2d(
        field_param,
        xarray,
        delayx,
        param_sety,
        yarray,
        delayy,
        *param_meas: qcnd.ParamMeasT,
        exp: Experiment = None,
        use_threads=False,
        enter_actions: qcnd.ActionsT = (),
        exit_actions: qcnd.ActionsT = (),
        additional_setpoints=tuple(),
):

    # get instrument for field param
    magnet = field_param.instrument

    # add field to measured params
    all_setpoint_params = (
        param_sety,
        field_param,
    ) + tuple(s for s in additional_setpoints)

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

    if (len(measured_parameters) > 2) or (use_threads == True):
        use_threads = True
    elif (use_threads == False):
        use_threads = False
    else:
        use_threads = False

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

    meas = Measurement(exp=exp)
    qcnd._register_parameters(meas, all_setpoint_params)
    qcnd._register_parameters(meas,
                              param_meas,
                              setpoints=all_setpoint_params,
                              shapes=None)
    qcnd._register_actions(meas, enter_actions, exit_actions)

    inner_loop_params = (field_param, ) + param_meas
    inner_loop_dict = {k.name: [] for k in inner_loop_params}

    with qcnd._catch_keyboard_interrupts() as interrupted, \
        meas.run(write_in_background=True) as datasaver:

        additional_setpoints_data = qcnd._process_params_meas(
            additional_setpoints)

        for set_pointy in yarray:
            param_sety.set(set_pointy)
            time.sleep(delayy)

            magnet.set_field(xarray[0], block=True)
            magnet.set_field(xarray[-1], block=False)

            while magnet.ramping_state() == 'ramping':
                time.sleep(delayx)

                for param, val in qcnd._process_params_meas(
                        inner_loop_params, use_threads=use_threads):
                    inner_loop_dict[param.name].append(val)

            datasaver.add_result(
                (param_sety, [set_pointy] * len(xarray)),
                *_bin_results_to_fit_shape(field_param, xarray,
                                           inner_loop_params, inner_loop_dict),
                *additional_setpoints_data,
            )

        dataset = datasaver.dataset

    return dataset
Example #5
0
def do2d(
        param_setx,
        xarray,
        delayx,
        param_sety,
        yarray,
        delayy,
        *param_meas: qcnd.ParamMeasT,
        enter_actions: qcnd.ActionsT = (),
        exit_actions: qcnd.ActionsT = (),
        before_inner_actions: qcnd.ActionsT = (),
        after_inner_actions: qcnd.ActionsT = (),
        exp: Optional[Experiment] = None,
        use_threads: Optional[bool] = None,
        additional_setpoints: Sequence[qcnd.ParamMeasT] = tuple(),
):

    meas = Measurement(exp=exp)
    all_setpoint_params = (
        param_sety,
        param_setx,
    ) + tuple(s for s in additional_setpoints)

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

    if (len(measured_parameters) > 2) or (use_threads == True):
        use_threads = True
    elif (use_threads == False):
        use_threads = False
    else:
        use_threads = False

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

    qcnd._register_parameters(meas, all_setpoint_params)
    qcnd._register_parameters(meas,
                              param_meas,
                              setpoints=all_setpoint_params,
                              shapes=shapes)
    qcnd._register_actions(meas, enter_actions, exit_actions)

    param_setx.post_delay = 0.0
    param_sety.post_delay = 0.0

    with qcnd._catch_keyboard_interrupts() as interrupted, \
        meas.run(write_in_background=True) as datasaver:

        additional_setpoints_data = qcnd._process_params_meas(
            additional_setpoints)
        for set_pointy in yarray:
            param_setx.set(xarray[0])
            param_sety.set(set_pointy)
            time.sleep(delayy)
            for action in before_inner_actions:
                action()
            for set_pointx in xarray:
                param_setx.set(set_pointx)
                time.sleep(delayx)

                datasaver.add_result(
                    (param_sety, set_pointy), (param_setx, set_pointx),
                    *qcnd._process_params_meas(param_meas,
                                               use_threads=use_threads),
                    *additional_setpoints_data)

            for action in after_inner_actions:
                action()

        dataset = datasaver.dataset
    return dataset
Example #6
0
def do1d_repeat_twoway(
        param_setx,
        xarray,
        delayx,
        num_repeats,
        delayy,
        *param_meas: qcnd.ParamMeasT,
        enter_actions: qcnd.ActionsT = (),
        exit_actions: qcnd.ActionsT = (),
        before_inner_actions: qcnd.ActionsT = (),
        after_inner_actions: qcnd.ActionsT = (),
        exp: Optional[Experiment] = None,
        use_threads: Optional[bool] = None,
        additional_setpoints: Sequence[qcnd.ParamMeasT] = tuple(),
):
    if (not _is_monotonic(xarray)) or (not _is_monotonic(yarray)):
        warn('Sweep array is not monotonic. This is pretty weird. Reconsider.')

    meas = Measurement(exp=exp)

    param_county = CountParameter("repeat")
    all_setpoint_params = (
        param_county,
        param_setx,
    ) + tuple(s for s in additional_setpoints)

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

    if (len(measured_parameters) > 2) or (use_threads == True):
        use_threads = True
    else:
        use_threads = False

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

    qcnd._register_parameters(meas, all_setpoint_params)
    qcnd._register_parameters(meas,
                              param_meas,
                              setpoints=all_setpoint_params,
                              shapes=shapes)
    qcnd._register_actions(meas, enter_actions, exit_actions)

    param_setx.post_delay = 0.0

    with qcnd._catch_keyboard_interrupts() as interrupted, \
        meas.run(write_in_background=True) as datasaver:

        additional_setpoints_data = qcnd._process_params_meas(
            additional_setpoints)
        for i in range(num_repeats):
            y = param_county.get()
            if y % 2 == 0:
                xsetpoints = xarray
            else:
                xsetpoints = xarray[::-1]
            param_setx.set(xsetpoints[0])
            time.sleep(delayy)

            for action in before_inner_actions:
                action()

            for set_pointx in xsetpoints:
                param_setx.set(set_pointx)
                time.sleep(delayx)

                datasaver.add_result(
                    (param_county, y), (param_setx, set_pointx),
                    *qcnd._process_params_meas(param_meas,
                                               use_threads=use_threads),
                    *additional_setpoints_data)
            for action in after_inner_actions:
                action()

        dataset = datasaver.dataset
    return dataset