Skip to content
Snippets Groups Projects
Commit 0f07bb6f authored by Valentin Bruch's avatar Valentin Bruch
Browse files

bug fixes, documentation in data_management

parent e5ac8e89
No related branches found
No related tags found
No related merge requests found
""" """
Data management for FRTRG data based on pytables Kondo FRTRG, data management
Idea: This file contains functions and classes to manage data generated using the
* Data + Metadata are stored in H5F files. kondo module.
* A single file can be any logical unit. An arbitrary number of files can be created.
* Metadata are partially stored in a database for simple access General concepts:
* a file "filename.lock" is created before writing to a file. * All metadata are stored in an SQL database.
* Floquet matrices are stored in H5F files.
Copyright 2022 Valentin Bruch * Each H5F file can contain multiple data points. Data points can be added to
H5F files.
* Each H5F file contains a table of metadata for the data points stored in
this file.
* Data points are identified in H5F files by a hash generated from their full
Floquet matrices at the end of the RG flow.
* The SQL database stores the directory, filename, and hash where the Floquet
matrices are stored.
Implementation:
* pandas for accessing the SQL database and managing the full table of metadata
* pytables for H5F files
* a file "filename.lock" is temporarily created when writing to a H5F file.
Copyright 2022 Valentin Bruch <valentin.bruch@rwth-aachen.de>
License: MIT License: MIT
""" """
...@@ -23,11 +37,24 @@ import random ...@@ -23,11 +37,24 @@ import random
import settings import settings
import warnings import warnings
# We use hashs as identifiers for data points in H5F files. These hashs are
# often not valid python names, which causes a warning. We ignore this warning.
warnings.simplefilter("ignore", tb.NaturalNameWarning) warnings.simplefilter("ignore", tb.NaturalNameWarning)
def random_string(length : int):
_to_char = lambda x: chr(x + 48 if x < 10 else x + 55 if x < 36 else x + 61) """
random_string = lambda n: ''.join(_to_char(random.randint(0,61)) for i in range(n)) Generate random strings of alphanumerical characters with given length.
"""
res = ""
for _ in range(length):
x = random.randint(0, 61)
if x < 10:
res += chr(x + 48)
elif x < 36:
res += chr(x + 55)
else:
res += chr(x + 61)
return res
def replace_all(string:str, replacements:dict): def replace_all(string:str, replacements:dict):
...@@ -69,6 +96,7 @@ class KondoExport: ...@@ -69,6 +96,7 @@ class KondoExport:
""" """
dictionary of metadata dictionary of metadata
""" """
# Determine method
if self.kondo.unitary_transformation: if self.kondo.unitary_transformation:
if self.kondo.compact == 2: if self.kondo.compact == 2:
method = 'J-compact-2' method = 'J-compact-2'
...@@ -78,27 +106,29 @@ class KondoExport: ...@@ -78,27 +106,29 @@ class KondoExport:
method = 'J' method = 'J'
else: else:
method = 'mu' method = 'mu'
# Collect solver flags
solver_flags = 0 solver_flags = 0
try: try:
if self.kondo.simplified_initial_conditions: if self.kondo.simplified_initial_conditions:
solver_flags |= DataManager.SOLVER_FLAGS["simplified_initial_conditions"] solver_flags |= DataManager.SOLVER_FLAGS["simplified_initial_conditions"]
except AttributeError: except AttributeError:
pass pass
for (key, value) in kondo.settings.items(): for (key, value) in self.kondo.global_settings.items():
if value: if value:
try: try:
solver_flags |= DataManager.SOLVER_FLAGS[key.lower()] solver_flags |= DataManager.SOLVER_FLAGS[key.lower()]
except KeyError: except KeyError:
pass pass
version = kondo.settings["VERSION"] version = self.kondo.global_settings["VERSION"]
return dict( return dict(
hash = self.hash, hash = self.hash,
omega = self.kondo.omega, omega = self.kondo.omega,
energy = self.kondo.energy, energy = self.kondo.energy,
version_major = version[0], version_major = version[0],
version_minor = version[1], version_minor = version[1],
lazy_inverse_factor = kondo.settings["LAZY_INVERSE_FACTOR"] lazy_inverse_factor = self.kondo.global_settings["LAZY_INVERSE_FACTOR"],
git_commit_count = version[2], git_commit_count = version[2],
git_commit_id = version[3], git_commit_id = version[3],
method = method, method = method,
...@@ -121,7 +151,12 @@ class KondoExport: ...@@ -121,7 +151,12 @@ class KondoExport:
""" """
dictionary of main results: DC current, DC conductance, AC current (absolute value and phase) dictionary of main results: DC current, DC conductance, AC current (absolute value and phase)
""" """
results = dict(dc_current=np.nan, dc_conductance=np.nan, ac_current_abs=np.nan, ac_current_phase=np.nan) results = dict(
dc_current = np.nan,
dc_conductance = np.nan,
ac_current_abs = np.nan,
ac_current_phase = np.nan
)
nmax = self.kondo.nmax nmax = self.kondo.nmax
try: try:
results['dc_current'] = self.kondo.gammaL[nmax, nmax].real results['dc_current'] = self.kondo.gammaL[nmax, nmax].real
......
...@@ -15,7 +15,7 @@ import settings ...@@ -15,7 +15,7 @@ import settings
import numpy as np import numpy as np
def gen_option_iter(steps, scales, **options): def gen_option_iter(steps=None, scales=None, **options):
""" """
Interpret given options to swipe over parameters. Interpret given options to swipe over parameters.
...@@ -46,9 +46,11 @@ def gen_option_iter(steps, scales, **options): ...@@ -46,9 +46,11 @@ def gen_option_iter(steps, scales, **options):
options.pop(key) options.pop(key)
steps = [max_length] steps = [max_length]
else: else:
if isinstance(scales, str): if scales is None:
scales = len(steps) * ["linear"]
elif isinstance(scales, str):
scales = len(steps)*[scales] scales = len(steps)*[scales]
if len(scales) == 1: elif len(scales) == 1:
scales *= len(steps) scales *= len(steps)
for key, value in options.items(): for key, value in options.items():
if type(value) != list or key == "fourier_coef": if type(value) != list or key == "fourier_coef":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment