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

Log when duration of forward model step is negative #10264

Merged
merged 1 commit into from
Mar 17, 2025
Merged
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
12 changes: 12 additions & 0 deletions src/ert/gui/model/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
state.COLOR_NOT_ACTIVE: QColor(*state.COLOR_NOT_ACTIVE),
}

_warn_once = True


def _estimate_duration(
start_time: datetime, end_time: datetime | None = None
Expand Down Expand Up @@ -429,6 +431,16 @@ def _fm_step_data(
)
# There is no method for truncating microseconds, so we remove them
delta -= timedelta(microseconds=delta.microseconds)
if delta < timedelta():
global _warn_once # noqa: PLW0603
if _warn_once:
_warn_once = False
logger.warning(
"Negative duration in snapshot encountered. "
f"start_time={start_time} end_time={node.data.get(ids.END_TIME)} "
f"delta={delta}"
)
Comment on lines +438 to +442
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xjules showed me a trick in 2023, and now I am showing it to you =)

Suggested change
logger.warning(
"Negative duration in snapshot encountered. "
f"start_time={start_time} end_time={node.data.get(ids.END_TIME)} "
f"delta={delta}"
)
end_time = node.data.get(ids.END_TIME)
logger.warning(
"Negative duration in snapshot encountered. "
f"{start_time=} {end_time=} {delta=}"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this instance it is not that useful. f"{object=} gives object.__repr__ while I want object.__str__
__str__ '2025-01-01 00:00:00'
__repr__ 'datetime.datetime(2025, 1, 1, 0, 0)'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why this shouldn't work @JHolba ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works, but you get different text. I want this representation: '2025-01-01 00:00:00'.

you can try this in a repl

from datetime import datetime
start = datetime.now()
print("print using {start=}: " f"{start=}")
print("print using start={start}: " f"start={start}")

delta = timedelta()
return str(delta)

return node.data.get(data_name)
Expand Down