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