Skip to content

Commit

Permalink
Merge pull request #1926 from QCoDeS/deprecate/dataset_add_result
Browse files Browse the repository at this point in the history
Deprecate DataSet.add_result
  • Loading branch information
WilliamHPNielsen authored Feb 18, 2020
2 parents e92ac07 + 6e16814 commit 742a8e6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 61 deletions.
9 changes: 9 additions & 0 deletions docs/changes/0.12.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changelog for QCoDeS 0.12.0
===========================

The March 2020 release of QCoDeS


Deprecations:
-------------
* The `DataSet` method `add_result` is now deprecated in favour of the `add_results` method. (#1926)
2 changes: 1 addition & 1 deletion docs/changes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Changelogs
0.8.1 <0.8.1>
0.9.0 <0.9.0>
0.10.0 <0.10.0>

0.12.0 <0.12.0>
1 change: 1 addition & 0 deletions qcodes/dataset/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def mark_completed(self) -> None:
def mark_complete(self) -> None:
self.mark_completed()

@deprecate(alternative='add_results')
def add_result(self, results: Mapping[str, VALUE]) -> int:
"""
Add a logically single result to existing parameters
Expand Down
10 changes: 5 additions & 5 deletions qcodes/tests/dataset/test_database_creation_and_upgrading.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,12 @@ def test_update_existing_guids(caplog):
idps = InterDependencies_(standalones=(xparam,))
ds1.set_interdependencies(idps)
ds1.mark_started()
ds1.add_result({'x': 1})
ds1.add_results([{'x': 1}])

ds2 = new_data_set('ds_two')
ds2.set_interdependencies(idps)
ds2.mark_started()
ds2.add_result({'x': 2})
ds2.add_results([{'x': 2}])

guid_comps_1 = parse_guid(ds1.guid)
assert guid_comps_1['location'] == 0
Expand All @@ -587,19 +587,19 @@ def test_update_existing_guids(caplog):
ds3 = new_data_set('ds_three')
ds3.set_interdependencies(idps)
ds3.mark_started()
ds3.add_result({'x': 3})
ds3.add_results([{'x': 3}])

with location_and_station_set_to(old_loc, 0):
ds4 = new_data_set('ds_four')
ds4.set_interdependencies(idps)
ds4.mark_started()
ds4.add_result({'x': 4})
ds4.add_results([{'x': 4}])

with location_and_station_set_to(old_loc, old_ws):
ds5 = new_data_set('ds_five')
ds5.set_interdependencies(idps)
ds5.mark_started()
ds5.add_result({'x': 5})
ds5.add_results([{'x': 5}])

with location_and_station_set_to(new_loc, new_ws):

Expand Down
56 changes: 28 additions & 28 deletions qcodes/tests/dataset/test_database_extract_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def test_missing_runs_raises(two_empty_temp_db_connections, some_interdeps):
source_dataset.mark_started()

for val in range(10):
source_dataset.add_result({name: val
for name in some_interdeps[1].names})
source_dataset.add_results([{name: val
for name in some_interdeps[1].names}])
source_dataset.mark_completed()

source_path = path_to_dbfile(source_conn)
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_basic_extraction(two_empty_temp_db_connections, some_interdeps):
for value in range(10):
result = {ps.name: type_casters[ps.type](value)
for ps in some_interdeps[0].paramspecs}
source_dataset.add_result(result)
source_dataset.add_results([result])

source_dataset.add_metadata('goodness', 'fair')
source_dataset.add_metadata('test', True)
Expand Down Expand Up @@ -200,8 +200,8 @@ def test_correct_experiment_routing(two_empty_temp_db_connections,
source_dataset.mark_started()

for val in range(10):
source_dataset.add_result({name: val
for name in some_interdeps[1].names})
source_dataset.add_results([{name: val
for name in some_interdeps[1].names}])
source_dataset.mark_completed()

# make a new experiment with 1 run
Expand All @@ -215,7 +215,7 @@ def test_correct_experiment_routing(two_empty_temp_db_connections,
ds.mark_started()

for val in range(10):
ds.add_result({name: val for name in some_interdeps[1].names})
ds.add_results([{name: val for name in some_interdeps[1].names}])

ds.mark_completed()

Expand Down Expand Up @@ -297,8 +297,8 @@ def test_runs_from_different_experiments_raises(two_empty_temp_db_connections,
source_dataset.mark_started()

for val in range(10):
source_dataset.add_result({name: val
for name in some_interdeps[1].names})
source_dataset.add_results([{name: val
for name in some_interdeps[1].names}])
source_dataset.mark_completed()

# make 5 runs in second experiment
Expand All @@ -315,8 +315,8 @@ def test_runs_from_different_experiments_raises(two_empty_temp_db_connections,
source_dataset.mark_started()

for val in range(10):
source_dataset.add_result({name: val
for name in some_interdeps[1].names})
source_dataset.add_results([{name: val
for name in some_interdeps[1].names}])
source_dataset.mark_completed()

run_ids = exp_1_run_ids + exp_2_run_ids
Expand Down Expand Up @@ -367,25 +367,25 @@ def test_result_table_naming_and_run_id(two_empty_temp_db_connections,
source_ds_1_1.set_interdependencies(some_interdeps[1])

source_ds_1_1.mark_started()
source_ds_1_1.add_result({name: 0.0
for name in some_interdeps[1].names})
source_ds_1_1.add_results([{name: 0.0
for name in some_interdeps[1].names}])
source_ds_1_1.mark_completed()

source_exp2 = Experiment(conn=source_conn)
source_ds_2_1 = DataSet(conn=source_conn, exp_id=source_exp2.exp_id)
source_ds_2_1.set_interdependencies(some_interdeps[1])
source_ds_2_1.mark_started()
source_ds_2_1.add_result({name: 0.0
for name in some_interdeps[1].names})
source_ds_2_1.add_results([{name: 0.0
for name in some_interdeps[1].names}])
source_ds_2_1.mark_completed()
source_ds_2_2 = DataSet(conn=source_conn,
exp_id=source_exp2.exp_id,
name="customname")

source_ds_2_2.set_interdependencies(some_interdeps[1])
source_ds_2_2.mark_started()
source_ds_2_2.add_result({name: 0.0
for name in some_interdeps[1].names})
source_ds_2_2.add_results([{name: 0.0
for name in some_interdeps[1].names}])
source_ds_2_2.mark_completed()

extract_runs_into_db(source_path, target_path, source_ds_2_2.run_id)
Expand Down Expand Up @@ -421,7 +421,7 @@ def test_load_by_X_functions(two_empty_temp_db_connections,
for ds in (source_ds_1_1, source_ds_2_1, source_ds_2_2):
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({name: 0.0 for name in some_interdeps[1].names})
ds.add_results([{name: 0.0 for name in some_interdeps[1].names}])
ds.mark_completed()

extract_runs_into_db(source_path, target_path, source_ds_2_2.run_id)
Expand Down Expand Up @@ -481,7 +481,7 @@ def test_combine_runs(two_empty_temp_db_connections,
for ds in source_all_datasets:
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({name: 0.0 for name in some_interdeps[1].names})
ds.add_results([{name: 0.0 for name in some_interdeps[1].names}])
ds.mark_completed()

# now let's insert all datasets in random order
Expand Down Expand Up @@ -555,7 +555,7 @@ def test_copy_datasets_and_add_new(two_empty_temp_db_connections,
for ds in source_datasets:
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({name: 0.0 for name in some_interdeps[1].names})
ds.add_results([{name: 0.0 for name in some_interdeps[1].names}])
ds.mark_completed()

# now let's insert only some of the datasets
Expand Down Expand Up @@ -591,7 +591,7 @@ def test_copy_datasets_and_add_new(two_empty_temp_db_connections,
for ds in new_datasets:
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({name: 0.0 for name in some_interdeps[1].names})
ds.add_results([{name: 0.0 for name in some_interdeps[1].names}])
ds.mark_completed()

expected_run_ids = [4, 5, 6]
Expand Down Expand Up @@ -649,8 +649,8 @@ def test_old_versions_not_touched(two_empty_temp_db_connections,
source_ds.set_interdependencies(some_interdeps[1])

source_ds.mark_started()
source_ds.add_result({name: 0.0
for name in some_interdeps[1].names})
source_ds.add_results([{name: 0.0
for name in some_interdeps[1].names}])
source_ds.mark_completed()

with raise_if_file_changed(fixturepath):
Expand Down Expand Up @@ -691,8 +691,8 @@ def test_experiments_with_NULL_sample_name(two_empty_temp_db_connections,
source_dataset.mark_started()

for val in range(10):
source_dataset.add_result({name: val
for name in some_interdeps[1].names})
source_dataset.add_results([{name: val
for name in some_interdeps[1].names}])
source_dataset.mark_completed()

sql = """
Expand Down Expand Up @@ -772,8 +772,8 @@ def test_atomicity(two_empty_temp_db_connections, some_interdeps):
for ds in (source_ds_1, source_ds_2):
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({name: 2.1
for name in some_interdeps[1].names})
ds.add_results([{name: 2.1
for name in some_interdeps[1].names}])

# importantly, source_ds_2 is NOT marked as completed
source_ds_1.mark_completed()
Expand Down Expand Up @@ -819,8 +819,8 @@ def test_column_mismatch(two_empty_temp_db_connections, some_interdeps, inst):
source_ds.set_interdependencies(some_interdeps[1])

source_ds.mark_started()
source_ds.add_result({name: 2.1
for name in some_interdeps[1].names})
source_ds.add_results([{name: 2.1
for name in some_interdeps[1].names}])
source_ds.mark_completed()

extract_runs_into_db(source_path, target_path, 1)
Expand Down
23 changes: 8 additions & 15 deletions qcodes/tests/dataset/test_dataset_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def test_dataset_states():
match = ('This DataSet has not been marked as started. '
'Please mark the DataSet as started before '
'adding results to it.')
with pytest.raises(RuntimeError, match=match):
ds.add_result({'x': 1})
with pytest.raises(RuntimeError, match=match):
ds.add_results([{'x': 1}])

Expand All @@ -145,7 +143,6 @@ def test_dataset_states():
with pytest.raises(RuntimeError, match=match):
ds.set_interdependencies(idps)

ds.add_result({parameter.name: 1})
ds.add_results([{parameter.name: 1}])

ds.mark_completed()
Expand All @@ -163,8 +160,7 @@ def test_dataset_states():

match = ('This DataSet is complete, no further '
'results can be added to it.')
with pytest.raises(CompletedError, match=match):
ds.add_result({parameter.name: 1})

with pytest.raises(CompletedError, match=match):
ds.add_results([{parameter.name: 1}])

Expand Down Expand Up @@ -362,7 +358,7 @@ def test_add_data_1d():
expected_x.append([x])
y = 3 * x + 10
expected_y.append([y])
mydataset.add_result({"x": x, "y": y})
mydataset.add_results([{"x": x, "y": y}])

shadow_ds = make_shadow_dataset(mydataset)

Expand All @@ -371,18 +367,15 @@ def test_add_data_1d():
assert shadow_ds.get_data('x') == expected_x
assert shadow_ds.get_data('y') == expected_y

with pytest.raises(ValueError):
mydataset.add_result({'y': 500})

assert mydataset.completed is False
mydataset.mark_completed()
assert mydataset.completed is True

with pytest.raises(CompletedError):
mydataset.add_result({'y': 500})
mydataset.add_results([{'y': 500}])

with pytest.raises(CompletedError):
mydataset.add_result({'x': 5})
mydataset.add_results([{'x': 5}])


@pytest.mark.usefixtures("experiment")
Expand All @@ -407,7 +400,7 @@ def test_add_data_array():
expected_x.append([x])
y = np.random.random_sample(10)
expected_y.append([y])
mydataset.add_result({"x": x, "y": y})
mydataset.add_results([{"x": x, "y": y}])

shadow_ds = make_shadow_dataset(mydataset)

Expand Down Expand Up @@ -671,7 +664,7 @@ def test_the_same_dataset_as(some_interdeps, experiment):
ds = DataSet()
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({'ps1': 1, 'ps2': 2})
ds.add_results([{'ps1': 1, 'ps2': 2}])

same_ds_from_load = DataSet(run_id=ds.run_id)
assert ds.the_same_dataset_as(same_ds_from_load)
Expand Down Expand Up @@ -724,7 +717,7 @@ def test_parent_dataset_links(some_interdeps):
with pytest.raises(RuntimeError, match=match):
ds.parent_dataset_links = links

ds.add_result({'ps1': 1, 'ps2': 2})
ds.add_results([{'ps1': 1, 'ps2': 2}])
run_id = ds.run_id

ds_loaded = DataSet(run_id=run_id)
Expand All @@ -750,7 +743,7 @@ def ds_with_vals(self, dataset):
dataset.set_interdependencies(idps)
dataset.mark_started()
for xv in self.xvals:
dataset.add_result({self.x.name: xv})
dataset.add_results([{self.x.name: xv}])

return dataset

Expand Down
16 changes: 8 additions & 8 deletions qcodes/tests/dataset/test_dataset_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ def test_get_data_by_id_order(dataset):

dataset.mark_started()

dataset.add_result({'depAB': 12,
'indep2': 2,
'indep1': 1})
dataset.add_results([{'depAB': 12,
'indep2': 2,
'indep1': 1}])

dataset.add_result({'depBA': 21,
'indep2': 2,
'indep1': 1})
dataset.add_results([{'depBA': 21,
'indep2': 2,
'indep1': 1}])
dataset.mark_completed()

data = get_data_by_id(dataset.run_id)
Expand All @@ -220,7 +220,7 @@ def test_load_by_guid(some_interdeps):
ds = DataSet()
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({'ps1': 1, 'ps2': 2})
ds.add_results([{'ps1': 1, 'ps2': 2}])

loaded_ds = load_by_guid(ds.guid)

Expand All @@ -233,7 +233,7 @@ def create_ds_with_exp_id(exp_id):
ds = DataSet(exp_id=exp_id)
ds.set_interdependencies(some_interdeps[1])
ds.mark_started()
ds.add_result({'ps1': 1, 'ps2': 2})
ds.add_results([{'ps1': 1, 'ps2': 2}])
return ds
# create 3 experiments that mix two experiment names and two sample names
exp_names = ["te1", "te2", "te1"]
Expand Down
4 changes: 2 additions & 2 deletions qcodes/tests/dataset/test_string_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_string_via_dataset(experiment):
test_set.set_interdependencies(idps)
test_set.mark_started()

test_set.add_result({"p": "some text"})
test_set.add_results([{"p": "some text"}])

test_set.mark_completed()

Expand Down Expand Up @@ -129,7 +129,7 @@ def test_string_saved_and_loaded_as_numeric_via_dataset(experiment):
test_set.set_interdependencies(idps)
test_set.mark_started()

test_set.add_result({"p": 'some text'})
test_set.add_results([{"p": 'some text'}])

test_set.mark_completed()

Expand Down
Loading

0 comments on commit 742a8e6

Please sign in to comment.