Skip to content

Commit

Permalink
Add event timestamps and runtime info
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreso committed Sep 15, 2024
1 parent ca68222 commit f80df4b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/ert/analysis/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import re
from collections.abc import Sequence
from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Optional, Union, Literal

Expand All @@ -18,19 +19,22 @@ class AnalysisEvent:
class AnalysisStatusEvent(AnalysisEvent):
msg: str
event_type: Literal['AnalysisStatusEvent'] = 'AnalysisStatusEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
class AnalysisTimeEvent(AnalysisEvent):
remaining_time: float
elapsed_time: float
event_type: Literal['AnalysisTimeEvent'] = 'AnalysisTimeEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
class AnalysisReportEvent(AnalysisEvent):
report: str
event_type: Literal['AnalysisReportEvent'] = 'AnalysisReportEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
Expand Down
5 changes: 4 additions & 1 deletion src/ert/ensemble_evaluator/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime
from typing import Dict, Literal, Optional

from .snapshot import Snapshot
Expand All @@ -13,6 +14,7 @@ class _UpdateEvent:
realization_count: int
status_count: Dict[str, int]
iteration: int
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
Expand All @@ -32,3 +34,4 @@ class EndEvent:
failed: bool
msg: Optional[str] = None
event_type: Literal['EndEvent'] = 'EndEvent'
timestamp: datetime = field(default_factory=datetime.now)
15 changes: 12 additions & 3 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
from datetime import datetime
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -221,6 +222,8 @@ def __init__(
self._job_label = QLabel(self)
self._job_overview = JobOverview(self._snapshot_model, self)

self._start_time: datetime = None
self._end_time: datetime = None
self.running_time = QLabel("")
self.memory_usage = QLabel("")

Expand Down Expand Up @@ -397,9 +400,12 @@ def _on_simulation_done(self, failed: bool, msg: str) -> None:

@Slot()
def _on_ticker(self) -> None:
runtime = 0
# runtime = self._run_model.get_runtime()
# TODO: This should be based event timestamps
if self._start_time is None:
runtime = 0
elif self._end_time is None:
runtime = (datetime.now() - self._start_time).total_seconds()
else:
runtime = (self._end_time - self._start_time).total_seconds()
self.running_time.setText(format_running_time(runtime))

maximum_memory_usage = self._snapshot_model.root.max_memory_usage
Expand All @@ -411,7 +417,10 @@ def _on_ticker(self) -> None:

@Slot(object)
def _on_event(self, event: object) -> None:
if self._start_time is None:
self._start_time = event.timestamp
if isinstance(event, EndEvent):
self._end_time = event.timestamp
self.simulation_done.emit(event.failed, event.msg)
self._ticker.stop()
self.done_button.setHidden(False)
Expand Down
9 changes: 8 additions & 1 deletion src/ert/run_models/event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime
from typing import Optional, Literal
from uuid import UUID

Expand All @@ -17,35 +18,41 @@ class RunModelEvent:
class RunModelStatusEvent(RunModelEvent):
msg: str
event_type: Literal['RunModelStatusEvent'] = 'RunModelStatusEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
class RunModelTimeEvent(RunModelEvent):
remaining_time: float
elapsed_time: float
event_type: Literal['RunModelTimeEvent'] = 'RunModelTimeEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
class RunModelUpdateBeginEvent(RunModelEvent):
event_type: Literal['RunModelUpdateBeginEvent'] = 'RunModelUpdateBeginEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
class RunModelDataEvent(RunModelEvent):
name: str
data: DataSection
event_type: Literal['RunModelDataEvent'] = 'RunModelDataEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
class RunModelUpdateEndEvent(RunModelEvent):
data: DataSection
event_type: Literal['RunModelUpdateEndEvent'] = 'RunModelUpdateEndEvent'
timestamp: datetime = field(default_factory=datetime.now)


@dataclass
class RunModelErrorEvent(RunModelEvent):
error_msg: str
data: Optional[DataSection] = None
event_type: Literal['RunModelErrorEvent'] = 'RunModelErrorEvent'
timestamp: datetime = field(default_factory=datetime.now)

0 comments on commit f80df4b

Please sign in to comment.