The command line¶
The rompy command validates, generates, runs and postprocesses models described in YAML or JSON files. It does what the Python API does, with the configuration in files instead of code.
| Command | Does | Python equivalent |
|---|---|---|
rompy validate CONFIG |
Checks a run configuration | ModelRun(**data) |
rompy generate CONFIG |
Writes the workspace | ModelRun.generate |
rompy run CONFIG --backend-config FILE |
Generates and runs the model | ModelRun.run |
rompy postprocess CONFIG --processor-config FILE |
Postprocesses the outputs | ModelRun.postprocess |
rompy pipeline FILE |
Generates, runs and postprocesses | ModelRun.pipeline |
rompy schema [MODEL_TYPE] |
Prints a JSON schema | ModelRun.model_json_schema() |
rompy backends list|validate|schema|create |
Lists and checks backend configurations |
The examples on this page run the commands through click's test runner so that their output is shown here. In a shell, type the same arguments after rompy.
from click.testing import CliRunner
from rompy.cli import cli
def rompy(*args):
result = CliRunner().invoke(cli, list(args), prog_name="rompy")
print(result.output.rstrip())
Usage: rompy [OPTIONS] COMMAND [ARGS]...
ROMPY (Regional Ocean Modeling PYthon) - Ocean Model Configuration and
Execution Tool.
ROMPY provides tools for generating, running, and processing ocean, wave, and
hydrodynamic model configurations with support for multiple execution
backends.
Options:
--version Show version information and exit
-h, --help Show this message and exit.
Commands:
backends Manage execution backends.
generate Generate model input files only.
pipeline Run full model pipeline: generate → run → postprocess.
postprocess Run postprocessing on model outputs using the specified...
run Run a model configuration using Pydantic backend configuration.
schema Show JSON schema for a rompy model.
validate Validate model configuration.
rompy --version prints the version and the model types installed:
Configuration files¶
CONFIG is a YAML or JSON file describing a ModelRun:
run_id: cli_demo
output_dir: ./runs
period:
start: "2023-01-01T00:00"
end: "2023-01-02T00:00"
interval: 1h
config:
model_type: base # or xbeach, swan, schism, ... with that model's settings
Every file the command line reads (run, backend, postprocessor and pipeline files) is processed the same way:
- YAML is parsed with
!includesupport; if that fails, the file is read as JSON. ${VAR}expressions are replaced from the environment. An unset variable without a default is an error.- The result is validated.
See Writing and sharing YAML configurations for !include and ${VAR}.
Configuration from an environment variable¶
With --config-from-env, the run configuration is read from the ROMPY_CONFIG environment variable instead of a file, as JSON or YAML. !include paths are then relative to the current directory. This suits containers and CI jobs:
Give either a file or --config-from-env, not both.
Options for every command¶
| Option | Environment variable | Meaning |
|---|---|---|
-v, -vv |
Log at INFO, or DEBUG. Without -v only warnings and errors are shown. |
|
--log-dir DIR |
ROMPY_LOG_DIR |
Also write the log to DIR/rompy.log |
--simple-logs / --detailed-logs |
ROMPY_SIMPLE_LOGS |
Messages only, or with time, level and module (default) |
--ascii-only / --unicode |
ROMPY_ASCII_ONLY |
Draw boxes and symbols with ASCII characters |
--show-warnings / --hide-warnings |
Show Python deprecation warnings | |
--config-from-env |
ROMPY_CONFIG |
Read the run configuration from the environment |
See Logging and output formatting.
validate¶
Checks a run configuration without writing anything:
Loading config from: /tmp/tmppk3qcrih/run.yml
Parsed config as YAML
✅ Configuration is valid
Model type: base
Run ID: cli_demo
Period:
Start: 2023-01-01 00:00:00
End: 2023-01-02 00:00:00
Duration: 1 day
Interval: 1:00:00
Include End: True
Output directory: /tmp/tmppk3qcrih/runs
An invalid file fails with the validation error and a non-zero exit code.
generate¶
Writes the workspace, output_dir/run_id. --output-dir replaces the output_dir of the file:
rompy("generate", str(CONFIG), "--output-dir", str(OUT_DIR / "test_inputs"))
print(sorted(p.name for p in (OUT_DIR / "test_inputs" / "cli_demo").iterdir()))
run¶
Generates the workspace and runs the model with a backend configuration. The backend file has a type key, local, docker or slurm:
rompy run run.yml --backend-config docker.yml
rompy run run.yml --backend-config docker.yml --dry-run # generate only
rompy generate run.yml # or generate first,
rompy run run.yml --backend-config docker.yml --skip-generate # then run the existing workspace
| Option | Meaning |
|---|---|
--backend-config FILE |
Backend configuration (required) |
--dry-run |
Generate the workspace but do not run |
--skip-generate |
Run the existing workspace; it must exist and not be empty |
With a local backend and a shell command in place of a model, the whole run works here:
backend = OUT_DIR / "local.yml"
backend.write_text("type: local\ncommand: echo finished > run.log\n")
rompy("run", str(CONFIG), "--backend-config", str(backend))
print((OUT_DIR / "runs" / "cli_demo" / "run.log").read_text())
postprocess¶
Runs a postprocessor on the outputs of a run. The postprocessor file's type selects a postprocessor registered under the rompy.postprocess.config entry point; rompy ships noop.
| Option | Meaning |
|---|---|
--processor-config FILE |
Postprocessor configuration (required) |
--output-dir DIR |
Folder to postprocess instead of the workspace |
--validate-outputs / --no-validate |
Passed to the postprocessor (default: validate) |
pipeline¶
Generates, runs and postprocesses from one file with three sections, config, backend and postprocessor, each inline or included from another file:
# pipeline.yml
config: !include run.yml
backend: !include backends/local.yml
postprocessor:
type: noop
| Option | Meaning |
|---|---|
--backend-config FILE |
Use this backend instead of the backend section |
--processor-config FILE |
Use this postprocessor instead of the postprocessor section |
--cleanup-on-failure / --no-cleanup |
Delete the workspace if the run fails (default: keep) |
--validate-stages / --no-validate |
Check the workspace exists after generating (default: check) |
See Pipelines.
schema¶
Prints the JSON schema of a model class, by default ModelRun with every installed model configuration. Editors use it to complete and check YAML files; see Writing and sharing YAML configurations.
rompy schema -o modelrun.schema.json
rompy schema --format yaml -o modelrun.schema.yaml
rompy schema rompy_xbeach.config.Config -o xbeach.schema.json
MODEL_TYPE is a class name from rompy.model or a full import path such as rompy_xbeach.config.Config. A model type name such as xbeach is not recognised.
import json
rompy("schema", "-o", str(OUT_DIR / "modelrun.schema.json"))
schema = json.loads((OUT_DIR / "modelrun.schema.json").read_text())
print(list(schema["properties"]))
backends¶
Four subcommands help with backend configuration files:
| Command | Does |
|---|---|
rompy backends list |
Lists the installed run backends, postprocessors and pipeline backends (use -v) |
rompy backends create --backend-type local|docker [--with-examples] [--output FILE] [--format yaml|json] |
Prints or writes a starting file |
rompy backends validate FILE [--backend-type local|docker] |
Validates a local or Docker backend file; the type comes from --backend-type or the file's type |
rompy backends validate FILE --processor-type noop |
Validates a postprocessor file |
rompy backends schema --backend-type local|docker [--format json|yaml] |
Prints the JSON schema of a backend configuration |
create, validate and schema cover the local and Docker backends; rompy run also accepts type: slurm.
Available Backends:
🏃 Run Backends:
- docker: DockerRunBackend
Execute models inside Docker containers.
- local: LocalRunBackend
Execute models locally using the system's Python interpreter.
- slurm: SlurmRunBackend
Execute models on SLURM clusters.
🔄 Postprocessors:
- noop: NoopPostprocessor
A postprocessor that does nothing.
🔗 Pipeline Backends:
- local: LocalPipelineBackend
Local pipeline backend that executes the full workflow locally.
⚙️ Backend Configurations:
- LocalConfig → LocalRunBackend
- DockerConfig → DockerRunBackend
rompy("backends", "create", "--backend-type", "local", "--output", str(OUT_DIR / "new.yml"))
print((OUT_DIR / "new.yml").read_text())
rompy("backends", "validate", str(OUT_DIR / "new.yml"), "-v", "--simple-logs")
capture_output: true
command: null
env_vars: {}
shell: true
timeout: 3600
type: local
Loading config from: /tmp/tmppk3qcrih/new.yml
Parsed config as YAML
✅ Local backend configuration is valid
Backend type: local
Timeout: 3600s
See also¶
- The run lifecycle and Backends, postprocessors and pipelines.
- Notebooks: YAML and the command line for XBeach and SWAN.