From 2bf263679d9180ba60bfcbe1756f5d35daeb9450 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Tue, 13 May 2025 09:45:00 +0000 Subject: [PATCH 1/2] Finish first version of cache --- TODO.md | 9 ++++----- corrlib/meas_io.py | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index 3c568dc..4153fc3 100644 --- a/TODO.md +++ b/TODO.md @@ -1,15 +1,14 @@ # TODO ## Features -- [ ] implement import of non-datalad projects -- [ ] implement a way to use another backlog repo as a project +- implement import of non-datalad projects +- implement a way to use another backlog repo as a project -- [ ] find a way to convey the mathematical structure of what EXACTLY is the form of the correlator in a specific project +- find a way to convey the mathematical structure of what EXACTLY is the form of the correlator in a specific project - this could e.g. be done along the lines of mandatory documentation -- [ ] keep better track of the versions the code, that was used for a specific measurement. +- keep better track of the versions of the code, that was used for a specific measurement. - maybe let this be an input in the project file? - git repo and commit hash/version tag -- [ ] implement local caching with pickle files ## Bugfixes - [ ] revisit the reimport function for single files diff --git a/corrlib/meas_io.py b/corrlib/meas_io.py index 1f1e920..9a3806b 100644 --- a/corrlib/meas_io.py +++ b/corrlib/meas_io.py @@ -139,8 +139,8 @@ def load_records(path: str, meas_paths: list[str], preloaded = {}) -> list[Union returned_data: list = [] for file in needed_data.keys(): for key in list(needed_data[file]): - if os.path.exists(cache_path(path, file, key)): - returned_data.append(load_object(cache_path(path, file, key))) + if os.path.exists(cache_path(path, file, key) + ".p"): + returned_data.append(load_object(cache_path(path, file, key) + ".p")) else: if file not in preloaded: preloaded[file] = preload(path, file) @@ -156,13 +156,13 @@ def cache_dir(path, file): cache_path_list = [path] cache_path_list.append(".cache") cache_path_list.extend(file.split("/")[1:]) - cache_path = os.path.join(cache_path_list) + cache_path = "/".join(cache_path_list) return cache_path def cache_path(path, file, key): cache_path = os.path.join(cache_dir(path, file), key) - return cache_path + ".p" + return cache_path def preload(path: str, file: str): From 4f7d9d71b35074e39c6666ed6950b70122c2afe4 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Tue, 13 May 2025 09:45:37 +0000 Subject: [PATCH 2/2] Implement better finding for sfcf projects --- corrlib/find.py | 29 ++++++++++++++++++++++++++--- corrlib/tools.py | 7 +++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/corrlib/find.py b/corrlib/find.py index a1b25f9..432bb26 100644 --- a/corrlib/find.py +++ b/corrlib/find.py @@ -5,6 +5,7 @@ import json import pandas as pd import numpy as np from .input.implementations import codes +from .tools import m2k, k2m # this will implement the search functionality @@ -65,11 +66,33 @@ def sfcf_filter(results, **kwargs): if kwargs.get('offset') != param['offset']: drops.append(ind) continue - if 'quark_masses' in kwargs: - quark_masses = kwargs['quark_masses'] - if (not np.isclose(quark_masses[0], param['quarks'][0]['mass']) or not np.isclose(quark_masses[1], param['quarks'][1]['mass'])): + if 'quark_kappas' in kwargs: + kappas = kwargs['quark_kappas'] + if (not np.isclose(kappas[0], param['quarks'][0]['mass']) or not np.isclose(kappas[1], param['quarks'][1]['mass'])): drops.append(ind) continue + if 'qm1' in kwargs: + quark_mass1 = kwargs['qm1'] + if not isinstance(quark_mass1, list): + if (not np.isclose(quark_mass1, k2m(param['quarks'][0]['mass']))): + drops.append(ind) + continue + else: + if len(quark_mass1) == 2: + if (quark_mass1[0] > k2m(param['quarks'][0]['mass'])) or (quark_mass1[1] < k2m(param['quarks'][0]['mass'])): + drops.append(ind) + continue + if 'qm2' in kwargs: + quark_mass2 = kwargs['qm2'] + if not isinstance(quark_mass2, list): + if (not np.isclose(quark_mass2, k2m(param['quarks'][1]['mass']))): + drops.append(ind) + continue + else: + if len(quark_mass2) == 2: + if (quark_mass2[0] > k2m(param['quarks'][1]['mass'])) or (quark_mass2[1] < k2m(param['quarks'][1]['mass'])): + drops.append(ind) + continue if 'quark_thetas' in kwargs: quark_thetas = kwargs['quark_thetas'] if (quark_thetas[0] != param['quarks'][0]['thetas'] and quark_thetas[1] != param['quarks'][1]['thetas']) or (quark_thetas[0] != param['quarks'][1]['thetas'] and quark_thetas[1] != param['quarks'][0]['thetas']): diff --git a/corrlib/tools.py b/corrlib/tools.py index e424b59..3ac8bfe 100644 --- a/corrlib/tools.py +++ b/corrlib/tools.py @@ -9,3 +9,10 @@ def list2str(mylist): return s cached = True + +def m2k(m): + return 1/(2*m+8) + + +def k2m(k): + return (1/(2*k))-4