Skip to content

Commit

Permalink
base information for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelduranfrigola committed Jun 20, 2023
1 parent 81a123f commit cc692a7
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 6 deletions.
57 changes: 57 additions & 0 deletions ersilia/hub/content/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
SourceCodeBaseInformationError,
LicenseBaseInformationError,
GithubBaseInformationError,
DockerhubBaseInformationError,
DockerArchitectureInformationError,
S3BaseInformationError,
BothIdentifiersBaseInformationError,
)
from ...utils.identifiers.model import ModelIdentifier
Expand Down Expand Up @@ -61,6 +64,9 @@ def __init__(self, config_json):
self._source_code = None
self._license = None
self._contributor = None
self._dockerhub = None
self._docker_architecture = None
self._s3 = None

def _is_valid_url(self, url_string: str) -> bool:
result = validators.url(url_string)
Expand Down Expand Up @@ -292,6 +298,39 @@ def github(self):
self._github = "https://github.com/ersilia-os/{0}".format(model_id)
return self._github

@property
def dockerhub(self):
return self._dockerhub

@dockerhub.setter
def dockerhub(self, new_dockerhub_url):
if not new_dockerhub_url.startswith("https://hub.docker.com/r/ersiliaos/"):
raise DockerhubBaseInformationError
self._dockerhub = new_dockerhub_url

@property
def docker_architecture(self):
return self._docker_architecture

@docker_architecture.setter
def docker_architecture(self, new_docker_architecture):
for d in new_docker_architecture:
if d not in self._read_default_fields("Docker Architecture"):
raise DockerArchitectureInformationError
self._docker_architecture = new_docker_architecture

@property
def s3(self):
return self._s3

@s3.setter
def s3(self, new_s3_url):
if not new_s3_url.startswith(
"https://ersilia-models-zipped.s3.eu-central-1.amazonaws.com/"
):
raise S3BaseInformationError
self._s3 = new_s3_url

@property
def both_identifiers(self):
model_id = self.identifier
Expand Down Expand Up @@ -321,6 +360,9 @@ def as_dict(self):
"Source Code": self.source_code,
"License": self.license,
"Contributor": self.contributor,
"DockerHub": self.dockerhub,
"Docker Architecture": self.docker_architecture,
"S3": self.s3,
}
data = dict((k, v) for k, v in data.items() if v is not None)
return data
Expand All @@ -345,6 +387,12 @@ def from_dict(self, data):
self.license = data["License"]
if "Contributor" in data:
self.contributor = data["Contributor"]
if "DockerHub" in data:
self.dockerhub = data["DockerHub"]
if "Docker Architecture" in data:
self.docker_architecture = data["Docker Architecture"]
if "S3" in data:
self.s3 = data["S3"]


class RepoMetadataFile(ErsiliaBase):
Expand Down Expand Up @@ -489,6 +537,15 @@ def write_information(self, data: BaseInformation, readme_path=None):
text += "* Ersilia contributor: [{0}](https://github.com/{0})\n\n".format(
d["Contributor"]
)
text += "## Ersilia model URLs\n"
text += "* [GitHub]({0})\n".format(data.github)
if d["S3"] in d:
text += "* [AWS S3]({0})\n".format(d["S3"])
if d["DockerHub"] in d:
text += "* [DockerHub]({0}) ({1})\n".format(
d["DockerHub"], ", ".join(d["Docker Architecture"])
)
text += "\n"
text += "## Citation\n\n"
text += "If you use this model, please cite the [original authors]({0}) of the model and the [Ersilia Model Hub](https://github.com/ersilia-os/ersilia/blob/master/CITATION.cff).\n\n".format(
d["Publication"]
Expand Down
2 changes: 2 additions & 0 deletions ersilia/hub/content/metadata/docker_architecture.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AMD64
ARM64
12 changes: 12 additions & 0 deletions ersilia/hub/fetch/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ def copy_metadata(self, model_id):
tag=DOCKERHUB_LATEST_TAG,
)

def copy_status(self, model_id):
fr_file = "/root/eos/dest/{0}/{1}".format(model_id, STATUS_FILE)
to_file = "{0}/dest/{1}/{2}".format(EOS, model_id, STATUS_FILE)
self.simple_docker.cp_from_image(
img_path=fr_file,
local_path=to_file,
org=DOCKERHUB_ORG,
img=model_id,
tag=DOCKERHUB_LATEST_TAG,
)

def fetch(self, model_id):
mp = ModelPuller(model_id=model_id, config_json=self.config_json)
mp.pull()
Expand All @@ -142,6 +153,7 @@ def fetch(self, model_id):
self.write_apis(model_id)
self.copy_information(model_id)
self.copy_metadata(model_id)
self.copy_status(model_id)


class ModelFetcher(ErsiliaBase):
Expand Down
3 changes: 1 addition & 2 deletions ersilia/serve/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,5 +577,4 @@ def close(self):
self.logger.debug(
"Stopping and removing container {0}".format(self.container_id)
)
self.container.stop()
self.container.remove()
self._stop_all_containers_of_image()
23 changes: 23 additions & 0 deletions ersilia/utils/exceptions_utils/card_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,29 @@ def __init__(self):
super().__init__(self.message, self.hints)


class DockerhubBaseInformationError(ErsiliaError):
def __init__(self):
self.message = "Wrong Ersilia DockerHub URL"
self.hints = "The model does not seem to be publicly available in Ersilia's DockerHub organization profile (ersiliaos). Make sure that a model identifier has been set."
super().__init__(self.message, self.hints)


class DockerArchitectureInformationError(ErsiliaError):
def __init__(self):
self.message = "Wrong Docker architecture"
self.hints = "Listed Docker architectures are: {}. If you are considering a Docker architecture that is not in this list, please open a PR on the 'docker_architecture.txt' file in the Ersilia repository".format(
", ".join(_read_default_fields("Docker Architecture"))
)
super().__init__(self.message, self.hints)


class S3BaseInformationError(ErsiliaError):
def __init__(self):
self.message = "Wrong Ersilia AWS S3 URL"
self.hints = "The model does not seem to be publicly available in Ersilia's AWS S3 bucket for zipped models. Make sure that a model identifier has been set."
super().__init__(self.message, self.hints)


class BothIdentifiersBaseInformationError(ErsiliaError):
def __init__(self):
self.message = "Both identifiers field error"
Expand Down
8 changes: 4 additions & 4 deletions notebooks/test-colab-notebook-python-api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -203,7 +203,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -218,7 +218,7 @@
"]\n",
"\n",
"em.serve()\n",
"data = em.predict(smiles, output=\"pandas\")"
"data = em.run(smiles, output=\"pandas\")"
]
},
{
Expand Down Expand Up @@ -260,7 +260,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.11"
"version": "3.10.11"
},
"vscode": {
"interpreter": {
Expand Down

0 comments on commit cc692a7

Please sign in to comment.