ersilia.db.environments package¶
Submodules¶
ersilia.db.environments.localdb module¶
- class ersilia.db.environments.localdb.EnvironmentDb(config_json=None)[source]¶
Bases:
ErsiliaBase
Manages the storage and retrieval of model environments.
Specifically it is essential for keeping track of the environments associated with each model. It provides a database where models and their corresponding environments (such as Docker images or conda environments) are stored and managed.
- Parameters:
config_json (dict, optional) – Configuration settings for initializing the environment database.
Examples
>>> env_db = EnvironmentDb(config_json) >>> env_db.table = "conda" >>> env_db.insert("model_id", "venv_name")
- delete(model_id, env)[source]¶
Deletes a specific entry from the database by model ID and environment.
- Parameters:
model_id (str) – Identifier of the model.
env (str) – Environment associated with the model.
- envs_of_model(model_id)[source]¶
Retrieves environments associated with a specific model ID.
- Parameters:
model_id (str) – Identifier of the model to search for.
- Returns:
Set of environments associated with the model ID.
- Return type:
set
- envs_with_same_model(env)[source]¶
Retrieves environments that share the same model as the given environment.
- Parameters:
env (str) – Environment to search for.
- Returns:
Set of environments that share the same model.
- Return type:
set
- fetchall()[source]¶
Retrieves all entries from the current table.
- Returns:
List of all entries in the table.
- Return type:
list
- insert(model_id, env)[source]¶
Inserts a model ID and environment into the database.
- Parameters:
model_id (str) – Identifier of the model.
env (str) – Environment associated with the model.
- models_of_env(env)[source]¶
Retrieves model IDs associated with a specific environment.
- Parameters:
env (str) – Environment to search for.
- Returns:
Set of model IDs associated with the environment.
- Return type:
set
- models_with_same_env(model_id)[source]¶
Retrieves model IDs that share the same environment as the given model ID.
- Parameters:
model_id (str) – Identifier of the model to search for.
- Returns:
Set of model IDs that share the same environment.
- Return type:
set
- property table¶
Gets the current table name.
- Returns:
The current table name.
- Return type:
str
ersilia.db.environments.managers module¶
- class ersilia.db.environments.managers.DockerManager(config_json=None, preferred_port=None, with_bentoml=False)[source]¶
Bases:
ErsiliaBase
Manages Docker operations for Ersilia models.
It provides methods to build, run, and manage Docker images and containers associated with Ersilia models.
- Parameters:
config_json (dict, optional) – Configuration settings for initializing the Docker manager.
preferred_port (int, optional) – Preferred port number for running Docker containers.
with_bentoml (bool, optional) – Flag indicating whether to use BentoML for model serving.
Examples
>>> docker_manager = DockerManager( ... config_json=config, preferred_port=8080 ... ) >>> docker_manager.build( ... model_id="eosxxxx", ... docker_user="user", ... docker_pwd="pass", ... ) >>> docker_manager.run(model_id="eosxxxx", workers=2)
- build(model_id, docker_user, docker_pwd, use_cache=True)[source]¶
Builds a Docker image for the model.
- Parameters:
model_id (str) – Identifier of the model.
docker_user (str) – Docker Hub username.
docker_pwd (str) – Docker Hub password.
use_cache (bool, optional) – If True, use Docker’s cache when building the image.
- build_with_bentoml(model_id, use_cache=True)[source]¶
Builds a Docker image for the model using BentoML.
- Parameters:
model_id (str) – Identifier of the model.
use_cache (bool, optional) – If True, use Docker’s cache when building the image.
- build_with_ersilia(model_id, docker_user, docker_pwd)[source]¶
Builds a Docker image for the model using Ersilia’s base image.
- Parameters:
model_id (str) – Identifier of the model.
docker_user (str) – Docker Hub username.
docker_pwd (str) – Docker Hub password.
- container_exists(container_name)[source]¶
Checks if a Docker container with the specified name exists.
- Parameters:
container_name (str) – Name of the Docker container.
- Returns:
True if the container exists, False otherwise.
- Return type:
bool
- containers(only_run)[source]¶
Retrieves a dictionary of Docker containers related to Ersilia models.
- Parameters:
only_run (bool) – If True, only return running containers.
- Returns:
Dictionary of Docker containers with container names as keys.
- Return type:
dict
- containers_of_model(model_id, only_run, only_latest=True)[source]¶
Retrieves Docker containers for a specific model.
- Parameters:
model_id (str) – Identifier of the model.
only_run (bool) – If True, only return running containers.
only_latest (bool, optional) – If True, only consider images with the latest tag.
- Returns:
Dictionary of Docker containers for the model.
- Return type:
dict
- delete_containers(model_id)[source]¶
Deletes all Docker containers associated with a model.
- Parameters:
model_id (str) – Identifier of the model.
- delete_images(model_id, purge_unnamed=True)[source]¶
Deletes Docker images associated with a model.
- Parameters:
model_id (str) – Identifier of the model.
purge_unnamed (bool, optional) – If True, also remove unnamed images.
- image_exists(model_id)[source]¶
Checks if a Docker image for the specified model exists.
- Parameters:
model_id (str) – Identifier of the model.
- Returns:
True if the Docker image exists, False otherwise.
- Return type:
bool
- images()[source]¶
Retrieves a dictionary of Docker images related to Ersilia models.
- Returns:
Dictionary of Docker images with image names as keys.
- Return type:
dict
- images_of_model(model_id, only_latest=True)[source]¶
Retrieves Docker images for a specific model.
- Parameters:
model_id (str) – Identifier of the model.
only_latest (bool, optional) – If True, only return images with the latest tag.
- Returns:
Dictionary of Docker images for the model.
- Return type:
dict
- is_active()[source]¶
Checks if Docker is active and running.
- Returns:
True if Docker is active, False otherwise.
- Return type:
bool
- is_inside_docker()[source]¶
Checks if the current process is running inside a Docker container.
- Returns:
True if running inside Docker, False otherwise.
- Return type:
bool
- is_installed()[source]¶
Checks if Docker is installed on the system.
- Returns:
True if Docker is installed, False otherwise.
- Return type:
bool
- is_logged_in()[source]¶
Checks if the user is logged in to Docker.
- Returns:
True if the user is logged in to Docker, False otherwise.
- Return type:
bool
- remove(model_id)[source]¶
Removes the Docker image for the specified model.
- Parameters:
model_id (str) – Identifier of the model.
- run(model_id, workers=1, enable_microbatch=True, memory=None)[source]¶
Runs a Docker container for the specified model.
- Parameters:
model_id (str) – Identifier of the model.
workers (int, optional) – Number of worker processes.
enable_microbatch (bool, optional) – If True, enable micro-batching.
memory (int, optional) – Memory limit for the container in gigabytes.
- Returns:
Dictionary containing container name and port.
- Return type:
dict
- start(container_name)[source]¶
Starts a stopped Docker container.
- Parameters:
container_name (str) – Name of the Docker container to start.