Compare commits
No commits in common. "4f3e78177e0497ff344f4d949cb8af8cbfb6c832" and "73d7687359b4d8f1b5e8351f6700fff8be0a6b4e" have entirely different histories.
4f3e78177e
...
73d7687359
5 changed files with 25 additions and 46 deletions
|
|
@ -1,33 +0,0 @@
|
||||||
from typing import Union, Optional
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
|
|
||||||
def drop_cache_files(path: str, fs: Optional[list[str]]=None):
|
|
||||||
cache_dir = os.path.join(path, ".cache")
|
|
||||||
if fs is None:
|
|
||||||
fs = os.listdir(cache_dir)
|
|
||||||
for f in fs:
|
|
||||||
shutil.rmtree(os.path.join(cache_dir, f))
|
|
||||||
|
|
||||||
|
|
||||||
def cache_dir(path, file):
|
|
||||||
cache_path_list = [path]
|
|
||||||
cache_path_list.append(".cache")
|
|
||||||
cache_path_list.extend(file.split("/")[1:])
|
|
||||||
cache_path = "/".join(cache_path_list)
|
|
||||||
return cache_path
|
|
||||||
|
|
||||||
|
|
||||||
def cache_path(path, file, hash, key):
|
|
||||||
cache_path = os.path.join(cache_dir(path, file), hash, key)
|
|
||||||
return cache_path
|
|
||||||
|
|
||||||
def is_in_cache(path, record, hash):
|
|
||||||
|
|
||||||
if os.file.exists(cache_path(path, file, hash, key)):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,15 +4,14 @@ import datalad.api as dl
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from .input import sfcf,openQCD
|
from .input import sfcf,openQCD
|
||||||
import json
|
import json
|
||||||
from typing import Union, Optional
|
from typing import Union
|
||||||
from pyerrors import Obs, Corr, dump_object, load_object
|
from pyerrors import Obs, Corr, dump_object, load_object
|
||||||
from hashlib import sha256, sha1
|
from hashlib import sha256, sha1
|
||||||
from .tools import cached, record2name_key
|
from .tools import cached
|
||||||
import shutil
|
import shutil
|
||||||
from .caching import cache_path, cache_dir
|
|
||||||
|
|
||||||
|
|
||||||
def write_measurement(path, ensemble, measurement, uuid, code, parameter_file: Optional[str]=None):
|
def write_measurement(path, ensemble, measurement, uuid, code, parameter_file=None):
|
||||||
"""
|
"""
|
||||||
Write a measurement to the backlog.
|
Write a measurement to the backlog.
|
||||||
If the file for the measurement already exists, update the measurement.
|
If the file for the measurement already exists, update the measurement.
|
||||||
|
|
@ -116,7 +115,7 @@ def load_record(path: str, meas_path: str):
|
||||||
return load_records(path, [meas_path])[0]
|
return load_records(path, [meas_path])[0]
|
||||||
|
|
||||||
|
|
||||||
def load_records(path: str, record_paths: list[str], preloaded = {}) -> list[Union[Corr, Obs]]:
|
def load_records(path: str, meas_paths: list[str], preloaded = {}) -> list[Union[Corr, Obs]]:
|
||||||
"""
|
"""
|
||||||
Load a list of records by their paths.
|
Load a list of records by their paths.
|
||||||
|
|
||||||
|
|
@ -132,10 +131,11 @@ def load_records(path: str, record_paths: list[str], preloaded = {}) -> list[Uni
|
||||||
List
|
List
|
||||||
"""
|
"""
|
||||||
needed_data: dict[str, list[str]] = {}
|
needed_data: dict[str, list[str]] = {}
|
||||||
for rpath in record_paths:
|
for mpath in meas_paths:
|
||||||
file, key = record2name_key(rpath)
|
file = mpath.split("::")[0]
|
||||||
if file not in needed_data.keys():
|
if file not in needed_data.keys():
|
||||||
needed_data[file] = []
|
needed_data[file] = []
|
||||||
|
key = mpath.split("::")[1]
|
||||||
needed_data[file].append(key)
|
needed_data[file].append(key)
|
||||||
returned_data: list = []
|
returned_data: list = []
|
||||||
for file in needed_data.keys():
|
for file in needed_data.keys():
|
||||||
|
|
@ -153,6 +153,19 @@ def load_records(path: str, record_paths: list[str], preloaded = {}) -> list[Uni
|
||||||
return returned_data
|
return returned_data
|
||||||
|
|
||||||
|
|
||||||
|
def cache_dir(path, file):
|
||||||
|
cache_path_list = [path]
|
||||||
|
cache_path_list.append(".cache")
|
||||||
|
cache_path_list.extend(file.split("/")[1:])
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def preload(path: str, file: str):
|
def preload(path: str, file: str):
|
||||||
dl.get(os.path.join(path, file), dataset=path)
|
dl.get(os.path.join(path, file), dataset=path)
|
||||||
filedict = pj.load_json_dict(os.path.join(path, file))
|
filedict = pj.load_json_dict(os.path.join(path, file))
|
||||||
|
|
@ -183,3 +196,7 @@ def drop_record(path: str, meas_path: str):
|
||||||
else:
|
else:
|
||||||
raise ValueError("This measurement does not exist as a file!")
|
raise ValueError("This measurement does not exist as a file!")
|
||||||
|
|
||||||
|
def drop_cache(path: str):
|
||||||
|
cache_dir = os.path.join(path, ".cache")
|
||||||
|
for f in os.listdir(cache_dir):
|
||||||
|
shutil.rmtree(os.path.join(cache_dir, f))
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,3 @@ def m2k(m):
|
||||||
|
|
||||||
def k2m(k):
|
def k2m(k):
|
||||||
return (1/(2*k))-4
|
return (1/(2*k))-4
|
||||||
|
|
||||||
|
|
||||||
def record2name_key(record_path: str):
|
|
||||||
file = record_path.split("::")[0]
|
|
||||||
key = record_path.split("::")[1]
|
|
||||||
return file, key
|
|
||||||
1
projects/tmp
Submodule
1
projects/tmp
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 216fe4ed3467ed486390735f8072856cf3d0a409
|
||||||
0
tests/test_import_project.py
Normal file
0
tests/test_import_project.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue