Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give users easier access to container logs #470

Merged
merged 8 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Formatted as described on [https://keepachangelog.com](https://keepachangelog.co

## Added

- `model.logs` property to inspect the logs of a containerized model ([#470](https://github.com/eWaterCycle/ewatercycle/pull/470)).
- mention remotebmi in docs ([#471](https://github.com/eWaterCycle/ewatercycle/issues/471))

## [2.4.0] (2024-12-04)
Expand Down
13 changes: 13 additions & 0 deletions docs/user_guide/03_models_obs_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@
"model_instance.initialize(cfg_file) # for some models, this step can take some time"
]
},
{
"cell_type": "markdown",
"id": "d94ad9b6",
"metadata": {},
"source": [
"Note that if anything goes wrong on the model side during initialization or at any other point in time you can inspect the model's logs. For example, if some input file is missing or corrupt.\n",
"In this case you would do:\n",
"\n",
"```py\n",
"print(model_instance.logs)\n",
"```"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down
21 changes: 21 additions & 0 deletions src/ewatercycle/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,27 @@
"""Version of the container image."""
return self.bmi_image.version

@property
def logs(self) -> str:
"""Return the container logs."""
if not hasattr(self, "_bmi"):
msg = (

Check warning on line 459 in src/ewatercycle/base/model.py

View check run for this annotation

Codecov / codecov/patch

src/ewatercycle/base/model.py#L459

Added line #L459 was not covered by tests
"The model has no BMI attached (yet).\n"
"Logs will only be available after running `.setup`"
)
raise ValueError(msg)
bmi = self._bmi

Check warning on line 464 in src/ewatercycle/base/model.py

View check run for this annotation

Codecov / codecov/patch

src/ewatercycle/base/model.py#L463-L464

Added lines #L463 - L464 were not covered by tests
while hasattr(bmi, "origin"):
bmi = bmi.origin # type: ignore[assignment,unused-ignore]

Check warning on line 466 in src/ewatercycle/base/model.py

View check run for this annotation

Codecov / codecov/patch

src/ewatercycle/base/model.py#L466

Added line #L466 was not covered by tests

if hasattr(bmi, "logs"):
return bmi.logs()
msg = (

Check warning on line 470 in src/ewatercycle/base/model.py

View check run for this annotation

Codecov / codecov/patch

src/ewatercycle/base/model.py#L469-L470

Added lines #L469 - L470 were not covered by tests
"No logs detected, only containerized models are expected to have logs.\n"
f"BMI is of unexpected type {type(bmi)}."
)
raise ValueError(msg)

Check warning on line 474 in src/ewatercycle/base/model.py

View check run for this annotation

Codecov / codecov/patch

src/ewatercycle/base/model.py#L474

Added line #L474 was not covered by tests

def _make_bmi_instance(self) -> OptionalDestBmi:
if self.parameter_set:
self._additional_input_dirs.append(str(self.parameter_set.directory))
Expand Down
Loading