Ejemplo n.º 1
0
def test_load_2dsoftsweep_known_shape(experiment):
    N = 1
    m = qc.Measurement(exp=experiment)
    m.register_custom_parameter('x', unit='cm')
    m.register_custom_parameter('y')

    # check that unused parameters don't mess with
    m.register_custom_parameter('foo')
    dd_expected = DataDict(x=dict(values=np.array([]), unit='cm'),
                           y=dict(values=np.array([])))
    for n in range(N):
        m.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])
        dd_expected[f'z_{n}'] = dict(values=np.array([]), axes=['x', 'y'])
    dd_expected.validate()

    shape = (3, 3)

    m.set_shapes({'z_0': shape})

    with m.run() as datasaver:
        for result in testdata.generate_2d_scalar_simple(*shape, N):
            row = [(k, v) for k, v in result.items()] + [('foo', 1)]
            datasaver.add_result(*row)
            dd_expected.add_data(**result)

    dd_expected['x']['values'] = dd_expected['x']['values'].reshape(*shape)
    dd_expected['y']['values'] = dd_expected['y']['values'].reshape(*shape)
    dd_expected['z_0']['values'] = dd_expected['z_0']['values'].reshape(*shape)

    # retrieve data as data dict
    ddict = ds_to_datadict(datasaver.dataset)
    assert ddict == dd_expected
Ejemplo n.º 2
0
def test_load_2dsoftsweep():
    qc.config.core.db_location = DBPATH
    initialise_database()
    exp = load_or_create_experiment('2d_softsweep', sample_name='no sample')

    N = 5
    m = qc.Measurement(exp=exp)
    m.register_custom_parameter('x')
    m.register_custom_parameter('y')

    # check that unused parameters don't mess with
    m.register_custom_parameter('foo')
    dd_expected = DataDict(x=dict(values=np.array([])),
                           y=dict(values=np.array([])))
    for n in range(N):
        m.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])
        dd_expected[f'z_{n}'] = dict(values=np.array([]), axes=['x', 'y'])
    dd_expected.validate()

    with m.run() as datasaver:
        for result in testdata.generate_2d_scalar_simple(3, 3, N):
            row = [(k, v) for k, v in result.items()] + [('foo', 1)]
            datasaver.add_result(*row)
            dd_expected.add_data(**result)

    # retrieve data as data dict
    run_id = datasaver.dataset.captured_run_id
    ddict = datadict_from_path_and_run_id(DBPATH, run_id)
    assert ddict == dd_expected
Ejemplo n.º 3
0
def database_with_three_datasets(empty_db_path):
    """Fixture of a database file with 3 DataSets"""
    exp1 = load_or_create_experiment('get_runs_from_db', sample_name='qubit')
    m1 = qc.Measurement(exp=exp1)

    m1.register_custom_parameter('x', unit='cm')
    m1.register_custom_parameter('y')
    m1.register_custom_parameter('foo')
    for n in range(2):
        m1.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])

    with m1.run() as datasaver:
        dataset11 = datasaver.dataset

    with m1.run() as datasaver:
        datasaver.add_result(('x', 1.), ('y', 2.), ('z_0', 42.), ('z_1', 0.2))

        dataset12 = datasaver.dataset

    exp2 = load_or_create_experiment('give_em', sample_name='now')
    m2 = qc.Measurement(exp=exp2)

    m2.register_custom_parameter('a')
    m2.register_custom_parameter('b', unit='mm')
    m2.register_custom_parameter('c', setpoints=['a', 'b'])

    with m2.run() as datasaver:
        datasaver.add_result(('a', 1.), ('b', 2.), ('c', 42.))
        datasaver.add_result(('a', 4.), ('b', 5.), ('c', 77.))
        dataset2 = datasaver.dataset

    datasets = (dataset11, dataset12, dataset2)

    yield empty_db_path, datasets

    for ds in datasets:
        ds.conn.close()
    exp1.conn.close()
    exp2.conn.close()
Ejemplo n.º 4
0
def measure_triggered_softsweep_vs_parameter(controller, sweep_param, sweep_vals, integration_time,
                                             parameter, values,
                                             exp_name=None, channel=0, **kw):
    """
    Set up and measure a series of triggered softsweep, iterating over an
    additional parameter.
    
    :param controller: softsweep controller to use
    :param sweep_param: qcodes parameter to sweep over
    :param sweep_vals: values for the sweep
    :param integration_time: total integration time per point [s]
    :param parameter: additional qcodes parameter to iterate over (as an outer loop)
    :param values: values for the additional parameter
    :param exp_name: name of the experiment. if ``None``, determine one automatically
    :param channel: Alazar channel that contains the data

    :return: qcodes dataset
    
    kws will be passed to ``setup_triggered_softsweep``.
    """
    station = qcodes.Station.default
    sample = qcodes.config.user.get('current_sample')    
    if exp_name is None:
        exp_name = f'{sweep_param.full_name}_triggered_softsweep'
    
    exp = qcodes.load_or_create_experiment(exp_name, sample)
    meas = qcodes.Measurement(exp, station)
    
    independents = [parameter, sweep_param]
    meas.register_parameter(parameter)
    meas.register_parameter(sweep_param, paramtype='array')
    meas.register_custom_parameter('amplitude', unit='V', setpoints=independents, 
                                   paramtype='array')
    meas.register_custom_parameter('phase', unit='rad', setpoints=independents,
                                   paramtype='array')
    
    with meas.run() as datasaver:
        for i, v in enumerate(values):
            setup_triggered_softsweep(controller, sweep_param, sweep_vals, integration_time,
                                      setup_awg=(i==0), verbose=(i==0), **kw)
            data = np.squeeze(controller.acquisition())[..., channel]

            result = []
            result.append((parameter, v))
            result.append((sweep_param, sweep_vals))
            result.append(('amplitude', np.abs(data)))
            result.append(('phase', np.angle(data)))
            datasaver.add_result(*result)
    
    return datasaver.dataset
Ejemplo n.º 5
0
def test_get_ds_info(experiment):
    N = 5

    m = qc.Measurement(exp=experiment)

    m.register_custom_parameter('x', unit='cm')
    m.register_custom_parameter('y')
    m.register_custom_parameter('foo')
    for n in range(N):
        m.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])

    with m.run() as datasaver:
        dataset = datasaver.dataset

        ds_info_with_empty_timestamps = get_ds_info(dataset,
                                                    get_structure=False)
        assert ds_info_with_empty_timestamps['completed_date'] == ''
        assert ds_info_with_empty_timestamps['completed_time'] == ''

    # timestamps are difficult to test for, so we will cheat here and
    # instead of hard-coding timestamps we will just get them from the dataset
    # The same applies to the guid as it contains the timestamp
    started_ts = dataset.run_timestamp()
    completed_ts = dataset.completed_timestamp()

    expected_ds_info = {
        'experiment': '2d_softsweep',
        'sample': 'no sample',
        'completed_date': completed_ts[:10],
        'completed_time': completed_ts[11:],
        'started_date': started_ts[:10],
        'started_time': started_ts[11:],
        'name': 'results',
        'structure': None,
        'records': 0,
        'guid': dataset.guid,
        'inspectr_tag': ''
    }

    ds_info = get_ds_info(dataset, get_structure=False)

    assert ds_info == expected_ds_info

    expected_ds_info_with_structure = expected_ds_info.copy()
    expected_ds_info_with_structure['structure'] = get_ds_structure(dataset)

    ds_info_with_structure = get_ds_info(dataset)

    assert ds_info_with_structure == expected_ds_info_with_structure
Ejemplo n.º 6
0
def test_update_qcloader(qtbot, empty_db_path):
    db_path = empty_db_path

    exp = load_or_create_experiment('2d_softsweep', sample_name='no sample')

    N = 2
    m = qc.Measurement(exp=exp)
    m.register_custom_parameter('x')
    m.register_custom_parameter('y')
    dd_expected = DataDict(x=dict(values=np.array([])),
                           y=dict(values=np.array([])))
    for n in range(N):
        m.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])
        dd_expected[f'z_{n}'] = dict(values=np.array([]), axes=['x', 'y'])
    dd_expected.validate()

    # setting up the flowchart
    fc = linearFlowchart(('loader', QCodesDSLoader))
    loader = fc.nodes()['loader']

    def check():
        nresults = ds.number_of_results
        loader.update()
        ddict = fc.output()['dataOut']

        if ddict is not None and nresults > 0:
            z_in = dd_expected.data_vals('z_1')
            z_out = ddict.data_vals('z_1')
            if z_out is not None:
                assert z_in.size == z_out.size
                assert np.allclose(z_in, z_out, atol=1e-15)

    with m.run() as datasaver:
        ds = datasaver.dataset
        run_id = datasaver.dataset.captured_run_id
        loader.pathAndId = db_path, run_id

        for result in testdata.generate_2d_scalar_simple(3, 3, N):
            row = [(k, v) for k, v in result.items()]
            datasaver.add_result(*row)
            dd_expected.add_data(**result)
            check()
        check()
Ejemplo n.º 7
0
def test_get_ds_structure(experiment):
    N = 5

    m = qc.Measurement(exp=experiment)
    m.register_custom_parameter('x', unit='cm', label='my_x_param')
    m.register_custom_parameter('y')

    # check that unused parameters don't mess with
    m.register_custom_parameter('foo')

    for n in range(N):
        m.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])

    with m.run() as datasaver:
        dataset = datasaver.dataset

    # test dataset structure function
    expected_structure = {
        'x': {
            'unit': 'cm',
            'label': 'my_x_param',
            'values': []
        },
        'y': {
            'unit': '',
            'label': '',
            'values': []
        }
        # note that parameter 'foo' is not expected to be included
        # because it's a "standalone" parameter
    }
    for n in range(N):
        expected_structure.update({
            f'z_{n}': {
                'unit': '',
                'label': '',
                'axes': ['x', 'y'],
                'values': []
            }
        })
    structure = get_ds_structure(dataset)
    assert structure == expected_structure
Ejemplo n.º 8
0
def dataset_with_shape(empty_db_path):
    """Fixture of a database file a shaped and an unshapeed dataset"""
    exp = load_or_create_experiment('get_runs_from_db', sample_name='qubit')
    m1 = qc.Measurement(exp=exp)

    m1.register_custom_parameter('x', unit='cm')
    m1.register_custom_parameter('y')
    for n in range(2):
        m1.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])

    shapes = (10, 5)
    m1.set_shapes({'z_0': shapes})

    with m1.run() as datasaver:
        for x in np.linspace(0, 1, shapes[0]):
            for y in np.linspace(4, 6, shapes[1]):
                datasaver.add_result(('x', x), ('y', y), ('z_0', x + y),
                                     ('z_1', x**2 + y))
        dataset = datasaver.dataset

    yield dataset

    dataset.conn.close()
    exp.conn.close()