Model run¶
ModelRun puts a model configuration together with a run period and an output directory, and generates, runs and postprocesses the model.
Model run implementation for ROMPY.
This module provides the ModelRun class which is the main entry point for running models with ROMPY.
ModelRun
pydantic-model
¶
ModelRun(**data: Any)
Bases: RompyBaseModel
A model run.
It is intented to be model agnostic. It deals primarily with how the model is to be run, i.e. the period of the run and where the output is going. The actual configuration of the run is provided by the config object.
Further explanation is given in the rompy.core.Baseconfig docstring.
Config:
protected_namespaces:()extra:forbid
Fields:
-
model_type(Literal['modelrun']) -
run_id(str) -
period(TimeRange) -
output_dir(Path) -
config(Union[CONFIG_TYPES]) -
delete_existing(bool) -
run_id_subdir(bool)
period
pydantic-field
¶
period: TimeRange = TimeRange(
start=datetime(2020, 2, 21, 4),
end=datetime(2020, 2, 24, 4),
interval="15M",
)
The time period to run the model
run_id_subdir
pydantic-field
¶
run_id_subdir: bool = True
Use run_id subdirectory in the output directory
staging_dir
property
¶
The directory where the model is staged for execution
Returns:
| Name | Type | Description |
|---|---|---|
staging_dir |
str
|
|
zip
¶
zip() -> str
Zip the input files for the model run
This function zips the input files for the model run and returns the name of the zip file. It also cleans up the staging directory leaving only the settings.json file that can be used to reproduce the run.
Returns:
| Name | Type | Description |
|---|---|---|
zip_fn |
str
|
|
run
¶
run(
backend: BackendConfig,
workspace_dir: Optional[str] = None,
) -> bool
Run the model using the specified backend configuration.
This method uses Pydantic configuration objects that provide type safety and validation for all backend parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendConfig
|
Pydantic configuration object (LocalConfig, DockerConfig, etc.) |
required |
workspace_dir
|
Optional[str]
|
Path to generated workspace directory (optional) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if execution was successful, False otherwise |
Raises:
| Type | Description |
|---|---|
TypeError
|
If backend is not a BackendConfig instance |
Examples:
from rompy.backends import LocalConfig, DockerConfig
Local execution¶
model.run(LocalConfig(timeout=3600, command="python run.py"))
Docker execution¶
model.run(DockerConfig(image="swan:latest", cpu=4, memory="2g"))
postprocess
¶
postprocess(
processor: BasePostprocessorConfig, **kwargs: Any
) -> Dict[str, Any]
Postprocess the model outputs using the specified processor configuration.
This method uses the provided configuration to instantiate and execute the appropriate postprocessor. The processor type is determined by the configuration object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
BasePostprocessorConfig
|
Configuration object for the postprocessor to use |
required |
**kwargs
|
Any
|
Additional processor-specific parameters (override config values) |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with results from the postprocessing |
Raises:
| Type | Description |
|---|---|
TypeError
|
If processor is not a BasePostprocessorConfig instance |
pipeline
¶
Run the complete model pipeline (generate, run, postprocess) using the specified pipeline backend.
This method executes the entire model workflow from input generation through running the model to postprocessing outputs. It uses entry points to load and execute the appropriate pipeline backend from the rompy.pipeline entry point group.
Built-in pipeline backends: - "local": Execute the complete pipeline locally using the existing ModelRun methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline_backend
|
str
|
Name of the pipeline backend to use (default: "local") |
'local'
|
**kwargs
|
Any
|
Additional backend-specific parameters. Common parameters include: - backend_config: BackendConfig instance for the run stage (for local pipeline) - processor: ProcessorConfig instance for postprocessing (for local pipeline) - run_kwargs: Additional parameters for the run stage - process_kwargs: Additional parameters for postprocessing |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with results from the pipeline execution |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified pipeline backend is not available |
check_for_typos
classmethod
¶
Suggest the closest field name for an unknown input key.
A field can be given by its name or, like in pydantic, by its alias.