rompy.model.ModelRun#

pydantic model rompy.model.ModelRun[source]#

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.

Show JSON schema
{
   "title": "ModelRun",
   "description": "A model run.\n\nIt is intented to be model agnostic.\nIt deals primarily with how the model is to be run, i.e. the period of the run\nand where the output is going. The actual configuration of the run is\nprovided by the config object.\n\nFurther explanation is given in the rompy.core.Baseconfig docstring.",
   "type": "object",
   "properties": {
      "model_type": {
         "const": "modelrun",
         "default": "modelrun",
         "description": "The model type.",
         "title": "Model Type",
         "type": "string"
      },
      "run_id": {
         "default": "run_id",
         "description": "The run id",
         "title": "Run Id",
         "type": "string"
      },
      "period": {
         "$ref": "#/$defs/TimeRange",
         "default": {
            "start": "2020-02-21T04:00:00",
            "end": "2020-02-24T04:00:00",
            "interval": "PT15M",
            "include_end": true
         },
         "description": "The time period to run the model"
      },
      "output_dir": {
         "default": "./simulations",
         "description": "The output directory",
         "format": "path",
         "title": "Output Dir",
         "type": "string"
      },
      "config": {
         "description": "The configuration object",
         "discriminator": {
            "mapping": {
               "base": "#/$defs/BaseConfig"
            },
            "propertyName": "model_type"
         },
         "oneOf": [
            {
               "$ref": "#/$defs/BaseConfig"
            }
         ],
         "title": "Config"
      },
      "delete_existing": {
         "default": false,
         "description": "Delete existing output directory",
         "title": "Delete Existing",
         "type": "boolean"
      },
      "run_id_subdir": {
         "default": true,
         "description": "Use run_id subdirectory in the output directory",
         "title": "Run Id Subdir",
         "type": "boolean"
      }
   },
   "$defs": {
      "BaseConfig": {
         "additionalProperties": true,
         "description": "Base class for model templates.\n\nThe template class provides the object that is used to set up the model configuration.\nWhen implemented for a given model, can move along a scale of complexity\nto suit the application.\n\nIn its most basic form, as implemented in this base object, it consists of path to a cookiecutter template\nwith the class providing the context for the {{config}} values in that template. Note that any\n{{runtime}} values are filled from the ModelRun object.\n\nIf the template is a git repo, the checkout parameter can be used to specify a branch or tag and it\nwill be cloned and used.\n\nIf the object is callable, it will be colled prior to rendering the template. This mechanism can be\nused to perform tasks such as fetching exteral data, or providing additional context to the template\nbeyond the arguments provided by the user..",
         "properties": {
            "model_type": {
               "const": "base",
               "default": "base",
               "title": "Model Type",
               "type": "string"
            },
            "template": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": "/opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/rompy/templates/base",
               "description": "The path to the model template",
               "title": "Template"
            },
            "checkout": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": "main",
               "description": "The git branch to use if the template is a git repo",
               "title": "Checkout"
            }
         },
         "title": "BaseConfig",
         "type": "object"
      },
      "TimeRange": {
         "description": "A time range object\n\nExamples\n--------\n>>> from rompy import TimeRange\n>>> tr = TimeRange(start=\"2020-01-01\", end=\"2020-01-02\")\n>>> tr\nTimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=datetime.datetime(2020, 1, 2, 0, 0), duration=None, interval=None, include_end=True)\n>>> tr = TimeRange(start=\"2020-01-01\", duration=\"1d\")\n>>> tr\nTimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=datetime.datetime(2020, 1, 2, 0, 0), duration=timedelta(days=1), interval=None, include_end=True)\n>>> tr = TimeRange(start=\"2020-01-01\", duration=\"1d\", interval=\"1h\")\n>>> tr\nTimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=None, duration=timedelta(days=1), interval=timedelta(hours=1), include_end=True)",
         "properties": {
            "start": {
               "anyOf": [
                  {
                     "format": "date-time",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The start date of the time range",
               "examples": [
                  "2020-01-01"
               ],
               "title": "Start"
            },
            "end": {
               "anyOf": [
                  {
                     "format": "date-time",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The end date of the time range",
               "examples": [
                  "2020-01-02"
               ],
               "title": "End"
            },
            "duration": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "format": "duration",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The duration of the time range",
               "examples": [
                  "1d"
               ],
               "title": "Duration"
            },
            "interval": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "format": "duration",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": "1h",
               "description": "The frequency of the time range",
               "examples": [
                  "1h",
                  "'1h'"
               ],
               "title": "Interval"
            },
            "include_end": {
               "default": true,
               "description": "Determines if the end date should be included in the range",
               "title": "Include End",
               "type": "boolean"
            }
         },
         "title": "TimeRange",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Fields:
field config: BaseConfig [Optional]#

The configuration object

field delete_existing: bool = False#

Delete existing output directory

field model_type: Literal['modelrun'] = 'modelrun'#

The model type.

field output_dir: Path = './simulations'#

The output directory

field period: TimeRange = TimeRange(start=datetime.datetime(2020, 2, 21, 4, 0), end=datetime.datetime(2020, 2, 24, 4, 0), duration=datetime.timedelta(days=3), interval=datetime.timedelta(seconds=900), include_end=True)#

The time period to run the model

field run_id: str = 'run_id'#

The run id

field run_id_subdir: bool = True#

Use run_id subdirectory in the output directory

generate() str[source]#

Generate the model input files

Returns:

staging_dir

Return type:

str

model_post_init(context: Any, /) None#

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

pipeline(pipeline_backend: str = 'local', **kwargs) Dict[str, Any][source]#

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:
  • pipeline_backend – Name of the pipeline backend to use (default: “local”)

  • **kwargs – Additional backend-specific parameters. Common parameters include: - run_backend: Backend to use for the run stage (for local pipeline) - processor: Processor to use for postprocessing (for local pipeline) - run_kwargs: Additional parameters for the run stage - process_kwargs: Additional parameters for postprocessing

Returns:

Dictionary with results from the pipeline execution

Raises:

ValueError – If the specified pipeline backend is not available

postprocess(processor: str = 'noop', **kwargs) Dict[str, Any][source]#

Postprocess the model outputs using the specified processor.

This method uses entry points to load and execute the appropriate postprocessor. Available processors are automatically discovered from the rompy.postprocess entry point group.

Built-in processors: - “noop”: A placeholder processor that does nothing but returns success

Parameters:
  • processor – Name of the postprocessor to use (default: “noop”)

  • **kwargs – Additional processor-specific parameters

Returns:

Dictionary with results from the postprocessing

Raises:

ValueError – If the specified processor is not available

run(backend: LocalConfig | DockerConfig, workspace_dir: str | None = None) bool[source]#

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:
  • backend – Pydantic configuration object (LocalConfig, DockerConfig, etc.)

  • workspace_dir – Path to generated workspace directory (optional)

Returns:

True if execution was successful, False otherwise

Raises:

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”))

zip() str[source]#

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:

zip_fn

Return type:

str

property staging_dir#

The directory where the model is staged for execution

Returns:

staging_dir

Return type:

str