From 004a5326045098c4993c406e0b9c1d6329e7f2b1 Mon Sep 17 00:00:00 2001 From: Malik Badmus <46167222+Malikbadmus@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:39:54 +0100 Subject: [PATCH 1/4] Add the path to information.json to local card --- ersilia/hub/content/card.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/ersilia/hub/content/card.py b/ersilia/hub/content/card.py index 4da997438..88e043476 100644 --- a/ersilia/hub/content/card.py +++ b/ersilia/hub/content/card.py @@ -8,6 +8,7 @@ from ...auth.auth import Auth from ...db.hubdata.interfaces import AirtableInterface import validators +from functools import lru_cache try: from validators import ValidationFailure @@ -45,7 +46,7 @@ except: Hdf5Explorer = None -from ...default import CARD_FILE, METADATA_JSON_FILE, SERVICE_CLASS_FILE +from ...default import EOS, LOCAL_CARD_FILE, METADATA_JSON_FILE class BaseInformation(ErsiliaBase): @@ -60,6 +61,7 @@ def __init__(self, config_json): self._mode = None self._task = None self._input = None + self._input_shape = None self._output = None self._output_type = None @@ -704,30 +706,33 @@ def get(self, model_id): class LocalCard(ErsiliaBase): def __init__(self, config_json): ErsiliaBase.__init__(self, config_json=config_json) - + + @lru_cache(maxsize=32) def get(self, model_id): - model_path = self._model_path(model_id) - card_path = os.path.join(model_path, CARD_FILE) + model_path = os.path.join(EOS, "dest", model_id) + card_path = os.path.join(model_path, LOCAL_CARD_FILE) if os.path.exists(card_path): with open(card_path, "r") as f: - card = json.load(f) + data = json.load(f) + card = data.get("card") return card else: return None - + + @lru_cache(maxsize=32) def get_service_class(self, model_id): """ This method returns information about how the model was fetched by reading the service class file located in the model's bundle directory. If the service class file does not exist, it returns None. """ - service_class_path = os.path.join( - self._get_bundle_location(model_id), SERVICE_CLASS_FILE - ) + model_path = os.path.join(EOS, "dest", model_id) + service_class_path = os.path.join(model_path, LOCAL_CARD_FILE) if os.path.exists(service_class_path): with open(service_class_path, "r") as f: - service_class = f.read().strip() + data = json.load(f) + service_class = data.get("service_class") return service_class else: return None @@ -758,15 +763,6 @@ def _get(self, model_id): card = self.lc.get(model_id) if card is not None: return card - card = self.mc.get(model_id) - if card is not None: - return card - card = self.ac.get(model_id) - if card is not None: - return card - card = self.rc.get(model_id) - if card is not None: - return card def get(self, model_id, as_json=False): card = self._get(model_id) From fd16444586125011055b13122b35516c6dd8f9a2 Mon Sep 17 00:00:00 2001 From: Malik Badmus <46167222+Malikbadmus@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:27:58 +0000 Subject: [PATCH 2/4] change file path --- ersilia/default.py | 3 ++- ersilia/hub/content/card.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ersilia/default.py b/ersilia/default.py index 0db7f68fa..4b56e778c 100644 --- a/ersilia/default.py +++ b/ersilia/default.py @@ -30,6 +30,7 @@ LOGGING_FILE = "console.log" CURRENT_LOGGING_FILE = "current.log" CARD_FILE = "card.json" +LOCAL_CARD_FILE = "information.json" SILENCE_FILE = ".silence.json" VERBOSE_FILE = ".verbose.json" API_SCHEMA_FILE = "api_schema.json" @@ -152,4 +153,4 @@ def bashrc_cli_snippet(overwrite=True): with open(fn, "w") as f: f.write(text) with open(fn, "a+") as f: - f.write(snippet) + f.write(snippet) \ No newline at end of file diff --git a/ersilia/hub/content/card.py b/ersilia/hub/content/card.py index 88e043476..7e5041ea4 100644 --- a/ersilia/hub/content/card.py +++ b/ersilia/hub/content/card.py @@ -46,7 +46,7 @@ except: Hdf5Explorer = None -from ...default import EOS, LOCAL_CARD_FILE, METADATA_JSON_FILE +from ...default import EOS, LOCAL_CARD_FILE, METADATA_JSON_FILE, SERVICE_CLASS_FILE class BaseInformation(ErsiliaBase): @@ -763,6 +763,15 @@ def _get(self, model_id): card = self.lc.get(model_id) if card is not None: return card + card = self.mc.get(model_id) + if card is not None: + return card + card = self.ac.get(model_id) + if card is not None: + return card + card = self.rc.get(model_id) + if card is not None: + return card def get(self, model_id, as_json=False): card = self._get(model_id) @@ -778,4 +787,4 @@ def get_service_class(self, model_id, as_json=False): if service is None: return else: - return service + return service \ No newline at end of file From 4c421fff5acd6fb7f615c5a2b2e9316fa5addbc1 Mon Sep 17 00:00:00 2001 From: Malik Badmus <46167222+Malikbadmus@users.noreply.github.com> Date: Fri, 12 Jul 2024 18:25:28 +0100 Subject: [PATCH 3/4] Remove local_card_file to avoid duplication Update card.py --- ersilia/default.py | 3 +-- ersilia/hub/content/card.py | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ersilia/default.py b/ersilia/default.py index 4b56e778c..0db7f68fa 100644 --- a/ersilia/default.py +++ b/ersilia/default.py @@ -30,7 +30,6 @@ LOGGING_FILE = "console.log" CURRENT_LOGGING_FILE = "current.log" CARD_FILE = "card.json" -LOCAL_CARD_FILE = "information.json" SILENCE_FILE = ".silence.json" VERBOSE_FILE = ".verbose.json" API_SCHEMA_FILE = "api_schema.json" @@ -153,4 +152,4 @@ def bashrc_cli_snippet(overwrite=True): with open(fn, "w") as f: f.write(text) with open(fn, "a+") as f: - f.write(snippet) \ No newline at end of file + f.write(snippet) diff --git a/ersilia/hub/content/card.py b/ersilia/hub/content/card.py index 7e5041ea4..5e33d6f86 100644 --- a/ersilia/hub/content/card.py +++ b/ersilia/hub/content/card.py @@ -46,7 +46,7 @@ except: Hdf5Explorer = None -from ...default import EOS, LOCAL_CARD_FILE, METADATA_JSON_FILE, SERVICE_CLASS_FILE +from ...default import EOS, INFORMATION_FILE, METADATA_JSON_FILE, SERVICE_CLASS_FILE class BaseInformation(ErsiliaBase): @@ -710,7 +710,7 @@ def __init__(self, config_json): @lru_cache(maxsize=32) def get(self, model_id): model_path = os.path.join(EOS, "dest", model_id) - card_path = os.path.join(model_path, LOCAL_CARD_FILE) + card_path = os.path.join(model_path, INFORMATION_FILE) if os.path.exists(card_path): with open(card_path, "r") as f: data = json.load(f) @@ -727,7 +727,7 @@ def get_service_class(self, model_id): class file does not exist, it returns None. """ model_path = os.path.join(EOS, "dest", model_id) - service_class_path = os.path.join(model_path, LOCAL_CARD_FILE) + service_class_path = os.path.join(model_path, INFORMATION_FILE) if os.path.exists(service_class_path): with open(service_class_path, "r") as f: @@ -787,4 +787,4 @@ def get_service_class(self, model_id, as_json=False): if service is None: return else: - return service \ No newline at end of file + return service From c2769e898a5bf770eaa44853c9ebdbfbedd5b156 Mon Sep 17 00:00:00 2001 From: Malik Badmus Date: Sun, 14 Jul 2024 04:26:28 +0100 Subject: [PATCH 4/4] Implementing rwview changes --- ersilia/hub/content/card.py | 60 +++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/ersilia/hub/content/card.py b/ersilia/hub/content/card.py index 5e33d6f86..ea3176205 100644 --- a/ersilia/hub/content/card.py +++ b/ersilia/hub/content/card.py @@ -704,38 +704,48 @@ def get(self, model_id): class LocalCard(ErsiliaBase): + """ + This class provides information on models that have been fetched and are available locally. + It retrieves and caches information about the models. + """ def __init__(self, config_json): ErsiliaBase.__init__(self, config_json=config_json) - + @lru_cache(maxsize=32) - def get(self, model_id): - model_path = os.path.join(EOS, "dest", model_id) - card_path = os.path.join(model_path, INFORMATION_FILE) - if os.path.exists(card_path): - with open(card_path, "r") as f: - data = json.load(f) - card = data.get("card") - return card - else: - return None + def _load_data(self, model_id): + """ + Loads the JSON data from the model's information file. + """ + model_path = self._model_path(model_id) + file_path = os.path.join(model_path, INFORMATION_FILE) + + if os.path.exists(file_path): + try: + with open(file_path, "r") as f: + return json.load(f) + except json.JSONDecodeError: + return None + return None - @lru_cache(maxsize=32) + def get(self, model_id): + """ + Returns the 'card' information for the specified model. + """ + data = self._load_data(model_id) + if data: + return data.get("card") + return None + def get_service_class(self, model_id): """ - This method returns information about how the model was fetched by reading - the service class file located in the model's bundle directory. If the service - class file does not exist, it returns None. + Returns the 'service class' information for the specified model. """ - model_path = os.path.join(EOS, "dest", model_id) - service_class_path = os.path.join(model_path, INFORMATION_FILE) - - if os.path.exists(service_class_path): - with open(service_class_path, "r") as f: - data = json.load(f) - service_class = data.get("service_class") - return service_class - else: - return None + + data = self._load_data(model_id) + if data: + return data.get("service_class") + return None + class LakeCard(ErsiliaBase): def __init__(self, config_json=None):