Skip to content

Version RunDescriber, and 5->6 DB upgrade, also reorg run descriptions module structure #1577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d08578a
Make RunDescriber always newest
WilliamHPNielsen May 13, 2019
02e1170
Use the versioning for serialization
WilliamHPNielsen May 13, 2019
cfe885c
Include version number in serialized output
WilliamHPNielsen May 14, 2019
3fc94e9
Add missing newlines
WilliamHPNielsen May 14, 2019
530aae3
Add upgrade function for version 5 -> 6
WilliamHPNielsen May 14, 2019
b7ff0c4
Add comments about versions
WilliamHPNielsen May 14, 2019
edebe0e
Make CI produce version 5 fixtures
WilliamHPNielsen May 14, 2019
190cada
Bump version number in test
WilliamHPNielsen May 15, 2019
91746e0
Make RunDescriber read unversioned JSON too
WilliamHPNielsen May 15, 2019
a56786c
Update a fix function from using now-obsolete attr
WilliamHPNielsen May 15, 2019
eb2e651
Remove missing imports
WilliamHPNielsen May 15, 2019
3cea76b
Fix broken call signature of to_yaml
WilliamHPNielsen May 16, 2019
8bf5e45
Substitute accidentally added import from sqlite_base with proper one
astafan8 May 27, 2019
559f37e
Add basic folder structure
WilliamHPNielsen May 21, 2019
673bbaa
Move files into new folder structure
WilliamHPNielsen May 21, 2019
6ed098d
Split out old version and converters
WilliamHPNielsen May 21, 2019
ea8f5d6
Restructure serialization of RunDescriber
WilliamHPNielsen May 23, 2019
61d0bec
Remove two unused imports
WilliamHPNielsen May 24, 2019
e3f3a60
Merge branch 'master' into dev/reorg_runs_descriptions
astafan8 May 27, 2019
84d27de
Remove unused new import
astafan8 May 27, 2019
31306c6
Get rid of accidental import from sqlite_base
astafan8 May 27, 2019
e21e306
Remove unused imports, and use public imports from qcodes module
astafan8 May 28, 2019
8b23fbc
Use public imports from qcodes module
astafan8 May 28, 2019
7e853f0
Make a sphinx reference to versioning module
astafan8 May 28, 2019
dedbeff
Fix reference to sqlite module in docstring
astafan8 May 28, 2019
55367f1
Minor whitespace formatting fixes
astafan8 May 28, 2019
1e572b6
Add more description to module docstring, and function docstrings
astafan8 May 28, 2019
3429d57
Use public imports from qcodes in example notebooks
astafan8 May 28, 2019
cb317c2
Use public imports from qcodes, make explicit cells for them
astafan8 May 28, 2019
855751c
Use load_by_id from qcodes, not from plotting
astafan8 May 28, 2019
d6df091
Add RunDescriber version log to converters.py
astafan8 May 28, 2019
1abce13
Add clarity to test's name and docstring
astafan8 May 28, 2019
aaf7051
Make RunDescriber.serialize private (in all versions)
astafan8 Jun 2, 2019
c57deb4
Make RunDescriber.deserialize private (in all versions)
astafan8 Jun 3, 2019
e3ffa59
Note usage of RunDescriber _de/_serialize methods in their docstrings
astafan8 Jun 3, 2019
ea42f23
Make serialize of Interdependencies_ private
astafan8 Jun 3, 2019
2774597
Make deserialize of Interdependencies_ private
astafan8 Jun 3, 2019
ef3e6ed
Make serialize of Interdependencies private
astafan8 Jun 3, 2019
4135f5b
Make deserialize of Interdependencies private
astafan8 Jun 3, 2019
d928df2
Make serialize of ParamSpec and ParamSpecBase private
astafan8 Jun 3, 2019
3500858
Make deserialize of ParamSpec and ParamSpecBase private
astafan8 Jun 3, 2019
eae20ba
Rename RunDescriber._serialize to _to_dict (all versions)
astafan8 Jun 3, 2019
c5a5344
Rename RunDescriber._deserialize to _from_dict (all versions)
astafan8 Jun 3, 2019
3b48cf2
Rename InterDependencies_ _serialize to _to_dict
astafan8 Jun 3, 2019
ec9f4d8
Rename InterDependencies_ _deserialize to _from_dict
astafan8 Jun 3, 2019
cea1799
Rename InterDependencies _serialize to _to_dict
astafan8 Jun 3, 2019
48c65a0
Rename InterDependencies _deserialize to _from_dict
astafan8 Jun 3, 2019
022faec
Rename ParamSpecBase/ParamSpec _serialize to _to_dict
astafan8 Jun 3, 2019
79e51c8
Rename ParamSpecBase/ParamSpec _deserialize to _from_dict
astafan8 Jun 3, 2019
bbd0fc9
Merge branch 'master' into dev/reorg_runs_descriptions
astafan8 Jun 3, 2019
c7df9a7
Remove serialize from names of tests in favor of to_dict
astafan8 Jun 3, 2019
952dd77
Remove serialize/deserialize from docstrings, favor dict conversion
astafan8 Jun 3, 2019
7a6c071
Rename test_descriptions.py tests for clarity
astafan8 Jun 3, 2019
3d9be27
Add _update_run_description that doesnt validate description string
astafan8 Jun 3, 2019
22e0bfc
Do not write version field in database fix for version 4a
astafan8 Jun 3, 2019
7938a55
Test run_description structure for fix_version_4a_run_description_bug
astafan8 Jun 3, 2019
cc8465b
Factor out run description fix from fix_version_4a_run_description_bug
astafan8 Jun 3, 2019
acfb5d5
Rename functions of serialization.py to be meaningful and consistent
astafan8 Jun 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ script:
python generate_version_3.py
python generate_version_4a.py
python generate_version_4.py
python generate_version_5.py
cd $TRAVIS_BUILD_DIR
pip uninstall -y qcodes
pip install .
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
python generate_version_3.py
python generate_version_4a.py
python generate_version_4.py
python generate_version_5.py
displayName: "Generate db fixtures"
condition: succeededOrFailed()
- script: |
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/DataSet/Dataset Context Manager.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
" load_or_create_experiment)\n",
"from qcodes.dataset.database import initialise_database\n",
"from qcodes.tests.instrument_mocks import DummyInstrument\n",
"from qcodes.dataset.param_spec import ParamSpec\n",
"from qcodes.dataset.descriptions.param_spec import ParamSpec\n",
"from qcodes.dataset.measurements import Measurement\n",
"from qcodes.dataset.plotting import plot_by_id\n",
"from qcodes.dataset.data_export import get_shaped_data_by_runid\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from qcodes.dataset.database import initialise_database\n",
"from qcodes.dataset.data_set import new_data_set, ParamSpec\n",
"from qcodes.dataset.data_set import new_data_set\n",
"from qcodes.dataset.descriptions.param_spec import ParamSpec\n",
"from qcodes.dataset.experiment_container import new_experiment\n",
"import logging\n",
"import warnings\n",
Expand Down
2 changes: 1 addition & 1 deletion qcodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
from qcodes.dataset.experiment_container import new_experiment, load_experiment, load_experiment_by_name, \
load_last_experiment, experiments, load_or_create_experiment
from qcodes.dataset.sqlite.settings import SQLiteSettings
from qcodes.dataset.param_spec import ParamSpec
from qcodes.dataset.descriptions.param_spec import ParamSpec
from qcodes.dataset.sqlite.database import initialise_database, \
initialise_or_create_database_at

Expand Down
34 changes: 15 additions & 19 deletions qcodes/dataset/data_set.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import functools
import json
from typing import (Any, Dict, List, Optional, Union, Sized, Callable, cast,
from typing import (Any, Dict, List, Optional, Union, Sized, Callable,
Sequence)
from threading import Thread
import time
Expand All @@ -11,7 +11,8 @@
import numpy
import pandas as pd

from qcodes.dataset.param_spec import ParamSpec, ParamSpecBase
from qcodes.dataset.descriptions.param_spec import ParamSpec, ParamSpecBase
import qcodes.dataset.descriptions.versioning.serialization as serial
from qcodes.dataset.sqlite.connection import atomic, atomic_transaction, \
transaction, make_connection_plus_from, ConnectionPlus
from qcodes.dataset.sqlite.queries import add_parameter, create_run, \
Expand All @@ -27,11 +28,12 @@
insert_many_values, insert_values, VALUE, one
from qcodes.dataset.sqlite.database import get_DB_location, connect
from qcodes.instrument.parameter import _BaseParameter
from qcodes.dataset.descriptions import RunDescriber
from qcodes.dataset.dependencies import (InterDependencies,
InterDependencies_,
old_to_new, new_to_old,
DependencyError)
from qcodes.dataset.descriptions.rundescriber import RunDescriber
from qcodes.dataset.descriptions.dependencies import (InterDependencies_,
DependencyError)
from qcodes.dataset.descriptions.versioning.v0 import InterDependencies
from qcodes.dataset.descriptions.versioning.converters import old_to_new, \
new_to_old
from qcodes.dataset.guids import generate_guid
from qcodes.utils.deprecate import deprecate
import qcodes.config
Expand Down Expand Up @@ -247,15 +249,7 @@ def __init__(self, path_to_db: str = None,
f"the database")
self._completed = completed(self.conn, self.run_id)
run_desc = self._get_run_description_from_db()
if run_desc._old_style_deps:
# TODO: what if the old run had invalid interdep.s?
old_idps: InterDependencies = cast(InterDependencies,
run_desc.interdeps)
self._interdeps = old_to_new(old_idps)
else:
new_idps: InterDependencies_ = cast(InterDependencies_,
run_desc.interdeps)
self._interdeps = new_idps
self._interdeps = run_desc.interdeps
self._metadata = get_metadata_from_run_id(self.conn, run_id)
self._started = self.run_timestamp_raw is not None

Expand Down Expand Up @@ -464,7 +458,7 @@ def _get_run_description_from_db(self) -> RunDescriber:
Look up the run_description from the database
"""
desc_str = get_run_description(self.conn, self.run_id)
return RunDescriber.from_json(desc_str)
return serial.read_json_to_current(desc_str)

def toggle_debug(self):
"""
Expand Down Expand Up @@ -590,8 +584,9 @@ def _perform_start_actions(self) -> None:
for spec in paramspecs:
add_parameter(self.conn, self.table_name, spec)

update_run_description(self.conn, self.run_id,
self.description.to_json())
desc_str = serial.make_json_for_storage(self.description)

update_run_description(self.conn, self.run_id, desc_str)

set_run_timestamp(self.conn, self.run_id)

Expand Down Expand Up @@ -901,6 +896,7 @@ def get_setpoints(self, param_name: str) -> Dict[str, List[List[Any]]]:
if param_name not in self.parameters:
raise ValueError('Unknown parameter, not in this DataSet')


if paramspec not in self._interdeps.dependencies.keys():
raise ValueError(f'Parameter {param_name} has no setpoints.')

Expand Down
2 changes: 1 addition & 1 deletion qcodes/dataset/database_extract_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from qcodes.dataset.dependencies import new_to_old
from qcodes.dataset.descriptions.versioning.converters import new_to_old
from qcodes.dataset.data_set import DataSet
from qcodes.dataset.experiment_container import load_or_create_experiment
from qcodes.dataset.sqlite.connection import atomic, ConnectionPlus
Expand Down
38 changes: 27 additions & 11 deletions qcodes/dataset/database_fix_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from tqdm import tqdm

from qcodes.dataset.descriptions import RunDescriber
from qcodes.dataset.dependencies import InterDependencies
import qcodes.dataset.descriptions.versioning.v0 as v0
import qcodes.dataset.descriptions.versioning.serialization as serial
from qcodes.dataset.sqlite.connection import ConnectionPlus, atomic, \
atomic_transaction
from qcodes.dataset.sqlite.db_upgrades import get_user_version
Expand All @@ -25,7 +25,7 @@ def fix_version_4a_run_description_bug(conn: ConnectionPlus) -> Dict[str, int]:
"""
Fix function to fix a bug where the RunDescriber accidentally wrote itself
to string using the (new) InterDependencies_ object instead of the (old)
InterDependencies object. After the first run, this function should be
InterDependencies object. After the first call, this function should be
idempotent.


Expand Down Expand Up @@ -55,18 +55,32 @@ def fix_version_4a_run_description_bug(conn: ConnectionPlus) -> Dict[str, int]:
runs_inspected = 0
runs_fixed = 0

old_style_keys = ['paramspecs']
new_style_keys = ['parameters', 'dependencies', 'inferences',
'standalones']

for run_id in pbar:

desc_str = get_run_description(conn, run_id)
desc_ser = json.loads(desc_str)
idps_ser = desc_ser['interdependencies']

if RunDescriber._is_description_old_style(idps_ser):
if list(idps_ser.keys()) == old_style_keys:
pass
else:
new_desc = RunDescriber.from_json(desc_str)
update_run_description(conn, run_id, new_desc.to_json())
elif list(idps_ser.keys()) == new_style_keys:
# we cheat a little here; we introduce a RunDescriber version
# number into a DB of schema version 4. That should be okay,
# since the only rule is that DBs of schema versions > 4
# MUST have a versioned RunDescriber,
desc_ser['version'] = 1
new_desc = serial.deserialize_to_current(desc_ser)
json_str = serial.make_json_in_version(new_desc, 0)
# the json_str has a "version" field with value 0
update_run_description(conn, run_id, json_str)
runs_fixed += 1
else:
raise RuntimeError(f'Invalid runs_description for run_id: '
f'{run_id}')

runs_inspected += 1

Expand Down Expand Up @@ -98,17 +112,19 @@ def fix_wrong_run_descriptions(conn: ConnectionPlus,
log.info('[*] Fixing run descriptions...')
for run_id in run_ids:
trusted_paramspecs = get_parameters(conn, run_id)
trusted_desc = RunDescriber(
interdeps=InterDependencies(*trusted_paramspecs))
trusted_desc = v0.RunDescriber(
v0.InterDependencies(*trusted_paramspecs))

actual_desc_str = select_one_where(conn, "runs",
"run_description",
"run_id", run_id)

if actual_desc_str == trusted_desc.to_json():
trusted_json = serial.make_json_in_version(trusted_desc, 0)

if actual_desc_str == trusted_json:
log.info(f'[+] Run id: {run_id} had an OK description')
else:
log.info(f'[-] Run id: {run_id} had a broken description. '
f'Description found: {actual_desc_str}')
update_run_description(conn, run_id, trusted_desc.to_json())
update_run_description(conn, run_id, trusted_json)
log.info(f' Run id: {run_id} has been updated.')
130 changes: 0 additions & 130 deletions qcodes/dataset/descriptions.py

This file was deleted.

8 changes: 8 additions & 0 deletions qcodes/dataset/descriptions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Module containing all objects used for the description of a run.

Since run descriptions are persisted to disk, we have a strong obligation to
ensure backwards compatibility. The code is organised such that everything at
this module's top level is the CURRENT version. Older objects and the functions
necessary to convert between different versions are found in .versioning
"""
Loading