def test_add_data_array(): exps = experiments() assert len(exps) == 1 exp = exps[0] assert exp.name == "test-experiment" assert exp.sample_name == "test-sample" assert exp.last_counter == 0 mydataset = new_data_set("test", specs=[ParamSpec("x", "numeric"), ParamSpec("y", "array")]) mydataset.mark_started() expected_x = [] expected_y = [] for x in range(100): expected_x.append([x]) y = np.random.random_sample(10) expected_y.append([y]) mydataset.add_result({"x": x, "y": y}) shadow_ds = make_shadow_dataset(mydataset) assert mydataset.get_data('x') == expected_x assert shadow_ds.get_data('x') == expected_x y_data = mydataset.get_data('y') np.testing.assert_allclose(y_data, expected_y) y_data = shadow_ds.get_data('y') np.testing.assert_allclose(y_data, expected_y)
def test_load_2dsoftsweep(): qc.config.core.db_location = DBPATH initialise_database() exp = load_or_create_experiment('2d_softsweep', sample_name='no sample') # define some test data x = np.linspace(0, 1., 5) y = np.linspace(0, 1., 5) xx, yy = np.meshgrid(x, y, indexing='ij') zz = np.random.rand(*xx.shape) # put data into a new dataset ds = new_data_set('2d_softsweep', specs=[ParamSpec('x', 'numeric', unit='A'), ParamSpec('y', 'numeric', unit='B'), ParamSpec('z', 'numeric', unit='C', depends_on=['x', 'y']), ], ) def get_next_result(): for x, y, z in zip(xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)): yield dict(x=x, y=y, z=z) results = get_next_result() for r in results: ds.add_result(r) ds.mark_complete() # retrieve data as data dict run_id = ds.run_id ddict = datadict_from_path_and_run_id(DBPATH, run_id) assert np.all(np.isclose(ddict.data_vals('z'), zz.reshape(-1), atol=1e-15)) assert np.all(np.isclose(ddict.data_vals('x'), xx.reshape(-1), atol=1e-15)) assert np.all(np.isclose(ddict.data_vals('y'), yy.reshape(-1), atol=1e-15))
def test_add_data_1d(experiment): exps = experiments() assert len(exps) == 1 exp = exps[0] assert exp.name == "test-experiment" assert exp.sample_name == "test-sample" assert exp.last_counter == 0 psx = ParamSpec("x", "numeric") psy = ParamSpec("y", "numeric", depends_on=['x']) mydataset = new_data_set("test-dataset", specs=[psx, psy]) expected_x = [] expected_y = [] for x in range(100): expected_x.append([x]) y = 3 * x + 10 expected_y.append([y]) mydataset.add_result({"x": x, "y": y}) assert mydataset.get_data('x') == expected_x assert mydataset.get_data('y') == expected_y with pytest.raises(ValueError): mydataset.add_result({'y': 500}) assert mydataset.completed is False mydataset.mark_complete() assert mydataset.completed is True with pytest.raises(ValueError): mydataset.add_result({'y': 500}) with pytest.raises(CompletedError): mydataset.add_result({'x': 5})
def test_add_paramspec_one_by_one(dataset): exps = experiments() assert len(exps) == 1 exp = exps[0] assert exp.name == "test-experiment" assert exp.sample_name == "test-sample" assert exp.last_counter == 1 parameters = [ParamSpec("a", "NUMERIC"), ParamSpec("b", "NUMERIC", key="value", number=1), ParamSpec("c", "array")] for parameter in parameters: dataset.add_parameter(parameter) shadow_ds = make_shadow_dataset(dataset) paramspecs = shadow_ds.paramspecs expected_keys = ['a', 'b', 'c'] keys = sorted(list(paramspecs.keys())) assert keys == expected_keys for expected_param_name in expected_keys: ps = paramspecs[expected_param_name] assert ps.name == expected_param_name assert paramspecs == dataset.paramspecs # Test that is not possible to add the same parameter again to the dataset with pytest.raises(ValueError, match=f'Duplicate parameter name: ' f'{parameters[0].name}'): dataset.add_parameter(parameters[0]) assert len(dataset.paramspecs.keys()) == 3 assert len(shadow_ds.paramspecs.keys()) == 3
def test_nest(): """ Test the simple 1D nesting functionality. """ a = ParamSpec("a", paramtype="numeric") b = ParamSpec("b", paramtype="numeric") table_a = ParamTable([a]) table_b = ParamTable([b]) # This represents a 1D sweep such as: # nest(sweep(a, [0, 1, 2]), b) # that is, sweep a and measure b at each set point table_nest = table_a.nest(table_b) table_nest.resolve_dependencies() # Extract specs from the table table_specs = table_nest.param_specs assert len(table_specs) == 2 # The specs extracted should have the correct dependencies assert table_specs[0].name == 'a' assert table_specs[0].depends_on == '' assert table_specs[1].name == 'b' assert table_specs[1].depends_on == 'a' # The original specs should not be touched assert b.depends_on == ''
def test_adding_too_many_results(experiment): """ This test really tests the "chunking" functionality of the insert_many_values function of the sqlite_base module """ dataset = new_data_set("test_adding_too_many_results") xparam = ParamSpec("x", "numeric", label="x parameter", unit='V') yparam = ParamSpec("y", 'numeric', label='y parameter', unit='Hz', depends_on=[xparam]) dataset.add_parameter(xparam) dataset.add_parameter(yparam) n_max = qc.SQLiteSettings.limits['MAX_VARIABLE_NUMBER'] vals = np.linspace(0, 1, int(n_max/2)+2) results = [{'x': val} for val in vals] dataset.add_results(results) vals = np.linspace(0, 1, int(n_max/2)+1) results = [{'x': val, 'y': val} for val in vals] dataset.add_results(results) vals = np.linspace(0, 1, n_max*3) results = [{'x': val} for val in vals] dataset.add_results(results)
def test_double_nest(): """ Test the 2D nesting functionality """ a = ParamSpec("a", paramtype="numeric") b = ParamSpec("b", paramtype="numeric") c = ParamSpec("c", paramtype="numeric") table_a = ParamTable([a]) table_b = ParamTable([b]) table_c = ParamTable([c]) # A 2D sweep # table_nest = table_a.nest(table_b.nest(table_c)) table_nest = table_a.nest(table_b).nest(table_c) table_nest.resolve_dependencies() # Extract specs from the table table_specs = table_nest.param_specs table_specs = sorted(table_specs, key=lambda v: v.name) assert len(table_specs) == 3 # The specs extracted should have the correct dependencies assert table_specs[0].name == 'a' assert table_specs[0].depends_on == '' assert table_specs[1].name == 'b' assert table_specs[1].depends_on == '' assert table_specs[2].name == 'c' assert table_specs[2].depends_on == 'a, b' # The original specs should not be touched assert a.depends_on == '' assert b.depends_on == '' assert c.depends_on == ''
def test_nest_chain(): """ We test the following in pseudo-code for a in [0, 1, 2]: b() c() Both 'b' and 'c' depend on 'a' """ a = ParamSpec("a", paramtype="numeric") b = ParamSpec("b", paramtype="numeric") c = ParamSpec("c", paramtype="numeric") table_a = ParamTable([a]) table_b = ParamTable([b]) table_c = ParamTable([c]) table_result = table_a.nest(table_b.chain(table_c)) table_result.resolve_dependencies() # Extract specs from the table table_specs = table_result.param_specs assert len(table_specs) == 3 assert table_specs[0].name == 'a' assert table_specs[0].depends_on == '' assert table_specs[1].name == 'b' assert table_specs[1].depends_on == 'a' assert table_specs[2].name == 'c' assert table_specs[2].depends_on == 'a'
def test_add_paramspec(dataset): exps = experiments() assert len(exps) == 1 exp = exps[0] assert exp.name == "test-experiment" assert exp.sample_name == "test-sample" assert exp.last_counter == 1 parameter_a = ParamSpec("a_param", "NUMERIC") parameter_b = ParamSpec("b_param", "NUMERIC", key="value", number=1) parameter_c = ParamSpec("c_param", "array", inferred_from=[parameter_a, parameter_b]) dataset.add_parameters([parameter_a, parameter_b, parameter_c]) # Now retrieve the paramspecs paramspecs = dataset.paramspecs expected_keys = ['a_param', 'b_param', 'c_param'] keys = sorted(list(paramspecs.keys())) assert keys == expected_keys for expected_param_name in expected_keys: ps = paramspecs[expected_param_name] assert ps.name == expected_param_name assert paramspecs['c_param'].inferred_from == 'a_param, b_param'
def test_add_paramspec_one_by_one(dataset): exps = experiments() assert len(exps) == 1 exp = exps[0] assert exp.name == "test-experiment" assert exp.sample_name == "test-sample" assert exp.last_counter == 1 parameters = [ ParamSpec("a", "NUMERIC"), ParamSpec("b", "NUMERIC", key="value", number=1), ParamSpec("c", "array") ] for parameter in parameters: dataset.add_parameter(parameter) paramspecs = dataset.paramspecs expected_keys = ['a', 'b', 'c'] keys = sorted(list(paramspecs.keys())) assert keys == expected_keys for expected_param_name in expected_keys: ps = paramspecs[expected_param_name] assert ps.name == expected_param_name with pytest.raises(ValueError): dataset.add_parameter(parameters[0]) assert len(dataset.paramspecs.keys()) == 3
def test_modify_result(dataset): xparam = ParamSpec("x", "numeric", label="x parameter", unit='V') yparam = ParamSpec("y", 'numeric', label='y parameter', unit='Hz', depends_on=[xparam]) zparam = ParamSpec("z", 'array', label='z parameter', unit='sqrt(Hz)', depends_on=[xparam]) dataset.add_parameter(xparam) dataset.add_parameter(yparam) dataset.add_parameter(zparam) xdata = 0 ydata = 1 zdata = np.linspace(0, 1, 100) dataset.add_result({'x': 0, 'y': 1, 'z': zdata}) shadow_ds = make_shadow_dataset(dataset) try: assert dataset.get_data('x')[0][0] == xdata assert dataset.get_data('y')[0][0] == ydata assert (dataset.get_data('z')[0][0] == zdata).all() assert shadow_ds.get_data('x')[0][0] == xdata assert shadow_ds.get_data('y')[0][0] == ydata assert (shadow_ds.get_data('z')[0][0] == zdata).all() with pytest.raises(ValueError): pytest.deprecated_call(dataset.modify_result, 0, {' x': 1}) xdata = 1 ydata = 12 zdata = np.linspace(0, 1, 99) pytest.deprecated_call(dataset.modify_result, 0, {'x': xdata}) assert dataset.get_data('x')[0][0] == xdata assert shadow_ds.get_data('x')[0][0] == xdata pytest.deprecated_call(dataset.modify_result, 0, {'y': ydata}) assert dataset.get_data('y')[0][0] == ydata assert shadow_ds.get_data('y')[0][0] == ydata pytest.deprecated_call(dataset.modify_result, 0, {'z': zdata}) assert (dataset.get_data('z')[0][0] == zdata).all() assert (shadow_ds.get_data('z')[0][0] == zdata).all() dataset.mark_complete() with pytest.raises(CompletedError): pytest.deprecated_call(dataset.modify_result, 0, {'x': 2}) finally: shadow_ds.conn.close()
def test_update_qcloader(qtbot): qc.config.core.db_location = DBPATH initialise_database() exp = load_or_create_experiment('2d_softsweep', sample_name='no sample') # define test data x = np.linspace(0, 1., 5) y = np.linspace(0, 1., 5) xx, yy = np.meshgrid(x, y, indexing='ij') zz = np.random.rand(*xx.shape) def get_2dsoftsweep_results(): for x, y, z in zip(xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)): yield dict(x=x, y=y, z=z) # create data set _ds = new_data_set( '2d_softsweep', exp_id=exp.exp_id, specs=[ ParamSpec('x', 'numeric', unit='A'), ParamSpec('y', 'numeric', unit='B'), ParamSpec('z', 'numeric', unit='C', depends_on=['x', 'y']), ], ) run_id = _ds.run_id results = get_2dsoftsweep_results() # setting up the flowchart nodes, fc = make_sequential_flowchart([QCodesDSLoader]) loader = nodes[0] loader.pathAndId = DBPATH, run_id def check(): nresults = _ds.number_of_results loader.update() ddict = fc.output()['dataOut'] z_in = zz.reshape(-1)[:nresults] z_out = ddict.data_vals('z') if z_out is not None: assert z_in.size == z_out.size assert np.allclose(z_in, z_out, atol=1e-15) # insert data in small chunks, and check while True: try: ninsertions = np.random.randint(0, 5) for n in range(ninsertions): _ds.add_result(next(results)) except StopIteration: _ds.mark_complete() break check() check()
def test_modify_results(dataset): xparam = ParamSpec("x", "numeric") dataset.add_parameter(xparam) dataset.add_result({'x': 0}) dataset.add_result({'x': 1}) pytest.deprecated_call(dataset.modify_results, 0, [{'x': [10]}]) assert [[10], [1]] == dataset.get_data(xparam) pytest.deprecated_call(dataset.modify_results, 1, [{'x': [14]}]) assert [[10], [14]] == dataset.get_data(xparam) with pytest.raises(RuntimeError, match='Rolling back due to unhandled exception'): # not sure calling `modify_results` like this is correct, anyway it # is difficult to find out what the call signature for multiple # results is supposed to look like... pytest.deprecated_call(dataset.modify_results, 0, [{ 'x': [5] }, { 'x': [6] }]) assert [[5], [6]] == dataset.get_data(xparam) pytest.xfail('modify_results does not seem to work for cases where ' 'multiple values of multiple parameters need to be changed. ' 'Anyway, the signature needs to be revisited, ' 'and consequently the correct behavior needs to be ' 'implemented and covered with tests.')
def resolve_dependencies(self) -> None: """ After creating sweep objects and param specs, resolve the dependencies. """ if self._dependencies_resolved: return param_spec_dict = { spec.name: i for i, spec in enumerate(self._param_specs) } for nest in self._nests: dependent_name = nest[-1] spec_index = param_spec_dict[dependent_name] spec = self._param_specs[spec_index] depends_on = deepcopy(spec._depends_on) depends_on.extend(nest[:-1]) new_spec = ParamSpec(spec.name, spec.type, spec.label, spec.unit, deepcopy(spec._inferred_from), depends_on) self._param_specs[spec_index] = new_spec self._dependencies_resolved = True
def _generate_tables(names_units: Iterable[Tuple]) -> List[ParamTable]: """ Generates ParamTables from a simple input list of tuples which describe the parameters. Args: names_units List of tuples with parameter names and units; optionally, 'paramtype' can be supplied that defines the way the parameter values are saved ('numeric' is a default). Example: [("gate", "V"), ("Isd", "A", "array")] Returns: A list of ParamTable with each table containing a single ParamSpec """ param_tables = [] for name_unit in names_units: param_spec_args = {"paramtype": "numeric", "label": name_unit[0]} param_spec_args.update({ key: value for key, value in zip( ["name", "unit", "paramtype", "label"], name_unit, ) }) param_tables.append(ParamTable([ParamSpec(**param_spec_args)])) return param_tables
def _make_param_spec_list(symbols_list, inferred_parameters, depends_on=None): param_spec_list = {} if depends_on is None: depends_on = [] inferred_or_not = [ it[0] in inferred_parameters.keys() for it in symbols_list ] sorted_symbols = sorted( symbols_list, key=lambda v: inferred_or_not[symbols_list.index(v)]) # We have sorted the symbols such that those that are not inferred # are encountered first in the loop for name, unit in sorted_symbols: param_spec_list[name] = ParamSpec( name=name, paramtype='numeric', unit=unit, depends_on=depends_on, inferred_from=[ param_spec_list[n] for n in inferred_parameters.get(name, []) ]) return list(param_spec_list.values())
def test_modify_result(experiment): dataset = new_data_set("test_modify_result") xparam = ParamSpec("x", "numeric", label="x parameter", unit='V') yparam = ParamSpec("y", 'numeric', label='y parameter', unit='Hz', depends_on=[xparam]) zparam = ParamSpec("z", 'array', label='z parameter', unit='sqrt(Hz)', depends_on=[xparam]) dataset.add_parameter(xparam) dataset.add_parameter(yparam) dataset.add_parameter(zparam) xdata = 0 ydata = 1 zdata = np.linspace(0, 1, 100) dataset.add_result({'x': 0, 'y': 1, 'z': zdata}) assert dataset.get_data('x')[0][0] == xdata assert dataset.get_data('y')[0][0] == ydata assert (dataset.get_data('z')[0][0] == zdata).all() with pytest.raises(ValueError): dataset.modify_result(0, {' x': 1}) xdata = 1 ydata = 12 zdata = np.linspace(0, 1, 99) dataset.modify_result(0, {'x': xdata}) assert dataset.get_data('x')[0][0] == xdata dataset.modify_result(0, {'y': ydata}) assert dataset.get_data('y')[0][0] == ydata dataset.modify_result(0, {'z': zdata}) assert (dataset.get_data('z')[0][0] == zdata).all() dataset.mark_complete() with pytest.raises(CompletedError): dataset.modify_result(0, {'x': 2})
def mk_tuple(name): param = Parameter(name, set_cmd=None, get_cmd=None) def getter(): return {name: param.get()} return param, getter, ParamTable([ParamSpec(name, "numeric")])
def test_numpy_nan(dataset): parameter_m = ParamSpec("m", "numeric") dataset.add_parameters([parameter_m]) data_dict = [{"m": value} for value in [0.0, np.nan, 1.0]] dataset.add_results(data_dict) retrieved = dataset.get_data("m") assert np.isnan(retrieved[1])
def test_missing_keys(dataset): """ Test that we can now have partial results with keys missing. This is for example handy when having an interleaved 1D and 2D sweep. """ x = ParamSpec("x", paramtype='numeric') y = ParamSpec("y", paramtype='numeric') a = ParamSpec("a", paramtype='numeric', depends_on=[x]) b = ParamSpec("b", paramtype='numeric', depends_on=[x, y]) dataset.add_parameter(x) dataset.add_parameter(y) dataset.add_parameter(a) dataset.add_parameter(b) dataset.mark_started() def fa(xv): return xv + 1 def fb(xv, yv): return xv + 2 - yv * 3 results = [] xvals = [1, 2, 3] yvals = [2, 3, 4] for xv in xvals: results.append({"x": xv, "a": fa(xv)}) for yv in yvals: results.append({"x": xv, "y": yv, "b": fb(xv, yv)}) dataset.add_results(results) assert dataset.get_values("x") == [[r["x"]] for r in results] assert dataset.get_values("y") == [[r["y"]] for r in results if "y" in r] assert dataset.get_values("a") == [[r["a"]] for r in results if "a" in r] assert dataset.get_values("b") == [[r["b"]] for r in results if "b" in r] assert dataset.get_setpoints("a")['x'] == [[xv] for xv in xvals] tmp = [list(t) for t in zip(*(itertools.product(xvals, yvals)))] expected_setpoints = [[[v] for v in vals] for vals in tmp] assert dataset.get_setpoints("b")['x'] == expected_setpoints[0] assert dataset.get_setpoints("b")['y'] == expected_setpoints[1]
def test_add_paramspec_one_by_one(dataset): exps = experiments() assert len(exps) == 1 exp = exps[0] assert exp.name == "test-experiment" assert exp.sample_name == "test-sample" assert exp.last_counter == 1 parameters = [ ParamSpec("a", "NUMERIC"), ParamSpec("b", "NUMERIC", key="value", number=1), ParamSpec("c", "array") ] for parameter in parameters: dataset.add_parameter(parameter) # test that we can not re-add any parameter already added once for param in parameters: with pytest.raises(ValueError, match=f'Duplicate parameter name: ' f'{param.name}'): dataset.add_parameter(param) dataset.mark_started() shadow_ds = make_shadow_dataset(dataset) paramspecs = shadow_ds.paramspecs expected_keys = ['a', 'b', 'c'] keys = sorted(list(paramspecs.keys())) assert keys == expected_keys for expected_param_name in expected_keys: ps = paramspecs[expected_param_name] assert ps.name == expected_param_name assert paramspecs == dataset.paramspecs # Test that is not possible to add any parameter to the dataset with pytest.raises(RuntimeError, match='Can not add parameters to a ' 'DataSet that has been started.'): dataset.add_parameter(parameters[0]) assert len(dataset.paramspecs.keys()) == 3 assert len(shadow_ds.paramspecs.keys()) == 3
def test_add_parameter_values(N, M): mydataset = new_data_set("test_add_parameter_values") xparam = ParamSpec('x', 'numeric') mydataset.add_parameter(xparam) x_results = [{'x': x} for x in range(N)] mydataset.add_results(x_results) if N != M: with pytest.raises(ValueError): mydataset.add_parameter_values(ParamSpec("y", "numeric"), [y for y in range(M)]) mydataset.add_parameter_values(ParamSpec("y", "numeric"), [y for y in range(N)]) mydataset.mark_complete()
class TestGetData: x = ParamSpec("x", paramtype='numeric') n_vals = 5 xvals = list(range(n_vals)) # this is the format of how data is returned by DataSet.get_data # which means "a list of table rows" xdata = [[x] for x in xvals] @pytest.fixture(autouse=True) def ds_with_vals(self, dataset): """ This fixture creates a DataSet with values that is to be used by all the tests in this class """ dataset.add_parameter(self.x) dataset.mark_started() for xv in self.xvals: dataset.add_result({self.x.name: xv}) return dataset @pytest.mark.parametrize( ("start", "end", "expected"), [ # test without start and end (None, None, xdata), # test for start only (0, None, xdata), (2, None, xdata[(2-1):]), (-2, None, xdata), (n_vals, None, xdata[(n_vals-1):]), (n_vals + 1, None, []), (n_vals + 2, None, []), # test for end only (None, 0, []), (None, 2, xdata[:2]), (None, -2, []), (None, n_vals, xdata), (None, n_vals + 1, xdata), (None, n_vals + 2, xdata), # test for start and end (0, 0, []), (1, 1, [xdata[1-1]]), (2, 1, []), (2, 0, []), (1, 0, []), (n_vals, n_vals, [xdata[n_vals-1]]), (n_vals, n_vals - 1, []), (2, 4, xdata[(2-1):4]), ], ) def test_get_data_with_start_and_end_args(self, ds_with_vals, start, end, expected): assert expected == ds_with_vals.get_data(self.x, start=start, end=end)
def mk_tuple(name): param = Parameter(name, set_cmd=None, get_cmd=None) def setter(value): param.set(value) return {name: value} return param, setter, ParamTable([ParamSpec(name, "numeric")])
def test_nest_chain_nest(): """ Test a sweep which is equivalent to for a in [0, 1, 2]: for b in [0, 1, 2]: c() for d in [0, 1, 2]: e() """ a = ParamSpec("a", paramtype="numeric") b = ParamSpec("b", paramtype="numeric") c = ParamSpec("c", paramtype="numeric") d = ParamSpec("d", paramtype="numeric") e = ParamSpec("e", paramtype="numeric") table_a = ParamTable([a]) table_b = ParamTable([b]) table_c = ParamTable([c]) table_d = ParamTable([d]) table_e = ParamTable([e]) table_result = table_a.nest( table_b.nest(table_c).chain(table_d.nest(table_e)) ) table_result.resolve_dependencies() table_specs = table_result.param_specs assert len(table_specs) == 5 assert table_specs[0].name == 'a' assert table_specs[0].depends_on == '' assert table_specs[1].name == 'b' assert table_specs[1].depends_on == '' assert table_specs[2].name == 'c' assert table_specs[2].depends_on == 'a, b' assert table_specs[3].name == 'd' assert table_specs[3].depends_on == '' assert table_specs[4].name == 'e' assert table_specs[4].depends_on == 'a, d'
def test_numpy_floats(dataset): """ Test that we can insert numpy floats in the data set """ float_param = ParamSpec('y', 'numeric') dataset.add_parameters([float_param]) numpy_floats = [np.float, np.float16, np.float32, np.float64] results = [{"y": tp(1.2)} for tp in numpy_floats] dataset.add_results(results) expected_result = [[tp(1.2)] for tp in numpy_floats] assert np.allclose(dataset.get_data("y"), expected_result, atol=1E-8)
def test_numpy_inf(dataset): """ Test that we can insert and retrieve numpy inf in the data set """ parameter_m = ParamSpec("m", "numeric") dataset.add_parameter(parameter_m) dataset.mark_started() data_dict = [{"m": value} for value in [-np.inf, np.inf]] dataset.add_results(data_dict) retrieved = dataset.get_data("m") assert np.isinf(retrieved).all()
def test_inferred_from(): """ Test the 2D nesting functionality whereby the measurement generates two parameters, the second being inferred from the first """ a = ParamSpec("a", paramtype="numeric") b = ParamSpec("b", paramtype="numeric") c = ParamSpec("c", paramtype="numeric") d = ParamSpec("d", paramtype="numeric", inferred_from='c') table_a = ParamTable([a]) table_b = ParamTable([b]) table_c = ParamTable([c, d]) table_nest = table_a.nest(table_b).nest(table_c) table_nest.resolve_dependencies() # Extract specs from the table table_specs = table_nest.param_specs table_specs = sorted(table_specs, key=lambda v: v.name) assert len(table_specs) == 4 # The specs extracted should have the correct dependencies assert table_specs[0].name == 'a' assert table_specs[0].depends_on == '' assert table_specs[1].name == 'b' assert table_specs[1].depends_on == '' assert table_specs[2].name == 'c' assert table_specs[2].depends_on == 'a, b' assert table_specs[3].name == 'd' assert table_specs[3].depends_on == 'a, b' assert table_specs[3].inferred_from == 'c' # The original specs should not be touched assert a.depends_on == '' assert b.depends_on == '' assert c.depends_on == ''
def create_dataset(self, dataset_name): self.data_set = exc.new_data_set(dataset_name, specs=[ ParamSpec('caled_field', 'numeric', unit='G'), ParamSpec('frequency', 'array', unit='Hz'), ParamSpec('magnitude', 'array', unit='dB'), ParamSpec('phase', 'array', unit='deg'), ParamSpec('temp', 'numeric', unit='K'), ParamSpec('set_power', 'numeric', unit='dB') ]) self.data_set.mark_started() return self.data_set
def benchmark_add_results_vs_MAX_VARIABLE_NUMBER(): filename = 'benchmark_add_results_vs_MAX_VARIABLE_NUMBER.png' if no_plots: return filename plt.figure() xr, yr = [], [] mvn = qc.SQLiteSettings.limits['MAX_VARIABLE_NUMBER'] for i in range(2, mvn, mvn // 50): ts = [] for j in range(3): qc.SQLiteSettings.limits['MAX_VARIABLE_NUMBER'] = i new_experiment("profile", "profile") data_set = new_data_set("stress_test_simple") t1 = ParamSpec('t', 'numeric', label='time', unit='s') x = ParamSpec('x', 'numeric', label='voltage', unit='v', depends_on=[t1]) data_set.add_parameter(t1) data_set.add_parameter(x) insertion_size = 400 * 600 t_values = np.linspace(-1, 1, insertion_size) results = [{"t": t, "x": 2 * t**2 + 1} for t in t_values] t1r = time.time() data_set.add_results(results) t = time.time() - t1r ts.append(t) xr.append(i) yr.append(mean(ts)) plt.plot(xr, yr) plt.ylabel('execution time of data_set.add_results(result)') plt.xlabel('MAX_VARIABLE_NUMBER') plt.savefig(filename) return filename