Skip to content

Commit

Permalink
Convert dict access of ForwardModel to get to avoid segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
JHolba committed Jun 21, 2024
1 parent 56899c1 commit 67b0e46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ert/ensemble_evaluator/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _stopped_handler(self, events: List[CloudEvent]) -> None:
with self._snapshot_mutex:
max_memory_usage = -1
for job in self.ensemble.snapshot.get_all_forward_models().values():
memory_usage = job[ids.MAX_MEMORY_USAGE] or "-1"
memory_usage = job.get(ids.MAX_MEMORY_USAGE) or "-1"
max_memory_usage = max(int(memory_usage), max_memory_usage)
logger.info(
f"Ensemble ran with maximum memory usage for a single realization job: {max_memory_usage}"
Expand Down
18 changes: 10 additions & 8 deletions src/ert/gui/model/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,20 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int):
data_name = COLUMNS[NodeType.REAL][index.column()]
if data_name in [ids.CURRENT_MEMORY_USAGE, ids.MAX_MEMORY_USAGE]:
data = node.data
_bytes: Optional[str] = data[data_name]
_bytes: Optional[str] = data.get(data_name)
if _bytes:
return byte_with_unit(float(_bytes))

if data_name in [ids.STDOUT, ids.STDERR]:
return "OPEN" if data_name in node.data else QVariant()

if data_name in [DURATION]:
start_time = node.data[ids.START_TIME]
start_time = node.data.get(ids.START_TIME)
if start_time is None:
return QVariant()
delta = _estimate_duration(start_time, end_time=node.data[ids.END_TIME])
delta = _estimate_duration(
start_time, end_time=node.data.get(ids.END_TIME)
)
# There is no method for truncating microseconds, so we remove them
delta -= datetime.timedelta(microseconds=delta.microseconds)
return str(delta)
Expand All @@ -490,7 +492,7 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int):
COLOR_RUNNING
in real.data.forward_model_step_status_color_by_id.values()
):
return node.data[data_name]
return node.data.get(data_name)

# if queue system status is WAIT, jobs should indicate WAIT
if (
Expand All @@ -500,7 +502,7 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int):
== COLOR_PENDING
):
return str("Waiting")
return node.data[data_name]
return node.data.get(data_name)

if role == FileRole:
data_name = COLUMNS[NodeType.REAL][index.column()]
Expand All @@ -517,12 +519,12 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int):
data_name = COLUMNS[NodeType.REAL][index.column()]
data = None
if data_name == ids.ERROR:
data = node.data[ids.ERROR]
data = node.data.get(ids.ERROR)
elif data_name == DURATION:
start_time = node.data[ids.START_TIME]
start_time = node.data.get(ids.START_TIME)
if start_time is not None:
delta = _estimate_duration(
start_time, end_time=node.data[ids.END_TIME]
start_time, end_time=node.data.get(ids.END_TIME)
)
data = f"Start time: {str(start_time)}\nDuration: {str(delta)}"
if data is not None:
Expand Down

0 comments on commit 67b0e46

Please sign in to comment.