def _QCoDeS_Loop(self,
                     measured_parameter,
                     sweeped_parameter,
                     sweep_value=[0, 0, 0],
                     **kw):

        Sweep_Values = sweeped_parameter[
            sweep_value[0]:sweep_value[1]:sweep_value[2]]

        #        Sweep_Values2 = sweeped_parameter2[sweep_value2[0]:sweep_value2[1]:sweep_value2[2]]

        LOOP = Loop(sweep_values=Sweep_Values).each(measured_parameter)

        data_set = LOOP.get_data_set(
            location=None,
            loc_record={
                'name': 'Chevron Pattern',
                'label': 'frequency-burst_time'
            },
            io=self.data_IO,
        )

        data_set = LOOP.run()

        return data_set
Exemple #2
0
    def test_measurement_with_many_nans(self):
        loop = Loop(self.p1.sweep(0, 1, num=10),
                    delay=0.05).each(self.p4_crazy)
        ds = loop.get_data_set()
        loop.run()

        # assert that both the snapshot and the datafile are there
        self.assertEqual(len(os.listdir(ds.location)), 2)
Exemple #3
0
    def test_halt(self):
        abort_after = 3
        self.res = list(np.arange(0, abort_after-1, 1.))
        [self.res.append(float('nan')) for i in range(0, abort_after-1)]

        p1 = AbortingGetter('p1', count=abort_after, vals=Numbers(-10, 10), set_cmd=None)
        loop = Loop(p1.sweep(0, abort_after, 1), 0.005).each(p1)
        # we want to test what's in data, so get it ahead of time
        # because loop.run will not return.
        data = loop.get_data_set(location=False)

        loop.run(quiet=True)
        self.assertEqual(repr(data.p1.tolist()), repr(self.res))
    def test_halt(self):
        p1 = AbortingGetter('p1',
                            count=2,
                            vals=Numbers(-10, 10),
                            msg=ActiveLoop.HALT_DEBUG)
        loop = Loop(p1[1:6:1], 0.005).each(p1)
        # we want to test what's in data, so get it ahead of time
        # because loop.run will not return.
        data = loop.get_data_set(location=False)
        p1.set_queue(loop.signal_queue)

        with self.assertRaises(_DebugInterrupt):
            # need to use explicit loop.run rather than run_temp
            # so we can avoid providing location=False twice, which
            # is an error.
            loop.run(background=False, data_manager=False, quiet=True)

        self.check_data(data)
Exemple #5
0
def scan_outside_awg(name, set_parameter, measured_parameter, start, end,
                     step):

    Sweep_Value = set_parameter[start:end:step]

    LOOP = Loop(sweep_values=Sweep_Value).each(measured_parameter)

    data_set = LOOP.get_data_set(
        location=None,
        loc_record={
            'name': name,
            'label': 'Freq_sweep'
        },
        io=data_IO,
    )

    data_set = LOOP.run()

    awg.stop()
    awg2.stop()

    vsg.status('Off')
    vsg2.status('Off')
    return data_set
Exemple #6
0
def _do_measurement(loop: Loop, set_params: tuple, meas_params: tuple,
                    do_plots: Optional[bool]=True,
                    use_threads: bool=True) -> Tuple[QtPlot, DataSet]:
    """
    The function to handle all the auxiliary magic of the T10 users, e.g.
    their plotting specifications, the device image annotation etc.
    The input loop should just be a loop ready to run and perform the desired
    measurement. The two params tuple are used for plotting.
    Args:
        loop: The QCoDeS loop object describing the actual measurement
        set_params: tuple of tuples. Each tuple is of the form
            (param, start, stop)
        meas_params: tuple of parameters to measure
        do_plots: Whether to do a live plot
        use_threads: Whether to use threads to parallelise simultaneous
            measurements. If only one thing is being measured at the time
            in loop, this does nothing.
    Returns:
        (plot, data)
    """
    try:
        parameters = [sp[0] for sp in set_params] + list(meas_params)
        _flush_buffers(*parameters)

        # startranges for _plot_setup
        try:
            startranges = {}
            for sp in set_params:
                minval = min(sp[1], sp[2])
                maxval = max(sp[1], sp[2])
                startranges[sp[0].full_name] = {'max': maxval, 'min': minval}
        except Exception:
            startranges = None

        interrupted = False

        data = loop.get_data_set()

        if do_plots:
            try:
                plot, _ = _plot_setup(data, meas_params, startranges=startranges)
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
        else:
            plot = None
        try:
            if do_plots:
                _ = loop.with_bg_task(plot.update).run(use_threads=use_threads)
            else:
                _ = loop.run(use_threads=use_threads)
        except KeyboardInterrupt:
            interrupted = True
            print("Measurement Interrupted")
        if do_plots:
            # Ensure the correct scaling before saving
            try:
                plot.autorange()
                plot.save()
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')

            if 'pdf_subfolder' in CURRENT_EXPERIMENT or 'png_subfolder' in CURRENT_EXPERIMENT:
                _do_MatPlot(data,meas_params)

        if CURRENT_EXPERIMENT.get('device_image'):
            log.debug('Saving device image')
            save_device_image(tuple(sp[0] for sp in set_params))

        # add the measurement ID to the logfile
        with open(CURRENT_EXPERIMENT['logfile'], 'a') as fid:
            print("#[QCoDeS]# Saved dataset to: {}".format(data.location),
                  file=fid)
        if interrupted:
            raise KeyboardInterrupt
    except:
        log.exception("Exception in doND")
        raise
    return plot, data
Exemple #7
0
def _do_measurement(loop: Loop,
                    set_params: tuple,
                    meas_params: tuple,
                    do_plots: bool = True,
                    use_threads: bool = True) -> Tuple[QtPlot, DataSet]:
    """
    The function to handle all the auxiliary magic of the T10 users, e.g.
    their plotting specifications, the device image annotation etc.
    The input loop should just be a loop ready to run and perform the desired
    measurement. The two params tuple are used for plotting.

    Args:
        loop: The QCoDeS loop object describing the actual measurement
        set_params: tuple of tuples. Each tuple is of the form
            (param, start, stop)
        meas_params: tuple of parameters to measure
        do_plots: Whether to do a live plot
        use_threads: Whether to use threads to parallelise simultaneous
            measurements. If only one thing is being measured at the time
            in loop, this does nothing.

    Returns:
        (plot, data)
    """
    try:
        parameters = [sp[0] for sp in set_params] + list(meas_params)
        _flush_buffers(*parameters)

        # startranges for _plot_setup
        startranges = {}
        for sp in set_params:
            minval = min(sp[1], sp[2])
            maxval = max(sp[1], sp[2])
            startranges[sp[0].full_name] = {'max': maxval, 'min': minval}
        interrupted = False

        data = loop.get_data_set()

        if do_plots:
            try:
                plot, _ = _plot_setup(data,
                                      meas_params,
                                      startranges=startranges)
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
        else:
            plot = None
        try:
            if do_plots:
                _ = loop.with_bg_task(plot.update).run(use_threads=use_threads)
            else:
                _ = loop.run(use_threads=use_threads)
        except KeyboardInterrupt:
            interrupted = True
            print("Measurement Interrupted")
        if do_plots:
            # Ensure the correct scaling before saving
            try:
                plot.autorange()
                plot.save()
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
            plt.ioff()
            pdfplot, num_subplots = _plot_setup(data, meas_params, useQT=False)
            # pad a bit more to prevent overlap between
            # suptitle and title
            pdfplot.rescale_axis()
            pdfplot.fig.tight_layout(pad=3)
            title_list = plot.get_default_title().split(sep)
            title_list.insert(-1, CURRENT_EXPERIMENT['pdf_subfolder'])
            title = sep.join(title_list)

            pdfplot.save("{}.pdf".format(title))
            if pdfdisplay['combined'] or (num_subplots == 1
                                          and pdfdisplay['individual']):
                pdfplot.fig.canvas.draw()
                plt.show()
            else:
                plt.close(pdfplot.fig)
            if num_subplots > 1:
                _save_individual_plots(data, meas_params,
                                       pdfdisplay['individual'])
            plt.ion()
        if CURRENT_EXPERIMENT.get('device_image'):
            log.debug('Saving device image')
            save_device_image(tuple(sp[0] for sp in set_params))

        # add the measurement ID to the logfile
        with open(CURRENT_EXPERIMENT['logfile'], 'a') as fid:
            print("#[QCoDeS]# Saved dataset to: {}".format(data.location),
                  file=fid)
        if interrupted:
            raise KeyboardInterrupt
    except:
        log.exception("Exception in doND")
        raise

    return plot, data
Exemple #8
0
class Measure(Metadatable):
    """
    Create a DataSet from a single (non-looped) set of actions.

    Args:
        *actions (Any): sequence of actions to perform. Any action that is
            valid in a ``Loop`` can be used here. If an action is a gettable
            ``Parameter``, its output will be included in the DataSet.
            Scalars returned by an action will be saved as length-1 arrays,
            with a dummy setpoint for consistency with other DataSets.
    """
    dummy_parameter = Parameter(name='single',
                                label='Single Measurement',
                                set_cmd=None, get_cmd=None)

    def __init__(self, *actions):
        super().__init__()
        self._dummyLoop = Loop(self.dummy_parameter[0]).each(*actions)

    def run_temp(self, **kwargs):
        """
        Wrapper to run this measurement as a temporary data set
        """
        return self.run(quiet=True, location=False, **kwargs)

    def get_data_set(self, *args, **kwargs):
        return self._dummyLoop.get_data_set(*args, **kwargs)

    def run(self, use_threads=False, quiet=False, station=None, **kwargs):
        """
        Run the actions in this measurement and return their data as a DataSet

        Args:
            quiet (Optional[bool]): Set True to not print anything except
                errors. Default False.

            station (Optional[Station]): the ``Station`` this measurement
                pertains to. Defaults to ``Station.default`` if one is defined.
                Only used to supply metadata.

            use_threads (Optional[bool]): whether to parallelize ``get``
                operations using threads. Default False.

            location (Optional[Union[str, bool]]): the location of the
                DataSet, a string whose meaning depends on formatter and io,
                or False to only keep in memory. May be a callable to provide
                automatic locations. If omitted, will use the default
                DataSet.location_provider

            name (Optional[str]): if location is default or another provider
                function, name is a string to add to location to make it more
                readable/meaningful to users

            formatter (Optional[Formatter]): knows how to read and write the
                file format. Default can be set in DataSet.default_formatter

            io (Optional[io_manager]): knows how to connect to the storage
                (disk vs cloud etc)

        location, name formatter and io are passed to ``data_set.new_data``
        along with any other optional keyword arguments.

        returns:
            a DataSet object containing the results of the measurement
        """

        data_set = self._dummyLoop.get_data_set(**kwargs)

        # set the DataSet to local for now so we don't save it, since
        # we're going to massage it afterward
        original_location = data_set.location
        data_set.location = False

        # run the measurement as if it were a Loop
        self._dummyLoop.run(use_threads=use_threads,
                            station=station, quiet=True)

        # look for arrays that are unnecessarily nested, and un-nest them
        all_unnested = True
        for array in data_set.arrays.values():
            if array.ndim == 1:
                if array.is_setpoint:
                    dummy_setpoint = array
                else:
                    # we've found a scalar - so keep the dummy setpoint
                    all_unnested = False
            else:
                # The original return was an array, so take off the extra dim.
                # (This ensures the outer dim length was 1, otherwise this
                # will raise a ValueError.)
                array.ndarray.shape = array.ndarray.shape[1:]

                # TODO: DataArray.shape masks ndarray.shape, and a user *could*
                # change it, thinking they were reshaping the underlying array,
                # but this would a) not actually reach the ndarray right now,
                # and b) if it *did* and the array was reshaped, this array
                # would be out of sync with its setpoint arrays, so bad things
                # would happen. So we probably want some safeguards in place
                # against this
                array.shape = array.ndarray.shape

                array.set_arrays = array.set_arrays[1:]

                array.init_data()

        # Do we still need the dummy setpoint array at all?
        if all_unnested:
            del data_set.arrays[dummy_setpoint.array_id]
            if hasattr(data_set, 'action_id_map'):
                del data_set.action_id_map[dummy_setpoint.action_indices]

        # now put back in the DataSet location and save it
        data_set.location = original_location
        data_set.write()

        # metadata: ActiveLoop already provides station snapshot, but also
        # puts in a 'loop' section that we need to replace with 'measurement'
        # but we use the info from 'loop' to ensure consistency and avoid
        # duplication.
        LOOP_SNAPSHOT_KEYS = ['ts_start', 'ts_end', 'use_threads']
        data_set.add_metadata({'measurement': {
            k: data_set.metadata['loop'][k] for k in LOOP_SNAPSHOT_KEYS
        }})
        del data_set.metadata['loop']

        # actions are included in self.snapshot() rather than in
        # LOOP_SNAPSHOT_KEYS because they are useful if someone just
        # wants a local snapshot of the Measure object
        data_set.add_metadata({'measurement': self.snapshot()})

        data_set.save_metadata()

        if not quiet:
            print(repr(data_set))
            print(datetime.now().strftime('acquired at %Y-%m-%d %H:%M:%S'))

        return data_set

    def snapshot_base(self, update: Optional[bool] = False,
                      params_to_skip_update: Optional[Sequence[str]] = None):
        return {
            '__class__': full_class(self),
            'actions': _actions_snapshot(self._dummyLoop.actions, update)
        }
Exemple #9
0
LP = Loop(sweep_values = Sweep_Value).each(F,E)

#%%
#LP.with_bg_task(task = Print,bg_final_task = None,min_delay=1).run()

#LP = Loop(sweep_values = Sweep_Value,).each(F)

print('loop.data_set: %s' % LP.data_set)

NewIO = DiskIO(base_location = 'C:\\Users\\LocalAdmin\\Documents')
formatter = HDF5FormatMetadata()

OldIO = DiskIO(base_location = 'D:\\文献\\QuTech\\QTlab\\xiaotest\\testIO')

## get_data_set should contain parameter like io, location, formatter and others
data = LP.get_data_set(location=None, loc_record = {'name':'T1', 'label':'Vread_sweep'}, 
                       io = NewIO, formatter = formatter)
#data = LP.get_data_set(data_manager=False, location=None, loc_record = {'name':'T1', 'label':'T_load_sweep'})
print('loop.data_set: %s' % LP.data_set)

#%%
DS = new_data(location = 'aaaaaaaaaa',io = NewIO)
def live_plotting():
    for para in data.arrays:
        DS.arrays[para] = data.arrays[para]
    return DS
DS = live_plotting()
#def add_T1exp_metadata(data):
#        
#        data.metadata['Parameters'] = {'Nrep': 10, 't_empty': 2, 't_load': 2.4, 't_read': 2.2}
#        data.write(write_metadata=True)
#
Exemple #10
0
def _do_measurement(loop: Loop, set_params: tuple, meas_params: tuple,
                    do_plots: Optional[bool]=True,
                    use_threads: bool=True,
                    auto_color_scale: Optional[bool]=None,
                    cutoff_percentile: Optional[Union[Tuple[Number, Number], Number]]=None) -> Tuple[QtPlot, DataSet]:
    """
    The function to handle all the auxiliary magic of the T10 users, e.g.
    their plotting specifications, the device image annotation etc.
    The input loop should just be a loop ready to run and perform the desired
    measurement. The two params tuple are used for plotting.
    Args:
        loop: The QCoDeS loop object describing the actual measurement
        set_params: tuple of tuples. Each tuple is of the form
            (param, start, stop)
        meas_params: tuple of parameters to measure
        do_plots: Whether to do a live plot
        use_threads: Whether to use threads to parallelise simultaneous
            measurements. If only one thing is being measured at the time
            in loop, this does nothing.
        auto_color_scale: if True, the colorscale of heatmap plots will be
            automatically adjusted to disregard outliers.
        cutoff_percentile: percentile of data that may maximally be clipped
            on both sides of the distribution.
            If given a tuple (a,b) the percentile limits will be a and 100-b.
            See also the plotting tuorial notebook.
    Returns:
        (plot, data)
    """
    try:
        parameters = [sp[0] for sp in set_params] + list(meas_params)
        _flush_buffers(*parameters)

        # startranges for _plot_setup
        try:
            startranges = {}
            for sp in set_params:
                minval = min(sp[1], sp[2])
                maxval = max(sp[1], sp[2])
                startranges[sp[0].full_name] = {'max': maxval, 'min': minval}
        except Exception:
            startranges = None

        interrupted = False

        data = loop.get_data_set()

        if do_plots:
            try:
                plot, _ = _plot_setup(data, meas_params, startranges=startranges,
                                      auto_color_scale=auto_color_scale,
                                      cutoff_percentile=cutoff_percentile)
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
                # if remote process crashed continue without plots
                do_plots = False
        else:
            plot = None
        try:
            if do_plots:
                _ = loop.with_bg_task(plot.update).run(use_threads=use_threads)
            else:
                _ = loop.run(use_threads=use_threads)
        except KeyboardInterrupt:
            interrupted = True
            print("Measurement Interrupted")
        if do_plots:
            # Ensure the correct scaling before saving
            try:
                plot.autorange()
                plot.save()
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
                # if remote process crashed continue without plots
                do_plots = False

            if 'pdf_subfolder' in CURRENT_EXPERIMENT or 'png_subfolder' in CURRENT_EXPERIMENT:
                _do_MatPlot(data,meas_params,
                            auto_color_scale=auto_color_scale,
                            cutoff_percentile=cutoff_percentile)

        if CURRENT_EXPERIMENT.get('device_image'):
            log.debug('Saving device image')
            save_device_image(tuple(sp[0] for sp in set_params))

        log.info("#[QCoDeS]# Saved dataset to: {}".format(data.location))
        if interrupted:
            raise KeyboardInterrupt
    except:
        log.exception("Exception in doND")
        raise
    return plot, data
Exemple #11
0
def _do_measurement(loop: Loop, set_params: tuple, meas_params: tuple,
                    do_plots: Optional[bool]=True) -> Tuple[QtPlot, DataSet]:
    """
    The function to handle all the auxiliary magic of the T10 users, e.g.
    their plotting specifications, the device image annotation etc.
    The input loop should just be a loop ready to run and perform the desired
    measurement. The two params tuple are used for plotting.

    Args:
        loop: The QCoDeS loop object describing the actual measurement
        set_params: tuple of tuples. Each tuple is of the form
            (param, start, stop)
        meas_params: tuple of parameters to measure

    Returns:
        (plot, data)
    """
    parameters = [sp[0] for sp in set_params] + list(meas_params)
    _flush_buffers(*parameters)

    # startranges for _plot_setup
    startranges = dict(zip((sp[0].label for sp in set_params),
                           ((sp[1], sp[2]) for sp in set_params)))

    interrupted = False

    data = loop.get_data_set()

    if do_plots:
        plot, _ = _plot_setup(data, meas_params, startranges=startranges)
    else:
        plot = None
    try:
        if do_plots:
            _ = loop.with_bg_task(plot.update).run()
        else:
            _ = loop.run()
    except KeyboardInterrupt:
        interrupted = True
        print("Measurement Interrupted")
    if do_plots:
        # Ensure the correct scaling before saving
        for subplot in plot.subplots:
            vBox = subplot.getViewBox()
            vBox.enableAutoRange(vBox.XYAxes)
        cmap = None
        # resize histogram
        for trace in plot.traces:
            if 'plot_object' in trace.keys():
                if (isinstance(trace['plot_object'], dict) and
                            'hist' in trace['plot_object'].keys()):
                    cmap = trace['plot_object']['cmap']
                    max = trace['config']['z'].max()
                    min = trace['config']['z'].min()
                    trace['plot_object']['hist'].setLevels(min, max)
                    trace['plot_object']['hist'].vb.autoRange()
        if cmap:
            plot.set_cmap(cmap)
        # set window back to original size
        plot.win.resize(1000, 600)
        plot.save()
        pdfplot, num_subplots = _plot_setup(data, meas_params, useQT=False)
        # pad a bit more to prevent overlap between
        # suptitle and title
        pdfplot.fig.tight_layout(pad=3)
        pdfplot.save("{}.pdf".format(plot.get_default_title()))
        pdfplot.fig.canvas.draw()
        if num_subplots > 1:
            _save_individual_plots(data, meas_params)
    if CURRENT_EXPERIMENT.get('device_image'):
        log.debug('Saving device image')
        save_device_image(tuple(sp[0] for sp in set_params))

    # add the measurement ID to the logfile
    with open(CURRENT_EXPERIMENT['logfile'], 'a') as fid:
        print("#[QCoDeS]# Saved dataset to: {}".format(data.location),
              file=fid)
    if interrupted:
        raise KeyboardInterrupt
    return plot, data
#LOOP = Loop(sweep_values = Sweep_Value1).each(AMP)

#Sweep_Value3 = Count[0:4000:1]
#LOOP = Loop(sweep_values = Sweep_Value3, delay = 0.5).each(AMP)

NewIO = DiskIO(base_location='D:\\Data\\RB_experiment')
NewIO = DiskIO(
    base_location=
    'K:\\ns\\qt\\spin-qubits\\data\\b059_data\\2018 data\\Data\\RB_experiment')

## get_data_set should contain parameter like io, location, formatter and others
data = LOOP.get_data_set(
    location=None,
    loc_record={
        'name': 'DAC',
        'label': 'V_sweep'
    },
    io=NewIO,
)
print('loop.data_set: %s' % LOOP.data_set)
'''
plot = QtPlot()
plot.add(data.keithley_amplitude, figsize=(1200, 500))
_ = LOOP.with_bg_task(plot.update, plot.save).run()
'''
'''
pt = MatPlot()
pt.add(x = data.gates_T_set, y = data.gates_LP_set, z = data.keithley_amplitude)

pt = MatPlot()
pt.add(x = data.gates_SQD1_set, y = data.gates_SQD3_set, z = data.keithley_amplitude)