-
Notifications
You must be signed in to change notification settings - Fork 320
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
Enhance run table query performance with indices #1277
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
154f07b
Enhance run table query performance with indices
geoffroth 672ba4c
Add indices as db upgrade 1->2
geoffroth f3fbe58
return None rather than bool
geoffroth 51ecf92
Merge branch 'master' into fix/run_indices
jenshnielsen 9a33f79
Merge branch 'master' into fix/run_indices
WilliamHPNielsen 061abba
Add version 1 hash
WilliamHPNielsen 45466c9
Add version description comment
WilliamHPNielsen da6ef10
Refactor the checkout
WilliamHPNielsen 1e9e7e9
Update README to reflect refactor
WilliamHPNielsen d855760
Add script for version 1 .db-file generation
WilliamHPNielsen 4df2a54
Correct out-of-date docstring
WilliamHPNielsen 121997a
Add a log message to 1 -> 2 upgrader
WilliamHPNielsen 9f824a3
PEP8 some SQL queries
WilliamHPNielsen 10d26c2
Add test for version 1 -> 2 db upgrade
WilliamHPNielsen 756c89f
Merge branch 'master' into fix/run_indices
WilliamHPNielsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
qcodes/tests/dataset/legacy_DB_generation/generate_version_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generate version 1 database files for qcodes' test suite to consume | ||
|
||
import os | ||
|
||
# NB: it's important that we do not import anything from qcodes before we | ||
# do the git magic (which we do below), hence the relative import here | ||
import utils as utils | ||
|
||
|
||
fixturepath = os.sep.join(os.path.realpath(__file__).split(os.sep)[:-2]) | ||
fixturepath = os.path.join(fixturepath, 'fixtures', 'db_files') | ||
|
||
|
||
def generate_empty_DB_file(): | ||
""" | ||
Generate the bare minimal DB file with no runs | ||
""" | ||
|
||
import qcodes.dataset.sqlite_base as sqlite_base | ||
|
||
v0fixturepath = os.path.join(fixturepath, 'version1') | ||
os.makedirs(v0fixturepath, exist_ok=True) | ||
path = os.path.join(v0fixturepath, 'empty.db') | ||
|
||
if os.path.exists(path): | ||
os.remove(path) | ||
|
||
sqlite_base.connect(path) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
gens = (generate_empty_DB_file,) | ||
|
||
# pylint: disable=E1101 | ||
utils.checkout_to_old_version_and_run_generators(version=1, gens=gens) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
# General utilities for the database generation and loading scheme | ||
from typing import Dict, List | ||
from typing import Dict, List, Tuple | ||
from contextlib import contextmanager | ||
import os | ||
|
||
GIT_HASHES: Dict[int, str] = {0: '78d42620fc245a975b5a615ed5e33061baac7846'} | ||
from git import Repo | ||
|
||
# A brief overview of what each version introduces: | ||
# | ||
# Version 0: the original table schema, runs, experiments, layouts, | ||
# dependencies, result-tables | ||
# | ||
# Version 1: a GUID column is added to the runs table | ||
|
||
|
||
GIT_HASHES: Dict[int, str] = {0: '78d42620fc245a975b5a615ed5e33061baac7846', | ||
1: '056d59627e22fa3ca7aad4c265e9897c343f79cf'} | ||
|
||
DB_NAMES: Dict[int, List[str]] = {0: ['']} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nein. Should have been removed. |
||
|
||
gitrepopath = os.sep.join(os.path.realpath(__file__).split(os.sep)[:-5]) | ||
repo = Repo(gitrepopath) | ||
|
||
|
||
@contextmanager | ||
def leave_untouched(repo): | ||
|
@@ -32,3 +47,31 @@ def leave_untouched(repo): | |
repo.git.reset('--hard', current_commit) | ||
if not was_detached: | ||
repo.git.checkout(current_branch) | ||
|
||
|
||
def checkout_to_old_version_and_run_generators(version: int, | ||
gens: Tuple) -> None: | ||
""" | ||
Check out the repo to an older version and run the generating functions | ||
supplied. | ||
""" | ||
|
||
with leave_untouched(repo): | ||
|
||
repo.git.checkout(GIT_HASHES[version]) | ||
|
||
# If QCoDeS is not installed in editable mode, it makes no difference | ||
# to do our git magic, since the import will be from site-packages in | ||
# the environment folder, and not from the git-managed folder | ||
import qcodes | ||
qcpath = os.sep.join(qcodes.__file__.split(os.sep)[:-2]) | ||
|
||
# Windows and paths... There can be random un-capitalizations | ||
if qcpath.lower() != gitrepopath.lower(): | ||
raise ValueError('QCoDeS does not seem to be installed in editable' | ||
' mode, can not proceed. To use this script, ' | ||
'uninstall QCoDeS and reinstall it with pip ' | ||
'install -e <path-to-qcodes-folder>') | ||
|
||
for generator in gens: | ||
generator() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is description of version 2 missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will add that when we need it, i.e. when we have version 3 on the table.