Run backends¶
Backends run a generated model: locally, in Docker or on a SLURM cluster. Each backend has a configuration class, used with ModelRun.run.
rompy.backends.config¶
Backend configuration classes for ROMPY.
This module provides Pydantic-based configuration classes for different execution backends. These configurations handle transient execution parameters while maintaining type safety and validation.
BaseBackendConfig
pydantic-model
¶
Base class for all backend configurations.
This class defines common configuration parameters that apply to all backend types, such as timeouts and environment variables.
Config:
validate_assignment:Trueextra:forbiduse_enum_values:True
Fields:
Validators:
timeout
pydantic-field
¶
timeout: int = 3600
Maximum execution time in seconds (1 minute to 24 hours)
env_vars
pydantic-field
¶
Additional environment variables to set during execution
working_dir
pydantic-field
¶
Working directory for execution (defaults to model output directory)
validate_working_dir
pydantic-validator
¶
Validate working directory exists if specified.
LocalConfig
pydantic-model
¶
Bases: BaseBackendConfig
Configuration for local execution backend.
This configuration is used when running models directly on the local system using the system's Python interpreter or shell commands.
Config:
json_schema_extra:{'examples': [{'timeout': 7200, 'env_vars': {'OMP_NUM_THREADS': '4'}, 'command': 'python run_model.py'}, {'timeout': 3600, 'working_dir': '/path/to/model/dir'}, {'timeout': 3600, 'stream_output': True}]}
Fields:
-
timeout(int) -
env_vars(Dict[str, str]) -
working_dir(Optional[Path]) -
command(Optional[str]) -
shell(bool) -
capture_output(bool) -
stream_output(bool)
Validators:
command
pydantic-field
¶
Optional shell command to run instead of config.run()
timeout
pydantic-field
¶
timeout: int = 3600
Maximum execution time in seconds (1 minute to 24 hours)
env_vars
pydantic-field
¶
Additional environment variables to set during execution
working_dir
pydantic-field
¶
Working directory for execution (defaults to model output directory)
validate_working_dir
pydantic-validator
¶
Validate working directory exists if specified.
DockerConfig
pydantic-model
¶
Bases: BaseBackendConfig
Configuration for Docker execution backend.
This configuration is used when running models inside Docker containers with appropriate resource limits and volume mounts.
Config:
json_schema_extra:{'examples': [{'image': 'swan:latest', 'cpu': 4, 'memory': '2g', 'timeout': 7200, 'volumes': ['/data:/app/data']}, {'dockerfile': './docker/Dockerfile', 'cpu': 2, 'build_args': {'VERSION': '1.0'}, 'mpiexec': 'mpirun'}]}
Fields:
-
timeout(int) -
env_vars(Dict[str, str]) -
working_dir(Optional[Path]) -
image(Optional[str]) -
dockerfile(Optional[Path]) -
executable(str) -
cpu(int) -
memory(Optional[str]) -
mpiexec(str) -
build_args(Dict[str, str]) -
build_context(Optional[Path]) -
volumes(List[str]) -
remove_container(bool) -
user(str)
Validators:
-
validate_working_dir→working_dir -
validate_env_vars→env_vars -
validate_image_or_dockerfile→image,dockerfile -
validate_dockerfile_exists→dockerfile -
validate_build_context_exists→build_context -
validate_volumes→volumes -
validate_memory_format→memory
image
pydantic-field
¶
Docker image to use (required if not building from dockerfile)
dockerfile
pydantic-field
¶
Path to Dockerfile to build (alternative to image)
executable
pydantic-field
¶
executable: str = '/usr/local/bin/run.sh'
Path to executable inside the container
build_context
pydantic-field
¶
Docker build context directory (defaults to dockerfile parent directory)
volumes
pydantic-field
¶
Additional volumes to mount (format: 'host_path:container_path')
remove_container
pydantic-field
¶
remove_container: bool = True
Whether to remove container after execution
timeout
pydantic-field
¶
timeout: int = 3600
Maximum execution time in seconds (1 minute to 24 hours)
env_vars
pydantic-field
¶
Additional environment variables to set during execution
working_dir
pydantic-field
¶
Working directory for execution (defaults to model output directory)
validate_image_or_dockerfile
pydantic-validator
¶
Validate that either image or dockerfile is provided, but not both.
validate_dockerfile_exists
pydantic-validator
¶
Validate dockerfile path format (should be relative).
validate_build_context_exists
pydantic-validator
¶
Validate build context directory exists if specified.
validate_working_dir
pydantic-validator
¶
Validate working directory exists if specified.
SlurmConfig
pydantic-model
¶
Bases: BaseBackendConfig
Configuration for SLURM cluster execution.
Config:
json_schema_extra:{'examples': [{'queue': 'general', 'command': 'python run_model.py', 'nodes': 1, 'ntasks': 1, 'cpus_per_task': 4, 'time_limit': '02:00:00', 'account': 'myproject', 'timeout': 7200}, {'queue': 'gpu', 'command': 'python run_model.py --gpu', 'nodes': 2, 'ntasks': 8, 'cpus_per_task': 2, 'time_limit': '24:00:00', 'reservation': 'special_reservation', 'additional_options': ['--gres=gpu:v100:2']}]}
Fields:
-
timeout(int) -
env_vars(Dict[str, str]) -
working_dir(Optional[Path]) -
model_type(Literal['slurm']) -
queue(Optional[str]) -
command(str) -
nodes(int) -
ntasks(int) -
cpus_per_task(int) -
time_limit(str) -
account(Optional[str]) -
qos(Optional[str]) -
reservation(Optional[str]) -
output_file(Optional[str]) -
error_file(Optional[str]) -
job_name(Optional[str]) -
mail_type(Optional[str]) -
mail_user(Optional[str]) -
additional_options(List[str])
Validators:
mail_type
pydantic-field
¶
Type of mail to send (BEGIN, END, FAIL, ALL, etc.)
additional_options
pydantic-field
¶
Additional SLURM options (e.g., '--gres=gpu:1')
timeout
pydantic-field
¶
timeout: int = 3600
Maximum execution time in seconds (1 minute to 24 hours)
env_vars
pydantic-field
¶
Additional environment variables to set during execution
working_dir
pydantic-field
¶
Working directory for execution (defaults to model output directory)
validate_time_limit
pydantic-validator
¶
Validate time limit format (HH:MM:SS).
validate_working_dir
pydantic-validator
¶
Validate working directory exists if specified.
rompy.run¶
Local execution backend for model runs.
This module provides the local run backend implementation.
LocalRunBackend
¶
Execute models locally using the system's Python interpreter.
This is the simplest backend that just runs the model directly on the local system.
run
¶
run(
model_run: ModelRun,
config: LocalConfig,
workspace_dir: Optional[str] = None,
) -> bool
Run the model locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_run
|
ModelRun
|
The ModelRun instance to execute |
required |
config
|
LocalConfig
|
LocalConfig instance with execution parameters |
required |
workspace_dir
|
Optional[str]
|
Path to the generated workspace directory (if None, will generate) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if execution was successful, False otherwise |
Raises:
| Type | Description |
|---|---|
ValueError
|
If model_run is invalid |
TimeoutError
|
If execution exceeds timeout |
rompy.run.docker¶
Docker backend for running models.
This module provides a Docker-based execution backend for rompy models.
DockerRunBackend
¶
Execute models inside Docker containers.
This backend builds Docker images if needed and runs models inside containers with appropriate volume mounts.
run
¶
run(
model_run: ModelRun,
config: DockerConfig,
workspace_dir: Optional[str] = None,
) -> bool
Run the model inside a Docker container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_run
|
ModelRun
|
The ModelRun instance to execute |
required |
config
|
DockerConfig
|
DockerConfig instance with execution parameters |
required |
workspace_dir
|
Optional[str]
|
Path to the generated workspace directory (if None, will generate) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if execution was successful, False otherwise |
rompy.run.slurm¶
SLURM backend for running models.
This module provides a SLURM-based execution backend for rompy models.
SlurmRunBackend
¶
Execute models on SLURM clusters.
This backend submits model runs to a SLURM-managed HPC cluster for execution.
run
¶
run(
model_run: ModelRun,
config: SlurmConfig,
workspace_dir: Optional[str] = None,
) -> bool
Submit model run to SLURM queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_run
|
ModelRun
|
The ModelRun instance to execute |
required |
config
|
SlurmConfig
|
SlurmConfig instance with execution parameters |
required |
workspace_dir
|
Optional[str]
|
Path to the generated workspace directory (if None, will generate) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if execution was successful, False otherwise |